List of usage examples for org.hibernate Criteria createCriteria
public Criteria createCriteria(String associationPath) throws HibernateException;
From source file:es.sm2.openppm.core.dao.ResourcepoolDAO.java
License:Open Source License
/** * Resource pools by resource managers//from ww w .j av a 2 s.com * * @param resourceManagers * @return */ @SuppressWarnings("unchecked") public List<Resourcepool> findByResourceManagers(List<Employee> resourceManagers) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.createCriteria(Resourcepool.MANAGEPOOLS).add(Restrictions.in(Managepool.EMPLOYEE, resourceManagers)); crit.addOrder(Order.asc(Resourcepool.NAME)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.SecurityDAO.java
License:Open Source License
/** * Return security by employee/*from w ww .j av a 2s.c o m*/ * @param employee * @return */ @SuppressWarnings("unchecked") public Security getByEmployee(Employee employee) { Security security = null; Criteria crit = getSession().createCriteria(getPersistentClass()); crit.createCriteria(Security.CONTACT).createCriteria(Contact.EMPLOYEES) .add(Restrictions.eq(Employee.IDEMPLOYEE, employee.getIdEmployee())); List<Security> list = crit.list(); if (list != null && !list.isEmpty()) { security = list.get(0); } return security; }
From source file:es.sm2.openppm.core.dao.SellerDAO.java
License:Open Source License
/** * Sellers by projects//w ww. j a va2s. c o m * * @param projects * @return */ public List<Seller> findByProcurement(Project... projects) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.createCriteria(Seller.ACTIVITYSELLERS).createCriteria(Activityseller.PROJECTACTIVITY) .add(Restrictions.in(Projectactivity.PROJECT, projects)); crit.addOrder(Order.asc(Seller.NAME)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Search Team Members by Project...//from w ww . j a v a 2 s.com * * @param project * @param since * @param until * @param showDisabled * @return */ public List<Teammember> consStaffinFtes(Project project, Date since, Date until, boolean showDisabled) { // Create query and restrictions Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.or(Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_ASSIGNED), Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_RELEASED))) .add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); // Restriction project crit.createCriteria(Teammember.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); if (!showDisabled) { // Exclude employees and contacts disabled crit.createCriteria(Teammember.EMPLOYEE, "em").add(Restrictions.ne(Employee.DISABLE, true)) .setFetchMode(Teammember.EMPLOYEE + "." + Employee.RESOURCEPROFILES, FetchMode.JOIN); crit.createCriteria("em." + Employee.CONTACT, "contact").add(Restrictions.ne(Contact.DISABLE, true)); } else { crit.setFetchMode(Teammember.EMPLOYEE, FetchMode.JOIN); crit.setFetchMode(Teammember.EMPLOYEE + "." + Employee.RESOURCEPROFILES, FetchMode.JOIN); crit.setFetchMode(Teammember.EMPLOYEE + "." + Employee.CONTACT, FetchMode.JOIN); // Create aliases for order crit.createAlias(Teammember.EMPLOYEE, "em").createAlias("em." + Employee.CONTACT, "contact"); } // Data needed crit.setFetchMode(Teammember.JOBCATEGORY, FetchMode.JOIN); // Order by name crit.addOrder(Order.asc("contact.fullName")); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Search Team Members by Project with actuals FTEs * /*from ww w . ja v a 2 s. c o m*/ * @param project * @param since * @param until * @return */ public List<Teammember> consStaffinActualsFtes(Project project, Date since, Date until) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_ASSIGNED)) .add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); crit.createCriteria(Teammember.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); Criteria timesheetsCrit = crit.createCriteria(Teammember.EMPLOYEE).createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.disjunction().add(Restrictions.between(Timesheet.INITDATE, since, until)) .add(Restrictions.between(Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, since), Restrictions.ge(Timesheet.ENDDATE, until)))); timesheetsCrit.createCriteria(Timesheet.PROJECTACTIVITY) .add(Restrictions.eq(Projectactivity.PROJECT, project)); crit.setFetchMode(Teammember.JOBCATEGORY, FetchMode.JOIN); crit.setFetchMode(Teammember.EMPLOYEE, FetchMode.JOIN); crit.setFetchMode(Teammember.EMPLOYEE + "." + Employee.CALENDARBASE, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Apply filters by table utility// w w w . j av a2s . co m * * @param crit * @param filtrosExtras * @param orders * @param listResourcepool * @throws ParseException */ private void applyFilters(Criteria crit, List<DatoColumna> filtrosExtras, List<DatoColumna> orders, List<Resourcepool> listResourcepool) throws ParseException { employeeCrit = crit.createCriteria(Teammember.EMPLOYEE); if (ValidateUtil.isNotNull(listResourcepool)) { employeeCrit.add(Restrictions.in(Employee.RESOURCEPOOL, listResourcepool)); } critContact = employeeCrit.createCriteria(Employee.CONTACT); critActivity = crit.createCriteria(Teammember.PROJECTACTIVITY); critProject = critActivity.createCriteria(Projectactivity.PROJECT); for (DatoColumna filtroColumna : filtrosExtras) { if (filtroColumna.getTipo() == List.class) { // Since Until if (filtroColumna.getSubTipo() != null && filtroColumna.getSubTipo() == Date.class) { Date sinceDate = (Date) filtroColumna.getObjectList()[0]; Date untilDate = (Date) filtroColumna.getObjectList()[1]; String sinceName = (String) filtroColumna.getNombreList()[0]; String untilName = (String) filtroColumna.getNombreList()[1]; crit.add(Restrictions.disjunction().add(Restrictions.between(sinceName, sinceDate, untilDate)) .add(Restrictions.between(untilName, sinceDate, untilDate)).add(Restrictions.and( Restrictions.le(sinceName, sinceDate), Restrictions.ge(untilName, untilDate)))); } else { // Tiene que estar en la lista crit.add(Restrictions.in(filtroColumna.getNombre(), filtroColumna.getValorList())); } } else if (filtroColumna.getTipo() == String.class) { if (filtroColumna.getSubTipo() == List.class) { if (!ValidateUtil.isNull(filtroColumna.getValor())) { String[] value = filtroColumna.getValor().split(","); List<Integer> ids = new ArrayList<Integer>(); for (String id : value) { ids.add(Integer.parseInt(id)); } if (filtroColumna.getNombre().equals(Project.EMPLOYEEBYPROJECTMANAGER)) { critProject.add(Restrictions.in(filtroColumna.getNombre() + ".idEmployee", ids)); } else if (filtroColumna.getCriteria() != null) { Criteria crit2 = crit.createCriteria(filtroColumna.getCriteria()); crit2.add(Restrictions.in(filtroColumna.getNombre(), ids)); } else { crit.add(Restrictions.in(filtroColumna.getNombre(), ids)); } } } else { // Add filters for fullname project name or charlabel if (filtroColumna.getNombre().equals(Contact.FULLNAME)) { critContact.add( Restrictions.like(filtroColumna.getNombre(), "%" + filtroColumna.getValor() + "%")); } else if (filtroColumna.getNombre().equals(Configurations.PROJECT_NAME)) { // Filter employees by project description OR project short name critProject.add(Restrictions.disjunction() .add(Restrictions.like(Project.PROJECTNAME, StringPool.PERCENT + filtroColumna.getValor() + StringPool.PERCENT)) .add(Restrictions.like(Project.CHARTLABEL, StringPool.PERCENT + filtroColumna.getValor() + StringPool.PERCENT))); } else { // Comparando texto crit.add( Restrictions.like(filtroColumna.getNombre(), "%" + filtroColumna.getValor() + "%")); } } } else if (filtroColumna.getTipo() == Integer.class) { // Filtrando Objectos Integer value = Integer.parseInt(filtroColumna.getValor()); crit.add(Restrictions.eq(filtroColumna.getNombre(), value)); } else if (filtroColumna.getTipo() != Date.class) { // Filtrando Objectos if (filtroColumna.getCriteria() != null) { crit.createCriteria(filtroColumna.getCriteria()) .add(Restrictions.eq(filtroColumna.getNombre(), filtroColumna.getObject())); } else { crit.add(Restrictions.eq(filtroColumna.getNombre(), filtroColumna.getObject())); } } } if (orders != null && !orders.isEmpty()) { appplyOrders(crit, orders); } }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Find members assigned by project in dates * //from ww w .j av a 2 s .c o m * @param employee * @param joins * @return * @throws Exception */ public List<Teammember> findByEmployeeOrderByProject(Employee employee, Date since, Date until, List<String> joins) throws Exception { Criteria crit = getSession().createCriteria(getPersistentClass()); addJoins(crit, joins); crit.add(Restrictions.eq(Teammember.EMPLOYEE, employee)) .add(Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_ASSIGNED)); if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); } else if (since != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, since))); } else if (until != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, until), Restrictions.ge(Teammember.DATEOUT, until))); } crit.createCriteria(Teammember.PROJECTACTIVITY).createCriteria(Projectactivity.PROJECT) .addOrder(Order.desc(Project.IDPROJECT)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Search Team Members by filter/*w w w .j a va 2s .c o m*/ * * @param idResourcePools * @param idProjects * @param idPMs * @param idJobCategories * @param statusList * @param fullName * @param since * @param until * @param nameOrder * @param order * @param idEmployee * @param user * @param idSellers * @param idCategories * @param settings * @return */ public List<Teammember> consStaffinFtes(Integer[] idResourcePools, Integer[] idProjects, Integer[] idPMs, Integer[] idJobCategories, String[] statusList, String fullName, Date since, Date until, String nameOrder, String order, Integer idEmployee, Employee user, Integer[] idSellers, Integer[] idCategories, HashMap<String, String> settings) { Criteria crit = getSession().createCriteria(getPersistentClass(), "t"); if (nameOrder == null && ValidateUtil.isNull(idJobCategories)) { crit.add(Restrictions.isNull(Teammember.JOBCATEGORY)); } Criteria projActCrit = crit.createCriteria(Teammember.PROJECTACTIVITY); // Filter by sellers if (ValidateUtil.isNotNull(idSellers)) { projActCrit.createCriteria(Projectactivity.ACTIVITYSELLERS).createCriteria(Activityseller.SELLER) .add(Restrictions.in(Seller.IDSELLER, idSellers)); } Criteria projCrit = projActCrit.createCriteria(Projectactivity.PROJECT); // Filter by category if (ValidateUtil.isNotNull(idCategories)) { projCrit.createCriteria(Project.CATEGORY).add(Restrictions.in(Category.IDCATEGORY, idCategories)); } // Filter by Project if (ValidateUtil.isNotNull(idProjects)) { projCrit.add(Restrictions.in(Project.IDPROJECT, idProjects)); } // Remove information if project is closed if (!SettingUtil.getBoolean(settings, SettingType.CLOSED_PROJECTS_CAPACITY_PLANNING)) { projCrit.add(Restrictions.and(Restrictions.ne(Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne(Project.STATUS, Constants.STATUS_ARCHIVED))); } // Filter by Project Manager if (user.getResourceprofiles().getIdProfile() == Constants.ROLE_PM) { projCrit.createCriteria(Project.EMPLOYEEBYPROJECTMANAGER) .add(Restrictions.eq(Employee.IDEMPLOYEE, user.getIdEmployee())); } else if (user.getResourceprofiles().getIdProfile() != Constants.ROLE_PM && ValidateUtil.isNotNull(idPMs)) { projCrit.createCriteria(Project.EMPLOYEEBYPROJECTMANAGER) .add(Restrictions.in(Employee.IDEMPLOYEE, idPMs)); } // Filter by Status if (ValidateUtil.isNotNull(statusList)) { crit.add(Restrictions.in(Teammember.STATUS, statusList)); } // Filter by Skill Criteria jobCrit = null; if (Jobcategory.IDJOBCATEGORY.equals(nameOrder) || ValidateUtil.isNotNull(idJobCategories)) { jobCrit = crit.createCriteria(Teammember.JOBCATEGORY); } if (ValidateUtil.isNotNull(idJobCategories)) { jobCrit.add(Restrictions.in(Jobcategory.IDJOBCATEGORY, idJobCategories)); } // Filter by dates (since && until) if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); } else if (since != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, since))); } else if (until != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, until), Restrictions.ge(Teammember.DATEOUT, until))); } // Filter By Employee Criteria employeeCrit = crit.createCriteria(Teammember.EMPLOYEE); if (idEmployee != null) { employeeCrit.add(Restrictions.idEq(idEmployee)); } // Filter by resource pool if (ValidateUtil.isNotNull(idResourcePools)) { employeeCrit.createCriteria(Employee.RESOURCEPOOL) .add(Restrictions.in(Resourcepool.IDRESOURCEPOOL, idResourcePools)); } // Filter by po if (user != null) { employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg())); } // Filter by Full Name Criteria contactCrit = employeeCrit.createCriteria(Employee.CONTACT); if (ValidateUtil.isNotNull(fullName)) { contactCrit.add(Restrictions.ilike(Contact.FULLNAME, "%" + fullName + "%")); } // Apply Order Criteria orderCrit = null; if (Project.IDPROJECT.equals(nameOrder)) { orderCrit = projCrit; } else if (Jobcategory.IDJOBCATEGORY.equals(nameOrder)) { orderCrit = jobCrit; } else { orderCrit = contactCrit; } if (nameOrder != null) { if (Constants.DESCENDENT.equals(order)) { orderCrit.addOrder(Order.desc(nameOrder)); } else { orderCrit.addOrder(Order.asc(nameOrder)); } } contactCrit.addOrder(Order.asc(Contact.IDCONTACT)); List<String> joins = new ArrayList<String>(); joins.add(Teammember.PROJECTACTIVITY); joins.add(Teammember.PROJECTACTIVITY + "." + Projectactivity.PROJECT); joins.add(Teammember.PROJECTACTIVITY + "." + Projectactivity.PROJECT + "." + Project.EMPLOYEEBYPROJECTMANAGER); joins.add(Teammember.PROJECTACTIVITY + "." + Projectactivity.PROJECT + "." + Project.EMPLOYEEBYPROJECTMANAGER + "." + Employee.CONTACT); addJoins(crit, joins); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Find teammembers of project in date/* www .j a va2 s . c om*/ * * @param project * @param closeDate * @return */ public List<Teammember> findByProjectInDate(Project project, Date closeDate) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, closeDate), Restrictions.ge(Teammember.DATEOUT, closeDate))); crit.createCriteria(Teammember.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Capacity planning resource //from ww w.j a v a 2 s .c o m * * @param idEmployee * @param since * @param until * @param statusList * @param joins * @param settings * @param user * @return */ public List<Teammember> capacityPlanningResource(Integer idEmployee, Date since, Date until, String[] statusList, List<String> joins, HashMap<String, String> settings, Employee user) { Criteria crit = getSession().createCriteria(getPersistentClass(), "t"); // Filter by dates (since && until) if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); } else if (since != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, since))); } else if (until != null) { crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, until), Restrictions.ge(Teammember.DATEOUT, until))); } if (ValidateUtil.isNotNull(statusList)) { crit.add(Restrictions.in(Teammember.STATUS, statusList)); } // Filter By Employee Criteria employeeCrit = crit.createCriteria(Teammember.EMPLOYEE); if (idEmployee != null) { employeeCrit.add(Restrictions.idEq(idEmployee)); } // Joins // Criteria projActCrit = crit.createCriteria(Teammember.PROJECTACTIVITY); Criteria projCrit = projActCrit.createCriteria(Projectactivity.PROJECT); // Remove information if project is closed if (!SettingUtil.getBoolean(settings, SettingType.CLOSED_PROJECTS_CAPACITY_PLANNING)) { projCrit.add(Restrictions.and(Restrictions.ne(Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne(Project.STATUS, Constants.STATUS_ARCHIVED))); } addJoins(crit, joins); // PM Projects if (!SettingUtil.getBoolean(settings, GeneralSetting.PM_VIEW_OTHER_PROJECTS) && user.getResourceprofiles().getIdProfile() == Constants.ROLE_PM) { projCrit.add(Restrictions.eq(Project.EMPLOYEEBYPROJECTMANAGER, user)); } // Orders // employeeCrit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); projCrit.addOrder(Order.asc(Project.PROJECTNAME)); projActCrit.addOrder(Order.asc(Projectactivity.ACTIVITYNAME)); return crit.list(); }