Search in sources :

Example 1 with DistributionJobDetailsModel

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

the class StaticJobAccessor method convertToDistributionJobModelFromEntity.

private DistributionJobModel convertToDistributionJobModelFromEntity(DistributionJobEntity distributionJobEntity) {
    DistributionJobModel result;
    ChannelKey channelKey = ChannelKeys.getChannelKey(distributionJobEntity.getChannelDescriptorName());
    if (jobDetailsAccessorMap.containsKey(channelKey)) {
        JobDetailsAccessor2<? extends DistributionJobDetailsModel> accessor = jobDetailsAccessorMap.get(channelKey);
        DistributionJobDetailsModel detailsModel = accessor.retrieveDetails(distributionJobEntity.getJobId()).orElse(null);
        result = convertToDistributionJobModel(distributionJobEntity, detailsModel);
    } else {
        result = convertToDistributionJobModel(distributionJobEntity);
    }
    return result;
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 2 with DistributionJobDetailsModel

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

the class StaticJobAccessor method convertToDistributionJobModel.

@Deprecated
private DistributionJobModel convertToDistributionJobModel(DistributionJobEntity jobEntity) {
    UUID jobId = jobEntity.getJobId();
    DistributionJobDetailsModel distributionJobDetailsModel = null;
    ChannelKey channelKey = ChannelKeys.getChannelKey(jobEntity.getChannelDescriptorName());
    if (ChannelKeys.AZURE_BOARDS.equals(channelKey)) {
        AzureBoardsJobDetailsEntity jobDetails = jobEntity.getAzureBoardsJobDetails();
        distributionJobDetailsModel = new AzureBoardsJobDetailsModel(jobId, jobDetails.getAddComments(), jobDetails.getProjectNameOrId(), jobDetails.getWorkItemType(), jobDetails.getWorkItemCompletedState(), jobDetails.getWorkItemReopenState());
    } else if (ChannelKeys.JIRA_CLOUD.equals(channelKey)) {
        JiraCloudJobDetailsEntity jobDetails = jobEntity.getJiraCloudJobDetails();
        List<JiraJobCustomFieldModel> customFields = jobDetails.getJobCustomFields().stream().map(entity -> new JiraJobCustomFieldModel(entity.getFieldName(), entity.getFieldValue())).collect(Collectors.toList());
        distributionJobDetailsModel = new JiraCloudJobDetailsModel(jobId, jobDetails.getAddComments(), jobDetails.getIssueCreatorEmail(), jobDetails.getProjectNameOrKey(), jobDetails.getIssueType(), jobDetails.getResolveTransition(), jobDetails.getReopenTransition(), customFields, jobDetails.getIssueSummary());
    } else if (ChannelKeys.MS_TEAMS.equals(channelKey)) {
        MSTeamsJobDetailsEntity jobDetails = jobEntity.getMsTeamsJobDetails();
        distributionJobDetailsModel = new MSTeamsJobDetailsModel(jobId, jobDetails.getWebhook());
    } else if (ChannelKeys.SLACK.equals(channelKey)) {
        SlackJobDetailsEntity slackJobDetails = jobEntity.getSlackJobDetails();
        distributionJobDetailsModel = new SlackJobDetailsModel(jobId, slackJobDetails.getWebhook(), slackJobDetails.getChannelName(), slackJobDetails.getChannelUsername());
    }
    return convertToDistributionJobModel(jobEntity, distributionJobDetailsModel);
}
Also used : MSTeamsJobDetailsEntity(com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity) AzureBoardsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.AzureBoardsJobDetailsModel) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) JiraCloudJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JiraCloudJobDetailsEntity(com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity) AzureBoardsJobDetailsEntity(com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) List(java.util.List) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) UUID(java.util.UUID) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)

Example 3 with DistributionJobDetailsModel

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

the class StaticJobAccessor method createJobWithId.

private DistributionJobModel createJobWithId(UUID jobId, DistributionJobRequestModel requestModel, OffsetDateTime createdAt, @Nullable OffsetDateTime lastUpdated) {
    String channelDescriptorName = requestModel.getChannelDescriptorName();
    DistributionJobEntity jobToSave = new DistributionJobEntity(jobId, requestModel.getName(), requestModel.isEnabled(), requestModel.getDistributionFrequency().name(), requestModel.getProcessingType().name(), channelDescriptorName, requestModel.getChannelGlobalConfigId(), createdAt, lastUpdated);
    DistributionJobEntity savedJobEntity = distributionJobRepository.save(jobToSave);
    UUID savedJobId = savedJobEntity.getJobId();
    BlackDuckJobDetailsEntity savedBlackDuckJobDetails = blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(savedJobId, requestModel);
    savedJobEntity.setBlackDuckJobDetails(savedBlackDuckJobDetails);
    DistributionJobDetailsModel distributionJobDetails = requestModel.getDistributionJobDetails();
    if (distributionJobDetails.isA(ChannelKeys.AZURE_BOARDS)) {
        AzureBoardsJobDetailsEntity savedAzureBoardsJobDetails = azureBoardsJobDetailsAccessor.saveAzureBoardsJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.AZURE));
        savedJobEntity.setAzureBoardsJobDetails(savedAzureBoardsJobDetails);
    } else if (distributionJobDetails.isA(ChannelKeys.JIRA_CLOUD)) {
        JiraCloudJobDetailsEntity savedJiraCloudJobDetails = jiraCloudJobDetailsAccessor.saveJiraCloudJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.JIRA_CLOUD));
        savedJobEntity.setJiraCloudJobDetails(savedJiraCloudJobDetails);
    } else if (distributionJobDetails.isA(ChannelKeys.MS_TEAMS)) {
        MSTeamsJobDetailsEntity savedMSTeamsJobDetails = msTeamsJobDetailsAccessor.saveMSTeamsJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.MS_TEAMS));
        savedJobEntity.setMsTeamsJobDetails(savedMSTeamsJobDetails);
    } else if (distributionJobDetails.isA(ChannelKeys.SLACK)) {
        SlackJobDetailsEntity savedSlackJobDetails = slackJobDetailsAccessor.saveSlackJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.SLACK));
        savedJobEntity.setSlackJobDetails(savedSlackJobDetails);
    } else {
        // In the future the contents of this else case should be the complete implementation of this method
        ChannelKey channelKey = ChannelKeys.getChannelKey(channelDescriptorName);
        if (jobDetailsAccessorMap.containsKey(channelKey) && distributionJobDetails.isA(channelKey)) {
            JobDetailsAccessor2<? extends DistributionJobDetailsModel> accessor = jobDetailsAccessorMap.get(channelKey);
            DistributionJobDetailsModel savedJobDetails = accessor.saveJobDetails(savedJobId, distributionJobDetails);
            return convertToDistributionJobModel(savedJobEntity, savedJobDetails);
        }
    }
    return convertToDistributionJobModel(savedJobEntity);
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JiraCloudJobDetailsEntity(com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity) MSTeamsJobDetailsEntity(com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity) JobDetailsAccessor2(com.synopsys.integration.alert.common.persistence.accessor.JobDetailsAccessor2) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AzureBoardsJobDetailsEntity(com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) UUID(java.util.UUID) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)

Example 4 with DistributionJobDetailsModel

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

the class JobFieldModelPopulationUtils method populateChannelFields.

public static void populateChannelFields(FieldModel channelFieldModel, DistributionJobModel jobModel) {
    String channelDescriptorName = jobModel.getChannelDescriptorName();
    putField(channelFieldModel, ChannelDescriptor.KEY_ENABLED, Boolean.toString(jobModel.isEnabled()));
    putField(channelFieldModel, ChannelDescriptor.KEY_NAME, jobModel.getName());
    putField(channelFieldModel, ChannelDescriptor.KEY_CHANNEL_NAME, channelDescriptorName);
    putField(channelFieldModel, ChannelDescriptor.KEY_PROVIDER_TYPE, DEFAULT_PROVIDER_NAME);
    putField(channelFieldModel, ChannelDescriptor.KEY_FREQUENCY, jobModel.getDistributionFrequency().name());
    putField(channelFieldModel, ProviderDescriptor.KEY_PROCESSING_TYPE, jobModel.getProcessingType().name());
    DistributionJobDetailsModel jobDetails = jobModel.getDistributionJobDetails();
    if (jobDetails.isA(ChannelKeys.AZURE_BOARDS)) {
        populateAzureBoardsFields(channelFieldModel, jobDetails.getAs(DistributionJobDetailsModel.AZURE));
    } else if (jobDetails.isA(ChannelKeys.EMAIL)) {
        populateEmailFields(channelFieldModel, jobDetails.getAs(DistributionJobDetailsModel.EMAIL));
    } else if (jobDetails.isA(ChannelKeys.JIRA_CLOUD)) {
        populateJiraCloudFields(channelFieldModel, jobDetails.getAs(DistributionJobDetailsModel.JIRA_CLOUD));
    } else if (jobDetails.isA(ChannelKeys.JIRA_SERVER)) {
        populateJiraServerFields(channelFieldModel, jobDetails.getAs(DistributionJobDetailsModel.JIRA_SERVER));
    } else if (jobDetails.isA(ChannelKeys.MS_TEAMS)) {
        populateMSTeamsField(channelFieldModel, jobDetails.getAs(DistributionJobDetailsModel.MS_TEAMS));
    } else if (jobDetails.isA(ChannelKeys.SLACK)) {
        populateSlackFields(channelFieldModel, jobDetails.getAs(DistributionJobDetailsModel.SLACK));
    }
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)

Example 5 with DistributionJobDetailsModel

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

the class DistributionEventHandlerTest method handleEventSuccessTest.

@Test
public void handleEventSuccessTest() {
    ProcessingAuditAccessor auditAccessor = Mockito.mock(ProcessingAuditAccessor.class);
    Mockito.doNothing().when(auditAccessor).setAuditEntrySuccess(Mockito.any(), Mockito.anySet());
    DistributionJobDetailsModel details = new DistributionJobDetailsModel(null, null) {
    };
    JobDetailsAccessor<DistributionJobDetailsModel> jobDetailsAccessor = x -> Optional.of(details);
    DistributionChannel<DistributionJobDetailsModel> channel = (x, y, z) -> null;
    DistributionEventHandler<DistributionJobDetailsModel> eventHandler = new DistributionEventHandler<>(channel, jobDetailsAccessor, auditAccessor);
    UUID testJobId = UUID.randomUUID();
    Set<Long> testNotificationIds = Set.of(1L, 3L, 5L);
    DistributionEvent testEvent = new DistributionEvent(channelKey, testJobId, "jobName", testNotificationIds, null);
    eventHandler.handle(testEvent);
    Mockito.verify(auditAccessor, Mockito.times(1)).setAuditEntrySuccess(Mockito.eq(testJobId), Mockito.eq(testNotificationIds));
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ProcessingAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProcessingAuditAccessor) Optional(java.util.Optional) Set(java.util.Set) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobDetailsAccessor) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DistributionEvent(com.synopsys.integration.alert.processor.api.distribute.DistributionEvent) DistributionEvent(com.synopsys.integration.alert.processor.api.distribute.DistributionEvent) ProcessingAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProcessingAuditAccessor) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)11 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)6 UUID (java.util.UUID)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)5 Test (org.junit.jupiter.api.Test)5 Optional (java.util.Optional)4 JobDetailsAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobDetailsAccessor)3 ProcessingAuditAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProcessingAuditAccessor)3 DistributionEvent (com.synopsys.integration.alert.processor.api.distribute.DistributionEvent)3 Set (java.util.Set)3 Mockito (org.mockito.Mockito)3 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)2 AzureBoardsJobDetailsEntity (com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity)2 JiraCloudJobDetailsEntity (com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity)2 MSTeamsJobDetailsEntity (com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity)2 SlackJobDetailsEntity (com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)2 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)2 List (java.util.List)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 AbstractChannelMessageConverter (com.synopsys.integration.alert.api.channel.convert.AbstractChannelMessageConverter)1