List of usage examples for org.hibernate.criterion Restrictions isNotNull
public static Criterion isNotNull(String propertyName)
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Approvals Time Sheets by Functional Manager * //from w w w .j a v a2s .c o m * @param user * @param initDate * @param endDate * @param status * @param statusResource * @param includeClosed * @param onlyOperations * @param employees - not equals * @return */ @SuppressWarnings("unchecked") public List<Employee> findApprovals(Employee user, Date initDate, Date endDate, String status, String statusResource, boolean includeClosed, List<Employee> employees, boolean onlyOperations) { Resourceprofiles profile = user.getResourceprofiles(); Criteria crit = getSession().createCriteria(getPersistentClass(), "e") .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setFetchMode(Employee.CONTACT, FetchMode.JOIN); if (ValidateUtil.isNotNull(employees)) { List<Integer> ids = new ArrayList<Integer>(); for (Employee item : employees) { ids.add(item.getIdEmployee()); } crit.add(Restrictions.not(Restrictions.in("e." + Employee.IDEMPLOYEE, ids))); } crit.createCriteria(Employee.TIMESHEETS, "ts").add(Restrictions.eq(Timesheet.INITDATE, initDate)) .add(Restrictions.eq(Timesheet.ENDDATE, endDate)).add(Restrictions.eq(Timesheet.STATUS, status)) .createAlias(Timesheet.PROJECTACTIVITY, "pa", Criteria.LEFT_JOIN) .createAlias("pa." + Projectactivity.PROJECT, "p", Criteria.LEFT_JOIN); if (ValidateUtil.isNotNull(statusResource)) { crit.createCriteria("pa." + Projectactivity.TEAMMEMBERS) .add(Restrictions.eq(Teammember.STATUS, statusResource)).createCriteria(Teammember.EMPLOYEE) .add(Restrictions.eqProperty(Employee.IDEMPLOYEE, "e." + Employee.IDEMPLOYEE)); } else if (onlyOperations) { crit.add(Restrictions.isNotNull("ts." + Timesheet.OPERATION)); } // Exluce projects closed if (!includeClosed) { crit.add(Restrictions.and(Restrictions.ne("p." + Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne("p." + Project.STATUS, Constants.STATUS_ARCHIVED))); } // Filter by User. Settings by company for last approval. if (profile.getIdProfile() == Constants.ROLE_FM) { crit.add(Restrictions.or(Restrictions.eq("p." + Project.EMPLOYEEBYFUNCTIONALMANAGER, user), Restrictions.and(Restrictions.isNull("ts." + Timesheet.PROJECTACTIVITY), Restrictions.eq("e." + Employee.PERFORMINGORG, user.getPerformingorg())))); } else if (profile.getIdProfile() == Constants.ROLE_PMO) { crit.add(Restrictions.or(Restrictions.eq("p." + Project.PERFORMINGORG, user.getPerformingorg()), Restrictions.and(Restrictions.isNull("ts." + Timesheet.PROJECTACTIVITY), Restrictions.eq("e." + Employee.PERFORMINGORG, user.getPerformingorg())))); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Employee> findInputedInOperations(List<Employee> employees, Date since, Date until, Integer idResourcePool) { List<Employee> returnEmployees = null; if (ValidateUtil.isNotNull(employees)) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Integer> ids = new ArrayList<Integer>(); for (Employee item : employees) { ids.add(item.getIdEmployee()); }/*from w ww .j av a 2 s . c o m*/ crit.add(Restrictions.not(Restrictions.in(Employee.IDEMPLOYEE, ids))); if (idResourcePool != null) { crit.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool))); } Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.isNotNull(Timesheet.OPERATION)); if (since != null && until != null) { sheets.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)))); } crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); returnEmployees = crit.list(); } return returnEmployees; }
From source file:es.sm2.openppm.core.dao.MilestoneDAO.java
License:Open Source License
/** * Find milestones filter by projects and milestone type and dates * /*w ww. ja va 2s .co m*/ * @param projects * @param milestonetype * @param milestonecategory * @param until * @param since * @param milestonePending * @param property * @param order * @param joins * @return */ @SuppressWarnings("unchecked") public List<Milestones> filter(List<Project> projects, Milestonetype milestonetype, Milestonecategory milestonecategory, Date since, Date until, String milestonePending, String property, String order, List<String> joins) { List<Milestones> list = new ArrayList<Milestones>(); if (ValidateUtil.isNotNull(projects)) { Criteria crit = getSession().createCriteria(getPersistentClass()); // Filter dates // if (since != null & until != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.between(Milestones.ACHIEVED, since, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.between(Milestones.ESTIMATEDDATE, since, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.between(Milestones.PLANNED, since, until)))); } else if (since != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.ge(Milestones.ACHIEVED, since))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.ge(Milestones.ESTIMATEDDATE, since))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.ge(Milestones.PLANNED, since)))); } else if (until != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.le(Milestones.ACHIEVED, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.le(Milestones.ESTIMATEDDATE, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.le(Milestones.PLANNED, until)))); } // Filter by projects // crit.add(Restrictions.in(Milestones.PROJECT, projects)); // Filter by milestone type // if (milestonetype != null) { crit.add(Restrictions.eq(Milestones.MILESTONETYPE, milestonetype)); } // Filter by milestone category // if (milestonecategory != null) { crit.add(Restrictions.eq(Milestones.MILESTONECATEGORY, milestonecategory)); } // Filter by pendings // if (MilestonePending.YES.name().equals(milestonePending)) { crit.add(Restrictions.isNull(Milestones.ACHIEVED)); } else if (MilestonePending.NO.name().equals(milestonePending)) { crit.add(Restrictions.isNotNull(Milestones.ACHIEVED)); } // Left join milestone type for null relation crit.createCriteria(Milestones.MILESTONETYPE, CriteriaSpecification.LEFT_JOIN); // Joins addJoins(crit, joins); // Orders addOrder(crit, property, order); list = crit.list(); } return list; }
From source file:es.sm2.openppm.core.dao.MilestoneDAO.java
License:Open Source License
/** * Find milestones filter by project and activity and dates * // www . j av a2 s. co m * @param project * @param projectactivity * @param since * @param until * @param hasCategory * @param property * @param order * @param joins * @return */ @SuppressWarnings("unchecked") public List<Milestones> filter(Project project, Projectactivity projectactivity, Date since, Date until, boolean hasCategory, String property, String order, List<String> joins) { List<Milestones> list = new ArrayList<Milestones>(); if (project != null) { Criteria crit = getSession().createCriteria(getPersistentClass()); // Filter dates // if (since != null & until != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.between(Milestones.ACHIEVED, since, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.between(Milestones.ESTIMATEDDATE, since, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.between(Milestones.PLANNED, since, until)))); } else if (since != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.ge(Milestones.ACHIEVED, since))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.ge(Milestones.ESTIMATEDDATE, since))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.ge(Milestones.PLANNED, since)))); } else if (until != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.le(Milestones.ACHIEVED, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.le(Milestones.ESTIMATEDDATE, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.le(Milestones.PLANNED, until)))); } // Filter by project // if (project != null) { crit.add(Restrictions.eq(Milestones.PROJECT, project)); } // Filter by activity // if (projectactivity != null) { crit.add(Restrictions.eq(Milestones.PROJECTACTIVITY, projectactivity)); } // Filter by has category // if (hasCategory) { crit.add(Restrictions.isNotNull(Milestones.MILESTONECATEGORY)); } // Joins addJoins(crit, joins); // Orders addOrder(crit, property, order); list = crit.list(); } return list; }
From source file:es.sm2.openppm.core.dao.OperationDAO.java
License:Open Source License
/** * Find operations by employees and dates and status app3 * // w w w . j a v a2 s. c o m * @param employees * @param since * @param until * @return */ @SuppressWarnings("unchecked") public List<Operation> findByEmployeesAndDatesAndApproved(List<Employee> employees, Date since, Date until, Company company) { List<Operation> operations = null; if (ValidateUtil.isNotNull(employees)) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Operation // crit.addOrder(Order.asc(Operation.OPERATIONNAME)).createCriteria(Operation.OPERATIONACCOUNT) .add(Restrictions.eq(Operationaccount.COMPANY, company)); // Timesheet // Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.isNotNull(Timesheet.OPERATION)); if (!employees.isEmpty()) { sheets.add(Restrictions.in(Timesheet.EMPLOYEE, employees)); } if (since != null && until != null) { sheets.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)))); } operations = crit.list(); } return operations; }
From source file:es.sm2.openppm.core.dao.ProjectDAO.java
License:Open Source License
/** * Find PMs by employee and dates/*from w w w .j a v a 2 s .co m*/ * * @param employee * @param dates * @return */ public List<Project> findPMs(Employee employee, List<Date> dates) { // Create criteria Criteria crit = getSession().createCriteria(getPersistentClass()); // Filter not null project managers crit.add(Restrictions.isNotNull(Project.EMPLOYEEBYPROJECTMANAGER)); // Filters teammember by assigned and employee Criteria teammembers = crit.createCriteria(Project.PROJECTACTIVITIES) .createCriteria(Projectactivity.TEAMMEMBERS) .add(Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_ASSIGNED)) .add(Restrictions.eq(Teammember.EMPLOYEE, employee)); // Filter dates if (ValidateUtil.isNotNull(dates)) { for (Date date : dates) { teammembers.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, date), Restrictions.ge(Teammember.DATEOUT, date))); } } return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProjectFollowupDAO.java
License:Open Source License
/** * Return Last Projectfollowup with general flag * @param proj/*from www . j a va 2 s . c o m*/ * @return */ public Projectfollowup findLastByProject(Project proj) { Projectfollowup followup = null; if (proj != null) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Projectfollowup.PROJECT, proj)) .add(Restrictions.isNotNull(Projectfollowup.GENERALFLAG)) .addOrder(Order.desc(Projectfollowup.FOLLOWUPDATE)).setMaxResults(1); followup = (Projectfollowup) crit.uniqueResult(); } return followup; }
From source file:es.sm2.openppm.core.dao.ProjectFollowupDAO.java
License:Open Source License
/** * Return Last Followup//from w ww.j av a 2 s .com * @param proj * @return */ public Projectfollowup findLast(Project proj) { Projectfollowup followup = null; if (proj != null) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Projectfollowup.PROJECT, proj)) .add(Restrictions.isNotNull(Projectfollowup.PV)) .addOrder(Order.desc(Projectfollowup.FOLLOWUPDATE)).setMaxResults(1); followup = (Projectfollowup) crit.uniqueResult(); } return followup; }
From source file:es.sm2.openppm.core.dao.ProjectFollowupDAO.java
License:Open Source License
/** * Return Last Projectfollowup with AC// ww w . ja va 2 s . c o m * @param proj * @return */ public Projectfollowup findLastByProjectWithAC(Project proj) { Projectfollowup followup = null; if (proj != null) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Projectfollowup.PROJECT, proj)) .add(Restrictions.isNotNull(Projectfollowup.AC)) .addOrder(Order.desc(Projectfollowup.FOLLOWUPDATE)).setMaxResults(1); followup = (Projectfollowup) crit.uniqueResult(); } return followup; }
From source file:es.sm2.openppm.core.dao.ProjectFollowupDAO.java
License:Open Source License
/** * Return Last Projectfollowup with risk flag * @param proj/* ww w.j a va2 s . co m*/ * @return */ public Projectfollowup findLastByProjectRisk(Project proj) { Projectfollowup followup = null; if (proj != null) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Projectfollowup.PROJECT, proj)) .add(Restrictions.isNotNull(Projectfollowup.RISKFLAG)) .addOrder(Order.desc(Projectfollowup.FOLLOWUPDATE)).setMaxResults(1); followup = (Projectfollowup) crit.uniqueResult(); } return followup; }