Search in sources :

Example 6 with ProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.

the class LicenseLimitNotificationMessageExtractor method extract.

@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, LicenseLimitNotificationContent notificationContent) {
    AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName());
    ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
    String summary = "License Limit Event";
    List<LinkableItem> details = new LinkedList<>();
    String marketingPageUrl = notificationContent.getMarketingPageUrl();
    if (StringUtils.isNotBlank(marketingPageUrl)) {
        LinkableItem marketingDetail = new LinkableItem("Marketing Page", "Visit", marketingPageUrl);
        details.add(marketingDetail);
    }
    Long usedCodeSize = notificationContent.getUsedCodeSize();
    if (null != usedCodeSize) {
        LinkableItem usedCodeSizeDetail = new LinkableItem("Used Code Size", usedCodeSize.toString());
        details.add(usedCodeSizeDetail);
    }
    Long hardLimit = notificationContent.getHardLimit();
    if (null != hardLimit) {
        LinkableItem hardLimitDetail = new LinkableItem("Hard Limit", hardLimit.toString());
        details.add(hardLimitDetail);
    }
    Long softLimit = notificationContent.getSoftLimit();
    if (null != softLimit) {
        LinkableItem softLimitDetail = new LinkableItem("Soft Limit", softLimit.toString());
        details.add(softLimitDetail);
    }
    SimpleMessage licenseLimitMessage = SimpleMessage.original(providerDetails, summary, notificationContent.getMessage(), details);
    return new ProviderMessageHolder(List.of(), List.of(licenseLimitMessage));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) LinkedList(java.util.LinkedList)

Example 7 with ProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.

the class AbstractBlackDuckComponentConcernMessageExtractor method extract.

@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
    AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = notificationModel.getProviderConfigId();
    String providerUrl;
    List<BomComponentDetails> bomComponentDetails;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
        bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    } catch (IntegrationException e) {
        logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
    Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
    LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
    // FIXME this is where I should put the additional info
    ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
    return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IntegrationException(com.synopsys.integration.exception.IntegrationException) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 8 with ProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.

the class DistributionChannelMessageTestAction method testConfig.

@Override
public final MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
    String topicString = Optional.ofNullable(customTopic).orElse(DEFAULT_TOPIC);
    String messageString = Optional.ofNullable(customMessage).orElse(DEFAULT_MESSAGE);
    D distributionJobDetails = resolveTestDistributionDetails(testJobModel);
    ProviderMessageHolder messages = createTestMessageHolder(testJobModel, topicString, messageString);
    return distributionChannel.distributeMessages(distributionJobDetails, messages, jobName);
}
Also used : ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)

Example 9 with ProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.

the class DistributionChannelMessageTestAction method createTestMessageHolder.

private ProviderMessageHolder createTestMessageHolder(DistributionJobModel testJobModel, String summary, String message) {
    // TODO determine if it's worth it to make a DB call to resolve the provider
    LinkableItem providerItem = new LinkableItem("Provider Label", "Provider Config Name");
    ProviderDetails providerDetails = new ProviderDetails(testJobModel.getBlackDuckGlobalConfigId(), providerItem);
    SimpleMessage testMessage = SimpleMessage.original(providerDetails, summary, message, List.of());
    return new ProviderMessageHolder(List.of(), List.of(testMessage));
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)

Example 10 with ProviderMessageHolder

use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder in project hub-alert by blackducksoftware.

the class AbstractChannelMessageConverterTest method convertToChannelMessagesTest.

@Test
public void convertToChannelMessagesTest() {
    MockChannelMessageFormatter mockChannelMessageFormatter = new MockChannelMessageFormatter(Integer.MAX_VALUE);
    MockChannelMessageConverter mockChannelMessageConverter = new MockChannelMessageConverter(mockChannelMessageFormatter);
    MockDistributionJobDetailsModel jobDetails = new MockDistributionJobDetailsModel(UUID.randomUUID());
    ProviderDetails providerDetails = new ProviderDetails(0L, new LinkableItem("Provider", "Black Duck"));
    ProjectMessage projectCreateMessage = ProjectMessage.projectStatusInfo(providerDetails, new LinkableItem("Project", "A project"), ProjectOperation.CREATE);
    SimpleMessage simpleMessage = SimpleMessage.original(providerDetails, "Summary", "Description", List.of());
    ProviderMessageHolder providerMessageHolder = new ProviderMessageHolder(List.of(projectCreateMessage), List.of(simpleMessage));
    List<MockOutputModel> mockOutputModels = mockChannelMessageConverter.convertToChannelMessages(jobDetails, providerMessageHolder, "jobName");
    assertEquals(2, mockOutputModels.size());
    for (MockOutputModel mockOutputModel : mockOutputModels) {
        assertEquals(1, mockOutputModel.getMessagePieces().size());
    }
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) MockChannelMessageFormatter(com.synopsys.integration.alert.api.channel.convert.mock.MockChannelMessageFormatter) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) Test(org.junit.jupiter.api.Test)

Aggregations

ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)14 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)9 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)8 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)7 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)6 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 Test (org.junit.jupiter.api.Test)5 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)3 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)3 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)2 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)2 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 MockChannelMessageFormatter (com.synopsys.integration.alert.api.channel.convert.mock.MockChannelMessageFormatter)1 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)1 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)1 ProcessedProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder)1 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)1 LicenseLimitNotificationContent (com.synopsys.integration.blackduck.api.manual.component.LicenseLimitNotificationContent)1