Search in sources :

Example 6 with DistributionJobDetailsModel

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

the class EmailTestActionHelper method createUpdatedEmailAddresses.

public Set<String> createUpdatedEmailAddresses(DistributionJobModel distributionJobModel) throws AlertException {
    Set<String> emailAddresses = new HashSet<>();
    DistributionJobDetailsModel distributionJobDetails = distributionJobModel.getDistributionJobDetails();
    EmailJobDetailsModel emailJobDetails = distributionJobDetails.getAs(DistributionJobDetailsModel.EMAIL);
    Long providerConfigId = distributionJobModel.getBlackDuckGlobalConfigId();
    boolean onlyAdditionalEmails = emailJobDetails.isAdditionalEmailAddressesOnly();
    if (null != providerConfigId && !onlyAdditionalEmails) {
        Set<ProviderProject> providerProjects = retrieveProviderProjects(distributionJobModel, providerConfigId);
        if (CollectionUtils.isNotEmpty(providerProjects)) {
            Set<String> providerEmailAddresses = addEmailAddresses(providerConfigId, providerProjects, distributionJobModel, emailJobDetails);
            emailAddresses.addAll(providerEmailAddresses);
        }
    }
    return emailAddresses;
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) HashSet(java.util.HashSet)

Example 7 with DistributionJobDetailsModel

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

the class DistributionJobModelExtractor method convertToJobModel.

public final DistributionJobModel convertToJobModel(UUID jobId, Map<String, ConfigurationFieldModel> configuredFieldsMap, OffsetDateTime createdAt, @Nullable OffsetDateTime lastUpdated, List<BlackDuckProjectDetailsModel> projectFilterDetails) {
    String channelDescriptorName = distributionJobFieldExtractor.extractFieldValueOrEmptyString(ChannelDescriptor.KEY_CHANNEL_NAME, configuredFieldsMap);
    DistributionJobModelBuilder builder = DistributionJobModel.builder().jobId(jobId).enabled(distributionJobFieldExtractor.extractFieldValue(ChannelDescriptor.KEY_ENABLED, configuredFieldsMap).map(Boolean::valueOf).orElse(true)).name(distributionJobFieldExtractor.extractFieldValueOrEmptyString(ChannelDescriptor.KEY_NAME, configuredFieldsMap)).distributionFrequency(distributionJobFieldExtractor.extractFieldValueOrEmptyString(ChannelDescriptor.KEY_FREQUENCY, configuredFieldsMap)).processingType(distributionJobFieldExtractor.extractFieldValueOrEmptyString(ProviderDescriptor.KEY_PROCESSING_TYPE, configuredFieldsMap)).channelDescriptorName(channelDescriptorName).channelGlobalConfigId(distributionJobFieldExtractor.extractFieldValue(ChannelDescriptor.KEY_CHANNEL_GLOBAL_CONFIG_ID, configuredFieldsMap).map(UUID::fromString).orElse(null)).createdAt(createdAt).lastUpdated(lastUpdated).blackDuckGlobalConfigId(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_COMMON_CONFIG_ID, configuredFieldsMap).map(Long::valueOf).orElse(-1L)).filterByProject(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_FILTER_BY_PROJECT, configuredFieldsMap).map(Boolean::valueOf).orElse(false)).projectNamePattern(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_PROJECT_NAME_PATTERN, configuredFieldsMap).orElse(null)).projectVersionNamePattern(distributionJobFieldExtractor.extractFieldValue(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN, configuredFieldsMap).orElse(null)).notificationTypes(distributionJobFieldExtractor.extractFieldValues(ProviderDescriptor.KEY_NOTIFICATION_TYPES, configuredFieldsMap)).policyFilterPolicyNames(distributionJobFieldExtractor.extractFieldValues("blackduck.policy.notification.filter", configuredFieldsMap)).vulnerabilityFilterSeverityNames(distributionJobFieldExtractor.extractFieldValues("blackduck.vulnerability.notification.filter", configuredFieldsMap)).projectFilterDetails(projectFilterDetails);
    DistributionJobDetailsExtractor extractor = jobDetailsExtractorMap.findRequiredAction(channelDescriptorName);
    DistributionJobDetailsModel distributionJobDetailsModel = extractor.extractDetails(jobId, configuredFieldsMap);
    builder.distributionJobDetails(distributionJobDetailsModel);
    return builder.build();
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) DistributionJobModelBuilder(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModelBuilder) UUID(java.util.UUID) DistributionJobDetailsExtractor(com.synopsys.integration.alert.common.persistence.model.job.details.processor.DistributionJobDetailsExtractor)

Example 8 with DistributionJobDetailsModel

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

the class DistributionEventHandlerTest method handleEventJobDetailsMissingTest.

@Test
public void handleEventJobDetailsMissingTest() {
    ProcessingAuditAccessor auditAccessor = Mockito.mock(ProcessingAuditAccessor.class);
    Mockito.doNothing().when(auditAccessor).setAuditEntryFailure(Mockito.any(), Mockito.anySet(), Mockito.anyString(), Mockito.any());
    JobDetailsAccessor<DistributionJobDetailsModel> jobDetailsAccessor = x -> Optional.empty();
    DistributionEventHandler<DistributionJobDetailsModel> eventHandler = new DistributionEventHandler<>(null, 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)).setAuditEntryFailure(Mockito.eq(testJobId), Mockito.eq(testNotificationIds), Mockito.anyString(), Mockito.any());
}
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)

Example 9 with DistributionJobDetailsModel

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

the class DistributionEventHandlerTest method handleEventExceptionTest.

@Test
public void handleEventExceptionTest() {
    ProcessingAuditAccessor auditAccessor = Mockito.mock(ProcessingAuditAccessor.class);
    Mockito.doNothing().when(auditAccessor).setAuditEntryFailure(Mockito.any(), Mockito.anySet(), Mockito.anyString(), Mockito.any());
    DistributionJobDetailsModel details = new DistributionJobDetailsModel(null, null) {
    };
    JobDetailsAccessor<DistributionJobDetailsModel> jobDetailsAccessor = x -> Optional.of(details);
    AlertException testException = new AlertException("Test exception");
    DistributionChannel<DistributionJobDetailsModel> channel = (x, y, z) -> {
        throw testException;
    };
    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)).setAuditEntryFailure(Mockito.eq(testJobId), Mockito.eq(testNotificationIds), Mockito.anyString(), Mockito.any());
}
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) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 10 with DistributionJobDetailsModel

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

the class MessageBoardChannelTest method distributeMessagesTest.

@Test
public void distributeMessagesTest() throws AlertException {
    MessageResult expectedResult = new MessageResult("Test result");
    DistributionJobDetailsModel testDetails = new DistributionJobDetailsModel(null, null) {
    };
    AbstractChannelMessageConverter<DistributionJobDetailsModel, Object> converter = createConverter();
    ChannelMessageSender<DistributionJobDetailsModel, Object, MessageResult> sender = (x, y) -> expectedResult;
    MessageBoardChannel<DistributionJobDetailsModel, Object> messageBoardChannel = new MessageBoardChannel<>(converter, sender) {
    };
    MessageResult testResult = messageBoardChannel.distributeMessages(testDetails, ProviderMessageHolder.empty(), "jobName");
    assertEquals(expectedResult, testResult);
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Test(org.junit.jupiter.api.Test) List(java.util.List) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ChannelMessageFormatter(com.synopsys.integration.alert.api.channel.convert.ChannelMessageFormatter) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) AbstractChannelMessageConverter(com.synopsys.integration.alert.api.channel.convert.AbstractChannelMessageConverter) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) 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