Search in sources :

Example 6 with NotFoundException

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());
    }
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException) UUID(java.util.UUID)

Example 7 with NotFoundException

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 */
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ValidationResult(com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) DataInputStream(java.io.DataInputStream) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with NotFoundException

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");
}
Also used : NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException) Test(org.junit.Test)

Example 9 with NotFoundException

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;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)

Example 10 with NotFoundException

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);
}
Also used : AlreadyExistsException(com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException) NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)

Aggregations

NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)12 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)3 AlreadyExistsException (com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException)2 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)1 ProjectMetaData (com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData)1 User (com.mercedesbenz.sechub.domain.administration.user.User)1 UserRepository (com.mercedesbenz.sechub.domain.administration.user.UserRepository)1 ProjectAccessCompositeKey (com.mercedesbenz.sechub.domain.scan.access.ScanAccess.ProjectAccessCompositeKey)1 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)1 ScanReport (com.mercedesbenz.sechub.domain.scan.report.ScanReport)1 ScanSecHubReport (com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport)1 ProjectAccessCompositeKey (com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey)1 RoleConstants (com.mercedesbenz.sechub.sharedkernel.RoleConstants)1 Step (com.mercedesbenz.sechub.sharedkernel.Step)1 UserContextService (com.mercedesbenz.sechub.sharedkernel.UserContextService)1 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)1 DomainMessageFactory (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageFactory)1 DomainMessageService (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageService)1