StepDAO { public void haltStep(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 successExecState = new ExecStatus(); successExecState.setExecStateId(3); 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(); Criteria checkEnqProcessId = session.createCriteria(Process.class).add(Restrictions.eq("processId", subPid)).setProjection(Projections.property("enqueuingProcessId")); String enqProcessIdString= (String) checkEnqProcessId.list().get(0); LOGGER.info("enqProcessIdString is "+enqProcessIdString); Long enqProcessIdSum=0L; if (!enqProcessIdString.equals("0")) { String[] stringArray = enqProcessIdString.split(","); for (String tmp : stringArray) System.out.println(tmp); for (String tmp : stringArray) enqProcessIdSum = enqProcessIdSum + Long.parseLong(tmp); } LOGGER.info("The sum of enqueuing ids of the sub process in BCQ :" + enqProcessIdSum); List<BatchConsumpQueue> batchConsumpQueueList = new ArrayList<BatchConsumpQueue>(); if (enqProcessIdSum == 0) { Criteria checkSubProcessBCQ = session.createCriteria(BatchConsumpQueue.class).add(Restrictions.eq(PROCESS, subProcess)); batchConsumpQueueList = checkSubProcessBCQ.list(); } else { 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(successExecState); 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 testHaltStep() throws Exception { stepDAO.haltStep(10805); LOGGER.info("The sub process halt step test executed"); }