ArrangePositions extends MetadataAPIBase { public Map<String, PositionsInfo> getListPositionInfo(Integer processId) { Map<String, PositionsInfo> positionsInfoMap = new HashMap<String, PositionsInfo>(); Map<Integer, List<PositionsInfo>> rankPositionsInfoMap = new HashMap<Integer, List<PositionsInfo>>(); try { com.wipro.ats.bdre.md.dao.jpa.Process jpaProcess = processDAO.get(processId); Process process = new Process(); if (jpaProcess != null) { process.setDescription(jpaProcess.getDescription()); process.setAddTS(jpaProcess.getAddTs()); process.setBatchPattern(jpaProcess.getBatchCutPattern()); if (jpaProcess.getBusDomain() != null) process.setBusDomainId(jpaProcess.getBusDomain().getBusDomainId()); process.setEditTS(jpaProcess.getEditTs()); process.setEnqProcessId(jpaProcess.getEnqueuingProcessId()); process.setProcessId(jpaProcess.getProcessId()); process.setNextProcessIds(jpaProcess.getNextProcessId()); process.setProcessName(jpaProcess.getProcessName()); process.setTableAddTS(jpaProcess.getAddTs().toString()); process.setTableEditTS(jpaProcess.getEditTs().toString()); if (jpaProcess.getWorkflowType() != null) process.setWorkflowId(jpaProcess.getWorkflowType().getWorkflowId()); if (jpaProcess.getProcessType() != null) process.setProcessTypeId(jpaProcess.getProcessType().getProcessTypeId()); process.setCanRecover(jpaProcess.getCanRecover()); if (jpaProcess.getProcessTemplate() != null) process.setProcessTemplateId(jpaProcess.getProcessTemplate().getProcessTemplateId()); if (jpaProcess.getProcess() != null) process.setParentProcessId(jpaProcess.getProcess().getProcessId()); } List<com.wipro.ats.bdre.md.dao.jpa.Process> jpaSubProcesses = processDAO.subProcesslist(processId); List<Process> processes = new ArrayList<Process>(); for (com.wipro.ats.bdre.md.dao.jpa.Process jpaSubProcess : jpaSubProcesses) { Process subProcess = new Process(); subProcess.setDescription(jpaSubProcess.getDescription()); subProcess.setAddTS(jpaSubProcess.getAddTs()); subProcess.setBatchPattern(jpaSubProcess.getBatchCutPattern()); if (jpaSubProcess.getBusDomain() != null) subProcess.setBusDomainId(jpaSubProcess.getBusDomain().getBusDomainId()); subProcess.setEditTS(jpaSubProcess.getEditTs()); subProcess.setEnqProcessId(jpaSubProcess.getEnqueuingProcessId()); subProcess.setProcessId(jpaSubProcess.getProcessId()); subProcess.setNextProcessIds(jpaSubProcess.getNextProcessId()); subProcess.setProcessName(jpaSubProcess.getProcessName()); subProcess.setTableAddTS(jpaSubProcess.getAddTs().toString()); subProcess.setTableEditTS(jpaSubProcess.getEditTs().toString()); if (jpaSubProcess.getWorkflowType() != null) subProcess.setWorkflowId(jpaSubProcess.getWorkflowType().getWorkflowId()); if (jpaSubProcess.getProcessType() != null) subProcess.setProcessTypeId(jpaSubProcess.getProcessType().getProcessTypeId()); subProcess.setCanRecover(jpaSubProcess.getCanRecover()); if (jpaProcess.getProcessTemplate() != null) subProcess.setProcessTemplateId(jpaSubProcess.getProcessTemplate().getProcessTemplateId()); if (jpaProcess.getProcess() != null) subProcess.setParentProcessId(jpaProcess.getProcess().getProcessId()); processes.add(subProcess); } processes.add(0, process); for (Process p : processes) { PositionsInfo positionsInfo = new PositionsInfo(); positionsInfo.setProcessId(p.getProcessId()); positionsInfo.setLevel(0); positionsInfo.setParentProcessId(processId); positionsInfoMap.put(p.getProcessId().toString(), positionsInfo); } for (Process p : processes) { PositionsInfo thisPositionInfo = positionsInfoMap.get(p.getProcessId().toString()); String[] nextProcesses = p.getNextProcessIds().split(","); List<PositionsInfo> children = new ArrayList<PositionsInfo>(); for (String nextProcess : nextProcesses) { if ("0".equals(nextProcess) || nextProcess.equals(processId.toString())) continue; children.add(positionsInfoMap.get(nextProcess)); } thisPositionInfo.setChildren(children); } setLevels(positionsInfoMap.get(processId.toString())); for (PositionsInfo positionsInfo : positionsInfoMap.values()) { int level = positionsInfo.getLevel(); List<PositionsInfo> positionsInfoInGivenLevelList = rankPositionsInfoMap.get(level); if (positionsInfoInGivenLevelList == null) positionsInfoInGivenLevelList = new ArrayList<PositionsInfo>(); positionsInfoInGivenLevelList.add(positionsInfo); rankPositionsInfoMap.put(level, positionsInfoInGivenLevelList); } arrangePositions(rankPositionsInfoMap); savePositionsInDB(rankPositionsInfoMap); LOGGER.info("Saved properties into DB"); } catch (Exception e) { LOGGER.error("error occurred", e); } return positionsInfoMap; } ArrangePositions(); Map<String, PositionsInfo> getListPositionInfo(Integer processId); @Override Object execute(String[] params);  }
@Test public void testGetListPositionInfo() throws Exception { Integer firstParentProcessId = null; Integer firstChildOfParentProcess1Id = null; Integer secondChildOfParentProcess1Id = null; Integer thirdChildOfParentProcess1Id=null; Integer fourthChildOfParentProcess1Id=null; Integer fifthChildOfParentProcess1Id=null; Integer sixthChildOfParentProcess1Id=null; Integer seventhChildOfParentProcess1Id=null; Integer flag=0; try { BusDomain busDomain = busDomainDAO.get(1); ProcessType parentProcessType = processTypeDAO.get(1); ProcessType childProcessType = processTypeDAO.get(12); ArrangePositions arrangePositions = new ArrangePositions(); WorkflowType parentWorkflowType = workflowTypeDAO.get(0); WorkflowType childWorkflowType = workflowTypeDAO.get(1); com.wipro.ats.bdre.md.dao.jpa.Process firstParentProcess = new Process(); firstParentProcess.setProcessName("Test"); firstParentProcess.setDescription("Test Process"); firstParentProcess.setBusDomain(busDomain); firstParentProcess.setProcessType(parentProcessType); firstParentProcess.setAddTs(new Date()); firstParentProcess.setCanRecover(true); firstParentProcess.setEnqueuingProcessId("0"); firstParentProcess.setProcess(null); firstParentProcess.setNextProcessId("1"); firstParentProcess.setDeleteFlag(false); firstParentProcess.setEditTs(new Date()); firstParentProcess.setWorkflowType(parentWorkflowType); firstParentProcessId = processDAO.insert(firstParentProcess); Process firstChildOfParentProcess1 = new Process(); firstChildOfParentProcess1.setProcessName("Test"); firstChildOfParentProcess1.setDescription("Test Process"); firstChildOfParentProcess1.setBusDomain(busDomain); firstChildOfParentProcess1.setProcessType(childProcessType); firstChildOfParentProcess1.setAddTs(new Date()); firstChildOfParentProcess1.setCanRecover(true); firstChildOfParentProcess1.setEnqueuingProcessId("0"); firstChildOfParentProcess1.setProcess(firstParentProcess); firstChildOfParentProcess1.setNextProcessId("0"); firstChildOfParentProcess1.setDeleteFlag(false); firstChildOfParentProcess1.setEditTs(new Date()); firstChildOfParentProcess1.setWorkflowType(childWorkflowType); firstChildOfParentProcess1Id = processDAO.insert(firstChildOfParentProcess1); Process process = processDAO.get(firstParentProcessId); process.setNextProcessId(firstChildOfParentProcess1Id.toString()); processDAO.update(process); Process secondChildOfParentProcess1 = new Process(); secondChildOfParentProcess1.setProcessName("Test"); secondChildOfParentProcess1.setDescription("Test Process"); secondChildOfParentProcess1.setBusDomain(busDomain); secondChildOfParentProcess1.setProcessType(childProcessType); secondChildOfParentProcess1.setAddTs(new Date()); secondChildOfParentProcess1.setCanRecover(true); secondChildOfParentProcess1.setEnqueuingProcessId("0"); secondChildOfParentProcess1.setProcess(firstParentProcess); secondChildOfParentProcess1.setNextProcessId("0"); secondChildOfParentProcess1.setDeleteFlag(false); secondChildOfParentProcess1.setEditTs(new Date()); secondChildOfParentProcess1.setWorkflowType(childWorkflowType); secondChildOfParentProcess1Id = processDAO.insert(secondChildOfParentProcess1); Process thirdChildOfParentProcess1 = new Process(); thirdChildOfParentProcess1.setProcessName("Test"); thirdChildOfParentProcess1.setDescription("Test Process"); thirdChildOfParentProcess1.setBusDomain(busDomain); thirdChildOfParentProcess1.setProcessType(childProcessType); thirdChildOfParentProcess1.setAddTs(new Date()); thirdChildOfParentProcess1.setCanRecover(true); thirdChildOfParentProcess1.setEnqueuingProcessId("0"); thirdChildOfParentProcess1.setProcess(firstParentProcess); thirdChildOfParentProcess1.setNextProcessId("0"); thirdChildOfParentProcess1.setDeleteFlag(false); thirdChildOfParentProcess1.setEditTs(new Date()); thirdChildOfParentProcess1.setWorkflowType(childWorkflowType); thirdChildOfParentProcess1Id = processDAO.insert(thirdChildOfParentProcess1); Process fourthChildOfParentProcess1 = new Process(); fourthChildOfParentProcess1.setProcessName("Test"); fourthChildOfParentProcess1.setDescription("Test Process"); fourthChildOfParentProcess1.setBusDomain(busDomain); fourthChildOfParentProcess1.setProcessType(childProcessType); fourthChildOfParentProcess1.setAddTs(new Date()); fourthChildOfParentProcess1.setCanRecover(true); fourthChildOfParentProcess1.setEnqueuingProcessId("0"); fourthChildOfParentProcess1.setProcess(firstParentProcess); fourthChildOfParentProcess1.setNextProcessId("0"); fourthChildOfParentProcess1.setDeleteFlag(false); fourthChildOfParentProcess1.setEditTs(new Date()); fourthChildOfParentProcess1.setWorkflowType(childWorkflowType); fourthChildOfParentProcess1Id = processDAO.insert(fourthChildOfParentProcess1); process = processDAO.get(firstChildOfParentProcess1Id); process.setNextProcessId(secondChildOfParentProcess1Id.toString() + "," + thirdChildOfParentProcess1Id.toString() + "," + fourthChildOfParentProcess1Id.toString()); processDAO.update(process); Process fifthChildOfParentProcess1 = new Process(); fifthChildOfParentProcess1.setProcessName("Test"); fifthChildOfParentProcess1.setDescription("Test Process"); fifthChildOfParentProcess1.setBusDomain(busDomain); fifthChildOfParentProcess1.setProcessType(childProcessType); fifthChildOfParentProcess1.setAddTs(new Date()); fifthChildOfParentProcess1.setCanRecover(true); fifthChildOfParentProcess1.setEnqueuingProcessId("0"); fifthChildOfParentProcess1.setProcess(firstParentProcess); fifthChildOfParentProcess1.setNextProcessId("0"); fifthChildOfParentProcess1.setDeleteFlag(false); fifthChildOfParentProcess1.setEditTs(new Date()); fifthChildOfParentProcess1.setWorkflowType(childWorkflowType); fifthChildOfParentProcess1Id = processDAO.insert(fifthChildOfParentProcess1); Process sixthChildOfParentProcess1 = new Process(); sixthChildOfParentProcess1.setProcessName("Test"); sixthChildOfParentProcess1.setDescription("Test Process"); sixthChildOfParentProcess1.setBusDomain(busDomain); sixthChildOfParentProcess1.setProcessType(childProcessType); sixthChildOfParentProcess1.setAddTs(new Date()); sixthChildOfParentProcess1.setCanRecover(true); sixthChildOfParentProcess1.setEnqueuingProcessId("0"); sixthChildOfParentProcess1.setProcess(firstParentProcess); sixthChildOfParentProcess1.setNextProcessId("0"); sixthChildOfParentProcess1.setDeleteFlag(false); sixthChildOfParentProcess1.setEditTs(new Date()); sixthChildOfParentProcess1.setWorkflowType(childWorkflowType); sixthChildOfParentProcess1Id = processDAO.insert(sixthChildOfParentProcess1); process = processDAO.get(secondChildOfParentProcess1Id); process.setNextProcessId(fifthChildOfParentProcess1Id.toString() + "," + sixthChildOfParentProcess1Id.toString()); processDAO.update(process); process = processDAO.get(thirdChildOfParentProcess1Id); process.setNextProcessId(fifthChildOfParentProcess1Id.toString() + "," + sixthChildOfParentProcess1Id.toString()); processDAO.update(process); process = processDAO.get(fourthChildOfParentProcess1Id); process.setNextProcessId(fifthChildOfParentProcess1Id.toString() + "," + sixthChildOfParentProcess1Id.toString()); processDAO.update(process); Process seventhChildOfParentProcess1 = new Process(); seventhChildOfParentProcess1.setProcessName("Test"); seventhChildOfParentProcess1.setDescription("Test Process"); seventhChildOfParentProcess1.setBusDomain(busDomain); seventhChildOfParentProcess1.setProcessType(childProcessType); seventhChildOfParentProcess1.setAddTs(new Date()); seventhChildOfParentProcess1.setCanRecover(true); seventhChildOfParentProcess1.setEnqueuingProcessId("0"); seventhChildOfParentProcess1.setProcess(firstParentProcess); seventhChildOfParentProcess1.setNextProcessId("0"); seventhChildOfParentProcess1.setDeleteFlag(false); seventhChildOfParentProcess1.setEditTs(new Date()); seventhChildOfParentProcess1.setWorkflowType(childWorkflowType); seventhChildOfParentProcess1Id = processDAO.insert(seventhChildOfParentProcess1); process = processDAO.get(fifthChildOfParentProcess1Id); process.setNextProcessId(seventhChildOfParentProcess1Id.toString()); processDAO.update(process); process = processDAO.get(sixthChildOfParentProcess1Id); process.setNextProcessId(seventhChildOfParentProcess1Id.toString()); processDAO.update(process); process = processDAO.get(seventhChildOfParentProcess1Id); process.setNextProcessId(firstParentProcessId.toString()); processDAO.update(process); Map<String, PositionsInfo> positionsInfoList = arrangePositions.getListPositionInfo(firstParentProcessId); LOGGER.info("list size" + positionsInfoList.size()); for (PositionsInfo pinfo : positionsInfoList.values()) { LOGGER.info(pinfo.getProcessId() + "-process id. " + pinfo.getxPos() + ":x-pos. " + pinfo.getyPos() + ":y-pos."); pinfo.setxPos(0); pinfo.setyPos(0); LOGGER.info(pinfo.getProcessId() + "-process id. " + pinfo.getxPos() + ":x-pos altered." + pinfo.getyPos() + ":y-pos."); } Map<String, PositionsInfo> positionsInfoListarranged = arrangePositions.getListPositionInfo(firstParentProcessId); for (PositionsInfo pinfo : positionsInfoListarranged.values()) { LOGGER.info(pinfo.getProcessId() + "-process id. " + pinfo.getxPos() + ":x-pos arranged. " + pinfo.getyPos() + ":y-pos arranged"); } assertEquals(new Integer(1000), positionsInfoListarranged.get(firstParentProcessId.toString()).getxPos()); assertEquals(new Integer(100),positionsInfoListarranged.get(firstParentProcessId.toString()).getyPos()); }finally { try { processDAO.testDelete(firstChildOfParentProcess1Id); }catch (Exception e) { LOGGER.info("unable to delete firstChildOfParentProcess1"); flag = 1; } try { processDAO.testDelete(secondChildOfParentProcess1Id); }catch (Exception e) { LOGGER.info("unable to delete secondChildOfParentProcess1"); flag = 1; } try { processDAO.testDelete(thirdChildOfParentProcess1Id); }catch (Exception e) { LOGGER.info("unable to delete thirdChildOfParentProcess1"); flag = 1; } try { processDAO.testDelete(fourthChildOfParentProcess1Id); }catch (Exception e) { LOGGER.info("unable to delete fourthChildOfParentProcess1"); flag = 1; } try { processDAO.testDelete(fifthChildOfParentProcess1Id); }catch (Exception e) { LOGGER.info("unable to delete fifthChildOfParentProcess1"); flag = 1; } try { processDAO.testDelete(sixthChildOfParentProcess1Id); }catch (Exception e) { LOGGER.info("unable to delete sixthChildOfParentProcess1"); flag = 1; } try { processDAO.testDelete(seventhChildOfParentProcess1Id); }catch (Exception e) { LOGGER.info("unable to delete seventhChildOfParentProcess1"); flag = 1; } try { processDAO.testDelete(firstParentProcessId); }catch (Exception e) { LOGGER.info("unable to delete firstParentProcess1"); flag = 1; } } assertEquals(new Integer(0),flag); }