Search in sources :

Example 16 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.

the class AuditEntryHandlerTestIT method getGetAuditInfoForJobIT.

@Test
public void getGetAuditInfoForJobIT() {
    DistributionJobRequestModel jobRequestModel = createJobRequestModel();
    DistributionJobModel job = jobAccessor.createJob(jobRequestModel);
    AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(job.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.eq(auditDescriptorKey))).thenReturn(true);
    AuditEntryActions auditEntryController = createAuditActions(authorizationManager);
    AuditJobStatusModel jobStatusModel = auditEntryController.getAuditInfoForJob(savedAuditEntryEntity.getCommonConfigId()).getContent().orElse(null);
    assertNotNull(jobStatusModel);
}
Also used : AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 17 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.

the class JobConfigActions method createWithoutChecks.

@Override
protected ActionResponse<JobFieldModel> createWithoutChecks(JobFieldModel resource) {
    try {
        Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
        for (FieldModel fieldModel : resource.getFieldModels()) {
            FieldModel beforeSaveEventFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
            Collection<ConfigurationFieldModel> savedFieldsModels = modelConverter.convertToConfigurationFieldModelMap(beforeSaveEventFieldModel).values();
            configurationFieldModels.addAll(savedFieldsModels);
        }
        List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
        DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, DateUtils.createCurrentDateTimestamp(), null);
        DistributionJobModel savedJob = jobAccessor.createJob(jobRequestModel);
        JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
        Set<FieldModel> updatedFieldModels = new HashSet<>();
        for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
            FieldModel updatedModel = fieldModelProcessor.performAfterSaveAction(fieldModel);
            updatedFieldModels.add(updatedModel);
        }
        savedJobFieldModel.setFieldModels(updatedFieldModels);
        return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
    } catch (AlertException ex) {
        logger.error("Error creating job", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet)

Example 18 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.

the class JobConfigActions method updateWithoutChecks.

@Override
protected ActionResponse<JobFieldModel> updateWithoutChecks(UUID id, JobFieldModel resource) {
    try {
        Optional<DistributionJobModel> jobModel = jobAccessor.getJobById(id);
        if (jobModel.isPresent()) {
            DistributionJobModel previousJob = jobModel.get();
            JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(previousJob);
            Map<String, FieldModel> descriptorAndContextToPreviousFieldModel = new HashMap<>();
            for (FieldModel previousJobFieldModel : jobFieldModel.getFieldModels()) {
                descriptorAndContextToPreviousFieldModel.put(previousJobFieldModel.getDescriptorName() + previousJobFieldModel.getContext(), previousJobFieldModel);
            }
            Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
            for (FieldModel fieldModel : resource.getFieldModels()) {
                FieldModel beforeUpdateEventFieldModel = fieldModelProcessor.performBeforeUpdateAction(fieldModel);
                String beforeFieldModelId = beforeUpdateEventFieldModel.getId();
                Long fieldModelId = (StringUtils.isNotBlank(beforeFieldModelId)) ? Long.parseLong(beforeFieldModelId) : null;
                Collection<ConfigurationFieldModel> updatedFieldModels = fieldModelProcessor.fillFieldModelWithExistingData(fieldModelId, beforeUpdateEventFieldModel);
                configurationFieldModels.addAll(updatedFieldModels);
            }
            List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
            DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, previousJob.getCreatedAt(), DateUtils.createCurrentDateTimestamp());
            DistributionJobModel savedJob = jobAccessor.updateJob(previousJob.getJobId(), jobRequestModel);
            JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
            Set<FieldModel> updatedFieldModels = new HashSet<>();
            for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
                FieldModel previousFieldModel = descriptorAndContextToPreviousFieldModel.get(fieldModel.getDescriptorName() + fieldModel.getContext());
                FieldModel updatedModel = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, fieldModel);
                updatedFieldModels.add(updatedModel);
            }
            savedJobFieldModel.setFieldModels(updatedFieldModels);
            return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
        } else {
            return new ActionResponse<>(HttpStatus.NOT_FOUND);
        }
    } catch (AlertException ex) {
        logger.error("Error creating job", ex);
        return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) HashSet(java.util.HashSet)

Example 19 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.

the class BlackDuckJobDetailsAccessorTest method saveBlackDuckJobDetailsTest.

@Test
public void saveBlackDuckJobDetailsTest() {
    UUID jobId = UUID.randomUUID();
    DistributionJobRequestModel distributionJobRequestModel = new DistributionJobRequestModel(true, jobName, FrequencyType.DAILY, ProcessingType.DEFAULT, null, UUID.randomUUID(), 3L, true, "*", "*", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = new BlackDuckJobDetailsEntity(jobId, distributionJobRequestModel.getBlackDuckGlobalConfigId(), distributionJobRequestModel.isFilterByProject(), distributionJobRequestModel.getProjectNamePattern().orElse(null), distributionJobRequestModel.getProjectVersionNamePattern().orElse(null));
    BlackDuckJobNotificationTypeEntity blackDuckJobNotificationTypeEntity = new BlackDuckJobNotificationTypeEntity(jobId, "testNotificationType");
    BlackDuckJobProjectEntity blackDuckJobProjectEntity = new BlackDuckJobProjectEntity();
    BlackDuckJobPolicyFilterEntity blackDuckJobPolicyFilterEntity = new BlackDuckJobPolicyFilterEntity();
    BlackDuckJobVulnerabilitySeverityFilterEntity blackDuckJobVulnerabilitySeverityFilterEntity = new BlackDuckJobVulnerabilitySeverityFilterEntity();
    Mockito.when(blackDuckJobDetailsRepository.save(Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(blackDuckJobNotificationTypeRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobNotificationTypeEntity));
    Mockito.when(blackDuckJobProjectRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobProjectEntity));
    Mockito.when(blackDuckJobPolicyFilterRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobPolicyFilterEntity));
    Mockito.when(blackDuckJobVulnerabilitySeverityFilterRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobVulnerabilitySeverityFilterEntity));
    BlackDuckJobDetailsEntity createdBlackDuckJobDetailsEntity = blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(jobId, distributionJobRequestModel);
    Mockito.verify(blackDuckJobNotificationTypeRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    Mockito.verify(blackDuckJobProjectRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    Mockito.verify(blackDuckJobPolicyFilterRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    Mockito.verify(blackDuckJobVulnerabilitySeverityFilterRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    assertEquals(jobId, createdBlackDuckJobDetailsEntity.getJobId());
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobNotificationTypes().size());
    assertEquals(blackDuckJobNotificationTypeEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobNotificationTypes().get(0));
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobProjects().size());
    assertEquals(blackDuckJobProjectEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobProjects().get(0));
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobPolicyFilters().size());
    assertEquals(blackDuckJobPolicyFilterEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobPolicyFilters().get(0));
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobVulnerabilitySeverityFilters().size());
    assertEquals(blackDuckJobVulnerabilitySeverityFilterEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobVulnerabilitySeverityFilters().get(0));
}
Also used : BlackDuckJobVulnerabilitySeverityFilterEntity(com.synopsys.integration.alert.database.job.blackduck.vulnerability.BlackDuckJobVulnerabilitySeverityFilterEntity) BlackDuckJobProjectEntity(com.synopsys.integration.alert.database.job.blackduck.projects.BlackDuckJobProjectEntity) BlackDuckJobNotificationTypeEntity(com.synopsys.integration.alert.database.job.blackduck.notification.BlackDuckJobNotificationTypeEntity) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) BlackDuckJobPolicyFilterEntity(com.synopsys.integration.alert.database.job.blackduck.policy.BlackDuckJobPolicyFilterEntity) Test(org.junit.jupiter.api.Test)

Example 20 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.

the class JobNotificationMapperTestIT method extractJobsWithMatchingProjectNamePatternFilter.

@Test
public void extractJobsWithMatchingProjectNamePatternFilter() {
    createJobs(List.of(new DistributionJobRequestModel(true, "name", FrequencyType.REAL_TIME, ProcessingType.DIGEST, ChannelKeys.SLACK.getUniversalKey(), UUID.randomUUID(), 0L, true, // Regex to verify we retrieve notifications without a number in the name (PROJECT_NAME_1)
    "^([^0-9]*)$", null, List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of(), new SlackJobDetailsModel(null, "webhook", "channelName", "username"))));
    testProjectJob();
}
Also used : SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)34 Test (org.junit.jupiter.api.Test)25 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)18 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 UUID (java.util.UUID)10 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)7 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)7 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)6 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)6 ArrayList (java.util.ArrayList)6 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)4 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)4 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)3