1 package org.apache.archiva.rest.services;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
23 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
24 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
25 import org.apache.archiva.rest.api.model.RemoteRepository;
26 import org.apache.archiva.rest.api.services.RepositoriesService;
27 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
28 import org.apache.archiva.scheduler.repository.RepositoryTask;
29 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
30 import org.apache.maven.archiva.configuration.Configuration;
31 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
32 import org.codehaus.plexus.redback.role.RoleManager;
33 import org.codehaus.plexus.registry.Registry;
34 import org.codehaus.plexus.taskqueue.TaskQueueException;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.stereotype.Service;
39 import javax.inject.Inject;
40 import javax.inject.Named;
41 import javax.ws.rs.PathParam;
42 import java.util.ArrayList;
43 import java.util.List;
46 * @author Olivier Lamy
49 @Service( "repositoriesService#rest" )
50 public class DefaultRepositoriesService
51 extends AbstractRestService
52 implements RepositoriesService
54 private Logger log = LoggerFactory.getLogger( getClass() );
56 // FIXME duplicate from xmlrpc
57 // olamy move this to a common remote services api
58 private static final String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
60 private static final String REPOSITORY_NAME_VALID_EXPRESSION = "^([a-zA-Z0-9.)/_(-]|\\s)+$";
62 private static final String REPOSITORY_LOCATION_VALID_EXPRESSION = "^[-a-zA-Z0-9._/~:?!&=\\\\]+$";
65 protected RoleManager roleManager;
68 protected ArchivaConfiguration archivaConfiguration;
71 @Named( value = "archivaTaskScheduler#repository" )
72 private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
75 @Named( value = "commons-configuration" )
76 private Registry registry;
79 private RepositoryStatisticsManager repositoryStatisticsManager;
82 private RepositorySessionFactory repositorySessionFactory;
85 private ManagedRepositoryAdmin managedRepositoryAdmin;
87 // FIXME olamy move this to repository admin component !
88 public Boolean scanRepository( String repositoryId, boolean fullScan )
90 if ( repositoryTaskScheduler.isProcessingRepositoryTask( repositoryId ) )
92 log.info( "scanning of repository with id {} already scheduled" );
94 RepositoryTask task = new RepositoryTask();
95 task.setRepositoryId( repositoryId );
96 task.setScanAll( fullScan );
99 repositoryTaskScheduler.queueTask( task );
101 catch ( TaskQueueException e )
103 log.error( "failed to schedule scanning of repo with id {}", repositoryId, e );
109 public Boolean alreadyScanning( String repositoryId )
111 return repositoryTaskScheduler.isProcessingRepositoryTask( repositoryId );
114 public Boolean removeScanningTaskFromQueue( @PathParam( "repositoryId" ) String repositoryId )
116 RepositoryTask task = new RepositoryTask();
117 task.setRepositoryId( repositoryId );
120 return repositoryTaskScheduler.unQueueTask( task );
122 catch ( TaskQueueException e )
124 log.error( "failed to unschedule scanning of repo with id {}", repositoryId, e );