public static List<Lock> getLocks(ProcessInstance processInstance, LockFactory lockFactory, String comment) { String contextDescription = ContextUtils.createContextDescriptor(processInstance,processInstance.getId()); Lock processInstanceLock = lockFactory.getWrappedLock(contextDescription, LockType.WRITE, comment); Lock contextLock = lockFactory.getWrappedLock(processInstance.getObjectInstance(), LockType.WRITE, comment); List<Lock> ret = new ArrayList<Lock>(); ret.add(processInstanceLock); ret.add(contextLock); return ret; }
protected Object getContext(ProcessInstance processInstance) { return getWorkflowManager().getContext(processInstance.getObjectInstance()); }
@Transactional public Object getField(ProcessInstance processInstance, FieldDescriptor fd) { Object o = getContextDAO().getContext(processInstance.getObjectInstance()); String prefix="get"; if (fd.getType().endsWith("Boolean")) { prefix="is"; } String name=prefix+StringUtils.capitalize(fd.getName()); try { Method getter = o.getClass().getMethod(name); return getter.invoke(o); } catch (Exception e) { throw new WorkflowException("Problem finding field: "+fd.getName()); } } @Transactional
public boolean execute(ProcessInstance processInstance) { log.debug("{}",this); for (ProcessDefinition subProcess:m_subProcess) { ProcessInstance subprocessInstance = new ProcessInstance(); subprocessInstance.setBundleName(processInstance.getBundleName()); subProcess.startProcess(subprocessInstance); processInstance.getChildProcesses().add(subprocessInstance); subprocessInstance.setObjectInstance(processInstance.getObjectInstance()); subprocessInstance.setParentProcess(processInstance); log.debug("subprocess launched: {}",subprocessInstance.getProcessDefinitionName()); } ProcessInstanceUtils.clearQueue(processInstance); processInstance.setWaitCount(m_subProcess.size()); log.debug("{} subprocesses launched for: {} {}",processInstance.getWaitCount(),processInstance.getProcessDefinitionName(),processInstance.getId()); return false; }
protected void launchOneCyclicSubprocess(ProcessInstance processInstance) { ProcessInstance subProcess = new ProcessInstance(); subProcess.setBundleName(processInstance.getBundleName()); getSubProcess().startProcess(subProcess); processInstance.getChildProcesses().add(subProcess); subProcess.setObjectInstance(processInstance.getObjectInstance()); subProcess.setParentProcess(processInstance); log.debug("subprocess launched: {}",subProcess.getProcessDefinitionName()); ProcessInstanceUtils.clearQueue(processInstance); processInstance.setWaitCount(1); log.debug("subprocess launched for: {} {}",processInstance.getProcessDefinitionName(),processInstance.getId()); }
@Transactional public void processMessage(ProcessInstance processInstance, Message<?> message, MessageMapper messageMapper) { Object context = getContextDAO().getContext(processInstance.getObjectInstance()); processInstance.setStatus(TaskStatus.GO); try { messageMapper.unpackMessage(message, context); } catch (Exception e) { processInstance.setStatus(TaskStatus.ABORTING); processInstance.setComment(e.getMessage()); } log.debug("set status to processInstance {} to {} {}",processInstance.getId(),processInstance.getStatus(),context); getContextDAO().mergeContext(context); getWorkflowDAO().mergeProcessInstance(processInstance); getWorkflowDAO().flush(); if (log.isDebugEnabled()) { getWorkflowDAO().getActiveProcesses(); } }
@Transactional public ProcessInstance launch(String processName, Object context, String comment, String bundleName, ProcessInstance processInstance) { ProcessDefinition processDefinition = getProcessDefinition(processName); if (processDefinition == null) { throw new WorkflowException("Failed to find process definition named "+processName); } Object mergedContext = getContextDAO().mergeContext(context); processInstance.setComment(comment==null?" ":comment); processInstance.setBundleName(bundleName); processInstance.setObjectInstance(getContextDAO().createContextDescriptor(mergedContext)); if (!ContextUtils.getContextClass(processInstance.getObjectInstance()).equals(mergedContext.getClass())) { throw new WorkflowException("Context object does not match process context in "+processName); } processDefinition.startProcess(processInstance); ProcessInstance processInstanceRet = getWorkflowDAO().mergeProcessInstance(processInstance); getWorkflowDAO().flush(); return processInstanceRet; }
public WorkflowForm getCurrentForm(ProcessInstance processInstance) { ProcessDefinition processDefinition = getProcessDefinition(processInstance.getProcessDefinitionName()); String formName = processDefinition.getLaunchForm(); boolean readOnly = true; TaskBase task = getCurrentTask(processInstance); if ((task instanceof TaskForm)) { formName = ((TaskForm)task).getFormName(); readOnly = false; } WorkflowForm workflowForm = m_formFactory.getForm(formName); Object context = getContext(processInstance.getObjectInstance()); workflowForm.setProcessDefinition(processDefinition); workflowForm.setProcessInstance(processInstance); workflowForm.setContext(context); workflowForm.setReadOnly(readOnly); workflowForm.bind(); return workflowForm; } public ContextDAO getContextDAO() {
theObjectInstance = this.getObjectInstance(); strategy.appendField(locator, this, "objectInstance", buffer, theObjectInstance);
lhsObjectInstance = this.getObjectInstance(); String rhsObjectInstance; rhsObjectInstance = that.getObjectInstance(); if (!strategy.equals(LocatorUtils.property(thisLocator, "objectInstance", lhsObjectInstance), LocatorUtils.property(thatLocator, "objectInstance", rhsObjectInstance), lhsObjectInstance, rhsObjectInstance)) { return false;
theObjectInstance = this.getObjectInstance(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "objectInstance", theObjectInstance), currentHashCode, theObjectInstance);