Search in sources :

Example 1 with SendCase

use of com.epam.ta.reportportal.entity.enums.SendCase in project service-api by reportportal.

the class LaunchNotificationSubscriber method sendEmail.

/**
 * Try to send email when it is needed
 *
 * @param launch       Launch to be used
 * @param project      Project
 * @param emailService Mail Service
 */
private void sendEmail(Launch launch, Project project, EmailService emailService, String baseUrl) {
    project.getSenderCases().stream().filter(SenderCase::isEnabled).forEach(ec -> {
        SendCase sendCase = ec.getSendCase();
        boolean successRate = isSuccessRateEnough(launch, sendCase);
        boolean matchedNames = isLaunchNameMatched(launch, ec);
        boolean matchedTags = isAttributesMatched(launch, ec.getLaunchAttributeRules());
        Set<String> recipients = ec.getRecipients();
        if (successRate && matchedNames && matchedTags) {
            String[] recipientsArray = findRecipients(userRepository.findLoginById(launch.getUserId()).orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, launch.getUserId())), recipients);
            try {
                emailService.sendLaunchFinishNotification(recipientsArray, String.format("%s/ui/#%s", baseUrl, project.getName()), project, launch);
            } catch (Exception e) {
                LOGGER.error("Unable to send email.", e);
            }
        }
    });
}
Also used : SendCase(com.epam.ta.reportportal.entity.enums.SendCase) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Aggregations

SendCase (com.epam.ta.reportportal.entity.enums.SendCase)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1