@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; }
@Transactional public ProcessInstance refreshProcessInstance( ProcessInstance processInstance) { log.debug("refreshProcessInstance"); ProcessInstance ret = m_entityManager.find(ProcessInstance.class, processInstance.getId()); m_entityManager.refresh(ret); log.debug("\n{}",displayProcess(ret, 0)); return ret; } /* (non-Javadoc)
@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; }
@Transactional public int clearDeferredEvents() { Query query = m_entityManager.createNamedQuery("clearDeferredEvents"); @SuppressWarnings("unchecked") List<DeferredEvent> result = query.getResultList(); int ret = result.size(); log.debug("#found {} deferred events",result.size()); for (DeferredEvent deferredEvent:result) { log.debug("#deferred pid: {} processName: {} eventType: {} fire: {} now: {} ",deferredEvent.getProcessInstance().getId(), deferredEvent.getProcessDefinitionName(), deferredEvent.getEventType(), deferredEvent.getFire(),new Date().getTime()); m_entityManager.remove(deferredEvent); } m_entityManager.flush(); return ret; }
@Transactional public List<ProcessInstance> getActiveProcesses() { if (log.isDebugEnabled()) { getAllProcesses(); } Query query = m_entityManager.createNamedQuery("ActiveProcesses"); @SuppressWarnings("unchecked") List<ProcessInstance> result = query.getResultList(); if (log.isDebugEnabled()) { for (ProcessInstance processInstance:result) { log.debug("processInstanceId={} processName={} taskId={} status={}",processInstance.getId(),processInstance.getProcessDefinitionName(),processInstance.getTaskId(), processInstance.getStatus()); } log.debug("found {} active processes",result.size()); } return result; }
@Override public void buttonClick(ClickEvent event) { m_attachmentsPopup.load(form.getProcessInstance().getId()); }}); Map<String,Field<?>> fields = m_maduraFieldGroup.buildAndBind(
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; }
@Transactional public long launch(WorkflowForm launchForm, String comment, String bundleName) { ProcessInstance processInstanceRet = launch(launchForm.getProcessName(), launchForm.getContext(),comment,bundleName, launchForm.getProcessInstance()); return processInstanceRet.getId(); } /* (non-Javadoc)
@Transactional public DeferredEvent removeDeferredEvent(ProcessInstance processInstance, TaskBase task) { List<DeferredEvent> deferredEvents = processInstance.getDeferredEvents(); for (DeferredEvent deferredEvent: deferredEvents) { if (deferredEvent.getEventType() != EventType.DONE && deferredEvent.getTaskId().longValue() == task.getTaskId() && task.getProcessDefinitionName().equals(deferredEvent.getProcessDefinitionName())) { log.debug("killed deferred event processId {} taskId {} status {} {}", deferredEvent.getProcessInstance().getId(), deferredEvent.getId(), deferredEvent.getEventType() ,deferredEvent.getComment() ); deferredEvent.setEventType(EventType.DONE); return deferredEvent; } } log.debug("failed to find deferred event processId {} {} taskId {}", processInstance.getId(), task.getProcessDefinitionName(), task.getTaskId()); return null; }
public boolean execute(ProcessInstance processInstance) { log.debug("{}",this); Object context = getContext(processInstance); ProcessInstanceUtils.clearQueue(processInstance); log.debug(getOwnerProcess().getName()+" Waiting for message "+this.toString()); if (!getMessageSender().send(context, processInstance.getId())) { throw new WorkflowException("Failed to send message "+getMessageName()); } return false; }
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()); }
public boolean execute(ProcessInstance processInstance) { log.debug("{}",this); WorkflowManager workflowManager = getOwnerProcess().getWorkflowManager(); List<?> list = (List<?>)workflowManager.getField(processInstance, getFd()); if (!list.isEmpty()) { for (Object o:list) { ProcessInstance subProcess = new ProcessInstance(); subProcess.setBundleName(processInstance.getBundleName()); getSubProcess().startProcess(subProcess); processInstance.getChildProcesses().add(subProcess); subProcess.setObjectInstance(workflowManager.createContextDescriptor(o)); subProcess.setParentProcess(processInstance); log.debug("subprocess launched: {}",subProcess.getProcessDefinitionName()); } ProcessInstanceUtils.clearQueue(processInstance); processInstance.setWaitCount(list.size()); log.debug("{} subprocesses launched for: {} {}",processInstance.getWaitCount(),processInstance.getProcessDefinitionName(),processInstance.getId()); } return false; } }
@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
@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(); } }
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)
public void setup(ProcessInstance processInstance) { m_container = JPAContainerFactory.makeReadOnly(Audit.class, m_entityManager); // Filter by AUDITS_PROCESSINSTANCE_ID // Collection<Object> filterablePropertyIds = m_container.getFilterablePropertyIds(); m_container.addContainerFilter(new Compare.Equal("parentId",processInstance.getId())); m_container.sort(new String[]{"created"}, new boolean[]{true}); m_auditTable = new AuditTable(); m_auditTable.addItemClickListener(new ItemClickEvent.ItemClickListener() { private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") @Override public void itemClick(ItemClickEvent event) { Audit audit = ((JPAContainerItem<Audit>)event.getItem()).getEntity(); getAuditPopup().load(audit); } }); removeAllComponents(); addComponent(m_auditTable); m_auditTable.setSizeFull(); }
@Override public void bind() { panel.removeAllComponents(); ValidationObject o = (ValidationObject)getContext(); BeanItem<ValidationObject> beanItem = new BeanItem<>(o); m_maduraSessionManager.getValidationSession().bind(o); fieldGroup = m_maduraSessionManager.createMaduraFieldGroup(); Layout actions = createButtons(); log.debug("park:{}",(park.isEnabled()?"enabled":"disabled")); Map<String,Field<?>> fields = fieldGroup.buildAndBind(m_fieldList,beanItem); for (Field<?> f:fields.values()) { if (isReadOnlyForm()) { f.setReadOnly(true); f.setEnabled(false); } panel.addComponent(f); } m_referenceField = fields.get(m_referenceName); m_launcher = (m_processInstance==null || m_processInstance.getId()== 0); park.setVisible(!isLauncher()); panel.addComponent(actions); if (isReadOnlyForm()) { park.setReadOnly(true); park.setEnabled(false); okay.setReadOnly(true); okay.setEnabled(false); } log.debug("park:{}",(park.isEnabled()?"enabled":"disabled")); } @Override
deferredEvent.setProcessInstance(parent); parent.getDeferredEvents().add(deferredEvent); deferredEvent.setComment("process instance: "+processInstance.getId());