List of usage examples for org.hibernate.criterion Restrictions idEq
public static Criterion idEq(Object value)
From source file:es.sm2.openppm.core.dao.ProjectDAO.java
License:Open Source License
/** * Check if project is in these status/*from w ww .j a v a 2 s . co m*/ * @param project * @param status * @return */ public boolean hasPermissionProject(Project project, String... status) { Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount()) .add(Restrictions.idEq(project.getIdProject())); Disjunction disjuntions = Restrictions.disjunction(); for (String stat : status) { disjuntions.add(Restrictions.eq(Project.STATUS, stat)); } crit.add(disjuntions); return ((Integer) crit.uniqueResult() > 0); }
From source file:es.sm2.openppm.core.dao.ProjectFollowupDAO.java
License:Open Source License
/** * Cons followup with project//from w ww . j a va2s . com * @param projectfollowup * @return */ public Projectfollowup consFollowupWithProject(Projectfollowup projectfollowup) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setFetchMode(Projectfollowup.PROJECT, FetchMode.JOIN) .add(Restrictions.idEq(projectfollowup.getIdProjectFollowup())); return (Projectfollowup) crit.uniqueResult(); }
From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java
License:Open Source License
/** * Search Team Members by filter// w w w . j av a2 s . c om * * @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
/** * Capacity planning resource /*from w w w.j a va 2 s . co 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(); }
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 ww. j a v a 2 s . 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
/** * Calculate Fte for inputed hours in project * @param project// w w w. j a v a 2 s .c om * @param member * @param firstWeekDay * @param lastWeekDay * @return */ public double getHoursResource(Project project, Teammember 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)); crit.createCriteria(Timesheet.EMPLOYEE).createCriteria(Employee.TEAMMEMBERS) .add(Restrictions.idEq(member.getIdTeamMember())); if (firstWeekDay != null && lastWeekDay != null) { crit.add(Restrictions.eq(Timesheet.INITDATE, firstWeekDay)) .add(Restrictions.eq(Timesheet.ENDDATE, lastWeekDay)); } if (project == null) { crit.add(Restrictions.eq(Timesheet.PROJECTACTIVITY, member.getProjectactivity())); } else { crit.createCriteria(Timesheet.PROJECTACTIVITY).add(Restrictions.eq(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.utils.hibernate.dao.AbstractGenericHibernateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public T findById(ID id, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()).add(Restrictions.idEq(id)); addJoins(crit, joins);//from w ww. ja v a 2 s . c o m return (T) crit.uniqueResult(); }
From source file:es.udc.tfg_es.clubtriatlon.utils.dao.GenericDaoHibernate.java
License:BSD License
public boolean exists(PK id) { return getSession().createCriteria(entityClass).add(Restrictions.idEq(id)).setProjection(Projections.id()) .uniqueResult() != null; }
From source file:eu.interedition.text.query.AnnotationIdentityCriterion.java
License:Apache License
@Override
Criterion restrict() {
return Restrictions.idEq(annotation);
}
From source file:gov.nih.nci.caarray.dao.AbstractCaArrayDaoImpl.java
License:BSD License
Criterion createExample(Object entity, MatchMode matchMode, boolean excludeNulls, boolean excludeZeroes, Collection<String> excludeProperties) { final Example example = Example.create(entity).enableLike(matchMode).ignoreCase(); if (excludeZeroes) { example.excludeZeroes();/* www . j a v a2 s . c om*/ } else if (!excludeNulls) { example.excludeNone(); } for (final String property : excludeProperties) { example.excludeProperty(property); } // ID property is not handled by Example, so we have to special case it final PersistentClass pclass = getClassMapping(entity.getClass()); Object idVal = null; if (pclass != null && pclass.hasIdentifierProperty()) { try { idVal = PropertyUtils.getProperty(entity, pclass.getIdentifierProperty().getName()); } catch (final Exception e) { LOG.warn("Could not retrieve identifier value in a by example query, ignoring it", e); } } if (idVal == null) { return example; } else { return Restrictions.and(Restrictions.idEq(idVal), example); } }