Search in sources :

Example 1 with MSTeamsJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel 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 2 with MSTeamsJobDetailsModel

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

the class StaticJobAccessorTestIT method verifyMSTeamsSavesTest.

@Test
public void verifyMSTeamsSavesTest() {
    MSTeamsJobDetailsModel msTeamsJobDetailsModel = new MSTeamsJobDetailsModel(UUID.randomUUID(), "webhook");
    DistributionJobRequestModel jobRequestModel = createJobRequestModel(msTeamsJobDetailsModel, new MsTeamsKey());
    createAndAssertJob(jobRequestModel);
}
Also used : MsTeamsKey(com.synopsys.integration.alert.descriptor.api.MsTeamsKey) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with MSTeamsJobDetailsModel

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

the class StaticJobAccessorTest method createMSTeamsJobTest.

@Test
void createMSTeamsJobTest() {
    UUID jobId = UUID.randomUUID();
    MSTeamsJobDetailsModel msTeamsJobDetailsModel = new MSTeamsJobDetailsModel(jobId, null);
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.MS_TEAMS.getUniversalKey(), msTeamsJobDetailsModel);
    MSTeamsJobDetailsEntity msTeamsJobDetailsEntity = new MSTeamsJobDetailsEntity();
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setMsTeamsJobDetails(msTeamsJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(msTeamsJobDetailsAccessor.saveMSTeamsJobDetails(Mockito.any(), Mockito.any())).thenReturn(msTeamsJobDetailsEntity);
    Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
    DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
    assertEquals(jobId, createdJob.getJobId());
    assertEquals(jobName, createdJob.getName());
}
Also used : MSTeamsJobDetailsEntity(com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 4 with MSTeamsJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel 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 5 with MSTeamsJobDetailsModel

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

the class MsTeamsChannelTest method sendMessageTestIT.

@Test
@Tag(TestTags.DEFAULT_INTEGRATION)
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void sendMessageTestIT() {
    ChannelRestConnectionFactory connectionFactory = createConnectionFactory();
    MarkupEncoderUtil markupEncoderUtil = new MarkupEncoderUtil();
    MSTeamsChannelMessageConverter messageConverter = new MSTeamsChannelMessageConverter(new MSTeamsChannelMessageFormatter(markupEncoderUtil));
    MSTeamsChannelMessageSender messageSender = new MSTeamsChannelMessageSender(ChannelKeys.MS_TEAMS, connectionFactory);
    MSTeamsChannel msTeamsChannel = new MSTeamsChannel(messageConverter, messageSender);
    MSTeamsJobDetailsModel msTeamsJobDetailsModel = new MSTeamsJobDetailsModel(UUID.randomUUID(), properties.getProperty(TestPropertyKey.TEST_MSTEAMS_WEBHOOK));
    MessageResult messageResult = null;
    try {
        messageResult = msTeamsChannel.distributeMessages(msTeamsJobDetailsModel, TEST_MESSAGE_HOLDER, "jobName");
    } catch (AlertException e) {
        Assertions.fail("Failed to distribute simple channel message due to an exception", e);
    }
    Assertions.assertFalse(messageResult.hasErrors(), "The message result had errors");
    Assertions.assertFalse(messageResult.hasWarnings(), "The message result had warnings");
}
Also used : ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) MarkupEncoderUtil(com.synopsys.integration.alert.common.util.MarkupEncoderUtil) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

MSTeamsJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel)5 Test (org.junit.jupiter.api.Test)3 ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)2 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)2 MSTeamsJobDetailsEntity (com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity)2 MsTeamsKey (com.synopsys.integration.alert.descriptor.api.MsTeamsKey)2 List (java.util.List)2 UUID (java.util.UUID)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ChannelMessageSender (com.synopsys.integration.alert.api.channel.ChannelMessageSender)1 RestChannelUtility (com.synopsys.integration.alert.api.channel.rest.RestChannelUtility)1 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)1 AzureBoardsJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.AzureBoardsJobDetailsModel)1 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)1 JiraCloudJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel)1 JiraJobCustomFieldModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel)1 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)1