Search in sources :

Example 21 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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 22 with DistributionJobModel

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

the class PhoneHomeTask method retrieveChannelMetadataForJobs.

private Set<String> retrieveChannelMetadataForJobs(List<DistributionJobModel> jobs) {
    Map<String, Integer> createdDistributions = new HashMap<>();
    for (DistributionJobModel job : jobs) {
        String channelName = job.getChannelDescriptorName();
        String providerName = providerKey.getUniversalKey();
        updateMetaDataCount(createdDistributions, channelName);
        updateMetaDataCount(createdDistributions, providerName);
        if (hasAuditSuccess(job.getJobId())) {
            updateMetaDataCount(createdDistributions, channelName + SUCCESS_KEY_PART);
            updateMetaDataCount(createdDistributions, providerName + SUCCESS_KEY_PART);
        }
    }
    return createdDistributions.entrySet().stream().map(entry -> entry.getKey() + "(" + entry.getValue() + ")").collect(Collectors.toSet());
}
Also used : TaskManager(com.synopsys.integration.alert.api.task.TaskManager) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) PhoneHomeClient(com.synopsys.integration.phonehome.PhoneHomeClient) LoggerFactory(org.slf4j.LoggerFactory) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) IntLogger(com.synopsys.integration.log.IntLogger) AboutReader(com.synopsys.integration.alert.web.api.about.AboutReader) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) NameVersion(com.synopsys.integration.util.NameVersion) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) RestApiAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.RestApiAuditAccessor) Gson(com.google.gson.Gson) Map(java.util.Map) PhoneHomeResponse(com.synopsys.integration.phonehome.PhoneHomeResponse) PhoneHomeRequestBodyBuilder(com.synopsys.integration.phonehome.request.PhoneHomeRequestBodyBuilder) ExecutorService(java.util.concurrent.ExecutorService) PhoneHomeRequestBody(com.synopsys.integration.phonehome.request.PhoneHomeRequestBody) BlackDuckPhoneHomeHelper(com.synopsys.integration.blackduck.phonehome.BlackDuckPhoneHomeHelper) ProviderPhoneHomeHandler(com.synopsys.integration.alert.api.provider.ProviderPhoneHomeHandler) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) Logger(org.slf4j.Logger) PhoneHomeService(com.synopsys.integration.phonehome.PhoneHomeService) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Set(java.util.Set) TaskScheduler(org.springframework.scheduling.TaskScheduler) UUID(java.util.UUID) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) GoogleAnalyticsConstants(com.synopsys.integration.phonehome.google.analytics.GoogleAnalyticsConstants) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ProviderKey(com.synopsys.integration.alert.descriptor.api.model.ProviderKey) List(java.util.List) Component(org.springframework.stereotype.Component) StartupScheduledTask(com.synopsys.integration.alert.api.task.StartupScheduledTask) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) HashMap(java.util.HashMap) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 23 with DistributionJobModel

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

the class EmailTestActionHelperTest method verifyProjectsRetrievedWithOnlyVersionPattern.

@Test
public void verifyProjectsRetrievedWithOnlyVersionPattern() throws AlertException {
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    List<ProviderProject> providerProjects = createProviderProjects();
    Mockito.when(providerDataAccessor.getProjectsByProviderConfigId(Mockito.anyLong())).thenReturn(providerProjects);
    Mockito.when(providerDataAccessor.getEmailAddressesForProjectHref(Mockito.anyLong(), Mockito.anyString())).thenAnswer(i -> Set.of(UUID.randomUUID().toString()));
    Mockito.when(providerDataAccessor.getProjectVersionNamesByHref(Mockito.anyLong(), Mockito.anyString(), Mockito.anyInt())).thenReturn(getProjectVersions());
    EmailTestActionHelper emailTestActionHelper = new EmailTestActionHelper(providerDataAccessor);
    DistributionJobModel distributionJobModel = createDistributionJobModel(createDefaultEmailJobDetails(), null, "1.0.*", List.of());
    Set<String> emailAddresses = emailTestActionHelper.createUpdatedEmailAddresses(distributionJobModel);
    assertEquals(providerProjects.size(), emailAddresses.size());
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 24 with DistributionJobModel

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

the class JobConfigActions method findJobFieldModel.

@Override
protected Optional<JobFieldModel> findJobFieldModel(UUID id) {
    Optional<DistributionJobModel> optionalJob = jobAccessor.getJobById(id);
    if (optionalJob.isPresent()) {
        DistributionJobModel distributionJobModel = optionalJob.get();
        List<JobProviderProjectFieldModel> jobProviderProjects = JobFieldModelPopulationUtils.createJobProviderProjects(distributionJobModel);
        providerProjectExistencePopulator.populateJobProviderProjects(distributionJobModel.getBlackDuckGlobalConfigId(), jobProviderProjects);
        JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(distributionJobModel, jobProviderProjects);
        return Optional.of(jobFieldModel);
    }
    return Optional.empty();
}
Also used : JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 25 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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)

Aggregations

DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)52 Test (org.junit.jupiter.api.Test)35 UUID (java.util.UUID)24 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)20 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)15 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)14 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)9 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)8 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)8 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)8 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)7 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)7 OffsetDateTime (java.time.OffsetDateTime)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6