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 List<ProcessInstance> getAllProcesses() { log.debug("getAllProcesses"); Query query = m_entityManager.createQuery("SELECT c FROM nz.co.senanque.workflow.instances.ProcessInstance c"); @SuppressWarnings("unchecked") List<ProcessInstance> result = query.getResultList(); if (log.isDebugEnabled()) { log.debug("----------all processInstances ---------------"); for (ProcessInstance processInstance:result) { log.debug("processInstanceId={} processName={} taskId={} status={}",processInstance.getId(),processInstance.getProcessDefinitionName(),processInstance.getTaskId(), processInstance.getStatus()); } log.debug("found {} processes",result.size()); log.debug("----------------------------------------------"); } return result; }
public static void clearQueue(ProcessInstance processInstance, TaskStatus status) { processInstance.setStatus(status); processInstance.setQueueName(""); processInstance.setPermission(""); processInstance.setReadPermission(""); }
public static String getTaskId(ProcessInstance processInstance) { return processInstance.getProcessDefinitionName()+"/"+processInstance.getTaskId(); }
theId = (true?this.getId(): 0L); strategy.appendField(locator, this, "id", buffer, theId); theVersion = (true?this.getVersion(): 0L); strategy.appendField(locator, this, "version", buffer, theVersion); theProcessDefinitionName = this.getProcessDefinitionName(); strategy.appendField(locator, this, "processDefinitionName", buffer, theProcessDefinitionName); theQueueName = this.getQueueName(); strategy.appendField(locator, this, "queueName", buffer, theQueueName); thePermission = this.getPermission(); strategy.appendField(locator, this, "permission", buffer, thePermission); theReadPermission = this.getReadPermission(); strategy.appendField(locator, this, "readPermission", buffer, theReadPermission); theBundleName = this.getBundleName(); strategy.appendField(locator, this, "bundleName", buffer, theBundleName); theComment = this.getComment(); strategy.appendField(locator, this, "comment", buffer, theComment); theReference = this.getReference(); strategy.appendField(locator, this, "reference", buffer, theReference); theObjectInstance = this.getObjectInstance(); strategy.appendField(locator, this, "objectInstance", buffer, theObjectInstance);
@Transactional public void executeDeferredEvent(long deferredEventId) { DeferredEvent deferredEvent = getWorkflowDAO().findDeferredEvent(deferredEventId); log.debug("fired deferred event {} for {} {}",deferredEvent.getEventType(),deferredEvent.getProcessInstance().getId(),deferredEvent.getComment()); ProcessInstance processInstance = deferredEvent.getProcessInstance(); switch (deferredEvent.getEventType()) { case DEFERRED: ProcessInstanceUtils.clearQueue(processInstance, TaskStatus.TIMEOUT); int lastAuditIndex = processInstance.getAudits().size()-1; Audit lastAudit = processInstance.getAudits().get(lastAuditIndex); lastAudit.setInterrupted(true); lastAudit.setStatus(TaskStatus.TIMEOUT); processInstance.setProcessDefinitionName(deferredEvent.getProcessDefinitionName()); processInstance.setTaskId(deferredEvent.getTaskId()); break; case FORCE_ABORT: ProcessInstanceUtils.clearQueue(processInstance, TaskStatus.ABORTING); processInstance.setComment("Sibling aborted"); break; case SUBPROCESS_END: if (processInstance.getWaitCount() == 0) { break; processInstance.setWaitCount(processInstance.getWaitCount()-1); if (processInstance.getWaitCount() == 0) { if (processInstance.isCyclic()) { processInstance.setStatus(TaskStatus.GO);
protected void tickleParentProcess(ProcessInstance processInstance, TaskStatus status) { ProcessInstance parent = processInstance.getParentProcess(); if (parent != null) for (ProcessInstance sibling: parent.getChildProcesses()) { if (sibling.getStatus() != TaskStatus.ABORTED && sibling.getStatus() != TaskStatus.ABORTING && sibling.getStatus() != TaskStatus.DONE) { sibling.setStatus(TaskStatus.ABORTING); deferredEvent.setProcessInstance(sibling); deferredEvent.setComment("aborting sibling"); sibling.getDeferredEvents().add(deferredEvent); if (parent.getWaitCount() > 0) { deferredEvent.setEventType(EventType.SUBPROCESS_END); deferredEvent.setProcessInstance(parent); parent.getDeferredEvents().add(deferredEvent); deferredEvent.setComment("process instance: "+processInstance.getId());
@Override public void buttonClick(ClickEvent event) { if (event.getComponent().equals(okay)) { if (StringUtils.hasText(m_referenceName) && m_processInstance.getId() == 0) { try { String reference = m_referenceField.getValue().toString(); m_processInstance.setReference(reference); } catch (Exception e) { m_processInstance.setStatus((m_launcher?TaskStatus.WAIT:TaskStatus.GO)); m_processInstance.setQueueName(null); m_processInstance.setLockedBy(null); long processId = save(); if (processId == 0) { long processId = m_processInstance.getId(); if (processId != 0 && !isReadOnly()) { m_processInstance = getWorkflowManager().refresh(m_processInstance); m_processInstance.setStatus(TaskStatus.WAIT); m_processInstance.setLockedBy(null); save(); long processId = m_processInstance.getId(); if (processId == 0) { return;
ret.append(processInstance.getId()); ret.append(" processName: "); ret.append(processInstance.getProcessDefinitionName()); ret.append(" status: "); ret.append(processInstance.getStatus()); ret.append(" waitCount: "); ret.append(processInstance.getWaitCount()); ret.append("\n"); for (Audit audit: processInstance.getAudits()) { ret.append(sb); ret.append("AUDIT: "); ret.append("\n"); for (DeferredEvent deferredEvent: processInstance.getDeferredEvents()) { ret.append(sb); ret.append("EVENT: "); ret.append(deferredEvent.getProcessDefinitionName()); ret.append(" processInstanceId:"); ret.append(deferredEvent.getProcessInstance().getId()); ret.append(" taskId:"); ret.append(deferredEvent.getTaskId()); ret.append("\n"); for (ProcessInstance child: processInstance.getChildProcesses()) { ret.append(displayProcess(child, indent+1));
@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(); } }
HashIdLogger.log(this,"execute"); TaskBase task = getCurrentTask(processInstance); if (processInstance.getStatus() == TaskStatus.DONE) { return; log.debug("processInstanceId={} processName={} taskId={} status={}",processInstance.getId(),task.getOwnerProcess().getName(),task.getTaskId(), processInstance.getStatus()); boolean b = true; Audit audit = createAudit(processInstance, task); try { if (processInstance.getStatus()==TaskStatus.ABORTING) throw new AbortException(processInstance.getComment()); if (processInstance.getStatus()==TaskStatus.TIMEOUT) if (processInstance.getStatus()==TaskStatus.GO) processInstance.setStatus(TaskStatus.ABORTED); processInstance.setStatus(TaskStatus.ABORTED); processInstance.getAudits().remove(audit); if (!handleTimeout(processInstance, audit)) { processInstance.setStatus(TaskStatus.ABORTED); tickleParentProcess(processInstance,processInstance.getStatus()); break; } else {
public void doAction() { String taskId = ProcessInstanceUtils.getTaskId(processInstance); ProcessInstance pi = getWorkflowDAO().refreshProcessInstance(processInstance); // if (log.isDebugEnabled()) { // log.debug("taskId {} ProcessInstanceUtils.getTaskId(pi) {} {}",taskId,ProcessInstanceUtils.getTaskId(pi),(!taskId.equals(ProcessInstanceUtils.getTaskId(pi)))); // log.debug("pi.getStatus() {} techSupport {} {}",pi.getStatus(),techSupport,((pi.getStatus() != TaskStatus.WAIT) && !techSupport)); // log.debug("pi.getStatus() {} userName {} pi.getLockedBy() {} {}",pi.getStatus(),userName,pi.getLockedBy(),(pi.getStatus() == TaskStatus.BUSY) && !userName.equals(pi.getLockedBy()) && !techSupport); // } if (!techSupport) { if (!(taskId.equals(ProcessInstanceUtils.getTaskId(pi)) && ((pi.getStatus() == TaskStatus.WAIT) || ((pi.getStatus() == TaskStatus.BUSY) && userName.equals(pi.getLockedBy()))))) { // // In this case we did not actually fail to get the lock but // // the process is not in the state // // it was in when we saw it in the table because another // // user (probably) has updated it. // // Therefore it is dangerous to proceed (unless we are tech support) throw new RuntimeException("ProcessInstance is already busy"); } } pi.setStatus(TaskStatus.BUSY); pi.setLockedBy(userName); TaskBase task = getCurrentTask(pi); Audit audit = createAudit(pi, task); getWorkflowDAO().mergeProcessInstance(pi); } });
String task = processDefinition.getTask(form.getProcessInstance().getTaskId()).toString(); new Object[]{new Long(form.getProcessInstance().getId()), ownerProcessDefinition.getName(), form.getProcessInstance().getReference(), ownerProcessDefinition.getDescription()})); formPanel.removeAllComponents();
protected Audit createAudit(ProcessInstance processInstance, TaskBase task) { Audit audit = new Audit(); audit.setCreated(new Timestamp(System.currentTimeMillis())); audit.setTaskId(task.getTaskId()); audit.setProcessDefinitionName(task.getOwnerProcess().getName()); audit.setComment(trimComment(task.toString())); audit.setHandler(task.getHandler()); audit.setInterrupted(false); audit.setLockedBy(processInstance.getLockedBy()); audit.setStatus(processInstance.getStatus()); audit.setParentId(processInstance.getId()); processInstance.getAudits().add(audit); return audit; } /* (non-Javadoc)
@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; }
@Transactional public long save(WorkflowForm workflowForm) { Object context = getContextDAO().mergeContext(workflowForm.getContext()); ProcessInstance processInstance = workflowForm.getProcessInstance(); processInstance.setLastUpdated(new Timestamp(System.currentTimeMillis())); processInstance.setObjectInstance(createContextDescriptor(context)); ProcessInstance pi = null; if (processInstance.getId() == 0) { processInstance.setTaskId(0L); TaskBase task = getTask(workflowForm.getProcessDefinition(),0L); pi = getWorkflowDAO().mergeProcessInstance(processInstance); Audit audit = createAudit(pi, task); audit.setStatus(TaskStatus.DONE); } else { TaskBase task = getCurrentTask(processInstance); pi = getWorkflowDAO().mergeProcessInstance(processInstance); createAudit(pi, task); } return pi.getId(); } @Transactional
@Override public ProcessInstance launch(String processName, Object o, String comment, String bundleName) { ProcessDefinition processDefinition = getProcessDefinition(processName); if (processDefinition == null) { throw new WorkflowException("Failed to find process definition named "+processName); } ProcessInstance processInstance = new ProcessInstance(); processInstance.setComment(comment); processInstance.setBundleName(bundleName); return processInstance; }
private Audit tidyAuditTrail(ProcessInstance processInstance, long taskId) { boolean found = false; Audit ret = null; for (Audit audit: processInstance.getAudits()) { if (audit.getProcessDefinitionName() != null && processInstance.getProcessDefinitionName().equals(audit.getProcessDefinitionName()) && processInstance.getTaskId() == taskId ) { found = true; ret = audit; } else if (found) { audit.setHandler(false); } } return ret; } private void dumpAuditTrail(ProcessInstance processInstance) {
@Transactional public ProcessInstance mergeProcessInstance(ProcessInstance processInstance) { log.debug("mergeProcessInstance"); ProcessInstance ret = m_entityManager.merge(processInstance); m_entityManager.flush(); if (log.isDebugEnabled()) { log.debug("updating processInstance {} to {}",processInstance.getId(),processInstance.getStatus()); } return ret; }