StepDAO { public void termStep(Integer subPid) { Session session = sessionFactory.openSession(); try { session.beginTransaction(); Process subProcess = (Process) session.get(Process.class, subPid); Process parentProcess = null; if (subProcess != null) { parentProcess = subProcess.getProcess(); } ExecStatus runningExecState = new ExecStatus(); runningExecState.setExecStateId(2); ExecStatus failedExecState = new ExecStatus(); failedExecState.setExecStateId(6); BatchStatus processedBatchState = new BatchStatus(); processedBatchState.setBatchStateId(1); Criteria checkParentProcessExec = session.createCriteria(InstanceExec.class).add(Restrictions.and(Restrictions.eq(PROCESS, parentProcess), Restrictions.eq(EXECSTATUS, runningExecState))); Integer runningProcessCount = checkParentProcessExec.list().size(); LOGGER.info("Running parent process count:" + runningProcessCount); Criteria checkSubProcessExec = session.createCriteria(InstanceExec.class).add(Restrictions.and(Restrictions.eq(PROCESS, subProcess), Restrictions.eq(EXECSTATUS, runningExecState))); Integer runningSubProcessCount = checkSubProcessExec.list().size(); LOGGER.info("Running sub process count:" + runningSubProcessCount); List<InstanceExec> subProcessExec = new ArrayList<InstanceExec>(); subProcessExec = checkSubProcessExec.list(); List<BatchConsumpQueue> batchConsumpQueueList = new ArrayList<BatchConsumpQueue>(); Criteria checkSubProcessBCQ = session.createCriteria(BatchConsumpQueue.class).add(Restrictions.and(Restrictions.eq(PROCESS, subProcess), Restrictions.isNotNull(BATCHBYTARGETBATCHID))); batchConsumpQueueList = checkSubProcessBCQ.list(); if (parentProcess == null) { throw new MetadataException("Invalid sub-process.sub_pid=" + subPid); } else if (runningProcessCount == 0) { throw new MetadataException("The parent process is not under execution,sub_pid=" + subPid); } else if (runningSubProcessCount == 0) { throw new MetadataException("This sub process is not running ! sub_pid=" + subPid); } else { subProcessExec.get(0).setProcess(subProcess); java.util.Date date = new java.util.Date(); subProcessExec.get(0).setEndTs(new Timestamp(date.getTime())); subProcessExec.get(0).setExecStatus(failedExecState); session.update(subProcessExec.get(0)); for (BatchConsumpQueue bcq : batchConsumpQueueList) { bcq.setEndTs(new Timestamp(date.getTime())); bcq.setBatchStatus(processedBatchState); session.update(bcq); } session.getTransaction().commit(); } } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error("Error Occurred", e); throw e; } finally { session.close(); } }  Long initStep(Integer subPid); void termStep(Integer subPid); void haltStep(Integer subPid);  }
@Ignore @Test public void testTermStep() throws Exception { stepDAO.termStep(10805); LOGGER.info("The sub process term step test executed"); }