use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class FalsePositiveJobDataService method addJobDataListToConfiguration.
private void addJobDataListToConfiguration(FalsePositiveProjectConfiguration config, FalsePositiveJobDataList jobDataList) {
List<FalsePositiveJobData> list = jobDataList.getJobData();
/* we want to load reports only one time, so sort by report job UUID... */
list.sort(Comparator.comparing(FalsePositiveJobData::getJobUUID));
ScanSecHubReport report = null;
for (FalsePositiveJobData data : list) {
UUID jobUUID = data.getJobUUID();
if (report == null || !jobUUID.equals(report.getJobUUID())) {
ScanReport scanReport = scanReportRepository.findBySecHubJobUUID(jobUUID);
if (scanReport == null) {
throw new NotFoundException("No report found for job " + jobUUID);
}
report = new ScanSecHubReport(scanReport);
}
merger.addJobDataWithMetaDataToConfig(report, config, data, userContextService.getUserId());
}
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class IntegrationTestServerRestController method getUploadedFile.
@RequestMapping(path = APIConstants.API_ANONYMOUS + "integrationtest/{projectId}/{jobUUID}/uploaded/{fileName}", method = RequestMethod.GET)
public ResponseEntity<Resource> getUploadedFile(@PathVariable("projectId") String projectId, @PathVariable("jobUUID") UUID jobUUID, @PathVariable("fileName") String fileName) throws IOException {
ValidationResult projectIdValidationResult = projectIdValidation.validate(projectId);
if (!projectIdValidationResult.isValid()) {
LOG.warn("Called with illegal projectId '{}'", logSanitizer.sanitize(projectId, 30));
return ResponseEntity.notFound().build();
}
LOG.info("Integration test server: getJobStorage for {} {}", logSanitizer.sanitize(projectId, 30), jobUUID);
JobStorage storage = storageService.getJobStorage(projectId, jobUUID);
if (!storage.isExisting(fileName)) {
throw new NotFoundException("file not uploaded:" + fileName);
}
InputStream inputStream = storage.fetch(fileName);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
/* @formatter:off */
byte[] bytes = new byte[inputStream.available()];
new DataInputStream(inputStream).readFully(bytes);
ByteArrayResource resource = new ByteArrayResource(bytes);
return ResponseEntity.ok().headers(headers).contentLength(resource.contentLength()).contentType(MediaType.parseMediaType("application/octet-stream")).body(resource);
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class ProjectDeleteServiceTest method when_a_project_is_not_found_nothing_not_found_exception_will_forwarded.
@Test
public void when_a_project_is_not_found_nothing_not_found_exception_will_forwarded() {
/* test */
expected.expect(NotFoundException.class);
/* prepare */
when(projectRepository.findOrFailProject("project1")).thenThrow(new NotFoundException());
/* execute */
serviceToTest.deleteProject("project1");
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class DownloadSpdxScanReportService method getScanSpdxJsonReport.
public String getScanSpdxJsonReport(String projectId, UUID jobUUID) {
/* validate */
assertion.assertIsValidProjectId(projectId);
assertion.assertIsValidJobUUID(jobUUID);
scanAssertService.assertUserHasAccessToProject(projectId);
scanAssertService.assertProjectAllowsReadAccess(projectId);
/* audit */
auditLogService.log("starts download of SPDX Json report for job: {}", jobUUID);
List<ProductResult> productResults = productResultRepository.findAllProductResults(jobUUID, ProductIdentifier.SERECO);
if (productResults.size() != 1) {
throw new SecHubRuntimeException("Did not found exactly one SERECO product result. Instead, " + productResults.size() + " product results were found.");
}
ProductResult productResult = productResults.iterator().next();
String spdxJson = spdxJsonResolver.resolveSpdxJson(productResult);
if (spdxJson == null) {
throw new NotFoundException("There was no JSON SPDX report available for job: " + jobUUID);
}
return spdxJson;
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class SchedulerRestartJobService method restartJob.
private void restartJob(UUID jobUUID, String ownerEmailAddress, boolean hard) {
assertion.assertIsValidJobUUID(jobUUID);
auditLogService.log("triggered restart of job:{}, variant:[hard={}]", jobUUID, hard);
Optional<ScheduleSecHubJob> optJob = jobRepository.findById(jobUUID);
if (!optJob.isPresent()) {
LOG.warn("SecHub job {} not found, so not able to restart!", jobUUID);
JobDataContext context = new JobDataContext();
context.sechubJobUUID = jobUUID;
context.ownerEmailAddress = ownerEmailAddress;
context.info = "Restart canceled, because job not found!";
sendJobRestartCanceled(context);
throw new NotFoundException("Job not found or you have no access");
}
/* job exists, so can be restarted - hard or soft */
ScheduleSecHubJob job = optJob.get();
if (job.getExecutionResult().hasFinished()) {
/* already done so just ignore */
LOG.warn("SecHub job {} has already finished, so not able to restart!", jobUUID);
sendJobRestartCanceled(job, ownerEmailAddress, "Restart canceled, because job already finished");
throw new AlreadyExistsException("Job has already finished - restart not necessary");
}
/*
* when we have still running batch jobs we must terminate them as well +
* abandon
*/
schedulerCancelJobService.stopAndAbandonAllRunningBatchJobsForSechubJobUUID(jobUUID);
if (hard) {
sendPurgeJobResultsSynchronousRequest(job);
}
ScheduleSecHubJob secHubJob = optJob.get();
markJobAsNewExecutedNow(secHubJob);
sendJobRestartTriggered(secHubJob, ownerEmailAddress);
launcherService.executeJob(secHubJob);
String type = (hard ? "hard" : "normal");
LOG.info("job {} has been {} restarted", jobUUID, type);
}
Aggregations