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); }
/** * @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); }
/** * @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; }
@Override public void execute( GetTaskCompletionRequest action, BaseResponse actionResult, ExecutionContext execContext) throws ActionException { GetTaskCompletionResponse response = (GetTaskCompletionResponse) actionResult; response.setData(DB.getDashboardDao().getTaskCompletionData()); }
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 DSConfiguration save(DSConfiguration configuration) { DSConfigDaoImpl dao = DB.getDSConfigDao(); DataSourceConfig configModel = get(configuration); dao.save(configModel); configuration = get(configModel); return configuration; }
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 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<DSConfiguration> getConfigurations() { DSConfigDaoImpl dao = DB.getDSConfigDao(); List<DSConfiguration> configurations = new ArrayList<>(); List<DataSourceConfig> models = dao.getConfigurations(); for (DataSourceConfig model : models) { configurations.add(get(model)); } return configurations; }
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 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 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; }
private static DataSourceConfig get(DSConfiguration configuration) { DSConfigDaoImpl dao = DB.getDSConfigDao(); DataSourceConfig model = new DataSourceConfig(); if (configuration.getId() != null) { model = dao.getConfiguration(configuration.getId()); } model.setId(configuration.getId()); model.setDriver(configuration.getDriver()); model.setJNDI(configuration.isJNDI()); model.setJNDIName(configuration.getJNDIName()); model.setRDBMS(configuration.getRDBMS()); model.setPassword(configuration.getPassword()); model.setUser(configuration.getUser()); model.setURL(configuration.getURL()); model.setConfigName(configuration.getName()); return model; }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { // super.doGet(req, resp); HttpSession session = null; Request wiraRequest = new Request(); try { session = request.getSession(true); SessionHelper.setHttpRequest(request); } catch (Exception e) { e.printStackTrace(); } Response response = new Response(); try { DB.beginTransaction(); wiraRequest.setCommandName(IncomingRequestImpl.NEWAPPROVALREQUESTCOMMAND); String parameter = request.getParameter("docType"); RequestType requestType = RequestType.getRequestType(parameter); // Create Context and set it wiraRequest.setContext(createContext(request, requestType, wiraRequest)); HTUser user = new HTUser(); user.setUserId(wiraRequest.getContext("ownerId").toString()); if (session != null) session.setAttribute(ServerConstants.USER, user); // Submit IncomingRequestImpl handler = new IncomingRequestImpl(); handler.executeClientRequest(wiraRequest, response); // Response PrintWriter out = resp.getWriter(); BusinessKey key = response.getBusinessKey(); assert key != null; resp.setContentType("text/json"); out.println( "Response:" + key.getDocumentId() + " : " + key.getProcessInstanceId() + ":" + key.getSessionId() + "</b>"); out.close(); DB.commitTransaction(); } catch (Exception e) { DB.rollback(); e.printStackTrace(); throw new RuntimeException(e); } finally { if (session != null) { session.invalidate(); } DB.closeSession(); SessionHelper.setHttpRequest(null); JBPMHelper.clearRequestData(); } }
/** * 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 boolean delete(Long configurationId) { DSConfigDaoImpl dao = DB.getDSConfigDao(); dao.delete(dao.getConfiguration(configurationId)); return true; }
public static Long getProcessInstanceIdByDocumentId(Long documentId) { DocumentDaoImpl dao = DB.getDocumentDao(); return dao.getProcessInstanceIdByDocumentId(documentId); }
public static List<KeyValuePair> getKeyValuePairs() { DSConfigDaoImpl dao = DB.getDSConfigDao(); List<KeyValuePair> lst = dao.getKeyValuePairs(); return lst; }
public static DSConfiguration getConfigurationByName(String configName) { DSConfigDaoImpl dao = DB.getDSConfigDao(); DSConfiguration config = get(dao.getConfigurationByName(configName)); return config; }