Search in sources :

Example 1 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class MSTeamsChannelMessageSender method sendMessages.

@Override
public MessageResult sendMessages(MSTeamsJobDetailsModel msTeamsJobDetailsModel, List<MSTeamsChannelMessageModel> channelMessages) throws AlertException {
    String webhook = msTeamsJobDetailsModel.getWebhook();
    Map<String, String> requestHeaders = new HashMap<>();
    requestHeaders.put("Content-Type", "application/json");
    IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
    RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
    List<Request> messageRequests = channelMessages.stream().map(this::createJsonString).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
    restChannelUtility.sendMessage(messageRequests, msTeamsKey.getUniversalKey());
    return new MessageResult(String.format("Successfully sent %d MSTeams message(s)", channelMessages.size()));
}
Also used : JsonObject(com.google.gson.JsonObject) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) ChannelMessageSender(com.synopsys.integration.alert.api.channel.ChannelMessageSender) List(java.util.List) Component(org.springframework.stereotype.Component) JsonArray(com.google.gson.JsonArray) Map(java.util.Map) MsTeamsKey(com.synopsys.integration.alert.descriptor.api.MsTeamsKey) HashMap(java.util.HashMap) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult)

Example 2 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class AzureBoardsGlobalFieldModelTestAction method testConfig.

@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
    try {
        Optional<ConfigurationFieldModel> configurationFieldModel = registeredFieldValues.getField(AzureBoardsDescriptor.KEY_ORGANIZATION_NAME);
        String organizationName = configurationFieldModel.flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
        AzureBoardsProperties azureBoardsProperties = AzureBoardsProperties.fromFieldAccessor(azureBoardsCredentialDataStoreFactory, azureRedirectUrlCreator.createOAuthRedirectUri(), registeredFieldValues);
        AzureHttpService azureHttpService = createAzureHttpService(azureBoardsProperties);
        AzureProjectService azureProjectService = new AzureProjectService(azureHttpService, new AzureApiVersionAppender());
        azureProjectService.getProjects(organizationName);
        return new MessageResult("Successfully connected to Azure instance.");
    } catch (HttpServiceException ex) {
        logger.error("Global Test Action failed testing Azure Boards connection.", ex);
        throw (ex);
    }
}
Also used : HttpServiceException(com.synopsys.integration.azure.boards.common.http.HttpServiceException) AzureApiVersionAppender(com.synopsys.integration.azure.boards.common.http.AzureApiVersionAppender) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AzureHttpService(com.synopsys.integration.azure.boards.common.http.AzureHttpService) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AzureProjectService(com.synopsys.integration.azure.boards.common.service.project.AzureProjectService) AzureBoardsProperties(com.synopsys.integration.alert.channel.azure.boards.AzureBoardsProperties)

Example 3 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class BlackDuckDistributionFieldModelTestActionTest method testConfigWithOnlyProjectVersionNamePatternTest.

@Test
public void testConfigWithOnlyProjectVersionNamePatternTest() throws IntegrationException {
    FieldUtility fieldUtility = createFieldUtilityData(null, "1.0.*");
    BlackDuckDistributionFieldModelTestAction testAction = createTestAction();
    MessageResult messageResult = testAction.testConfig(null, null, fieldUtility);
    assertNotNull(messageResult);
    assertFalse(messageResult.hasErrors(), messageResult.getFieldStatusesBySeverity(FieldStatusSeverity.ERROR).toString());
    assertFalse(messageResult.hasWarnings(), messageResult.getFieldStatusesBySeverity(FieldStatusSeverity.WARNING).toString());
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) Test(org.junit.jupiter.api.Test)

Example 4 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class BlackDuckDistributionFieldModelTestActionTest method testConfigWithProjectVersionAndProjectNamePatternsTest.

@Test
public void testConfigWithProjectVersionAndProjectNamePatternsTest() throws IntegrationException {
    FieldUtility fieldUtility = createFieldUtilityData("na.*", "1.0.*");
    BlackDuckDistributionFieldModelTestAction testAction = createTestAction();
    MessageResult messageResult = testAction.testConfig(null, null, fieldUtility);
    assertNotNull(messageResult);
    assertFalse(messageResult.hasErrors(), messageResult.getFieldStatusesBySeverity(FieldStatusSeverity.ERROR).toString());
    assertFalse(messageResult.hasWarnings(), messageResult.getFieldStatusesBySeverity(FieldStatusSeverity.WARNING).toString());
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) Test(org.junit.jupiter.api.Test)

Example 5 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class BlackDuckDistributionFieldModelTestActionTest method testConfigWithProjectVersionAndProjectNamePatternsNotMatchingTest.

@Test
public void testConfigWithProjectVersionAndProjectNamePatternsNotMatchingTest() throws IntegrationException {
    FieldUtility fieldUtility = createFieldUtilityData("fake*", "wrong");
    BlackDuckDistributionFieldModelTestAction testAction = createTestAction();
    MessageResult messageResult = testAction.testConfig(null, null, fieldUtility);
    assertNotNull(messageResult);
    assertFalse(messageResult.hasErrors(), messageResult.getFieldStatusesBySeverity(FieldStatusSeverity.ERROR).toString());
    assertTrue(messageResult.hasWarnings(), messageResult.getFieldStatusesBySeverity(FieldStatusSeverity.WARNING).toString());
    assertEquals(2, messageResult.getFieldStatuses().size(), messageResult.getFieldStatuses().toString());
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) Test(org.junit.jupiter.api.Test)

Aggregations

MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)39 Test (org.junit.jupiter.api.Test)25 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)22 List (java.util.List)12 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)11 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)10 UUID (java.util.UUID)9 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)8 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)8 OffsetDateTime (java.time.OffsetDateTime)8 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)7 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)7 IssueTrackerMessageSender (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender)6 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)6 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)6 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)6 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)6 IssueTrackerMessageSenderFactory (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSenderFactory)5 FrequencyType (com.synopsys.integration.alert.common.enumeration.FrequencyType)5 ProcessingType (com.synopsys.integration.alert.common.enumeration.ProcessingType)5