ProcessAncestorsDAO { public List<Process> listUpstreams(Integer processId) { List<Process> upstreamProcessList = new ArrayList<Process>(); Session session = sessionFactory.openSession(); try { session.beginTransaction(); Criteria checkParentProcess = session.createCriteria(com.wipro.ats.bdre.md.dao.jpa.Process.class).add(Restrictions.eq(PROCESSID, processId)).add(Restrictions.isNull(PARENTPROCESSID)); Integer parentProcessCount = checkParentProcess.list().size(); LOGGER.info("Parent process count:" + parentProcessCount); if (parentProcessCount == 0) { throw new MetadataException("Invalid parent process:" + processId); } Criteria checkEnqueuingProcesses = session.createCriteria(com.wipro.ats.bdre.md.dao.jpa.Process.class).add(Restrictions.eq(PARENTPROCESSID, processId)).add(Restrictions.eq("deleteFlag", false)).setProjection(Projections.distinct(Projections.property("enqueuingProcessId"))); List<Integer> enqueuingProcessIdList = new ArrayList<>(); List<String> enqueuingProcessIdListString=checkEnqueuingProcesses.list(); for (String enqString:enqueuingProcessIdListString) { String[] tmp=enqString.split(","); for (String a:tmp){ LOGGER.info("a is "+a); try { enqueuingProcessIdList.add(new Integer(a)); } catch (NullPointerException e){ LOGGER.info(e); } } } LOGGER.info("Number of enqueuing process count:" + checkEnqueuingProcesses.list().size()); if (enqueuingProcessIdList!=null && !enqueuingProcessIdList.isEmpty()) { Criteria fetchEnqueuingProcessList = session.createCriteria(com.wipro.ats.bdre.md.dao.jpa.Process.class).add(Restrictions.eq("deleteFlag", false)).add(Restrictions.in(PROCESSID, enqueuingProcessIdList)); List<com.wipro.ats.bdre.md.dao.jpa.Process> enqueuingProcessList = fetchEnqueuingProcessList.list(); Integer enqProcessListCount = fetchEnqueuingProcessList.list().size(); LOGGER.info("No. of upstream processes:" + enqProcessListCount); for (com.wipro.ats.bdre.md.dao.jpa.Process jpaProcess : enqueuingProcessList) { Process process = new Process(); process.setProcessId(jpaProcess.getProcessId()); process.setProcessName(jpaProcess.getProcessName()); process.setProcessTypeId(jpaProcess.getProcessType().getProcessTypeId()); process.setBusDomainId(jpaProcess.getBusDomain().getBusDomainId()); process.setWorkflowId(jpaProcess.getWorkflowType().getWorkflowId()); process.setAddTS(jpaProcess.getAddTs()); process.setBatchPattern(jpaProcess.getBatchCutPattern()); process.setCanRecover(jpaProcess.getCanRecover()); process.setDescription(jpaProcess.getDescription()); process.setEditTS(jpaProcess.getEditTs()); process.setEnqProcessId(jpaProcess.getEnqueuingProcessId()); process.setNextProcessIds(jpaProcess.getNextProcessId()); if (jpaProcess.getProcess() != null) { process.setParentProcessId(jpaProcess.getProcess().getProcessId()); } if (jpaProcess.getProcessTemplate() != null) { process.setProcessTemplateId(jpaProcess.getProcessTemplate().getProcessTemplateId()); } process.setCounter(enqProcessListCount); upstreamProcessList.add(process); } } session.getTransaction().commit(); return upstreamProcessList; } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error("Error occurred"); throw new MetadataException(e); } finally { session.close(); } }  List<Process> listUpstreams(Integer processId); ProcessAncestorsInfo fetchDetails(Integer processId);  }
@Test public void testListUpstreams() throws Exception { List<Process> upstreamProcessList = processAncestorsDAO.listUpstreams(3); LOGGER.info("Total number of upstream processes:" + upstreamProcessList.size()); for (Process process : upstreamProcessList) { LOGGER.info(process); } }