]> source.dussan.org Git - archiva.git/blob
7fbfe16ce28bc0653b2ec44d99e7c441ec193937
[archiva.git] /
1 package org.apache.archiva.rest.services.v2;
2 /*
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
10  *
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
17  * under the License.
18  */
19
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;
36
37 import javax.inject.Inject;
38 import javax.ws.rs.PathParam;
39 import javax.ws.rs.core.Response;
40 import java.util.List;
41
42 /**
43  * @author Martin Stockhammer <martin_s@apache.org>
44  */
45 @Service("v2.managedMavenRepositoryService#rest")
46 public class DefaultMavenManagedRepositoryService implements MavenManagedRepositoryService
47 {
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"} );
50     static
51     {
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 );
59     }
60
61     private ManagedRepositoryAdmin managedRepositoryAdmin;
62     private RepositoryRegistry repositoryRegistry;
63
64     public DefaultMavenManagedRepositoryService( RepositoryRegistry repositoryRegistry, ManagedRepositoryAdmin managedRepositoryAdmin )
65     {
66         this.managedRepositoryAdmin = managedRepositoryAdmin;
67     }
68
69     @Override
70     public PagedResult<MavenManagedRepository> getManagedRepositories( String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order ) throws ArchivaRestServiceException
71     {
72         try
73         {
74             List<org.apache.archiva.admin.model.beans.ManagedRepository> result = managedRepositoryAdmin.getManagedRepositories( );
75             int totalCount = Math.toIntExact( result.stream( ).count( ) );
76         }
77         catch (ArithmeticException e) {
78             log.error( "Invalid number of repositories detected." );
79             throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.INVALID_RESULT_SET_ERROR ) );
80         }
81         catch ( RepositoryAdminException e )
82         {
83             e.printStackTrace( );
84         }
85         return null;
86
87     }
88
89     @Override
90     public MavenManagedRepository getManagedRepository( String repositoryId ) throws ArchivaRestServiceException
91     {
92         return null;
93     }
94
95     @Override
96     public Response deleteManagedRepository( String repositoryId, boolean deleteContent ) throws ArchivaRestServiceException
97     {
98         return null;
99     }
100
101     @Override
102     public MavenManagedRepository addManagedRepository( MavenManagedRepository managedRepository ) throws ArchivaRestServiceException
103     {
104         return null;
105     }
106
107     @Override
108     public MavenManagedRepository updateManagedRepository( MavenManagedRepository managedRepository ) throws ArchivaRestServiceException
109     {
110         return null;
111     }
112
113     @Override
114     public FileInfo getFileStatus( String repositoryId, String fileLocation ) throws ArchivaRestServiceException
115     {
116         return null;
117     }
118
119     @Override
120     public Response copyArtifact( String srcRepositoryId, String dstRepositoryId,
121                                   String path ) throws ArchivaRestServiceException
122     {
123         ManagedRepository srcRepo = repositoryRegistry.getManagedRepository( srcRepositoryId );
124         if (srcRepo==null) {
125             throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, srcRepositoryId ), 404 );
126         }
127         ManagedRepository dstRepo = repositoryRegistry.getManagedRepository( dstRepositoryId );
128         if (dstRepo==null) {
129             throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, dstRepositoryId ), 404 );
130         }
131         if (dstRepo.getAsset( path ).exists()) {
132             throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.ARTIFACT_EXISTS_AT_DEST, path ) );
133         }
134
135
136         return null;
137     }
138
139     @Override
140     public Response deleteArtifact( String repositoryId, String path ) throws ArchivaRestServiceException
141     {
142         return null;
143     }
144
145
146     @Override
147     public Response removeProjectVersion( String repositoryId, String namespace, String projectId, String version ) throws org.apache.archiva.rest.api.services.ArchivaRestServiceException
148     {
149         return null;
150     }
151
152     @Override
153     public Response deleteProject( String repositoryId, String namespace, String projectId ) throws org.apache.archiva.rest.api.services.ArchivaRestServiceException
154     {
155         return null;
156     }
157
158     @Override
159     public Response deleteNamespace( String repositoryId, String namespace ) throws org.apache.archiva.rest.api.services.ArchivaRestServiceException
160     {
161         return null;
162     }
163
164 }