/** * @param id * @return */ public static Document getDocumentByProcessInstance(Long processInstanceId, boolean checkUser) { DocumentDaoImpl dao = DB.getDocumentDao(); DocumentModel model = dao.getDocumentByProcessInstanceId(processInstanceId, checkUser); return getDoc(model); }
public static DocumentType getDocumentType(String docTypeName) { DocumentDaoImpl dao = DB.getDocumentDao(); ADDocType adtype = dao.getDocumentTypeByName(docTypeName); return getType(adtype); }
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); }
public static void getCounts(String userId, HashMap<TaskType, Integer> counts) { DocumentDaoImpl dao = DB.getDocumentDao(); counts.put(TaskType.DRAFT, dao.count(userId, DocStatus.DRAFTED)); // counts.put(TaskType.INPROGRESS, dao.count(DocStatus.INPROGRESS)); // counts.put(TaskType.APPROVED, dao.count(DocStatus.APPROVED)); // counts.put(TaskType.REJECTED, dao.count(DocStatus.REJECTED)); counts.put(TaskType.PARTICIPATED, dao.count(userId, DocStatus.DRAFTED, false)); // counts.put(TaskType.FLAGGED, dao.count(DocStatus.)); }
public static List<Document> search(String userId, SearchFilter filter) { DocumentDaoImpl dao = DB.getDocumentDao(); List<DocumentModel> models = dao.search(userId, filter); List<Document> docs = new ArrayList<>(); for (DocumentModel doc : models) { docs.add(getDoc(doc)); } return docs; }
/** * @param docId * @param isApproved */ public static void saveApproval(Long docId, Boolean isApproved) { DocumentDaoImpl dao = DB.getDocumentDao(); DocumentModel model = dao.getById(docId); if (model == null) { throw new IllegalArgumentException("Cannot Approve/Reject document: Unknown Model"); } model.setStatus(isApproved ? DocStatus.APPROVED : DocStatus.REJECTED); dao.saveDocument(model); }
public static List<Document> search(String subject) { DocumentDaoImpl dao = DB.getDocumentDao(); List<DocumentModel> models = dao.search(subject); List<Document> docs = new ArrayList<>(); for (DocumentModel doc : models) { docs.add(getDoc(doc)); } return docs; }
public static Document getDocument(Long id, boolean checkUser) { DocumentDaoImpl dao = DB.getDocumentDao(); DocumentModel model = null; if (checkUser) { model = dao.getDocumentByIdAndUser(id, SessionHelper.getCurrentUser().getUserId()); } else { model = dao.getById(id); } return getDoc(model); }
public boolean getHasAttachment(Long documentId) { if (documentId == null) { return false; } Long count = (Long) em.createQuery( "Select count(l) FROM LocalAttachment l " + "where l.document= :document") .setParameter("document", DB.getDocumentDao().getById(documentId)) .getSingleResult(); return count > 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; }
public static List<Doc> getAllDocuments(DocStatus... status) { DocumentDaoImpl dao = DB.getDocumentDao(); List<DocumentModel> models = dao.getAllDocuments(status); List<Doc> lst = new ArrayList<>(); for (DocumentModel m : models) { lst.add(getDoc(m)); } return lst; }
public static List<DocumentType> getDocumentTypes() { DocumentDaoImpl dao = DB.getDocumentDao(); List<ADDocType> adtypes = dao.getDocumentTypes(); List<DocumentType> types = new ArrayList<>(); if (adtypes != null) for (ADDocType adtype : adtypes) { types.add(getType(adtype, true)); } return types; }
public static DocumentType getType(ADDocType adtype, boolean loadDetails) { DocumentDaoImpl dao = DB.getDocumentDao(); DocumentType type = new DocumentType( adtype.getId(), adtype.getName(), adtype.getDisplay(), adtype.getClassName()); if (loadDetails) { type.setFormId(dao.getFormId(adtype.getId())); } if (adtype.getProcessDef() != null) { type.setProcessId(adtype.getProcessDef().getProcessId()); } return type; }
/** * 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; }
public static boolean exists(String subject) { DocumentDaoImpl dao = DB.getDocumentDao(); return dao.exists(subject); }
public static void delete(DocumentLine line) { DocumentDaoImpl dao = DB.getDocumentDao(); DetailModel model = dao.getDetailById(line.getId()); dao.delete(model); }
public static Long getProcessInstanceIdByDocumentId(Long documentId) { DocumentDaoImpl dao = DB.getDocumentDao(); return dao.getProcessInstanceIdByDocumentId(documentId); }