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);
}
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);
}
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());
}
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()));
}
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");
}
Aggregations