Ejemplo n.º 1
0
  /**
   * @param content
   * @return
   */
  public static Document getDocument(Map<String, Object> content) {
    Document doc = new Document();
    if (content.get("documentOut") != null) {

      doc = (Document) content.get("documentOut");
      System.out.println("(1) ::" + doc.getCaseNo());
    } else if (content.get("document") != null) {

      doc = (Document) content.get("document");
      System.out.println("(2) :: " + doc.getCaseNo());

    } else {
      // System.err.println("DocumentDaoHelper.getDocument says Document is null!!");
      String description =
          content.get("description") == null ? null : (String) content.get("description");

      String subject = content.get("subject") == null ? null : (String) content.get("subject");
      if (subject == null) {
        subject = content.get("caseNo") == null ? null : (String) content.get("caseNo");
      }

      String value = content.get("value") == null ? null : (String) content.get("value");

      Integer priority = content.get("priority") == null ? null : (Integer) content.get("priority");

      doc.setDescription(description);
      doc.setCaseNo(subject);
      doc.setValue(value);
      doc.setPriority(priority);
      System.out.println("(3) :: " + doc.getCaseNo());
    }

    if (doc.getId() == null) {

      Object idStr = content.get("documentId");
      if (idStr == null || idStr.equals("null")) {
        idStr = null;
      }
      Long id = idStr == null ? null : new Long(idStr.toString());
      doc.setId(id);
    }

    return doc;
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 3
0
  public void sendNotification(ADTaskNotification template, Map<String, Object> params) {

    String caseNo = null;
    String noteType = null;
    String documentId = null;
    String groupId = null;
    String actorId = null;
    String ownerId = null;
    Object isApproved = null;
    String html = null;

    if (template != null
        && !template.isUseDefaultNotification()
        && template.getNotificationTemplate() != null) {
      html = template.getNotificationTemplate();
    }

    caseNo = (String) params.get("Subject");
    // noteType = (String) params.get("NotificationType");
    // NotificationType type = NotificationType.valueOf(noteType);
    documentId = (String) params.get("DocumentId");
    groupId = (String) params.get("GroupId");
    actorId = (String) params.get("ActorId");
    ownerId = (String) params.get("OwnerId");
    // isApproved = params.get("isApproved");

    String[] groups = null;
    if (groupId != null) {
      groups = groupId.split(",");
    }

    Document doc = params.get("document") == null ? null : (Document) params.get("document");
    try {
      doc = DocumentDaoHelper.getDocument(Long.parseLong(documentId));
    } catch (Exception e) {
    }

    log.debug("Class : " + this.getClass());
    log.debug("Subject : " + caseNo);
    log.debug("NotificationType : " + noteType);
    log.debug("DocumentId : " + documentId);
    log.debug("GroupId : " + groupId);
    log.debug("ActorId : " + actorId);
    log.debug("OwnerId : " + ownerId);

    List<HTUser> receipients = null;

    // notification.setTargetUserId(targetUserId);
    if (actorId != null && !actorId.trim().isEmpty()) {
      receipients = new ArrayList<>();
      receipients.add(LoginHelper.get().getUser(actorId));
    } else if (groups != null) {
      receipients = LoginHelper.get().getUsersForGroups(groups);
    }

    //		List<HTUser> owner = new ArrayList<>();
    //		owner.add(LoginHelper.get().getUser(ownerId));

    String emailSubject =
        (doc.getType() == null ? "Work item" : doc.getType().getDisplayName())
            + " "
            + doc.getCaseNo();
    if (template != null) {
      emailSubject = parse(template.getSubject(), doc);
    }

    params.put("emailSubject", emailSubject);
    sendMail(html, doc, receipients, params);
    log.info("EMAILSUBJECT = " + emailSubject);
    log.info("EMAILRECIEPIENTS = " + receipients);
  }
Ejemplo n.º 4
0
  /**
   * This method saves updates a document
   *
   * @param document
   * @return Document
   * @throws InvalidSubjectExeption
   */
  public static Document save(Document document) throws InvalidSubjectExeption {

    DocumentDaoImpl dao = DB.getDocumentDao();

    // save
    if (document.getId() == null) {
      if (exists(document.getCaseNo())) {
        throw new InvalidSubjectExeption(
            "Case '" + document.getCaseNo() + "' already exists, this number cannot be reused");
      }

      if (document.getCaseNo() == null) {
        ADDocType type = dao.getDocumentTypeByName(document.getType().getName());
        document.setCaseNo(dao.generateDocumentSubject(type));

        Value value = document.getValues().get("caseNo");
        if (value == null) {
          value = new StringValue(null, "caseNo", "");
        }
        value.setValue(document.getCaseNo());
        document.setValue("caseNo", value);
      }

      if (document.getDescription() == null) {
        document.setDescription(document.getCaseNo());
        Value value = document.getValues().get("description");
        if (value == null) {
          value = new StringValue(null, "description", "");
        }
        value.setValue(document.getCaseNo());
        document.getValues().put("description", value);
      }
    }
    DocumentModel model = getDoc(document);

    if (document.getId() != null) {
      model = dao.getById(document.getId());
      model.setDescription(document.getDescription());
      model.setDocumentDate(document.getDocumentDate());
      model.setPartner(document.getPartner());
      model.setPriority(document.getPriority());
      model.setSubject(document.getCaseNo());
      model.setType(getType(document.getType()));
      model.setValue(document.getValue());
      model.setStatus(document.getStatus());
      model.setProcessInstanceId(document.getProcessInstanceId());
      model.setSessionId(document.getSessionId());
    }

    model.getValues().clear();
    Map<String, Value> vals = document.getValues();
    Collection<Value> values = vals.values();
    for (Value val : values) {
      if (val == null || (val instanceof GridValue)) {
        // Ignore
        continue;
      }

      ADValue previousValue = new ADValue();
      if (val.getId() != null) {
        previousValue = DB.getFormDao().getValue(val.getId());
      }

      ADValue adValue = getValue(previousValue, val);
      assert adValue != null;
      model.addValue(adValue);
    }

    // setDetails
    setDetails(model, document.getDetails());

    model = dao.saveDocument(model);

    Document doc = getDoc(model);

    return doc;
  }
Ejemplo n.º 5
0
  /**
   * @param document
   * @return
   */
  private static DocumentModel getDoc(Document document) {
    DocumentModel model =
        new DocumentModel(
            document.getId(),
            document.getCaseNo(),
            document.getDescription(),
            getType(document.getType()));

    model.setDocumentDate(document.getDocumentDate());
    model.setPartner(document.getPartner());
    model.setPriority(document.getPriority());
    model.setValue(document.getValue());
    model.setCreated(document.getCreated());
    model.setStatus(document.getStatus());
    model.setProcessInstanceId(document.getProcessInstanceId());
    model.setSessionId(document.getSessionId());

    return model;
  }
Ejemplo n.º 6
0
  /**
   * @param model
   * @return
   */
  public static Document getDoc(DocumentModel model) {
    if (model == null) {
      return null;
    }
    Document doc = new Document();
    doc.setCreated(model.getCreated());
    doc.setDescription(model.getDescription());
    doc.setDocumentDate(model.getDocumentDate());
    doc.setId(model.getId());
    doc.setOwner(LoginHelper.get().getUser(model.getCreatedBy()));
    doc.setCaseNo(model.getSubject());
    doc.setType(getType(model.getType()));
    doc.setDocumentDate(model.getDocumentDate());
    doc.setPartner(model.getPartner());
    doc.setPriority(model.getPriority());
    doc.setValue(model.getValue());
    doc.setStatus(model.getStatus());
    doc.setProcessInstanceId(model.getProcessInstanceId());

    if (model.getProcessInstanceId() != null) {
      ProcessInstanceLog log =
          JPAProcessInstanceDbLog.findProcessInstance(model.getProcessInstanceId());
      if (log != null) doc.setDateSubmitted(log.getStart());
    }

    if (model.getProcessInstanceId() != null) {
      try {
        JBPMHelper.get().loadProgressInfo(doc, model.getProcessInstanceId());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (model.getProcessId() == null && model.getType() != null) {
      doc.setProcessId(model.getType().getProcessDef().getProcessId());
    } else {
      doc.setProcessId(model.getProcessId());
    }

    if (doc.getProcessId() != null) {
      doc.setProcessName(JBPMHelper.get().getProcessName(doc.getProcessId()));
    }

    doc.setSessionId(model.getSessionId());
    doc.setHasAttachment(DB.getAttachmentDao().getHasAttachment(model.getId()));
    Collection<ADValue> values = model.getValues();
    if (values != null) {
      for (ADValue val : values) {
        // val.
        DataType type = getDataType(val);

        doc.setValue(val.getFieldName(), getValue(val, type));
      }
    }

    doc.setDetails(getDetails(model.getDetails()));

    return doc;
  }