List of usage examples for org.hibernate Criteria createCriteria
public Criteria createCriteria(String associationPath) throws HibernateException;
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Employees where inputed hours is approval * /*w ww. j a v a 2s . co m*/ * @param idResourcePools * @param projects * @param fullName * @param idJobCategories * @param idPMs * @param idSellers * @param idCategories * @param since * @param until * @param order * @param nameOrder * @return */ @SuppressWarnings("unchecked") public List<Employee> findInputedInProjects(Integer[] idResourcePools, List<Project> projects, Integer[] idPMs, Integer[] idJobCategories, Integer[] idSellers, Integer[] idCategories, String fullName, Date since, Date until, String nameOrder, String order, Employee user) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Filter by user if (user != null) { crit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg())); } // Aliases // crit.createAlias(Employee.TEAMMEMBERS, "tm", CriteriaSpecification.INNER_JOIN) .createAlias(Employee.TIMESHEETS, "ts", CriteriaSpecification.INNER_JOIN) .createAlias("tm." + Teammember.PROJECTACTIVITY, "pa", CriteriaSpecification.INNER_JOIN) .createAlias("pa." + Projectactivity.PROJECT, "p", CriteriaSpecification.LEFT_JOIN) .createAlias("p." + Project.EMPLOYEEBYPROJECTMANAGER, "pm", CriteriaSpecification.LEFT_JOIN) .createAlias(Employee.RESOURCEPOOL, "rp", CriteriaSpecification.LEFT_JOIN) .createAlias(Employee.SELLER, "s", CriteriaSpecification.LEFT_JOIN) .createAlias("tm." + Teammember.JOBCATEGORY, "jc", CriteriaSpecification.LEFT_JOIN) .createAlias("p." + Project.CATEGORY, "c", CriteriaSpecification.LEFT_JOIN); // Teammembers // crit.add(Restrictions.eq("tm." + Teammember.STATUS, Constants.RESOURCE_ASSIGNED)); if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between("tm." + Teammember.DATEIN, since, until)) .add(Restrictions.between("tm." + Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le("tm." + Teammember.DATEIN, since), Restrictions.ge("tm." + Teammember.DATEOUT, until)))); } // Timesheets // crit.add(Restrictions.eq("ts." + Timesheet.STATUS, Constants.TIMESTATUS_APP3)); if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between("ts." + Timesheet.INITDATE, since, until)) .add(Restrictions.between("ts." + Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le("ts." + Timesheet.INITDATE, since), Restrictions.ge("ts." + Timesheet.ENDDATE, until)))); } // Filters // Conjunction conjunction = Restrictions.conjunction(); // Filter by projects if (ValidateUtil.isNotNull(projects)) { conjunction.add(Restrictions.in("pa." + Projectactivity.PROJECT, projects)); } // Filter by project managers if (ValidateUtil.isNotNull(idPMs)) { conjunction.add(Restrictions.in("pm." + Employee.IDEMPLOYEE, idPMs)); } // Filter by resourcepools if (ValidateUtil.isNotNull(idResourcePools)) { conjunction.add(Restrictions.in("rp." + Resourcepool.IDRESOURCEPOOL, idResourcePools)); } // Filter by sellers if (ValidateUtil.isNotNull(idSellers)) { conjunction.add(Restrictions.in("s." + Seller.IDSELLER, idSellers)); } // Filter by jobcategories if (ValidateUtil.isNotNull(idJobCategories)) { conjunction.add(Restrictions.in("jc." + Jobcategory.IDJOBCATEGORY, idJobCategories)); } // Filter by categories if (ValidateUtil.isNotNull(idCategories)) { conjunction.add(Restrictions.in("c." + Category.IDCATEGORY, idCategories)); } crit.add(conjunction); // Filter by Full Name Criteria contactCrit = crit.createCriteria(Employee.CONTACT); if (ValidateUtil.isNotNull(fullName)) { contactCrit.add(Restrictions.ilike(Contact.FULLNAME, "%" + fullName + "%")); } // Apply Order Criteria orderCrit = null; String alias = StringPool.BLANK; if (Project.IDPROJECT.equals(nameOrder)) { alias = "pm."; orderCrit = crit; } else if (Jobcategory.IDJOBCATEGORY.equals(nameOrder)) { alias = "jc."; orderCrit = crit; } else { orderCrit = contactCrit; } if (nameOrder != null) { if (Constants.DESCENDENT.equals(order)) { orderCrit.addOrder(Order.desc(alias + nameOrder)); } else { orderCrit.addOrder(Order.asc(alias + nameOrder)); } } // Calendar base crit.setFetchMode(Employee.CALENDARBASE, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Management operations//from ww w . j a v a 2 s. co m * * @param search * @param user * @param resourcePools * @return */ public List<Employee> find(TimeSheetOperationSearch search, Employee user, List<Resourcepool> resourcePools) { Criteria timeSheetCrit = getSession().createCriteria(Timesheet.class); // Operation // timeSheetCrit.createCriteria(Timesheet.OPERATION) .add(Restrictions.eq(Operation.IDOPERATION, search.getCodeOperation())) .add(Restrictions.eq(Operation.AVAILABLEFORMANAGER, Boolean.TRUE)); if (search.getSince() != null && search.getUntil() != null) { timeSheetCrit.add(Restrictions.disjunction() .add(Restrictions.between(Timesheet.INITDATE, search.getSince(), search.getUntil())) .add(Restrictions.between(Timesheet.ENDDATE, search.getSince(), search.getUntil())) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, search.getSince()), Restrictions.ge(Timesheet.ENDDATE, search.getUntil())))); } // Filter by NOT Resource if (user != null && user.getResourceprofiles() != null && !Resourceprofiles.Profile.RESOURCE.equals(user.getResourceprofiles().getProfile())) { List<String> statusList = new ArrayList<String>(); statusList.add(Constants.TIMESTATUS_APP1); statusList.add(Constants.TIMESTATUS_APP2); statusList.add(Constants.TIMESTATUS_APP3); timeSheetCrit.add(Restrictions.in(Timesheet.STATUS, statusList)); } // Employee // Criteria employeeCriteria = timeSheetCrit.createCriteria(Timesheet.EMPLOYEE); if (ValidateUtil.isNotNull(resourcePools)) { employeeCriteria.add(Restrictions.in(Employee.RESOURCEPOOL, resourcePools)); } if (search.getCodePool() != null) { employeeCriteria.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(search.getCodePool()))); } if (ValidateUtil.isNotNull(search.getCodeJobCategoryList())) { employeeCriteria.createCriteria(Employee.JOBCATEMPLOYEES).createCriteria(Jobcatemployee.JOBCATEGORY) .add(Restrictions.in(Jobcategory.IDJOBCATEGORY, search.getCodeJobCategoryList())); } if (ValidateUtil.isNotNull(search.getCodeSkillList())) { employeeCriteria.createCriteria(Employee.SKILLSEMPLOYEES).createCriteria(Skillsemployee.SKILL) .add(Restrictions.in(Skill.IDSKILL, search.getCodeSkillList())); } // Contact // Criteria critContact = employeeCriteria.createCriteria(Employee.CONTACT); if (ValidateUtil.isNotNull(search.getCodeContactList())) { critContact.add(Restrictions.in(Contact.IDCONTACT, search.getCodeContactList())); } critContact.createCriteria(Contact.COMPANY) .add(Restrictions.eq(Company.IDCOMPANY, search.getCompany().getIdCompany())) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE, FetchMode.JOIN); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE + StringPool.PERIOD + Employee.CONTACT, FetchMode.JOIN); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE + StringPool.PERIOD + Employee.RESOURCEPOOL, FetchMode.JOIN); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE + StringPool.PERIOD + Employee.SELLER, FetchMode.JOIN); HashMap<Integer, Employee> groupingTime = new HashMap<Integer, Employee>(); List<Employee> employees = new ArrayList<Employee>(); for (Timesheet timesheet : (List<Timesheet>) timeSheetCrit.list()) { if (groupingTime.containsKey(timesheet.getEmployee().getIdEmployee())) { Employee employee = groupingTime.get(timesheet.getEmployee().getIdEmployee()); employee.getTimesheets().add(timesheet); } else { Employee employee = timesheet.getEmployee(); employee.setTimesheets(new HashSet<Timesheet>()); employee.getTimesheets().add(timesheet); groupingTime.put(timesheet.getEmployee().getIdEmployee(), employee); employees.add(employee); } } return employees; }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find by search// w ww. j a v a 2 s . com * * @param search * @return */ public List<Employee> find(EmployeeSearch search) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); // PO Criteria critPO = crit.createCriteria(Employee.PERFORMINGORG); if (search.getCodePerformingOrganization() != null) { critPO.add(Restrictions.eq(Performingorg.IDPERFORG, search.getCodePerformingOrganization())); } // Resource profile Criteria critProfile = crit.createCriteria(Employee.RESOURCEPROFILES); if (search.getCodeProfile() != null) { critProfile.add(Restrictions.eq(Resourceprofiles.IDPROFILE, search.getCodeProfile())); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.ExpensesDAO.java
License:Open Source License
/** * Check if budget account is in use in project and expense * @param project/* w w w. ja v a 2s.c o m*/ * @param expenses * @param budgetaccounts * @return */ public boolean isBudgetInUse(Project project, Expenses expenses, Budgetaccounts budgetaccounts) { Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount()) .add(Restrictions.eq(Expenses.BUDGETACCOUNTS, budgetaccounts)); if (expenses.getIdExpense() != -1) { crit.add(Restrictions.ne(Expenses.IDEXPENSE, expenses.getIdExpense())); } crit.createCriteria(Expenses.PROJECTCOSTS).add(Restrictions.eq(Projectcosts.PROJECT, project)); Integer count = (Integer) crit.uniqueResult(); return (count != null && count > 0); }
From source file:es.sm2.openppm.core.dao.ExpensesDAO.java
License:Open Source License
/** * Find by project/*from w w w . j ava 2 s. com*/ * * @param project * @return */ @SuppressWarnings("unchecked") public List<Expenses> findByProject(Project project) { Criteria crit = getSession().createCriteria(getPersistentClass()); // Filter project crit.createCriteria(Expenses.PROJECTCOSTS).add(Restrictions.eq(Projectcosts.PROJECT, project)); // Order crit.createCriteria(Expenses.BUDGETACCOUNTS).addOrder(Order.asc(Budgetaccounts.DESCRIPTION)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ExpensesheetDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Expensesheet> findByResource(Employee employee, Date since, Date until, String minStatus, String maxStatus, Employee user, Project project, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until)); Criteria employeeCrit = crit.createCriteria(Expensesheet.EMPLOYEE) .add(Restrictions.idEq(employee.getIdEmployee())); if (minStatus != null && maxStatus != null) { crit.add(Restrictions.or(Restrictions.eq(Expensesheet.STATUS, minStatus), Restrictions.eq(Expensesheet.STATUS, maxStatus))); }//from www . j av a 2 s .co m if (project != null) { crit.add(Restrictions.eq(Expensesheet.PROJECT, project)); } else if (user != null) { employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg())); } addJoins(crit, joins); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ExpensesheetDAO.java
License:Open Source License
public double getCostResource(Integer idEmployee, Integer id, Date since, Date until, String minStatus, String maxStatus, Employee user) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setProjection(Projections.sum(Expensesheet.COST)) .add(Restrictions.or(Restrictions.eq(Expensesheet.STATUS, minStatus), Restrictions.eq(Expensesheet.STATUS, maxStatus))) .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until)); Criteria employeeCrit = crit.createCriteria(Expensesheet.EMPLOYEE).add(Restrictions.idEq(idEmployee)); if (Constants.EXPENSE_STATUS_APP1.equals(minStatus)) { crit.add(Restrictions.eq(Expensesheet.PROJECT, new Project(id))); } else if (Constants.EXPENSE_STATUS_APP2.equals(minStatus)) { employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg())); }/*from ww w. ja v a 2 s . co m*/ double cost = (Double) (crit.uniqueResult() == null ? 0D : crit.uniqueResult()); return cost; }
From source file:es.sm2.openppm.core.dao.ExpensesheetDAO.java
License:Open Source License
/** * Is in status// ww w .j a v a 2s .co m * @param idEmployee * @param id * @param since * @param until * @param status * @param user * @return */ public boolean isStatusResource(Integer idEmployee, Integer id, Date since, Date until, String status, Employee user) { Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount()) .add(Restrictions.eq(Expensesheet.STATUS, status)) .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until)); Criteria employeeCrit = crit.createCriteria(Expensesheet.EMPLOYEE).add(Restrictions.idEq(idEmployee)); if (Constants.EXPENSE_STATUS_APP1.equals(status)) { crit.add(Restrictions.eq(Expensesheet.PROJECT, new Project(id))); } else if (Constants.EXPENSE_STATUS_APP2.equals(status)) { employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg())); } Integer count = (Integer) crit.uniqueResult(); return (count != null && count > 0); }
From source file:es.sm2.openppm.core.dao.JobcatemployeeDAO.java
License:Open Source License
/** * Find jobs categories by employee//from ww w.j av a2s.c o m * @param employee * @return */ @SuppressWarnings("unchecked") public List<Jobcatemployee> findByEmployee(Employee employee) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.add(Restrictions.eq(Jobcatemployee.EMPLOYEE, employee)); crit.createCriteria(Jobcatemployee.JOBCATEGORY).addOrder(Order.asc(Jobcategory.NAME)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ManagepoolDAO.java
License:Open Source License
/** * Find employees resource managers by company * /* w w w. j a v a 2s . c o m*/ * @param company * @return */ @SuppressWarnings("unchecked") public List<Managepool> findResourceManagers(Company company) { Criteria crit = getSession().createCriteria(getPersistentClass()); Criteria critEmployee = crit.createCriteria(Managepool.EMPLOYEE); critEmployee.createCriteria(Employee.CONTACT).add(Restrictions.eq(Contact.COMPANY, company)) .addOrder(Order.asc(Contact.FULLNAME)); return crit.list(); }