1 package org.apache.archiva.rest.services.v2;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org.apache.archiva.admin.model.RepositoryAdminException;
21 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
22 import org.apache.archiva.components.rest.model.PagedResult;
23 import org.apache.archiva.components.rest.util.QueryHelper;
24 import org.apache.archiva.repository.ManagedRepository;
25 import org.apache.archiva.repository.RepositoryRegistry;
26 import org.apache.archiva.rest.api.model.v2.Artifact;
27 import org.apache.archiva.rest.api.model.v2.FileInfo;
28 import org.apache.archiva.rest.api.model.v2.MavenManagedRepository;
29 import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException;
30 import org.apache.archiva.rest.api.services.v2.ErrorKeys;
31 import org.apache.archiva.rest.api.services.v2.ErrorMessage;
32 import org.apache.archiva.rest.api.services.v2.MavenManagedRepositoryService;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.stereotype.Service;
37 import javax.inject.Inject;
38 import javax.ws.rs.PathParam;
39 import javax.ws.rs.core.Response;
40 import java.util.List;
43 * @author Martin Stockhammer <martin_s@apache.org>
45 @Service("v2.managedMavenRepositoryService#rest")
46 public class DefaultMavenManagedRepositoryService implements MavenManagedRepositoryService
48 private static final Logger log = LoggerFactory.getLogger( DefaultMavenManagedRepositoryService.class );
49 private static final QueryHelper<org.apache.archiva.admin.model.beans.ManagedRepository> QUERY_HELPER = new QueryHelper<>( new String[]{"id", "name"} );
52 QUERY_HELPER.addStringFilter( "id", org.apache.archiva.admin.model.beans.ManagedRepository::getId );
53 QUERY_HELPER.addStringFilter( "name", org.apache.archiva.admin.model.beans.ManagedRepository::getName );
54 QUERY_HELPER.addStringFilter( "location", org.apache.archiva.admin.model.beans.ManagedRepository::getName );
55 QUERY_HELPER.addBooleanFilter( "snapshot", org.apache.archiva.admin.model.beans.ManagedRepository::isSnapshots );
56 QUERY_HELPER.addBooleanFilter( "release", org.apache.archiva.admin.model.beans.ManagedRepository::isReleases );
57 QUERY_HELPER.addNullsafeFieldComparator( "id", org.apache.archiva.admin.model.beans.ManagedRepository::getId );
58 QUERY_HELPER.addNullsafeFieldComparator( "name", org.apache.archiva.admin.model.beans.ManagedRepository::getName );
61 private ManagedRepositoryAdmin managedRepositoryAdmin;
62 private RepositoryRegistry repositoryRegistry;
64 public DefaultMavenManagedRepositoryService( RepositoryRegistry repositoryRegistry, ManagedRepositoryAdmin managedRepositoryAdmin )
66 this.managedRepositoryAdmin = managedRepositoryAdmin;
70 public PagedResult<MavenManagedRepository> getManagedRepositories( String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order ) throws ArchivaRestServiceException
74 List<org.apache.archiva.admin.model.beans.ManagedRepository> result = managedRepositoryAdmin.getManagedRepositories( );
75 int totalCount = Math.toIntExact( result.stream( ).count( ) );
77 catch (ArithmeticException e) {
78 log.error( "Invalid number of repositories detected." );
79 throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.INVALID_RESULT_SET_ERROR ) );
81 catch ( RepositoryAdminException e )
90 public MavenManagedRepository getManagedRepository( String repositoryId ) throws ArchivaRestServiceException
96 public Response deleteManagedRepository( String repositoryId, boolean deleteContent ) throws ArchivaRestServiceException
102 public MavenManagedRepository addManagedRepository( MavenManagedRepository managedRepository ) throws ArchivaRestServiceException
108 public MavenManagedRepository updateManagedRepository( MavenManagedRepository managedRepository ) throws ArchivaRestServiceException
114 public FileInfo getFileStatus( String repositoryId, String fileLocation ) throws ArchivaRestServiceException
120 public Response copyArtifact( String srcRepositoryId, String dstRepositoryId,
121 String path ) throws ArchivaRestServiceException
123 ManagedRepository srcRepo = repositoryRegistry.getManagedRepository( srcRepositoryId );
125 throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, srcRepositoryId ), 404 );
127 ManagedRepository dstRepo = repositoryRegistry.getManagedRepository( dstRepositoryId );
129 throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, dstRepositoryId ), 404 );
131 if (dstRepo.getAsset( path ).exists()) {
132 throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.ARTIFACT_EXISTS_AT_DEST, path ) );
140 public Response deleteArtifact( String repositoryId, String path ) throws ArchivaRestServiceException
147 public Response removeProjectVersion( String repositoryId, String namespace, String projectId, String version ) throws org.apache.archiva.rest.api.services.ArchivaRestServiceException
153 public Response deleteProject( String repositoryId, String namespace, String projectId ) throws org.apache.archiva.rest.api.services.ArchivaRestServiceException
159 public Response deleteNamespace( String repositoryId, String namespace ) throws org.apache.archiva.rest.api.services.ArchivaRestServiceException