/** * @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; }
public List<ActiveNodeInfo> getActiveNodeInfo(String instanceId) { ProcessInstanceLog processInstance = JPAProcessInstanceDbLog.findProcessInstance(new Long(instanceId)); if (processInstance == null) { throw new IllegalArgumentException("Could not find process instance " + instanceId); } Map<String, NodeInstanceLog> nodeInstances = new HashMap<String, NodeInstanceLog>(); for (NodeInstanceLog nodeInstance : JPAProcessInstanceDbLog.findNodeInstances(new Long(instanceId))) { if (nodeInstance.getType() == NodeInstanceLog.TYPE_ENTER) { nodeInstances.put(nodeInstance.getNodeInstanceId(), nodeInstance); } else { nodeInstances.remove(nodeInstance.getNodeInstanceId()); } } if (!nodeInstances.isEmpty()) { List<ActiveNodeInfo> result = new ArrayList<ActiveNodeInfo>(); for (NodeInstanceLog nodeInstance : nodeInstances.values()) { boolean found = false; DiagramInfo diagramInfo = getDiagramInfo(processInstance.getProcessId()); for (DiagramNodeInfo nodeInfo : diagramInfo.getNodeList()) { if (nodeInfo.getName().equals("id=" + nodeInstance.getNodeId())) { result.add( new ActiveNodeInfo(diagramInfo.getWidth(), diagramInfo.getHeight(), nodeInfo)); found = true; break; } } if (!found) { throw new IllegalArgumentException( "Could not find info for node " + nodeInstance.getNodeId() + " of process " + processInstance.getProcessId()); } } return result; } return null; }
@Override public void completeTask( Long id, String assignee, String outcome, Map<String, Object> variables) { // should be handled upstream in controller assert (assignee != null); log.debug(assignee + " starting task with ID: " + id); BlockingGetTaskResponseHandler getTaskResponseHandler = new BlockingGetTaskResponseHandler(); taskClient.getTask(id, getTaskResponseHandler); org.jbpm.task.Task task = getTaskResponseHandler.getTask(); // convert to COW task so we can verify the decision Task cowTask = converter.convert(task, Task.class); if (cowTask.getOutcomes() != null && cowTask.getOutcomes().size() > 0) { // This is a decision task! if (outcome == null) { throw new RuntimeException("ERROR: no decision provided for a Decision task"); } if (!cowTask.getOutcomes().contains(outcome)) { throw new RuntimeException("ERROR: decision value " + outcome + " is not a valid choice."); } } BlockingGetContentResponseHandler getContentResponseHandler = new BlockingGetContentResponseHandler(); taskClient.getContent(task.getTaskData().getDocumentContentId(), getContentResponseHandler); Content inputContent = getContentResponseHandler.getContent(); Map<String, Object> inputMap = (Map<String, Object>) ContentMarshallerHelper.unmarshall(inputContent.getContent(), null); for (Map.Entry<String, Object> entry : inputMap.entrySet()) { log.debug(entry.getKey() + " = " + entry.getValue()); } Map<String, Object> outputMap = new HashMap<String, Object>(); // put Outcome into the outputMap // The InputMap contains a variable that tells us what key to use if (inputMap.get(DECISION_VAR_NAME) != null) { log.debug("Decision outcome: " + outcome); outputMap.put((String) inputMap.get(DECISION_VAR_NAME), outcome); } Map<String, Object> outputVarsMap = new HashMap<String, Object>(); // NOTE: obtaining the map from the Task results in a copy of the map as of the // time when the task became available. It's possible that in the meantime (e.g. due to // a parallel task) the map has been altered. // Map<String, Object> inputVarsMap = (Map<String, Object>) // inputMap.get(TASK_INPUT_VARIABLES_NAME); // So, instead, we get the current values directly from the process instance, rather than the // values copied into the task Long processInstanceId = task.getTaskData().getProcessInstanceId(); Map<String, Object> inputVarsMap = null; try { WorkflowProcessInstance pi = (WorkflowProcessInstance) kSession.getProcessInstance(processInstanceId); inputVarsMap = (Map<String, Object>) pi.getVariable(VARIABLES_PROPERTY); } catch (Exception e) { // not an active process? look in the dB. log.error(e); List<VariableInstanceLog> vars = JPAProcessInstanceDbLog.findVariableInstances(processInstanceId, VARIABLES_PROPERTY); log.info("variable count: " + vars.size()); if (vars.size() > 0) { // why more than one??? inputVarsMap = (Map<String, Object>) vars.get(0); } } if (inputVarsMap != null) { // initialize the output map with the input values log.debug("Copying input map: " + inputVarsMap); outputVarsMap.putAll(inputVarsMap); } if (variables != null && variables.size() > 0) { log.debug("Adding variables: " + variables); // update with any new or modified values outputVarsMap.putAll(variables); } if (outputVarsMap.size() > 0) { log.debug("Adding map to output"); outputMap.put(TASK_OUTPUT_VARIABLES_NAME, outputVarsMap); } // start the task if (task.getTaskData().getStatus().equals(org.jbpm.task.Status.Reserved)) { BlockingTaskOperationResponseHandler operationResponseHandler = new BlockingTaskOperationResponseHandler(); // change status to InProgress taskClient.start(id, assignee, operationResponseHandler); } // kSession.getWorkItemManager().completeWorkItem(task.getTaskData().getWorkItemId(), new // HashMap<String,Object>()); BlockingTaskOperationResponseHandler taskResponseHandler = new BlockingTaskOperationResponseHandler(); // TODO: since we're passing the variables map further down, maybe we don't need to pass it // here? Test this. ContentData contentData = ContentMarshallerHelper.marshal(outputMap, null); taskClient.complete(id, assignee, contentData, taskResponseHandler); taskResponseHandler.waitTillDone(1000); // note that we have to pass the variables again. kSession.getWorkItemManager().completeWorkItem(task.getTaskData().getWorkItemId(), outputMap); // update completed date // For some reason this does not get updated by default, and // there appears to be no JBPM API way to do this! org.jbpm.task.Task t = taskRepo.findOne(task.getId()); t.getTaskData().setCompletedOn(new Date()); // update the user t.getTaskData().setActualOwner(new User(assignee)); // note that JPA handles updating of this object automatically }