Exemple #1
0
  private static void setDetails(DocumentModel docModel, DocumentLine line) {
    DocumentDaoImpl dao = DB.getDocumentDao();

    DetailModel detail = new DetailModel();
    if (line.getId() != null) {
      detail = dao.getDetailById(line.getId());
    }

    detail.setName(line.getName());

    detail.getValues().clear();
    Map<String, Value> vals = line.getValues();
    Collection<Value> values = vals.values();
    for (Value val : values) {
      ADValue previousValue = new ADValue();
      if (val.getId() != null) {
        previousValue = DB.getFormDao().getValue(val.getId());
      }

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

    docModel.addDetail(detail);
  }
Exemple #2
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;
  }