/** * Handles the GET request for downloading an artifact. * * @param softwareModuleId * of the parent SoftwareModule * @param artifactId * of the related Artifact * * @return responseEntity with status ok if successful */ @Override public ResponseEntity<InputStream> downloadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId) { final SoftwareModule module = softwareModuleManagement.get(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); final Artifact artifact = module.getArtifact(artifactId) .orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId)); final AbstractDbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash()) .orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash())); final HttpServletRequest request = requestResponseContextHolder.getHttpServletRequest(); final String ifMatch = request.getHeader(HttpHeaders.IF_MATCH); if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) { return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED); } return FileStreamingUtil.writeFileResponse(file, artifact.getFilename(), artifact.getCreatedAt(), requestResponseContextHolder.getHttpServletResponse(), request, null); }
final Artifact artifact = module.getArtifactByFilename(fileName).get(); final AbstractDbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash()) .orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));
final Artifact artifact = module.getArtifactByFilename(fileName).get(); final AbstractDbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash()) .orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));