Browse Source

[MRM-1681] addProxy Connectors Rules screen

add REST services.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1392952 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-1.4-M3
Olivier Lamy 11 years ago
parent
commit
3ebdc4a971

+ 76
- 0
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java View File

@@ -0,0 +1,76 @@
package org.apache.archiva.rest.api.services;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.security.common.ArchivaRoleConstants;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
* <b>No update method for changing pattern as id is pattern, use delete then add.</b>
*
* @author Olivier Lamy
* @since 1.4-M3
*/
@Path ( "/proxyConnectorRuleService/" )
public interface ProxyConnectorRuleService
{
@Path ( "proxyConnectorRules" )
@GET
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
List<ProxyConnectorRule> getProxyConnectorRules()
throws ArchivaRestServiceException;

@Path ( "proxyConnectorRule" )
@PUT
@Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
Boolean addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
throws ArchivaRestServiceException;

@Path ( "deleteProxyConnectorRule" )
@POST
@Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
Boolean deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
throws ArchivaRestServiceException;

/**
* <b>only to update attached proxy connectors to update pattern use delete then add</b>
*/
@Path ( "updateProxyConnectorRule" )
@POST
@Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
Boolean updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
throws ArchivaRestServiceException;
}

+ 97
- 0
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java View File

@@ -0,0 +1,97 @@
package org.apache.archiva.rest.services;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

/**
* @author Olivier Lamy
*/
@Service ( "proxyConnectorRuleService#rest" )
public class DefaultProxyConnectorRuleService
extends AbstractRestService
implements ProxyConnectorRuleService
{

@Inject
private ProxyConnectorRuleAdmin proxyConnectorRuleAdmin;

public List<ProxyConnectorRule> getProxyConnectorRules()
throws ArchivaRestServiceException
{
try
{
return proxyConnectorRuleAdmin.getProxyConnectorRules();
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage(), e );
}
}

public Boolean addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
throws ArchivaRestServiceException
{
try
{
proxyConnectorRuleAdmin.addProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
return Boolean.TRUE;
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage(), e );
}
}

public Boolean deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
throws ArchivaRestServiceException
{
try
{
proxyConnectorRuleAdmin.deleteProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
return Boolean.TRUE;
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage(), e );
}
}

public Boolean updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
throws ArchivaRestServiceException
{
try
{
proxyConnectorRuleAdmin.updateProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
return Boolean.TRUE;
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage(), e );
}
}
}

+ 1
- 0
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml View File

@@ -71,6 +71,7 @@
<ref bean="systemStatusService#rest"/>
<ref bean="reportRepositoriesService#rest" />
<ref bean="mergeRepositoriesService#rest"/>
<ref bean="proxyConnectorRuleService#rest"/>
</jaxrs:serviceBeans>

<jaxrs:outInterceptors>

+ 19
- 39
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java View File

@@ -29,6 +29,7 @@ import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.archiva.rest.api.services.MergeRepositoriesService;
import org.apache.archiva.rest.api.services.NetworkProxyService;
import org.apache.archiva.rest.api.services.PingService;
import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
import org.apache.archiva.rest.api.services.ProxyConnectorService;
import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
import org.apache.archiva.rest.api.services.RepositoriesService;
@@ -55,7 +56,7 @@ import java.util.Date;
/**
* @author Olivier Lamy
*/
@RunWith (ArchivaBlockJUnit4ClassRunner.class)
@RunWith ( ArchivaBlockJUnit4ClassRunner.class )
public abstract class AbstractArchivaRestTest
extends AbstractRestServicesTest
{
@@ -123,12 +124,10 @@ public abstract class AbstractArchivaRestTest
return getRepositoriesService( null );
}

protected MergeRepositoriesService getMergeRepositoriesService( String authzHeader )
protected <T> T getService( Class<T> clazz, String authzHeader )
{
MergeRepositoriesService service =
JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
MergeRepositoriesService.class,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
T service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", clazz,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );

if ( authzHeader != null )
{
@@ -140,54 +139,35 @@ public abstract class AbstractArchivaRestTest
return service;
}

protected RepositoriesService getRepositoriesService( String authzHeader )
protected ProxyConnectorRuleService getProxyConnectorRuleService( String authzHeader )
{
RepositoriesService service =
JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
RepositoriesService.class,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );

if ( authzHeader != null )
{
WebClient.client( service ).header( "Authorization", authzHeader );
}
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
return service;
return getService( ProxyConnectorRuleService.class, authzHeader );
}

protected MergeRepositoriesService getMergeRepositoriesService( String authzHeader )
{
return getService( MergeRepositoriesService.class, authzHeader );
}

protected ManagedRepositoriesService getManagedRepositoriesService( String authzHeader )
protected RepositoriesService getRepositoriesService( String authzHeader )
{
ManagedRepositoriesService service =
JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
ManagedRepositoriesService.class,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
return getService( RepositoriesService.class, authzHeader );

if ( authzHeader != null )
{
WebClient.client( service ).header( "Authorization", authzHeader );
}
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
return service;
}

protected ManagedRepositoriesService getManagedRepositoriesService( String authzHeader )
{
return getService( ManagedRepositoriesService.class, authzHeader );
}

protected PingService getPingService()
{
return JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
PingService.class,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
return getService( PingService.class, null );
}

protected RemoteRepositoriesService getRemoteRepositoriesService()
{
return JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
RemoteRepositoriesService.class,
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
return getService( RemoteRepositoriesService.class, null );


}

+ 76
- 0
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorRuleServiceTest.java View File

@@ -0,0 +1,76 @@
package org.apache.archiva.rest.services;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.archiva.admin.model.beans.ProxyConnector;
import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
import org.apache.archiva.admin.model.beans.ProxyConnectorRuleType;
import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
import org.junit.Test;

import java.util.Arrays;

/**
* @author Olivier Lamy
*/
public class ProxyConnectorRuleServiceTest
extends AbstractArchivaRestTest
{

@Test
public void addProxyConnectorRule()
throws Exception
{
ProxyConnector proxyConnector = new ProxyConnector();
proxyConnector.setSourceRepoId( "snapshots" );
proxyConnector.setTargetRepoId( "central" );

ProxyConnectorRuleService service = getProxyConnectorRuleService( authorizationHeader );

ProxyConnectorRule rule = null;
try
{

int size = service.getProxyConnectorRules().size();
assertEquals( 0, size );

getProxyConnectorService().addProxyConnector( proxyConnector );

rule = new ProxyConnectorRule( "org/apache/maven", ProxyConnectorRuleType.BLACK_LIST,
Arrays.asList( proxyConnector ) );

service.addProxyConnectorRule( rule );
assertEquals( size + 1, service.getProxyConnectorRules().size() );

rule = service.getProxyConnectorRules().get( 0 );

assertEquals( "org/apache/maven", rule.getPattern() );
assertEquals( 1, rule.getProxyConnectors().size() );
assertEquals( "snapshots", rule.getProxyConnectors().get( 0 ).getSourceRepoId() );
assertEquals( "central", rule.getProxyConnectors().get( 0 ).getTargetRepoId() );
assertEquals( ProxyConnectorRuleType.BLACK_LIST, rule.getProxyConnectorRuleType() );
}
finally
{
service.deleteProxyConnectorRule( rule );
getProxyConnectorService().deleteProxyConnector( proxyConnector );
}
}
}


Loading…
Cancel
Save