private static boolean checkModule(final String fileName, final SoftwareModule module) { return null == module || !module.getArtifactByFilename(fileName).isPresent(); }
private static boolean checkModule(final String fileName, final SoftwareModule module) { return null == module || !module.getArtifactByFilename(fileName).isPresent(); }
private static Artifact checkForExistingArtifact(final String filename, final boolean overrideExisting, final SoftwareModule softwareModule) { final Optional<Artifact> artifact = softwareModule.getArtifactByFilename(filename); if (artifact.isPresent()) { if (overrideExisting) { LOG.debug("overriding existing artifact with new filename {}", filename); return artifact.get(); } else { throw new EntityAlreadyExistsException("File with that name already exists in the Software Module"); } } return null; }
private static Artifact checkForExistingArtifact(final String filename, final boolean overrideExisting, final SoftwareModule softwareModule) { final Optional<Artifact> artifact = softwareModule.getArtifactByFilename(filename); if (artifact.isPresent()) { if (overrideExisting) { LOG.debug("overriding existing artifact with new filename {}", filename); return artifact.get(); } else { throw new EntityAlreadyExistsException("File with that name already exists in the Software Module"); } } return null; }
@Override // Exception squid:S3655 - Optional access is checked in checkModule // subroutine @SuppressWarnings("squid:S3655") public ResponseEntity<Void> downloadArtifactMd5(@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId, @PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("fileName") final String fileName) { final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); final SoftwareModule module = controllerManagement.getSoftwareModule(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); if (checkModule(fileName, module)) { LOG.warn("Software module with id {} could not be found.", softwareModuleId); return ResponseEntity.notFound().build(); } final Artifact artifact = module.getArtifactByFilename(fileName) .orElseThrow(() -> new EntityNotFoundException(Artifact.class, fileName)); checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(), target, module.getId()); try { FileStreamingUtil.writeMD5FileResponse(requestResponseContextHolder.getHttpServletResponse(), artifact.getMd5Hash(), fileName); } catch (final IOException e) { LOG.error("Failed to stream MD5 File", e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } return ResponseEntity.ok().build(); }
@Override // Exception squid:S3655 - Optional access is checked in checkModule // subroutine @SuppressWarnings("squid:S3655") public ResponseEntity<Void> downloadArtifactMd5(@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId, @PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("fileName") final String fileName) { final Target target = controllerManagement.getByControllerId(controllerId) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); final SoftwareModule module = controllerManagement.getSoftwareModule(softwareModuleId) .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId)); if (checkModule(fileName, module)) { LOG.warn("Software module with id {} could not be found.", softwareModuleId); return ResponseEntity.notFound().build(); } final Artifact artifact = module.getArtifactByFilename(fileName) .orElseThrow(() -> new EntityNotFoundException(Artifact.class, fileName)); checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(), target, module.getId()); try { FileStreamingUtil.writeMD5FileResponse(requestResponseContextHolder.getHttpServletResponse(), artifact.getMd5Hash(), fileName); } catch (final IOException e) { LOG.error("Failed to stream MD5 File", e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } return ResponseEntity.ok().build(); }
final Artifact artifact = module.getArtifactByFilename(fileName).get();
final Artifact artifact = module.getArtifactByFilename(fileName).get();