@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testUpdateMetadataOnDeleteReleaseVersionDirectory(@MavenRepository(repositoryId = REPOSITORY_RELEASES_2, setup = MavenIndexedRepositorySetup.class) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_RELEASES_2, id = "org.carlspring.strongbox.delete-metadata:metadata-foo", versions = { "1.2.1", "1.2.2" }, classifiers = "javadoc") List<Path> artifactsPaths) throws Exception { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); RepositoryPath artifact1RepositoryPath = (RepositoryPath) artifactsPaths.get(0).normalize(); String artifact1RepositoryPathStr = RepositoryFiles.relativizePath(artifact1RepositoryPath); String unixBasedRelativePath = FilenameUtils.separatorsToUnix(artifact1RepositoryPathStr); Artifact artifact1 = MavenArtifactUtils.convertPathToArtifact(unixBasedRelativePath); RepositoryPath artifact2RepositoryPath = (RepositoryPath) artifactsPaths.get(1).normalize(); String artifact2RepositoryPathStr = RepositoryFiles.relativizePath(artifact2RepositoryPath); mavenMetadataServiceHelper.generateMavenMetadata(repository); client.delete(storageId, repositoryId, artifact2RepositoryPathStr); assertThat(artifact1).isNotNull(); String metadataPath = String.format("/storages/%s/%s/%s", storageId, repositoryId, getArtifactLevelMetadataPath(artifact1)); Metadata metadata = defaultMavenArtifactDeployer.retrieveMetadata(metadataPath); assertThat(metadata).isNotNull(); assertThat(metadata.getVersioning()).isNotNull(); assertThat(metadata.getVersioning().getVersions()).isNotNull(); assertThat(metadata.getVersioning().getVersions().contains("1.2.2")).isFalse(); }
@ApiOperation(value = "Deletes a path from a repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deleted."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The specified storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") @DeleteMapping(value = "/{storageId}/{repositoryId}/{artifactPath:.+}") public ResponseEntity delete(@RepositoryMapping Repository repository, @ApiParam(value = "Whether to use force delete") @RequestParam(defaultValue = "false", name = "force", required = false) boolean force, @PathVariable String artifactPath) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); logger.info("Deleting {}:{}/{}...", storageId, repositoryId, artifactPath); try { final RepositoryPath repositoryPath = repositoryPathResolver.resolve(storageId, repositoryId, artifactPath); if (!Files.exists(repositoryPath)) { return ResponseEntity.status(NOT_FOUND) .body("The specified path does not exist!"); } artifactManagementService.delete(repositoryPath, force); } catch (ArtifactStorageException e) { logger.error(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(e.getMessage()); } return ResponseEntity.ok("The artifact was deleted."); }
MavenArtifactController extends BaseArtifactController { @ApiOperation(value = "Deletes a path from a repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deleted."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The specified storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") @DeleteMapping(value = "/{storageId}/{repositoryId}/{artifactPath:.+}") public ResponseEntity delete(@RepositoryMapping Repository repository, @ApiParam(value = "Whether to use force delete") @RequestParam(defaultValue = "false", name = "force", required = false) boolean force, @PathVariable String artifactPath) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); logger.info("Deleting {}:{}/{}...", storageId, repositoryId, artifactPath); try { final RepositoryPath repositoryPath = repositoryPathResolver.resolve(storageId, repositoryId, artifactPath); if (!Files.exists(repositoryPath)) { return ResponseEntity.status(NOT_FOUND) .body("The specified path does not exist!"); } artifactManagementService.delete(repositoryPath, force); } catch (ArtifactStorageException e) { logger.error(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(e.getMessage()); } return ResponseEntity.ok("The artifact was deleted."); } }
MavenArtifactController extends BaseArtifactController { @ApiOperation(value = "Deletes a path from a repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deleted."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The specified storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") @DeleteMapping(value = "/{storageId}/{repositoryId}/{artifactPath:.+}") public ResponseEntity delete(@RepositoryMapping Repository repository, @ApiParam(value = "Whether to use force delete") @RequestParam(defaultValue = "false", name = "force", required = false) boolean force, @PathVariable String artifactPath) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); logger.info("Deleting {}:{}/{}...", storageId, repositoryId, artifactPath); try { final RepositoryPath repositoryPath = repositoryPathResolver.resolve(storageId, repositoryId, artifactPath); if (!Files.exists(repositoryPath)) { return ResponseEntity.status(NOT_FOUND) .body("The specified path does not exist!"); } artifactManagementService.delete(repositoryPath, force); } catch (ArtifactStorageException e) { logger.error(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(e.getMessage()); } return ResponseEntity.ok("The artifact was deleted."); }  }
MavenArtifactController extends BaseArtifactController { @ApiOperation(value = "Deletes a path from a repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deleted."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The specified storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") @DeleteMapping(value = "/{storageId}/{repositoryId}/{artifactPath:.+}") public ResponseEntity delete(@RepositoryMapping Repository repository, @ApiParam(value = "Whether to use force delete") @RequestParam(defaultValue = "false", name = "force", required = false) boolean force, @PathVariable String artifactPath) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); logger.info("Deleting {}:{}/{}...", storageId, repositoryId, artifactPath); try { final RepositoryPath repositoryPath = repositoryPathResolver.resolve(storageId, repositoryId, artifactPath); if (!Files.exists(repositoryPath)) { return ResponseEntity.status(NOT_FOUND) .body("The specified path does not exist!"); } artifactManagementService.delete(repositoryPath, force); } catch (ArtifactStorageException e) { logger.error(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(e.getMessage()); } return ResponseEntity.ok("The artifact was deleted."); }  @PreAuthorize("authenticated") @GetMapping(value = "/{storageId}/{repositoryId}") ResponseEntity<String> checkRepositoryAccess(); @ApiOperation(value = "Used to retrieve an artifact") @ApiResponses(value = { @ApiResponse(code = 200, message = ""), @ApiResponse(code = 404, message = "Requested path not found."), @ApiResponse(code = 500, message = "Server error."), @ApiResponse(code = 503, message = "Repository currently not in service.")}) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(value = { "/{storageId}/{repositoryId}/{artifactPath:.+}" }, method = {RequestMethod.GET, RequestMethod.HEAD}) void download(@RepositoryMapping Repository repository,
                         @RequestHeader HttpHeaders httpHeaders,
                         @PathVariable String artifactPath,
                         HttpServletRequest request,
                         HttpServletResponse response); @ApiOperation(value = "Used to deploy an artifact") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deployed successfully."), @ApiResponse(code = 400, message = "An error occurred.") }) @PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')") @PutMapping(value = "{storageId}/{repositoryId}/{artifactPath:.+}") ResponseEntity upload(@RepositoryMapping Repository repository,
                                 @PathVariable String artifactPath,
                                 HttpServletRequest request); @ApiOperation(value = "Copies a path from one repository to another.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The path was copied successfully."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The source/destination storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_COPY')") @PostMapping(value = "/copy/{path:.+}") ResponseEntity copy(
            @RepositoryMapping(storageVariableName = "srcStorageId", repositoryVariableName = "srcRepositoryId")
                    Repository srcRepository,
            @RepositoryMapping(storageVariableName = "destStorageId", repositoryVariableName = "destRepositoryId")
                    Repository destRepository,
            @PathVariable String path); @ApiOperation(value = "Deletes a path from a repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deleted."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The specified storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") @DeleteMapping(value = "/{storageId}/{repositoryId}/{artifactPath:.+}") ResponseEntity delete(@RepositoryMapping Repository repository,
                                 @ApiParam(value = "Whether to use force delete")
                                 @RequestParam(defaultValue = "false",
                                               name = "force",
                                               required = false) boolean force,
                                 @PathVariable String artifactPath); }
MavenArtifactController extends BaseArtifactController { @ApiOperation(value = "Deletes a path from a repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deleted."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The specified storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") @DeleteMapping(value = "/{storageId}/{repositoryId}/{artifactPath:.+}") public ResponseEntity delete(@RepositoryMapping Repository repository, @ApiParam(value = "Whether to use force delete") @RequestParam(defaultValue = "false", name = "force", required = false) boolean force, @PathVariable String artifactPath) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); logger.info("Deleting {}:{}/{}...", storageId, repositoryId, artifactPath); try { final RepositoryPath repositoryPath = repositoryPathResolver.resolve(storageId, repositoryId, artifactPath); if (!Files.exists(repositoryPath)) { return ResponseEntity.status(NOT_FOUND) .body("The specified path does not exist!"); } artifactManagementService.delete(repositoryPath, force); } catch (ArtifactStorageException e) { logger.error(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(e.getMessage()); } return ResponseEntity.ok("The artifact was deleted."); }  @PreAuthorize("authenticated") @GetMapping(value = "/{storageId}/{repositoryId}") ResponseEntity<String> checkRepositoryAccess(); @ApiOperation(value = "Used to retrieve an artifact") @ApiResponses(value = { @ApiResponse(code = 200, message = ""), @ApiResponse(code = 404, message = "Requested path not found."), @ApiResponse(code = 500, message = "Server error."), @ApiResponse(code = 503, message = "Repository currently not in service.")}) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(value = { "/{storageId}/{repositoryId}/{artifactPath:.+}" }, method = {RequestMethod.GET, RequestMethod.HEAD}) void download(@RepositoryMapping Repository repository,
                         @RequestHeader HttpHeaders httpHeaders,
                         @PathVariable String artifactPath,
                         HttpServletRequest request,
                         HttpServletResponse response); @ApiOperation(value = "Used to deploy an artifact") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deployed successfully."), @ApiResponse(code = 400, message = "An error occurred.") }) @PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')") @PutMapping(value = "{storageId}/{repositoryId}/{artifactPath:.+}") ResponseEntity upload(@RepositoryMapping Repository repository,
                                 @PathVariable String artifactPath,
                                 HttpServletRequest request); @ApiOperation(value = "Copies a path from one repository to another.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The path was copied successfully."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The source/destination storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_COPY')") @PostMapping(value = "/copy/{path:.+}") ResponseEntity copy(
            @RepositoryMapping(storageVariableName = "srcStorageId", repositoryVariableName = "srcRepositoryId")
                    Repository srcRepository,
            @RepositoryMapping(storageVariableName = "destStorageId", repositoryVariableName = "destRepositoryId")
                    Repository destRepository,
            @PathVariable String path); @ApiOperation(value = "Deletes a path from a repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The artifact was deleted."), @ApiResponse(code = 400, message = "Bad request."), @ApiResponse(code = 404, message = "The specified storageId/repositoryId/path does not exist!") }) @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") @DeleteMapping(value = "/{storageId}/{repositoryId}/{artifactPath:.+}") ResponseEntity delete(@RepositoryMapping Repository repository,
                                 @ApiParam(value = "Whether to use force delete")
                                 @RequestParam(defaultValue = "false",
                                               name = "force",
                                               required = false) boolean force,
                                 @PathVariable String artifactPath);  }