Exemplo n.º 1
0
  @Override
  public void execute(DelegateExecution oExecution) throws Exception {

    // MultiPartEmail oMultiPartEmail = MultiPartEmail_BaseFromTask(oExecution);
    Mail oMail = Mail_BaseFromTask(oExecution);

    // send the email
    // oMultiPartEmail.send();
    oMail.send();
  }
Exemplo n.º 2
0
  @Override
  public void execute(DelegateExecution oExecution) throws Exception {
    System.setProperty("mail.mime.address.strict", "false");

    // MultiPartEmail oMultiPartEmail = MultiPartEmail_BaseFromTask(oExecution);
    Mail oMail = Mail_BaseFromTask(oExecution);

    String sAttachmentsForSend =
        getStringFromFieldExpression(this.saAttachmentsForSend, oExecution);
    sAttachmentsForSend = sAttachmentsForSend == null ? "" : sAttachmentsForSend;
    LOG.info("(sAttachmentsForSend={})", sAttachmentsForSend);
    List<Attachment> aAttachment = new ArrayList<>();
    String[] asID_Attachment = sAttachmentsForSend.split(",");
    for (String sID_Attachment : asID_Attachment) {
      // log.info("sID_Attachment=" + sID_Attachment);
      if (sID_Attachment != null
          && !"".equals(sID_Attachment.trim())
          && !"null".equals(sID_Attachment.trim())) {
        String sID_AttachmentTrimmed = sID_Attachment.replaceAll("^\"|\"$", "");
        LOG.info("(sID_AttachmentTrimmed={})", sID_AttachmentTrimmed);
        Attachment oAttachment = taskService.getAttachment(sID_AttachmentTrimmed);
        if (oAttachment != null) {
          aAttachment.add(oAttachment);
        }
      } else {
        LOG.warn("(sID_Attachment={})", sID_Attachment);
      }
    }

    if (aAttachment != null && !aAttachment.isEmpty()) {
      InputStream oInputStream_Attachment = null;
      String sFileName = "document";
      String sFileExt = "txt";
      String sDescription = "";
      for (Attachment oAttachment : aAttachment) {
        sFileName = oAttachment.getName();
        String sExt = "";
        int nAt = sFileName.lastIndexOf(".");
        if (nAt >= 0) {
          sExt = sFileName.substring(nAt);
        }
        sFileName = "Attach_" + oAttachment.getId() + sExt; //
        sFileExt = oAttachment.getType().split(";")[0];
        sDescription = oAttachment.getDescription();
        if (sDescription == null || "".equals(sDescription.trim())) {
          sDescription = "(no description)";
        }
        LOG.info(
            "(oAttachment.getId()={}, sFileName={}, sFileExt={}, sDescription={})",
            oAttachment.getId(),
            sFileName,
            sFileExt,
            sDescription);
        oInputStream_Attachment =
            oExecution
                .getEngineServices()
                .getTaskService()
                .getAttachmentContent(oAttachment.getId());
        if (oInputStream_Attachment == null) {
          LOG.error(
              "Attachment with (id={}) doesn't have content associated with it.",
              oAttachment.getId());
          throw new ActivitiObjectNotFoundException(
              "Attachment with id '"
                  + oAttachment.getId()
                  + "' doesn't have content associated with it.",
              Attachment.class);
        }
        DataSource oDataSource = new ByteArrayDataSource(oInputStream_Attachment, sFileExt);
        if (oDataSource == null) {
          LOG.error("Attachment: oDataSource == null");
        }

        // oMail._Attach(oDataSource, sFileName + "." + sFileExt, sDescription);
        oMail._Attach(oDataSource, sFileName, sDescription);

        LOG.info("oMultiPartEmail.attach: Ok!");
      }
    } else {
      LOG.error("aAttachment has nothing!");
      throw new ActivitiObjectNotFoundException("add the file to send");
    }

    // send the email
    // oMultiPartEmail.send();
    oMail.send();
  }