ProcessDependencyDAO { public List<ProcessDependencyInfo> listUD(Integer parentProcessId) { List<ProcessDependencyInfo> upstreamDownstreamProcessList = new ArrayList<ProcessDependencyInfo>(); Session session = sessionFactory.openSession(); try { session.beginTransaction(); Process passedProcess = (Process) session.get(Process.class, parentProcessId); Process parentProcess = null; if (passedProcess != null) { parentProcess = passedProcess.getProcess(); } if (passedProcess == null || parentProcess != null) { throw new MetadataException("Invalid parent-process. pid=:" + parentProcessId); } else { ProcessDependencyInfo processInfo = new ProcessDependencyInfo(); processInfo.setProcessId(passedProcess.getProcessId()); processInfo.setBusDomainId(passedProcess.getBusDomain().getBusDomainId()); processInfo.setBatchPattern(passedProcess.getBatchCutPattern()); processInfo.setCanRecover(passedProcess.getCanRecover()); processInfo.setProcessName(passedProcess.getProcessName()); processInfo.setDescription(passedProcess.getDescription()); processInfo.setProcessTypeId(passedProcess.getProcessType().getProcessTypeId()); processInfo.setParentProcessId(null); processInfo.setEnqProcessId(passedProcess.getEnqueuingProcessId()); processInfo.setNextProcessIds(passedProcess.getNextProcessId()); processInfo.setAddTS((Timestamp) passedProcess.getAddTs()); processInfo.setRowType("P"); LOGGER.info(processInfo); upstreamDownstreamProcessList.add(processInfo); Criteria checkDownstreamParentProcesses = session.createCriteria(Process.class).add(Restrictions.or(Restrictions.eq("enqueuingProcessId", parentProcessId.toString()),Restrictions.like("enqueuingProcessId","%,"+parentProcessId.toString()),Restrictions.like("enqueuingProcessId",parentProcessId.toString()+",%"),Restrictions.like("enqueuingProcessId","%,"+parentProcessId.toString()+",%"))) .add(Restrictions.eq(DELETEFLAG, false)).setProjection(Projections.property("process")); List<Integer> downstreamParentProcessIdList = new ArrayList<Integer>(); if (!checkDownstreamParentProcesses.list().isEmpty()) { List<Process> downstreamParentProcessList = checkDownstreamParentProcesses.list(); for (Process p : downstreamParentProcessList) { if (p!=null) downstreamParentProcessIdList.add(p.getProcessId()); } Criteria checkDownstreamProcesses = session.createCriteria(Process.class).add(Restrictions.in("processId", downstreamParentProcessIdList)); List<Process> downstreamProcessList = new ArrayList<Process>(); if (!checkDownstreamProcesses.list().isEmpty()) { downstreamProcessList = checkDownstreamProcesses.list(); for (Process downProcess : downstreamProcessList) { ProcessDependencyInfo downProcessInfo = new ProcessDependencyInfo(); downProcessInfo.setProcessId(downProcess.getProcessId()); downProcessInfo.setBusDomainId(downProcess.getBusDomain().getBusDomainId()); downProcessInfo.setBatchPattern(downProcess.getBatchCutPattern()); downProcessInfo.setCanRecover(downProcess.getCanRecover()); downProcessInfo.setProcessName(downProcess.getProcessName()); downProcessInfo.setDescription(downProcess.getDescription()); downProcessInfo.setProcessTypeId(downProcess.getProcessType().getProcessTypeId()); downProcessInfo.setParentProcessId(null); downProcessInfo.setEnqProcessId(downProcess.getEnqueuingProcessId()); downProcessInfo.setNextProcessIds(downProcess.getNextProcessId()); downProcessInfo.setAddTS((Timestamp) downProcess.getAddTs()); downProcessInfo.setRowType("D"); LOGGER.info(downProcessInfo); upstreamDownstreamProcessList.add(downProcessInfo); } } } else { LOGGER.info("No downstream processes present"); } Criteria checkUpstreamParentProcesses = session.createCriteria(Process.class).add(Restrictions.eq("process", passedProcess)).add(Restrictions.eq(DELETEFLAG, false)).setProjection(Projections.property("enqueuingProcessId")); List<String> upstreamParentProcessListString=checkUpstreamParentProcesses.list(); List<Integer> upstreamParentProcessList = new ArrayList<Integer>(); for (String temp:upstreamParentProcessListString) { LOGGER.info(temp); String[] arrayUp=temp.split(","); for (int i=0;i<arrayUp.length;i++) upstreamParentProcessList.add(Integer.parseInt(arrayUp[i])); } if (!upstreamParentProcessList.isEmpty()) { Criteria checkUpstreamProcesses = session.createCriteria(Process.class).add(Restrictions.in("processId", upstreamParentProcessList)).add(Restrictions.eq(DELETEFLAG, false)); List<Process> upstreamProcessList = new ArrayList<Process>(); if (!checkUpstreamProcesses.list().isEmpty()) { upstreamProcessList = checkUpstreamProcesses.list(); for (Process upProcess : upstreamProcessList) { ProcessDependencyInfo upProcessInfo = new ProcessDependencyInfo(); upProcessInfo.setProcessId(upProcess.getProcessId()); upProcessInfo.setBusDomainId(upProcess.getBusDomain().getBusDomainId()); upProcessInfo.setBatchPattern(upProcess.getBatchCutPattern()); upProcessInfo.setCanRecover(upProcess.getCanRecover()); upProcessInfo.setProcessName(upProcess.getProcessName()); upProcessInfo.setDescription(upProcess.getDescription()); upProcessInfo.setProcessTypeId(upProcess.getProcessType().getProcessTypeId()); upProcessInfo.setParentProcessId(null); upProcessInfo.setEnqProcessId(upProcess.getEnqueuingProcessId()); upProcessInfo.setNextProcessIds(upProcess.getNextProcessId()); upProcessInfo.setAddTS((Timestamp) upProcess.getAddTs()); upProcessInfo.setRowType("U"); LOGGER.info(upProcessInfo); upstreamDownstreamProcessList.add(upProcessInfo); } } else { LOGGER.info("No upstream processes present"); } } session.getTransaction().commit(); } } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error("Error occurred", e); } finally { session.close(); } return upstreamDownstreamProcessList; }  List<ProcessDependencyInfo> listUD(Integer parentProcessId);  }
@Test @Ignore public void testListUD() throws Exception { List<ProcessDependencyInfo> upstreamDownstreamProcessList = new ArrayList<ProcessDependencyInfo>(); upstreamDownstreamProcessList = processDependencyDAO.listUD(1); for (ProcessDependencyInfo pdInfo : upstreamDownstreamProcessList) { LOGGER.info(pdInfo + "\n"); } }