1 package org.apache.archiva.rest.api.v2.svc.maven;
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 io.swagger.v3.oas.annotations.Operation;
21 import io.swagger.v3.oas.annotations.Parameter;
22 import io.swagger.v3.oas.annotations.headers.Header;
23 import io.swagger.v3.oas.annotations.media.Content;
24 import io.swagger.v3.oas.annotations.media.Schema;
25 import io.swagger.v3.oas.annotations.responses.ApiResponse;
26 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
27 import io.swagger.v3.oas.annotations.tags.Tag;
28 import org.apache.archiva.components.rest.model.PagedResult;
29 import org.apache.archiva.redback.authorization.RedbackAuthorization;
30 import org.apache.archiva.rest.api.v2.model.FileInfo;
31 import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
32 import org.apache.archiva.rest.api.v2.model.MavenManagedRepositoryUpdate;
33 import org.apache.archiva.rest.api.v2.svc.ArchivaRestError;
34 import org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException;
35 import org.apache.archiva.security.common.ArchivaRoleConstants;
37 import javax.ws.rs.Consumes;
38 import javax.ws.rs.DELETE;
39 import javax.ws.rs.DefaultValue;
40 import javax.ws.rs.GET;
41 import javax.ws.rs.POST;
42 import javax.ws.rs.PUT;
43 import javax.ws.rs.Path;
44 import javax.ws.rs.PathParam;
45 import javax.ws.rs.Produces;
46 import javax.ws.rs.QueryParam;
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
49 import java.util.List;
51 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
52 import static org.apache.archiva.rest.api.v2.svc.RestConfiguration.DEFAULT_PAGE_LIMIT;
53 import static org.apache.archiva.security.common.ArchivaRoleConstants.*;
56 * Service interface for update, delete, add of Managed Maven Repositories
58 * @author Martin Stockhammer <martin_s@apache.org>
61 @Schema( name = "ManagedRepositoryService", description = "Managing and configuration of managed repositories" )
62 @Path( "repositories/maven/managed" )
64 @Tag(name = "v2/Repositories")
65 public interface MavenManagedRepositoryService
69 @Produces( {APPLICATION_JSON} )
70 @RedbackAuthorization( permissions = OPERATION_MANAGE_CONFIGURATION )
71 @Operation( summary = "Returns all managed repositories.",
73 @Parameter( name = "q", description = "Search term" ),
74 @Parameter( name = "offset", description = "The offset of the first element returned" ),
75 @Parameter( name = "limit", description = "Maximum number of items to return in the response" ),
76 @Parameter( name = "orderBy", description = "List of attribute used for sorting (key, value)" ),
77 @Parameter( name = "order", description = "The sort order. Either ascending (asc) or descending (desc)" )
81 name = OPERATION_MANAGE_CONFIGURATION
85 @ApiResponse( responseCode = "200",
86 description = "If the list could be returned",
87 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = PagedResult.class ) )
89 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
90 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
93 PagedResult<MavenManagedRepository> getManagedRepositories(
94 @QueryParam( "q" ) @DefaultValue( "" ) String searchTerm,
95 @QueryParam( "offset" ) @DefaultValue( "0" ) Integer offset,
96 @QueryParam( "limit" ) @DefaultValue( value = DEFAULT_PAGE_LIMIT ) Integer limit,
97 @QueryParam( "orderBy" ) @DefaultValue( "id" ) List<String> orderBy,
98 @QueryParam( "order" ) @DefaultValue( "asc" ) String order )
99 throws ArchivaRestServiceException;
104 @Produces( {MediaType.APPLICATION_JSON} )
105 @RedbackAuthorization(
106 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_READ_REPOSITORY},
109 @Operation( summary = "Returns the managed repository with the given id.",
111 @SecurityRequirement(
112 name = OPERATION_MANAGE_CONFIGURATION
114 @SecurityRequirement(
115 name = OPERATION_READ_REPOSITORY,
120 @ApiResponse( responseCode = "200",
121 description = "If the managed repository could be returned",
122 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = MavenManagedRepository.class ) )
124 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
125 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
126 @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist",
127 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
130 MavenManagedRepository getManagedRepository( @PathParam( "id" ) String repositoryId )
131 throws ArchivaRestServiceException;
136 @Produces( {MediaType.APPLICATION_JSON} )
137 @RedbackAuthorization(
138 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_REPOSITORY },
141 @Operation( summary = "Deletes the managed repository with the given id.",
143 @SecurityRequirement(
144 name = OPERATION_MANAGE_CONFIGURATION
146 @SecurityRequirement(
147 name = OPERATION_DELETE_REPOSITORY,
152 @ApiResponse( responseCode = "200",
153 description = "If the managed repository could be returned"
155 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
156 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
157 @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist",
158 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
161 Response deleteManagedRepository( @PathParam( "id" ) String repositoryId,
162 @QueryParam( "deleteContent" ) boolean deleteContent )
163 throws ArchivaRestServiceException;
168 @Consumes( {MediaType.APPLICATION_JSON} )
169 @Produces( {MediaType.APPLICATION_JSON} )
170 @RedbackAuthorization(
171 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_ADD_REPOSITORY },
174 @Operation( summary = "Creates the managed repository",
176 @SecurityRequirement(
177 name = OPERATION_MANAGE_CONFIGURATION
179 @SecurityRequirement(
180 name = OPERATION_ADD_REPOSITORY,
185 @ApiResponse( responseCode = "201",
186 description = "If the managed repository could be created",
187 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = MavenManagedRepository.class ) )
189 @ApiResponse( responseCode = "303", description = "The repository exists already",
191 @Header( name = "Location", description = "The URL of existing repository ", schema = @Schema( type = "string" ) )
194 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to add repositories",
195 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
196 @ApiResponse( responseCode = "422", description = "The body data is not valid",
197 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
200 MavenManagedRepository addManagedRepository( MavenManagedRepository managedRepository )
201 throws ArchivaRestServiceException;
206 @Consumes( {MediaType.APPLICATION_JSON} )
207 @Produces( {MediaType.APPLICATION_JSON} )
208 @RedbackAuthorization(
209 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_EDIT_REPOSITORY },
212 @Operation( summary = "Updates the managed repository with the given id",
214 @SecurityRequirement(
215 name = OPERATION_MANAGE_CONFIGURATION
217 @SecurityRequirement(
218 name = OPERATION_EDIT_REPOSITORY,
223 @ApiResponse( responseCode = "200",
224 description = "If the managed repository could be updated",
225 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = MavenManagedRepository.class ) )
227 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to add repositories",
228 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
229 @ApiResponse( responseCode = "422", description = "The body data is not valid",
230 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
231 @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist",
232 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
235 MavenManagedRepository updateManagedRepository( @PathParam( "id" ) String repositoryId, MavenManagedRepositoryUpdate managedRepository )
236 throws ArchivaRestServiceException;
239 @Path( "{id}/path/{filePath: .+}" )
241 @Produces( {MediaType.APPLICATION_JSON} )
242 @RedbackAuthorization(
243 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_READ_REPOSITORY},
246 @Operation( summary = "Returns the status of a given file in the repository",
248 @SecurityRequirement(
249 name = OPERATION_MANAGE_CONFIGURATION
251 @SecurityRequirement(
252 name = OPERATION_READ_REPOSITORY,
258 @ApiResponse( responseCode = "200",
259 description = "If the file status is returned",
260 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = FileInfo.class ) )
262 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to add repositories",
263 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
264 @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the file does not exist.",
265 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
268 FileInfo getFileStatus( @PathParam( "id" ) String repositoryId, @PathParam( "filePath" ) String fileLocation )
269 throws ArchivaRestServiceException;
273 * Permissions are checked in impl
274 * will copy an artifact from the source repository to the target repository
276 @Path ("{srcId}/path/{path: .+}/copyto/{dstId}")
278 @Produces({APPLICATION_JSON})
279 @RedbackAuthorization (noPermission = true)
280 @Operation( summary = "Copies a artifact from the source repository to the destination repository",
282 @SecurityRequirement(
283 name = OPERATION_READ_REPOSITORY,
288 @SecurityRequirement(
289 name= OPERATION_ADD_ARTIFACT,
297 @ApiResponse( responseCode = "200",
298 description = "If the artifact was copied"
300 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
301 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
302 @ApiResponse( responseCode = "404", description = "The repository does not exist, or if the artifact was not found",
303 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
306 Response copyArtifact( @PathParam( "srcId" ) String srcRepositoryId, @PathParam( "dstId" ) String dstRepositoryId,
307 @PathParam( "path" ) String path )
308 throws ArchivaRestServiceException;
311 @Path ("{id}/path/{path: .+}")
313 @Consumes ({ APPLICATION_JSON })
314 @RedbackAuthorization (
315 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_ARTIFACT },
318 @Operation( summary = "Deletes a artifact in the repository.",
320 @SecurityRequirement(
321 name = OPERATION_MANAGE_CONFIGURATION
323 @SecurityRequirement(
324 name = OPERATION_DELETE_ARTIFACT,
330 @ApiResponse( responseCode = "200",
331 description = "If the artifact was deleted"
333 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
334 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
335 @ApiResponse( responseCode = "404", description = "The repository or the artifact does not exist",
336 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
339 Response deleteArtifact( @PathParam( "id" ) String repositoryId, @PathParam( "path" ) String path )
340 throws ArchivaRestServiceException;
342 @Path ( "{id}/co/{group}/{project}/{version}" )
344 @Produces ({ MediaType.APPLICATION_JSON })
345 @RedbackAuthorization (
346 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_VERSION},
349 @Operation( summary = "Removes a version tree in the repository",
351 @SecurityRequirement(
352 name = OPERATION_MANAGE_CONFIGURATION
354 @SecurityRequirement(
355 name = OPERATION_DELETE_VERSION,
361 @ApiResponse( responseCode = "200",
362 description = "If the deletion was successful"
364 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete in repositories",
365 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
366 @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the version does not exist.",
367 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
370 Response removeProjectVersion( @PathParam ( "id" ) String repositoryId,
371 @PathParam ( "group" ) String namespace, @PathParam ( "project" ) String projectId,
372 @PathParam ( "version" ) String version )
373 throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;
376 @Path ( "{id}/co/{group}/{project}" )
378 @Produces ({ MediaType.APPLICATION_JSON })
379 @RedbackAuthorization (noPermission = true)
380 @Operation( summary = "Removes a project tree in the repository",
382 @SecurityRequirement(
383 name = OPERATION_MANAGE_CONFIGURATION
385 @SecurityRequirement(
386 name = OPERATION_DELETE_PROJECT,
392 @ApiResponse( responseCode = "200",
393 description = "If the deletion was successful"
395 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete in repositories",
396 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
397 @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the project does not exist.",
398 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
401 Response deleteProject( @PathParam ("id") String repositoryId, @PathParam ( "group" ) String namespace, @PathParam ( "project" ) String projectId )
402 throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;
404 @Path ( "{id}/co/{namespace}" )
406 @Produces ({ MediaType.APPLICATION_JSON })
407 @RedbackAuthorization (
408 permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_NAMESPACE },
411 @Operation( summary = "Removes a namespace tree in the repository",
413 @SecurityRequirement(
414 name = OPERATION_MANAGE_CONFIGURATION
416 @SecurityRequirement(
417 name = OPERATION_DELETE_NAMESPACE,
422 @ApiResponse( responseCode = "200",
423 description = "If the deletion was successful"
425 @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete namespaces in repositories",
426 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
427 @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the namespace does not exist.",
428 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
431 Response deleteNamespace( @PathParam ("id") String repositoryId, @PathParam ( "namespace" ) String namespace )
432 throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;