Author: olamy
Date: Thu Sep 1 07:33:21 2011
New Revision: 1163923
URL: http://svn.apache.org/viewvc?rev=1163923&view=rev
Log:
[MRM-1490] expose rest services: split in more smaller classes rather than a
big one with all services
Added:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
- copied, changed from r1163922,
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
Modified:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
Copied:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
(from r1163922,
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java)
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java?p2=archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java&p1=archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java&r1=1163922&r2=1163923&rev=1163923&view=diff
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
(original)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
Thu Sep 1 07:33:21 2011
@@ -39,8 +39,8 @@ import java.util.List;
* @author Olivier Lamy
* @since 1.4
*/
-@Path( "/repositoriesService/" )
-public interface RepositoriesService
+@Path( "/managedRepositoriesService/" )
+public interface ManagedRepositoriesService
{
@Path( "getManagedRepositories" )
@GET
@@ -82,30 +82,6 @@ public interface RepositoriesService
Boolean updateManagedRepository( ManagedRepository managedRepository )
throws Exception;
- @Path( "getRemoteRepositories" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- List<RemoteRepository> getRemoteRepositories();
-
- @Path( "scanRepository" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_RUN_INDEXER )
- Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId,
- @QueryParam( "fullScan" ) boolean fullScan );
- @Path( "alreadyScanning/{repositoryId}" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_RUN_INDEXER )
- Boolean alreadyScanning( @PathParam( "repositoryId" ) String repositoryId
);
-
- @Path( "removeScanningTaskFromQueue/{repositoryId}" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_RUN_INDEXER )
- Boolean removeScanningTaskFromQueue( @PathParam( "repositoryId" ) String
repositoryId );
-
}
Modified:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java?rev=1163923&r1=1163922&r2=1163923&view=diff
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
(original)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
Thu Sep 1 07:33:21 2011
@@ -42,45 +42,7 @@ import java.util.List;
@Path( "/repositoriesService/" )
public interface RepositoriesService
{
- @Path( "getManagedRepositories" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- List<ManagedRepository> getManagedRepositories()
- throws RepositoryAdminException;
-
- @Path( "getManagedRepository/{repositoryId}" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- ManagedRepository getManagedRepository( @PathParam( "repositoryId" )
String repositoryId )
- throws RepositoryAdminException;
-
- @Path( "deleteManagedRepository" )
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- Boolean deleteManagedRepository( @QueryParam( "repositoryId" ) String
repositoryId,
- @QueryParam( "deleteContent" ) boolean
deleteContent )
- throws Exception;
-
- @Path( "addManagedRepository" )
- @POST
- @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- Boolean addManagedRepository( ManagedRepository managedRepository )
- throws Exception;
-
-
- @Path( "updateManagedRepository" )
- @POST
- @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
MediaType.TEXT_PLAIN } )
- @RedbackAuthorization( permission =
ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
- Boolean updateManagedRepository( ManagedRepository managedRepository )
- throws Exception;
@Path( "getRemoteRepositories" )
@GET
Added:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java?rev=1163923&view=auto
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
(added)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
Thu Sep 1 07:33:21 2011
@@ -0,0 +1,60 @@
+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.AuditInformation;
+import org.apache.archiva.audit.AuditListener;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
+import org.codehaus.redback.rest.services.RedbackRequestInformation;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * abstract class with common utilities methods
+ *
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public abstract class AbstractRestService
+{
+
+ @Inject
+ private List<AuditListener> auditListeners = new
ArrayList<AuditListener>();
+
+ protected AuditInformation getAuditInformation()
+ {
+ RedbackRequestInformation redbackRequestInformation =
RedbackAuthenticationThreadLocal.get();
+ User user = redbackRequestInformation == null ? null :
redbackRequestInformation.getUser();
+ String remoteAddr = redbackRequestInformation == null ? null :
redbackRequestInformation.getRemoteAddr();
+ return new AuditInformation( user, remoteAddr );
+ }
+
+ public List<AuditListener> getAuditListeners()
+ {
+ return auditListeners;
+ }
+
+ public void setAuditListeners( List<AuditListener> auditListeners )
+ {
+ this.auditListeners = auditListeners;
+ }
+}
Added:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java?rev=1163923&view=auto
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
(added)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
Thu Sep 1 07:33:21 2011
@@ -0,0 +1,124 @@
+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.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
+import org.apache.archiva.rest.api.model.ManagedRepository;
+import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+@Service( "managedRepositoriesService#rest" )
+public class DefaultManagedRepositoriesService
+ extends AbstractRestService
+ implements ManagedRepositoriesService
+{
+
+ @Inject
+ private ManagedRepositoryAdmin managedRepositoryAdmin;
+
+ public List<ManagedRepository> getManagedRepositories()
+ throws RepositoryAdminException
+ {
+ List<org.apache.archiva.admin.repository.managed.ManagedRepository>
repos =
+ managedRepositoryAdmin.getManagedRepositories();
+
+ List<ManagedRepository> managedRepos = new
ArrayList<ManagedRepository>( repos.size() );
+
+ for ( org.apache.archiva.admin.repository.managed.ManagedRepository
repoConfig : repos )
+ {
+ // TODO staging repo too
+ ManagedRepository repo =
+ new ManagedRepository( repoConfig.getId(),
repoConfig.getName(), repoConfig.getLocation(),
+ repoConfig.getLayout(),
repoConfig.isSnapshots(), repoConfig.isReleases(),
+ repoConfig.isBlockRedeployments(),
false, repoConfig.getCronExpression() );
+ managedRepos.add( repo );
+ }
+
+ return managedRepos;
+ }
+
+ public ManagedRepository getManagedRepository( String repositoryId )
+ throws RepositoryAdminException
+ {
+ List<ManagedRepository> repos = getManagedRepositories();
+ for ( ManagedRepository repo : repos )
+ {
+ if ( StringUtils.equals( repo.getId(), repositoryId ) )
+ {
+ return repo;
+ }
+ }
+ return null;
+ }
+
+
+ public Boolean deleteManagedRepository( String repoId, boolean
deleteContent )
+ throws Exception
+ {
+
+ return managedRepositoryAdmin.deleteManagedRepository( repoId,
getAuditInformation(), deleteContent );
+ }
+
+ public Boolean addManagedRepository( ManagedRepository managedRepository )
+ throws Exception
+ {
+ org.apache.archiva.admin.repository.managed.ManagedRepository repo =
+ new
org.apache.archiva.admin.repository.managed.ManagedRepository();
+ repo.setLocation( managedRepository.getLocation() );
+ repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
+ repo.setCronExpression( managedRepository.getCronExpression() );
+ repo.setId( managedRepository.getId() );
+ repo.setLayout( managedRepository.getLayout() );
+ repo.setName( managedRepository.getName() );
+ repo.setReleases( managedRepository.isReleases() );
+ repo.setSnapshots( managedRepository.isSnapshots() );
+ return managedRepositoryAdmin.addManagedRepository( repo,
managedRepository.isStageRepoNeeded(),
+
getAuditInformation() );
+ }
+
+
+ public Boolean updateManagedRepository( ManagedRepository
managedRepository )
+ throws Exception
+ {
+ org.apache.archiva.admin.repository.managed.ManagedRepository repo =
+ new
org.apache.archiva.admin.repository.managed.ManagedRepository();
+ repo.setLocation( managedRepository.getLocation() );
+ repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
+ repo.setCronExpression( managedRepository.getCronExpression() );
+ repo.setId( managedRepository.getId() );
+ repo.setLayout( managedRepository.getLayout() );
+ repo.setName( managedRepository.getName() );
+ repo.setReleases( managedRepository.isReleases() );
+ repo.setSnapshots( managedRepository.isSnapshots() );
+ return managedRepositoryAdmin.updateManagedRepository( repo,
managedRepository.isStageRepoNeeded(),
+
getAuditInformation(),
+
managedRepository.isResetStats() );
+ }
+
+}
Modified:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java?rev=1163923&r1=1163922&r2=1163923&view=diff
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
(original)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
Thu Sep 1 07:33:21 2011
@@ -19,33 +19,19 @@ package org.apache.archiva.rest.services
* under the License.
*/
-import org.apache.archiva.admin.AuditInformation;
-import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
-import org.apache.archiva.audit.AuditEvent;
-import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import
org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
-import org.apache.archiva.rest.api.model.ManagedRepository;
import org.apache.archiva.rest.api.model.RemoteRepository;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.RepositoryTask;
-import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
-import
org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
-import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.redback.role.RoleManager;
-import org.codehaus.plexus.redback.role.RoleManagerException;
-import org.codehaus.plexus.redback.users.User;
import org.codehaus.plexus.registry.Registry;
-import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.taskqueue.TaskQueueException;
-import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
-import org.codehaus.redback.rest.services.RedbackRequestInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -53,8 +39,6 @@ import org.springframework.stereotype.Se
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.PathParam;
-import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -64,6 +48,7 @@ import java.util.List;
*/
@Service( "repositoriesService#rest" )
public class DefaultRepositoriesService
+ extends AbstractRestService
implements RepositoriesService
{
private Logger log = LoggerFactory.getLogger( getClass() );
@@ -76,10 +61,6 @@ public class DefaultRepositoriesService
private static final String REPOSITORY_LOCATION_VALID_EXPRESSION =
"^[-a-zA-Z0-9._/~:?!&=\\\\]+$";
- // TODO move this field to an abstract class
- @Inject
- private List<AuditListener> auditListeners = new
ArrayList<AuditListener>();
-
@Inject
protected RoleManager roleManager;
@@ -103,47 +84,6 @@ public class DefaultRepositoriesService
@Inject
private ManagedRepositoryAdmin managedRepositoryAdmin;
- public List<ManagedRepository> getManagedRepositories()
- throws RepositoryAdminException
- {
- List<org.apache.archiva.admin.repository.managed.ManagedRepository>
repos =
- managedRepositoryAdmin.getManagedRepositories();
-
- List<ManagedRepository> managedRepos = new
ArrayList<ManagedRepository>( repos.size() );
-
- for ( org.apache.archiva.admin.repository.managed.ManagedRepository
repoConfig : repos )
- {
- // TODO staging repo too
- ManagedRepository repo =
- new ManagedRepository( repoConfig.getId(),
repoConfig.getName(), repoConfig.getLocation(),
- repoConfig.getLayout(),
repoConfig.isSnapshots(), repoConfig.isReleases(),
- repoConfig.isBlockRedeployments(),
false, repoConfig.getCronExpression() );
- managedRepos.add( repo );
- }
-
- return managedRepos;
- }
-
- public ManagedRepository getManagedRepository( String repositoryId )
- throws RepositoryAdminException
- {
- List<ManagedRepository> repos = getManagedRepositories();
- for ( ManagedRepository repo : repos )
- {
- if ( StringUtils.equals( repo.getId(), repositoryId ) )
- {
- return repo;
- }
- }
- return null;
- }
-
- public Boolean deleteManagedRepository( String repoId, boolean
deleteContent )
- throws Exception
- {
-
- return managedRepositoryAdmin.deleteManagedRepository( repoId,
getAuditInformation(), deleteContent );
- }
public List<RemoteRepository> getRemoteRepositories()
{
@@ -162,42 +102,7 @@ public class DefaultRepositoriesService
return remoteRepos;
}
- public Boolean addManagedRepository( ManagedRepository managedRepository )
- throws Exception
- {
- org.apache.archiva.admin.repository.managed.ManagedRepository repo =
- new
org.apache.archiva.admin.repository.managed.ManagedRepository();
- repo.setLocation( managedRepository.getLocation() );
- repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
- repo.setCronExpression( managedRepository.getCronExpression() );
- repo.setId( managedRepository.getId() );
- repo.setLayout( managedRepository.getLayout() );
- repo.setName( managedRepository.getName() );
- repo.setReleases( managedRepository.isReleases() );
- repo.setSnapshots( managedRepository.isSnapshots() );
- return managedRepositoryAdmin.addManagedRepository( repo,
managedRepository.isStageRepoNeeded(),
-
getAuditInformation() );
- }
-
-
- public Boolean updateManagedRepository( ManagedRepository
managedRepository )
- throws Exception
- {
- org.apache.archiva.admin.repository.managed.ManagedRepository repo =
- new
org.apache.archiva.admin.repository.managed.ManagedRepository();
- repo.setLocation( managedRepository.getLocation() );
- repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
- repo.setCronExpression( managedRepository.getCronExpression() );
- repo.setId( managedRepository.getId() );
- repo.setLayout( managedRepository.getLayout() );
- repo.setName( managedRepository.getName() );
- repo.setReleases( managedRepository.isReleases() );
- repo.setSnapshots( managedRepository.isSnapshots() );
- return managedRepositoryAdmin.updateManagedRepository( repo,
managedRepository.isStageRepoNeeded(),
-
getAuditInformation(), managedRepository.isResetStats() );
- }
-
-
+ // FIXME olamy move this to repository admin component !
public Boolean scanRepository( String repositoryId, boolean fullScan )
{
if ( repositoryTaskScheduler.isProcessingRepositoryTask( repositoryId
) )
@@ -238,132 +143,6 @@ public class DefaultRepositoriesService
return false;
}
}
-
- //-----------------------------------------------
- // util methods
- // FIXME most are copied from xmlrpc
- // olamt move those in common utility classes
- //-----------------------------------------------
-
- protected void triggerAuditEvent( String repositoryId, String resource,
String action )
- {
- User user = RedbackAuthenticationThreadLocal.get().getUser();
- if ( user == null )
- {
- log.warn( "no user found in Redback ThreadLocal" );
- AuditEvent event =
- new AuditEvent( repositoryId, user == null ? "null" :
user.getUsername(), resource, action );
- // FIXME use a thread local through cxf interceptors to store this
- //event.setRemoteIP( getRemoteAddr() );
-
- for ( AuditListener listener : auditListeners )
- {
- listener.auditEvent( event );
- }
- }
- }
-
- protected void addRepositoryRoles( ManagedRepositoryConfiguration
newRepository )
- throws RoleManagerException
- {
- String repoId = newRepository.getId();
-
- // TODO: double check these are configured on start up
- // TODO: belongs in the business logic
-
- if ( !roleManager.templatedRoleExists(
ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
- {
- roleManager.createTemplatedRole(
ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
- }
-
- if ( !roleManager.templatedRoleExists(
ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
- {
- roleManager.createTemplatedRole(
ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
- }
- }
-
- public Boolean executeRepositoryScanner( String repoId )
- throws Exception
- {
- return scanRepository( repoId, true );
- }
-
- private void saveConfiguration( Configuration config )
- throws Exception
- {
- try
- {
- archivaConfiguration.save( config );
- }
- catch ( RegistryException e )
- {
- throw new Exception( "Error occurred in the registry." );
- }
- catch ( IndeterminateConfigurationException e )
- {
- throw new Exception( "Error occurred while saving the
configuration." );
- }
- }
-
- protected void addRepository( ManagedRepositoryConfiguration repository,
Configuration configuration )
- throws IOException
- {
- // Normalize the path
- File file = new File( repository.getLocation() );
- repository.setLocation( file.getCanonicalPath() );
- if ( !file.exists() )
- {
- file.mkdirs();
- }
- if ( !file.exists() || !file.isDirectory() )
- {
- throw new IOException(
- "Unable to add repository - no write access, can not create
the root directory: " + file );
- }
-
- configuration.addManagedRepository( repository );
- }
-
- private ManagedRepositoryConfiguration getStageRepoConfig(
ManagedRepositoryConfiguration repository )
- {
- ManagedRepositoryConfiguration stagingRepository = new
ManagedRepositoryConfiguration();
- stagingRepository.setId( repository.getId() + "-stage" );
- stagingRepository.setLayout( repository.getLayout() );
- stagingRepository.setName( repository.getName() + "-stage" );
- stagingRepository.setBlockRedeployments(
repository.isBlockRedeployments() );
- stagingRepository.setDaysOlder( repository.getDaysOlder() );
- stagingRepository.setDeleteReleasedSnapshots(
repository.isDeleteReleasedSnapshots() );
- stagingRepository.setIndexDir( repository.getIndexDir() );
- String path = repository.getLocation();
- int lastIndex = path.lastIndexOf( '/' );
- stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" +
stagingRepository.getId() );
- stagingRepository.setRefreshCronExpression(
repository.getRefreshCronExpression() );
- stagingRepository.setReleases( repository.isReleases() );
- stagingRepository.setRetentionCount( repository.getRetentionCount() );
- stagingRepository.setScanned( repository.isScanned() );
- stagingRepository.setSnapshots( repository.isSnapshots() );
- return stagingRepository;
- }
-
-
- private String removeExpressions( String directory )
- {
- String value = StringUtils.replace( directory, "${appserver.base}",
- registry.getString(
"appserver.base", "${appserver.base}" ) );
- value = StringUtils.replace( value, "${appserver.home}",
- registry.getString( "appserver.home",
"${appserver.home}" ) );
- return value;
- }
-
-
- private AuditInformation getAuditInformation()
- {
- RedbackRequestInformation redbackRequestInformation =
RedbackAuthenticationThreadLocal.get();
- User user = redbackRequestInformation == null ? null :
redbackRequestInformation.getUser();
- String remoteAddr = redbackRequestInformation == null ? null :
redbackRequestInformation.getRemoteAddr();
- return new AuditInformation( user, remoteAddr );
- }
-
}
Modified:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml?rev=1163923&r1=1163922&r2=1163923&view=diff
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
(original)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
Thu Sep 1 07:33:21 2011
@@ -50,6 +50,7 @@
<jaxrs:serviceBeans>
<ref bean="pingService#rest"/>
<ref bean="repositoriesService#rest"/>
+ <ref bean="managedRepositoriesService#rest"/>
</jaxrs:serviceBeans>
<jaxrs:outInterceptors>
Modified:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java?rev=1163923&r1=1163922&r2=1163923&view=diff
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
(original)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
Thu Sep 1 07:33:21 2011
@@ -19,6 +19,10 @@ package org.apache.archiva.rest.services
*/
+import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
+import org.apache.archiva.rest.api.services.PingService;
+import org.apache.archiva.rest.api.services.RepositoriesService;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.codehaus.redback.rest.services.AbstractRestServicesTest;
/**
@@ -35,4 +39,25 @@ public abstract class AbstractArchivaRes
{
return
"classpath*:META-INF/spring-context.xml,classpath:META-INF/spring-context-test.xml";
}
+
+ protected RepositoriesService getRepositoriesService()
+ {
+ return JAXRSClientFactory.create( "http://localhost:" + port +
"/services/archivaServices/",
+ RepositoriesService.class );
+
+ }
+
+ protected ManagedRepositoriesService getManagedRepositoriesService()
+ {
+ return JAXRSClientFactory.create( "http://localhost:" + port +
"/services/archivaServices/",
+ ManagedRepositoriesService.class );
+
+ }
+
+ protected PingService getPingService()
+ {
+ return JAXRSClientFactory.create( "http://localhost:" + port +
"/services/archivaServices/",
+ PingService.class );
+
+ }
}
Modified:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java?rev=1163923&r1=1163922&r2=1163923&view=diff
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java
(original)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java
Thu Sep 1 07:33:21 2011
@@ -20,10 +20,8 @@ package org.apache.archiva.rest.services
*/
import org.apache.archiva.rest.api.services.PingService;
-import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.apache.cxf.jaxrs.client.WebClient;
-import org.codehaus.redback.rest.services.AbstractRestServicesTest;
import org.junit.Ignore;
import org.junit.Test;
@@ -35,13 +33,6 @@ public class PingServiceTest
extends AbstractArchivaRestTest
{
- PingService getPingService()
- {
- return JAXRSClientFactory.create( "http://localhost:" + port +
"/services/archivaServices/",
- PingService.class );
-
- }
-
@Test
public void ping()
@@ -83,7 +74,7 @@ public class PingServiceTest
assertEquals( "Yeah Baby It rocks!", res );
}
- @Ignore("FIXME guest failed ???")
+ @Ignore( "FIXME guest failed ???" )
public void pingWithAuthzGuest()
throws Exception
{
Modified:
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
URL:
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java?rev=1163923&r1=1163922&r2=1163923&view=diff
==============================================================================
---
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
(original)
+++
archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
Thu Sep 1 07:33:21 2011
@@ -21,8 +21,8 @@ package org.apache.archiva.rest.services
import org.apache.archiva.rest.api.model.ManagedRepository;
import org.apache.archiva.rest.api.model.RemoteRepository;
+import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.archiva.rest.api.services.RepositoriesService;
-import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.maven.archiva.common.utils.FileUtil;
@@ -38,12 +38,6 @@ public class RepositoriesServiceTest
extends AbstractArchivaRestTest
{
- RepositoriesService getRepositoriesService()
- {
- return JAXRSClientFactory.create( "http://localhost:" + port +
"/services/archivaServices/",
- RepositoriesService.class );
-
- }
@Test( expected = ServerWebApplicationException.class )
public void listRemoteRepositoriesKarmaFailed()
@@ -98,7 +92,12 @@ public class RepositoriesServiceTest
RepositoriesService service = getRepositoriesService();
WebClient.client( service ).header( "Authorization",
authorizationHeader );
WebClient.getConfig( service
).getHttpConduit().getClient().setReceiveTimeout( 300000 );
- String repoId = service.getManagedRepositories().get( 0 ).getId();
+
+ ManagedRepositoriesService managedRepositoriesService =
getManagedRepositoriesService();
+ WebClient.client( managedRepositoriesService ).header(
"Authorization", authorizationHeader );
+ WebClient.getConfig( managedRepositoriesService
).getHttpConduit().getClient().setReceiveTimeout( 300000 );
+
+ String repoId =
managedRepositoriesService.getManagedRepositories().get( 0 ).getId();
assertTrue( service.scanRepository( repoId, true ) );
@@ -108,51 +107,6 @@ public class RepositoriesServiceTest
}
- @Test
- public void addManagedRepo()
- throws Exception
- {
- RepositoriesService service = getRepositoriesService();
- WebClient.client( service ).header( "Authorization",
authorizationHeader );
- WebClient.getConfig( service
).getHttpConduit().getClient().setReceiveTimeout( 300000 );
- ManagedRepository repo = getTestManagedRepository();
- if ( service.getManagedRepository( repo.getId() ) != null )
- {
- service.deleteManagedRepository( repo.getId(), true );
- assertNull( service.getManagedRepository( repo.getId() ) );
- }
- service.addManagedRepository( repo );
- assertNotNull( service.getManagedRepository( repo.getId() ) );
- }
-
- @Test
- public void updateManagedRepo()
- throws Exception
- {
- RepositoriesService service = getRepositoriesService();
- WebClient.client( service ).header( "Authorization",
authorizationHeader );
- WebClient.getConfig( service
).getHttpConduit().getClient().setReceiveTimeout( 300000 );
- ManagedRepository repo = getTestManagedRepository();
- if ( service.getManagedRepository( repo.getId() ) != null )
- {
- service.deleteManagedRepository( repo.getId(), true );
- assertNull( service.getManagedRepository( repo.getId() ) );
- }
- service.addManagedRepository( repo );
- repo = service.getManagedRepository( repo.getId() );
- assertNotNull( repo );
- assertEquals( "test", repo.getName() );
- // toto is foo in French :-)
- repo.setName( "toto" );
-
- service.updateManagedRepository( repo );
-
- repo = service.getManagedRepository( repo.getId() );
- assertNotNull( repo );
- assertEquals( "toto", repo.getName() );
-
- }
-
private ManagedRepository getTestManagedRepository()
{