List of usage examples for org.hibernate.criterion Restrictions disjunction
public static Disjunction disjunction()
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Capacity planning resource /* w w w . j a v a2 s. c om*/ * * @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(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find time sheets of the resource/* w ww. j a va 2 s . co m*/ * * @param employee * @param initDate * @param endDate * @param joins * @param project * @param minStatus * @param maxStatus * @param filterUser * @param statusResource * @param settings * @return */ @SuppressWarnings("unchecked") public List<Timesheet> findByCriteria(Employee employee, Date initDate, Date endDate, List<String> joins, Project project, String minStatus, String maxStatus, Employee filterUser, String statusResource, boolean includeClosed, HashMap<String, String> settings) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq(Timesheet.EMPLOYEE, employee)) .add(Restrictions.eq(Timesheet.INITDATE, initDate)) .add(Restrictions.eq(Timesheet.ENDDATE, endDate)); if (minStatus != null && maxStatus != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.eq(Timesheet.STATUS, minStatus)); disjunction.add(Restrictions.eq(Timesheet.STATUS, maxStatus)); if (Constants.TIMESTATUS_APP0.equals(minStatus) && (Constants.TIMESTATUS_APP2.equals(maxStatus) || Constants.TIMESTATUS_APP3.equals(maxStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)); } if (Constants.TIMESTATUS_APP3.equals(maxStatus) && (Constants.TIMESTATUS_APP0.equals(minStatus) || Constants.TIMESTATUS_APP1.equals(minStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)); } //TODO 21/04/2015 - jordi.ripoll- tarea 1095 -pendiente de confirmacion // Last level be approved hours app1 by setting // // String lastLevelForApprove = SettingUtil.getString(settings, Settings.SETTING_LAST_LEVEL_FOR_APPROVE_SHEET, // Settings.DEFAULT_LAST_LEVEL_FOR_APPROVE_SHEET); // // if ((filterUser != null && lastLevelForApprove.equals(String.valueOf(filterUser.getResourceprofiles().getIdProfile()))) && // (settings != null && SettingUtil.getBoolean(settings, GeneralSetting.LAST_LEVEL_APPROVED_APP1))) { // // disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)); // } crit.add(disjunction); } Criteria critEmployee = crit.createCriteria(Timesheet.EMPLOYEE); critEmployee.createCriteria(Employee.CONTACT); Criteria critActivity = crit.createCriteria(Timesheet.PROJECTACTIVITY); Criteria critMembers = critActivity.createCriteria(Projectactivity.TEAMMEMBERS) .add(Restrictions.eq(Teammember.EMPLOYEE, employee)); if (ValidateUtil.isNotNull(statusResource)) { critMembers.add(Restrictions.eq(Teammember.STATUS, statusResource)); } Criteria critProject = critActivity.createCriteria(Projectactivity.PROJECT); if (!includeClosed) { critProject.add(Restrictions.and(Restrictions.ne(Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne(Project.STATUS, Constants.STATUS_ARCHIVED))); } if (project != null) { critProject.add(Restrictions.eq(Project.IDPROJECT, project.getIdProject())); } else if (filterUser != null) { // Filter by User. Settings by company for last approval. Resourceprofiles profile = filterUser.getResourceprofiles(); if (profile.getIdProfile() == Constants.ROLE_FM) { critProject.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser)); } else if (profile.getIdProfile() == Constants.ROLE_PMO) { critProject.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg())); } } addJoins(crit, joins); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find Time Sheets operations//from w ww .jav a 2 s . c om * @param employee * @param initDate * @param endDate * @param joins * @return */ @SuppressWarnings("unchecked") public List<Timesheet> findByOperation(Employee employee, Date initDate, Date endDate, List<String> joins, String minStatus, String maxStatus) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Timesheet.EMPLOYEE, employee)).add(Restrictions.isNotNull(Timesheet.OPERATION)) .add(Restrictions.eq(Timesheet.INITDATE, initDate)) .add(Restrictions.eq(Timesheet.ENDDATE, endDate)); if (minStatus != null && maxStatus != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.eq(Timesheet.STATUS, minStatus)); disjunction.add(Restrictions.eq(Timesheet.STATUS, maxStatus)); if (Constants.TIMESTATUS_APP0.equals(minStatus) && (Constants.TIMESTATUS_APP2.equals(maxStatus) || Constants.TIMESTATUS_APP3.equals(maxStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)); } if (Constants.TIMESTATUS_APP3.equals(maxStatus) && (Constants.TIMESTATUS_APP0.equals(minStatus) || Constants.TIMESTATUS_APP1.equals(minStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)); } crit.add(disjunction); } addJoins(crit, joins); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Get Hours resource/* w w w. ja va 2 s . co m*/ * @param idEmployee * @param id * @param initDate * @param endDate * @param minStatus * @param maxStatus * @return */ public double getHoursResource(Integer idEmployee, Integer id, Date initDate, Date endDate, String minStatus, Employee filterUser) { ProjectionList proList = Projections.projectionList(); proList.add(Projections.sum(Timesheet.HOURSDAY1)); proList.add(Projections.sum(Timesheet.HOURSDAY2)); proList.add(Projections.sum(Timesheet.HOURSDAY3)); proList.add(Projections.sum(Timesheet.HOURSDAY4)); proList.add(Projections.sum(Timesheet.HOURSDAY5)); proList.add(Projections.sum(Timesheet.HOURSDAY6)); proList.add(Projections.sum(Timesheet.HOURSDAY7)); Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList) .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .add(Restrictions.eq(Timesheet.INITDATE, initDate)).add(Restrictions.eq(Timesheet.ENDDATE, endDate)) .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee))); if (Constants.TIMESTATUS_APP1.equals(minStatus)) { crit.createCriteria(Timesheet.PROJECTACTIVITY) .add(Restrictions.eq(Projectactivity.PROJECT, new Project(id))); } else if (Constants.TIMESTATUS_APP2.equals(minStatus)) { // Filter by User. Settings by company for last approval. Criteria critFilter = crit.createCriteria(Timesheet.PROJECTACTIVITY) .createCriteria(Projectactivity.PROJECT); Resourceprofiles profile = filterUser.getResourceprofiles(); if (profile.getIdProfile() == Constants.ROLE_FM) { critFilter.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser)); } else if (profile.getIdProfile() == Constants.ROLE_PMO) { critFilter.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg())); } } Object[] hoursList = (Object[]) crit.uniqueResult(); double hours = 0; if (hoursList != null) { hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]); hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]); hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]); hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]); hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]); hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]); hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]); } return hours; }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Get Hours resource by operation/*from w w w . j a v a2 s .c om*/ * @param idEmployee * @param initDate * @param endDate * @return */ public double getHoursResourceOpeartion(Integer idEmployee, Date initDate, Date endDate) { ProjectionList proList = Projections.projectionList(); proList.add(Projections.sum(Timesheet.HOURSDAY1)); proList.add(Projections.sum(Timesheet.HOURSDAY2)); proList.add(Projections.sum(Timesheet.HOURSDAY3)); proList.add(Projections.sum(Timesheet.HOURSDAY4)); proList.add(Projections.sum(Timesheet.HOURSDAY5)); proList.add(Projections.sum(Timesheet.HOURSDAY6)); proList.add(Projections.sum(Timesheet.HOURSDAY7)); Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList) .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .add(Restrictions.eq(Timesheet.INITDATE, initDate)).add(Restrictions.eq(Timesheet.ENDDATE, endDate)) .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee))) .add(Restrictions.isNotNull(Timesheet.OPERATION)); Object[] hoursList = (Object[]) crit.uniqueResult(); double hours = 0; if (hoursList != null) { hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]); hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]); hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]); hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]); hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]); hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]); hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]); } return hours; }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Calculate Fte for inputed hours in project * /*from w w w. j a v a 2 s .c om*/ * @param project * @param member * @param firstWeekDay * @param lastWeekDay * @return */ public double getHoursResource(Project project, Employee member, Date firstWeekDay, Date lastWeekDay) { ProjectionList proList = Projections.projectionList(); proList.add(Projections.sum(Timesheet.HOURSDAY1)); proList.add(Projections.sum(Timesheet.HOURSDAY2)); proList.add(Projections.sum(Timesheet.HOURSDAY3)); proList.add(Projections.sum(Timesheet.HOURSDAY4)); proList.add(Projections.sum(Timesheet.HOURSDAY5)); proList.add(Projections.sum(Timesheet.HOURSDAY6)); proList.add(Projections.sum(Timesheet.HOURSDAY7)); Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.eq(Timesheet.EMPLOYEE, member)); if (firstWeekDay != null && lastWeekDay != null) { crit.add(Restrictions.eq(Timesheet.INITDATE, firstWeekDay)) .add(Restrictions.eq(Timesheet.ENDDATE, lastWeekDay)); } // Aliases // crit.createAlias(Timesheet.PROJECTACTIVITY, "pa", CriteriaSpecification.LEFT_JOIN); // Projects or operations crit.add(Restrictions.disjunction().add(Restrictions.isNotNull(Timesheet.OPERATION)) .add(Restrictions.eq("pa." + Projectactivity.PROJECT, project))); Object[] hoursList = (Object[]) crit.uniqueResult(); double hours = 0; if (hoursList != null) { hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]); hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]); hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]); hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]); hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]); hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]); hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]); } return hours; }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
public double getHoursResourceInDates(Project project, Employee member, Date since, Date until, Integer idResourcePool, Operation operation, Projectactivity activity) { Criteria crit = getSession().createCriteria(getPersistentClass()); Criteria employeeCrit = null;//from w w w. j a va 2s . com if (member != null || idResourcePool != null) { employeeCrit = crit.createCriteria(Timesheet.EMPLOYEE); } if (idResourcePool != null) { employeeCrit.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool))); } if (member != null) { employeeCrit.add(Restrictions.idEq(member.getIdEmployee())); } if (since != null && until != null) { crit.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)))); } if (project != null) { crit.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)); Criteria activitiesCrit = crit.createCriteria(Timesheet.PROJECTACTIVITY) .add(Restrictions.eq(Projectactivity.PROJECT, project)); // Select only timesheet whose activity is control account Criteria wbsnodeCrit = activitiesCrit.createCriteria(Projectactivity.WBSNODE) .add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true)); } else if (operation != null) { crit.add(Restrictions.or(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2), Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .add(Restrictions.eq(Timesheet.OPERATION, operation)); } else if (activity != null) { crit.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.eq(Timesheet.PROJECTACTIVITY, activity)); } return calcHours(crit.list(), since, until); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * The node has hours in APP1, APP2 or APP3 * //ww w . jav a2 s . c om * @param wbsNode * @return */ public boolean isInputedApprovedHours(Wbsnode wbsNode) { Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount()) .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .createCriteria(Timesheet.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.WBSNODE, wbsNode)); return (Integer) crit.uniqueResult() > 0; }
From source file:eu.interedition.text.Name.java
License:Apache License
public static Set<Name> get(Session session, Set<Name> names) { final Set<Name> result = Sets.newHashSet(); if (names.isEmpty()) { return result; }//from w ww . j a v a 2s . c o m final Set<Name> toFind = Sets.newHashSet(names); final Disjunction or = Restrictions.disjunction(); for (Name name : toFind) { final Conjunction and = Restrictions.conjunction(); and.add(Restrictions.eq("localName", name.getLocalName())); final URI ns = name.getNamespace(); and.add(ns == null ? Restrictions.isNull("namespaceURI") : Restrictions.eq("namespaceURI", ns.toString())); or.add(and); } for (Name name : SQL.iterate(session.createCriteria(Name.class).add(or), Name.class)) { toFind.remove(name); result.add(name); } for (Name name : toFind) { result.add((Name) session.merge(name)); } return result; }
From source file:eu.interedition.text.query.OrQueryOperator.java
License:Apache License
@Override
Junction junction() {
return Restrictions.disjunction();
}