Exemplo n.º 1
0
  /**
   * @param act
   * @param locale
   * @param exception
   */
  private void sendKrashAuditEmail(Act act, Locale locale, Exception exception) {
    ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
    String emailFrom = bundle.getString(RECIPIENT_KEY);
    String projectName = getProjectNameFromAct(act);

    if (isAllowedToSendKrashReport && CollectionUtils.isNotEmpty(krashReportMailList)) {
      Set<String> emailToSet = new HashSet<>();
      emailToSet.addAll(krashReportMailList);
      String host = "";
      try {
        host = InetAddress.getLocalHost().getHostName();
      } catch (UnknownHostException uhe) {
      }

      String msgSubject = bundle.getString(KRASH_ADMIN_SUBJECT_KEY);
      msgSubject = StringUtils.replace(msgSubject, PROJECT_NAME_TO_REPLACE, projectName);
      msgSubject = StringUtils.replace(msgSubject, HOST_TO_REPLACE, host);

      String msgContent = bundle.getString(KRASH_ADMIN_MSG_CONTENT_KEY);
      msgContent = StringUtils.replace(msgContent, PROJECT_NAME_TO_REPLACE, projectName);
      msgContent =
          StringUtils.replace(
              msgContent, USER_EMAIL_TO_REPLACE, act.getContract().getUser().getEmail1());
      msgContent = StringUtils.replace(msgContent, HOST_TO_REPLACE, host);
      msgContent =
          StringUtils.replace(
              msgContent, EXCEPTION_TO_REPLACE, ExceptionUtils.getStackTrace(exception));
      if (act.getAudit().getSubject() != null) {
        msgContent =
            StringUtils.replace(
                msgContent, AUDIT_URL_TO_REPLACE, act.getAudit().getSubject().getURL());
      }
      LOGGER.info(
          "krash email sent to " + krashReportMailList + " on audit n° " + act.getAudit().getId());
      sendEmail(emailFrom, emailToSet, msgSubject, msgContent);
    }

    String emailTo = act.getContract().getUser().getEmail1();
    if (this.emailSentToUserExclusionList.contains(emailTo)) {
      LOGGER.info("Email not set cause user " + emailTo + " belongs to " + "exlusion list");
      return;
    }
    Set<String> emailToSet = new HashSet<>();
    emailToSet.add(emailTo);
    String msgSubject = bundle.getString(KRASH_SUBJECT_KEY);
    msgSubject = StringUtils.replace(msgSubject, PROJECT_NAME_TO_REPLACE, projectName);
    String msgContent = bundle.getString(KRASH_MSG_CONTENT_KEY);
    msgContent = StringUtils.replace(msgContent, PROJECT_NAME_TO_REPLACE, projectName);
    msgContent =
        StringUtils.replace(
            msgContent, PROJECT_URL_TO_REPLACE, buildContractUrl(act.getContract()));
    LOGGER.info("krash email sent to [" + emailTo + "]" + " on audit n° " + act.getAudit().getId());
    sendEmail(emailFrom, emailToSet, msgSubject, msgContent);
  }
Exemplo n.º 2
0
 /**
  * Send an email when an audit terminates
  *
  * @param act
  * @param locale
  * @param exception
  */
 private void sendAuditResultEmail(Act act, Locale locale) {
   String emailTo = act.getContract().getUser().getEmail1();
   if (this.emailSentToUserExclusionList.contains(emailTo)) {
     LOGGER.info("Email not set cause user " + emailTo + " belongs to " + "exlusion list");
     return;
   }
   ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
   String emailFrom = bundle.getString(RECIPIENT_KEY);
   Set<String> emailToSet = new HashSet<>();
   emailToSet.add(emailTo);
   if (act.getStatus().equals(ActStatus.COMPLETED)) {
     sendSuccessfulMessageOnActTerminated(
         act, bundle, emailFrom, emailToSet, getProjectNameFromAct(act));
   } else if (act.getStatus().equals(ActStatus.ERROR)) {
     sendFailureMessageOnActTerminated(
         act, bundle, emailFrom, emailToSet, getProjectNameFromAct(act));
   }
 }