示例#1
0
  public static ADDocType getType(DocumentType type) {
    DocumentDaoImpl dao = DB.getDocumentDao();

    ADDocType adtype = new ADDocType(type.getId(), type.getName(), type.getDisplayName());

    if (type.getId() != null) {
      adtype = dao.getDocumentTypeById(type.getId());
      adtype.setName(type.getName());
      adtype.setDisplay(type.getDisplayName());
    }

    return adtype;
  }
示例#2
0
  private void sendMail(
      String htmlTemplate, Document doc, List<HTUser> receipients, Map<String, Object> params) {

    if (receipients == null || receipients.isEmpty()) {
      return;
    }

    /**
     * Sending mail
     *
     * <p>Schedule async
     */
    CommandContext context = new CommandContext();
    params.put("callbacks", CommandCodes.SendEmailCallback.name());
    params.put("To", receipients);
    params.put("From", params.get("From") == null ? "*****@*****.**" : params.get("From"));
    params.put(
        "docDate",
        SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM)
            .format(doc.getDocumentDate() == null ? doc.getCreated() : doc.getDocumentDate()));
    DocumentType type = doc.getType();
    params.put("DocType", type.getDisplayName());
    params.put("DocumentURL", getDocUrl(doc.getId()));
    params.put("ownerId", doc.getOwner());

    try {
      if (htmlTemplate == null) {
        InputStream is =
            Thread.currentThread().getContextClassLoader().getResourceAsStream("email.html");
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        IOUtils.copy(is, bout);
        htmlTemplate = new String(bout.toByteArray());
      }

      // Merge params & doc
      for (String key : params.keySet()) {
        doc.setValue(
            key, params.get(key) == null ? null : new StringValue(params.get(key).toString()));
      }
      htmlTemplate = parse(htmlTemplate, doc);

      params.put("Body", htmlTemplate);
    } catch (Exception e) {
      e.printStackTrace();
    }

    params.put("businessKey", UUID.randomUUID().toString());
    context.setData(params);

    log.info("BODY = " + htmlTemplate);
    ExecutorModule.getInstance()
        .getExecutorServiceEntryPoint()
        .scheduleRequest(CommandCodes.SendEmailCommand, context);
  }