You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryGroupService.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package org.apache.archiva.rest.api.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. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  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.parameters.RequestBody;
  26. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  27. import io.swagger.v3.oas.annotations.security.SecurityRequirement;
  28. import org.apache.archiva.components.rest.model.PagedResult;
  29. import org.apache.archiva.redback.authorization.RedbackAuthorization;
  30. import org.apache.archiva.rest.api.model.v2.RepositoryGroup;
  31. import org.apache.archiva.security.common.ArchivaRoleConstants;
  32. import javax.ws.rs.Consumes;
  33. import javax.ws.rs.DELETE;
  34. import javax.ws.rs.DefaultValue;
  35. import javax.ws.rs.GET;
  36. import javax.ws.rs.POST;
  37. import javax.ws.rs.PUT;
  38. import javax.ws.rs.Path;
  39. import javax.ws.rs.PathParam;
  40. import javax.ws.rs.Produces;
  41. import javax.ws.rs.QueryParam;
  42. import javax.ws.rs.core.Response;
  43. import java.util.List;
  44. import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
  45. import static org.apache.archiva.rest.api.services.v2.RestConfiguration.DEFAULT_PAGE_LIMIT;
  46. /**
  47. * Endpoint for repository groups that combine multiple repositories into a single virtual repository.
  48. *
  49. * @author Olivier Lamy
  50. * @author Martin Stockhammer
  51. * @since 3.0
  52. */
  53. @Path( "/repository_groups" )
  54. @Schema( name = "RepositoryGroups", description = "Managing of repository groups or virtual repositories" )
  55. public interface RepositoryGroupService
  56. {
  57. @Path( "" )
  58. @GET
  59. @Produces( {APPLICATION_JSON} )
  60. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  61. @Operation( summary = "Returns all repository group entries.",
  62. parameters = {
  63. @Parameter( name = "q", description = "Search term" ),
  64. @Parameter( name = "offset", description = "The offset of the first element returned" ),
  65. @Parameter( name = "limit", description = "Maximum number of items to return in the response" ),
  66. @Parameter( name = "orderBy", description = "List of attribute used for sorting (key, value)" ),
  67. @Parameter( name = "order", description = "The sort order. Either ascending (asc) or descending (desc)" )
  68. },
  69. security = {
  70. @SecurityRequirement(
  71. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  72. )
  73. },
  74. responses = {
  75. @ApiResponse( responseCode = "200",
  76. description = "If the list could be returned",
  77. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = PagedResult.class ) )
  78. ),
  79. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  80. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  81. }
  82. )
  83. PagedResult<RepositoryGroup> getRepositoriesGroups( @QueryParam( "q" ) @DefaultValue( "" ) String searchTerm,
  84. @QueryParam( "offset" ) @DefaultValue( "0" ) Integer offset,
  85. @QueryParam( "limit" ) @DefaultValue( value = DEFAULT_PAGE_LIMIT ) Integer limit,
  86. @QueryParam( "orderBy" ) @DefaultValue( "id" ) List<String> orderBy,
  87. @QueryParam( "order" ) @DefaultValue( "asc" ) String order )
  88. throws ArchivaRestServiceException;
  89. @Path( "{id}" )
  90. @GET
  91. @Produces( {APPLICATION_JSON} )
  92. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  93. @Operation( summary = "Returns a single repository group configuration.",
  94. security = {
  95. @SecurityRequirement(
  96. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  97. )
  98. },
  99. responses = {
  100. @ApiResponse( responseCode = "200",
  101. description = "If the configuration is returned",
  102. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
  103. ),
  104. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  105. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  106. @ApiResponse( responseCode = "404", description = "The repository group with the given id does not exist",
  107. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  108. }
  109. )
  110. RepositoryGroup getRepositoryGroup( @PathParam( "id" ) String repositoryGroupId )
  111. throws ArchivaRestServiceException;
  112. @Path( "" )
  113. @POST
  114. @Consumes( {APPLICATION_JSON} )
  115. @Produces( {APPLICATION_JSON} )
  116. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  117. @Operation( summary = "Creates a new group entry.",
  118. requestBody =
  119. @RequestBody( required = true, description = "The configuration of the repository group.",
  120. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
  121. )
  122. ,
  123. security = {
  124. @SecurityRequirement(
  125. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  126. )
  127. },
  128. responses = {
  129. @ApiResponse( responseCode = "201",
  130. description = "If the repository group was created",
  131. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
  132. ),
  133. @ApiResponse( responseCode = "303", description = "The repository group exists already",
  134. headers = {
  135. @Header( name = "Location", description = "The URL of existing group", schema = @Schema( type = "string" ) )
  136. }
  137. ),
  138. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  139. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  140. @ApiResponse( responseCode = "422", description = "The body data is not valid",
  141. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  142. }
  143. )
  144. RepositoryGroup addRepositoryGroup( RepositoryGroup repositoryGroup )
  145. throws ArchivaRestServiceException;
  146. @Path( "{id}" )
  147. @PUT
  148. @Consumes( {APPLICATION_JSON} )
  149. @Produces( {APPLICATION_JSON} )
  150. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  151. @Operation( summary = "Returns all repository group entries.",
  152. requestBody =
  153. @RequestBody( required = true, description = "The configuration of the repository group.",
  154. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
  155. )
  156. ,
  157. security = {
  158. @SecurityRequirement(
  159. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  160. )
  161. },
  162. responses = {
  163. @ApiResponse( responseCode = "200",
  164. description = "If the group is returned",
  165. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
  166. ),
  167. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  168. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  169. @ApiResponse( responseCode = "404", description = "The group with the given id does not exist",
  170. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  171. @ApiResponse( responseCode = "422", description = "The body data is not valid",
  172. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  173. }
  174. )
  175. RepositoryGroup updateRepositoryGroup( @PathParam( "id" ) String groupId, RepositoryGroup repositoryGroup )
  176. throws ArchivaRestServiceException;
  177. @Path( "{id}" )
  178. @DELETE
  179. @Produces( {APPLICATION_JSON} )
  180. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  181. @Operation( summary = "Deletes the repository group entry with the given id.",
  182. security = {
  183. @SecurityRequirement(
  184. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  185. )
  186. },
  187. responses = {
  188. @ApiResponse( responseCode = "200",
  189. description = "If the group was deleted"
  190. ),
  191. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete the group",
  192. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  193. @ApiResponse( responseCode = "404", description = "The group with the given id does not exist",
  194. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  195. }
  196. )
  197. Response deleteRepositoryGroup( @PathParam( "id" ) String repositoryGroupId )
  198. throws ArchivaRestServiceException;
  199. @Path( "{id}/repositories/{repositoryId}" )
  200. @PUT
  201. @Produces( {APPLICATION_JSON} )
  202. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  203. @Operation( summary = "Adds the repository with the given id to the repository group.",
  204. security = {
  205. @SecurityRequirement(
  206. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  207. )
  208. },
  209. responses = {
  210. @ApiResponse( responseCode = "200",
  211. description = "If the repository was added or if it was already part of the group"
  212. ),
  213. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete the group",
  214. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  215. @ApiResponse( responseCode = "404", description = "The group with the given id does not exist",
  216. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  217. }
  218. )
  219. RepositoryGroup addRepositoryToGroup( @PathParam( "id" ) String repositoryGroupId,
  220. @PathParam( "repositoryId" ) String repositoryId )
  221. throws ArchivaRestServiceException;
  222. @Path( "{id}/repositories/{repositoryId}" )
  223. @DELETE
  224. @Produces( {APPLICATION_JSON} )
  225. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  226. @Operation( summary = "Removes the repository with the given id from the repository group.",
  227. security = {
  228. @SecurityRequirement(
  229. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  230. )
  231. },
  232. responses = {
  233. @ApiResponse( responseCode = "200",
  234. description = "If the repository was removed."
  235. ),
  236. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete the group",
  237. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  238. @ApiResponse( responseCode = "404", description = "Either the group with the given id does not exist, or the repository was not part of the group.",
  239. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  240. }
  241. )
  242. RepositoryGroup deleteRepositoryFromGroup( @PathParam( "id" ) String repositoryGroupId,
  243. @PathParam( "repositoryId" ) String repositoryId )
  244. throws ArchivaRestServiceException;
  245. }