ProcessDAO { public List<com.wipro.ats.bdre.md.dao.jpa.Process> list(Integer pid, Integer processTypeId,Integer pageNum, Integer numResults,String userName) { Session session = sessionFactory.openSession(); List<Process> processes = new ArrayList<Process>(); try { session.beginTransaction(); Process argument = new Process(); Process process = new Process(); if (pid != null) { argument.setProcessId(pid); process = (Process) session.get(Process.class, pid); } Criteria checkSubProcessCriteria = session.createCriteria(Process.class).add(Restrictions.eq(PROCESS, argument)).add(Restrictions.eq(DELETE_FLAG, false)); if (pid == null) { Criteria roleCriteria = session.createCriteria(UserRoles.class).add(Restrictions.eq("users.username", userName)); List<UserRoles> userRoles = roleCriteria.list(); List<String> userRoleListOfLoggedUser=new ArrayList<>(); for (UserRoles userRoles1 : userRoles){ userRoleListOfLoggedUser.add(userRoles1.getRole()); } List<Integer> userRoleIdListOfLoggedUser=new ArrayList<>(); Criteria userRoleIdCriteria = session.createCriteria(UserRoles.class).add(Restrictions.in("role", userRoleListOfLoggedUser)).setProjection(Projections.property("userRoleId")); userRoleIdListOfLoggedUser=userRoleIdCriteria.list(); if(processTypeId==null){ if(userRoleListOfLoggedUser.contains("ROLE_ADMIN")){ Criteria criteria = session.createCriteria(Process.class).add(Restrictions.isNull(PARENTPROCESSID)).add(Restrictions.eq(DELETE_FLAG, false)).add(Restrictions.not(Restrictions.eq("processType.processTypeId",41))).add(Restrictions.not(Restrictions.eq("processType.processTypeId",86))) .addOrder(Order.desc(PROCESSID)); criteria.setFirstResult(pageNum); criteria.setMaxResults(numResults); processes = criteria.list(); } else { Criteria criteria = session.createCriteria(Process.class). add(Restrictions.isNull(PARENTPROCESSID)). add(Restrictions.eq(DELETE_FLAG, false)). addOrder(Order.desc(PROCESSID)). add(Restrictions.disjunction(). add(Restrictions.and(Restrictions.eq("users.username",userName),Restrictions.gt("permissionTypeByUserAccessId.permissionTypeId",3))).add(Restrictions.not(Restrictions.eq("processType.processTypeId",41))). add(Restrictions.and(Restrictions.in("userRoles.userRoleId",userRoleIdListOfLoggedUser),Restrictions.gt("permissionTypeByGroupAccessId.permissionTypeId",3))). add(Restrictions.and(Restrictions.not(Restrictions.in("userRoles.userRoleId",userRoleIdListOfLoggedUser)),Restrictions.gt("permissionTypeByOthersAccessId.permissionTypeId",3)))); criteria.setFirstResult(pageNum); criteria.setMaxResults(numResults); LOGGER.info("size of list is " + criteria.list().size()); processes = criteria.list(); } } else { if(userRoleListOfLoggedUser.contains("ROLE_ADMIN")){ Criteria criteria = session.createCriteria(Process.class).add(Restrictions.isNull(PARENTPROCESSID)).add(Restrictions.eq(DELETE_FLAG, false)).add(Restrictions.eq("processType.processTypeId",processTypeId)) .addOrder(Order.desc(PROCESSID)); criteria.setFirstResult(pageNum); criteria.setMaxResults(numResults); processes = criteria.list(); } else { Criteria criteria = session.createCriteria(Process.class). add(Restrictions.isNull(PARENTPROCESSID)). add(Restrictions.eq(DELETE_FLAG, false)). addOrder(Order.desc(PROCESSID)). add(Restrictions.disjunction(). add(Restrictions.and(Restrictions.eq("users.username",userName),Restrictions.gt("permissionTypeByUserAccessId.permissionTypeId",3))).add(Restrictions.eq("processType.processTypeId",processTypeId)). add(Restrictions.and(Restrictions.in("userRoles.userRoleId",userRoleIdListOfLoggedUser),Restrictions.gt("permissionTypeByGroupAccessId.permissionTypeId",3))). add(Restrictions.and(Restrictions.not(Restrictions.in("userRoles.userRoleId",userRoleIdListOfLoggedUser)),Restrictions.gt("permissionTypeByOthersAccessId.permissionTypeId",3)))); criteria.setFirstResult(pageNum); criteria.setMaxResults(numResults); LOGGER.info("size of list is " + criteria.list().size()); processes = criteria.list(); } } } else if (checkSubProcessCriteria.list().isEmpty() && process.getProcessId() == pid) { Criteria listOfRelatedSP = session.createCriteria(Process.class).add(Restrictions.eq(PROCESSID, process.getProcess().getProcessId())).add(Restrictions.eq(DELETE_FLAG, false)) .addOrder(Order.desc(PROCESSID)); listOfRelatedSP.setFirstResult(pageNum); listOfRelatedSP.setMaxResults(numResults); processes = listOfRelatedSP.list(); } else { Criteria processList = session.createCriteria(Process.class).add(Restrictions.isNull(PARENTPROCESSID)).add(Restrictions.eq(PROCESSID, pid)) .add(Restrictions.eq(DELETE_FLAG, false)); processList.setFirstResult(pageNum); processList.setMaxResults(numResults); processes = processList.list(); } session.getTransaction().commit(); } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error(e); } finally { session.close(); } return processes; }  List<com.wipro.ats.bdre.md.dao.jpa.Process> list(Integer pid, Integer processTypeId,Integer pageNum, Integer numResults,String userName); List<com.wipro.ats.bdre.md.dao.jpa.Process> processList(); Integer totalRecordCount(Integer pid,Integer processTypeId); Integer totalCount(); Process get(Integer id); Process getParent(Integer id); Integer insert(Process process); Process update(Process process); void delete(Integer id); void testDelete(Integer id); List<com.wipro.ats.bdre.md.dao.jpa.Process> subProcesslist(Integer processId); String getParentProcessTypeId(Integer pid); String getProcessTypeName(Integer pid); List<Process> selectProcessList(Integer processId); List<Process> selectProcessList(String processCode,String username); Process returnProcess(String processCode,String username); List<Process> returnProcesses(String processCode); void updateProcessId(Integer oldProcessId, Integer newProcessId); Process cloneProcess(Integer processId); List<ProcessInfo> selectProcessListWithExec(Integer processId, Long instanceExecId); List<Process> createOneChildJob(Process parentProcess, Process childProcess, List<Properties> parentProps, List<Properties> childProps ); List<Process> createHiveMigrationJob(Process parentProcess, List<Process> childProcesses, List<Properties> parentProperties); List<Process> createAnalyticsAppJob(Process parentProcess, List<Process> childProcesses, List<Properties> appProperties); List<Process> createDataloadJob(Process parentProcess, List<Process> childProcesses, List<Properties> parentProps, Map<Process,List<Properties>> childProps ); String securityCheck(Integer processId,String username,String action); List<com.wipro.ats.bdre.md.dao.jpa.Process> listByName(String processName); List<Process> getDownStreamProcess(Integer pid);  }
@Test @Ignore public void testList() throws Exception { }