Search in sources :

Example 1 with ProviderMessageHolder

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

the class SlackDistributionEventHandlerTest method createTwoMessages.

private ProviderMessageHolder createTwoMessages() {
    ProviderDetails providerDetails = new ProviderDetails(1L, new LinkableItem("", ""));
    SimpleMessage simpleMessage = SimpleMessage.original(providerDetails, "", "", List.of());
    return new ProviderMessageHolder(List.of(), List.of(simpleMessage, simpleMessage));
}
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 2 with ProviderMessageHolder

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

the class JiraServerExternalConnectionTest method createMessage.

private ProviderMessageHolder createMessage() {
    ProviderDetails providerDetails = new ProviderDetails(1L, new LinkableItem("ProviderLabel", "ProviderName"));
    SimpleMessage simpleMessage = SimpleMessage.original(providerDetails, "Test Summary", "Test Description", List.of());
    return new ProviderMessageHolder(List.of(), List.of(simpleMessage));
}
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 3 with ProviderMessageHolder

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

the class ProjectVersionNotificationMessageExtractorTest method extractTest.

@Test
public void extractTest() throws IntegrationException {
    NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl("https://a.blackduck.server.example.com"));
    Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
    Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.anyLong())).thenReturn(blackDuckServicesFactory);
    ProjectVersionNotificationContent projectVersionNotificationContent = createProjectVersionNotificationContent();
    NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectVersionNotificationContent);
    ProjectVersionNotificationMessageExtractor extractor = new ProjectVersionNotificationMessageExtractor(providerKey, servicesFactoryCache);
    ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectVersionNotificationContent);
    assertEquals(1, providerMessageHolder.getProjectMessages().size());
    assertEquals(0, providerMessageHolder.getSimpleMessages().size());
    ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
    assertEquals(MessageReason.PROJECT_VERSION_STATUS, projectMessage.getMessageReason());
    assertTrue(projectMessage.getOperation().isPresent());
    assertEquals(ProjectOperation.CREATE, projectMessage.getOperation().get());
    assertTrue(projectMessage.getBomComponents().isEmpty());
    assertEquals(PROJECT, projectMessage.getProject().getValue());
    assertTrue(projectMessage.getProject().getUrl().isPresent());
    assertEquals(PROJECT_URL, projectMessage.getProject().getUrl().get());
    assertTrue(projectMessage.getProjectVersion().isPresent());
    LinkableItem projectVersion = projectMessage.getProjectVersion().get();
    assertEquals(PROJECT_VERSION, projectVersion.getValue());
    assertTrue(projectVersion.getUrl().isPresent());
    assertEquals(PROJECT_VERSION_URL, projectVersion.getUrl().get());
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) HttpUrl(com.synopsys.integration.rest.HttpUrl) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Example 4 with ProviderMessageHolder

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

the class ProjectVersionNotificationMessageExtractor method extract.

@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, ProjectVersionNotificationContent notificationContent) {
    AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = alertNotificationModel.getProviderConfigId();
    String providerUrl;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, alertNotificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), notificationContent.getProject());
    LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersion());
    ProjectOperation operation = ProjectOperation.fromOperationType(notificationContent.getOperationType());
    ProjectMessage projectVersionMessage = ProjectMessage.projectVersionStatusInfo(providerDetails, project, projectVersion, operation);
    return new ProviderMessageHolder(List.of(projectVersionMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

Example 5 with ProviderMessageHolder

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

the class ProjectNotificationMessageExtractor method extract.

@Override
protected ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, ProjectNotificationContent notificationContent) {
    AlertNotificationModel alertNotificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = alertNotificationModel.getProviderConfigId();
    String providerUrl;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, alertNotificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), alertNotificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(alertNotificationModel.getProviderConfigId(), providerItem);
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), notificationContent.getProject());
    ProjectOperation operation = ProjectOperation.fromOperationType(notificationContent.getOperationType());
    ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(providerDetails, project, operation);
    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) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)

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