Example usage for org.hibernate.criterion Restrictions le

List of usage examples for org.hibernate.criterion Restrictions le

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions le.

Prototype

public static SimpleExpression le(String propertyName, Object value) 

Source Link

Document

Apply a "less than or equal" constraint to the named property

Usage

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  2 s  .c  o  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  va 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.MilestoneDAO.java

License:Open Source License

/**
 * Find milestones filter by projects and milestone type and dates
 * //from w ww .ja  va 2 s  .com
 * @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
 * /*from ww  w . j a  v  a 2 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
 * /* ww  w  .  j a v  a  2s  .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.ProgramDAO.java

License:Open Source License

/**
 * Find restriction type/*from  w  w  w  .  j av  a  2 s .com*/
 * @param propertyRelation
 * @return
 */
@SuppressWarnings("unchecked")
private Criterion findRestriction(PropertyRelation propertyRelation) {

    Criterion criterion = null;

    if (propertyRelation.getRestriction() == Constants.EQUAL_RESTRICTION) {
        criterion = Restrictions.eq(propertyRelation.getProperty(), propertyRelation.getRelation());
    } else if (propertyRelation.getRestriction() == Constants.NOT_EQUAL_RESTRICTION) {
        criterion = Restrictions.ne(propertyRelation.getProperty(), propertyRelation.getRelation());
    } else if (propertyRelation.getRestriction() == Constants.GREATER_OR_EQUAL_RESTRICTION) {
        criterion = Restrictions.ge(propertyRelation.getProperty(), propertyRelation.getRelation());
    } else if (propertyRelation.getRestriction() == Constants.LESS_OR_EQUAL_RESTRICTION) {
        criterion = Restrictions.le(propertyRelation.getProperty(), propertyRelation.getRelation());
    } else if (propertyRelation.getRestriction() == Constants.ILIKE_RESTRICTION) {
        criterion = Restrictions.ilike(propertyRelation.getProperty(), propertyRelation.getRelation());
    } else if (propertyRelation.getRestriction() == Constants.DISJUNCTION) {
        ArrayList<PropertyRelation> listDisjunctions = (ArrayList<PropertyRelation>) propertyRelation
                .getRelation();

        Disjunction d = Restrictions.disjunction();

        for (PropertyRelation propertyRelationDis : listDisjunctions) {
            d.add(findRestriction(propertyRelationDis));
        }

        criterion = d;
    }

    return criterion;
}

From source file:es.sm2.openppm.core.dao.ProjectActivityDAO.java

License:Open Source License

/**
 * Checks whether an activity with a start date is imputed hours than
 * /*w  w  w  .j  a  va  2 s .  c  o  m*/
 * @param activity
 * @return
 */
public boolean checkAfterActivityInputed(Projectactivity activity) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.idEq(activity.getIdActivity())).createCriteria(Projectactivity.TIMESHEETS)
            .add(Restrictions.disjunction().add(Restrictions.ne(Timesheet.HOURSDAY1, 0D))
                    .add(Restrictions.ne(Timesheet.HOURSDAY2, 0D)).add(Restrictions.ne(Timesheet.HOURSDAY3, 0D))
                    .add(Restrictions.ne(Timesheet.HOURSDAY4, 0D)).add(Restrictions.ne(Timesheet.HOURSDAY5, 0D))
                    .add(Restrictions.ne(Timesheet.HOURSDAY6, 0D))
                    .add(Restrictions.ne(Timesheet.HOURSDAY7, 0D)))
            .add(Restrictions.le(Timesheet.ENDDATE, activity.getPlanInitDate()));

    return ((Integer) crit.uniqueResult() > 0);
}

From source file:es.sm2.openppm.core.dao.ProjectActivityDAO.java

License:Open Source License

/**
 * Filter by project and since until over planned dates
 * /*from   w  ww . j ava  2 s.  co  m*/
 * @param project
 * @param since
 * @param until
 * @param typeOrder 
 * @param propertyOrder 
 * @return
 */
@SuppressWarnings("unchecked")
public List<Projectactivity> findByProject(Project project, Date since, Date until, String propertyOrder,
        String typeOrder) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.disjunction()
                    .add(Restrictions.between(Projectactivity.PLANINITDATE, since, until))
                    .add(Restrictions.between(Projectactivity.PLANENDDATE, since, until))
                    .add(Restrictions.and(Restrictions.le(Projectactivity.PLANINITDATE, since),
                            Restrictions.ge(Projectactivity.PLANENDDATE, until))))
            .add(Restrictions.eq(Projectactivity.PROJECT, project));

    addOrder(crit, propertyOrder, typeOrder);

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.ProjectActivityDAO.java

License:Open Source License

/**
 * Find activities inputed//from w w  w .  jav a2  s. c o m
 *
 * @param ids
 * @param since
 * @param until
 * @param idResourcePool
 * @return
 */
@SuppressWarnings("unchecked")
public List<Projectactivity> findActivitiesInputedByProjectsAndEmployees(Integer[] ids, Date since, Date until,
        Integer idResourcePool) {

    List<Projectactivity> activities = null;

    if (ValidateUtil.isNotNull(ids)) {

        Criteria crit = getSession().createCriteria(getPersistentClass())
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

        // All activities by projects
        //
        crit.createCriteria(Projectactivity.PROJECT).add(Restrictions.in(Project.IDPROJECT, ids))
                .addOrder(Order.asc(Project.ACCOUNTINGCODE));

        crit.createCriteria(Projectactivity.WBSNODE).add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true));

        crit.addOrder(Order.asc(Projectactivity.IDACTIVITY));

        // Teammmembers
        //
        Criteria members = crit.createCriteria(Projectactivity.TEAMMEMBERS);

        if (since != null && until != null) {

            members.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))));
        }

        // Employees 
        //
        Criteria employees = members.createCriteria(Teammember.EMPLOYEE);

        if (idResourcePool != null) {
            employees.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool)));
        }

        Criteria sheets = employees.createCriteria(Employee.TIMESHEETS)
                .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3));

        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))));
        }

        activities = crit.list();
    } else {
        activities = new ArrayList<Projectactivity>();
    }

    return activities;
}

From source file:es.sm2.openppm.core.dao.ProjectcalendarDAO.java

License:Open Source License

/**
 * Check if is Exception day in project//ww  w.j  a  v  a 2s .c  o m
 * @param time
 * @param idActivity
 * @return
 */
public boolean isException(Date day, Projectcalendar projCal, Calendarbase calBase) {

    boolean isException = false;

    if (calBase != null) {

        Criteria crit = getSession().createCriteria(Calendarbase.class).setProjection(Projections.rowCount())
                .add(Restrictions.idEq(calBase.getIdCalendarBase()))
                .createCriteria(Calendarbase.CALENDARBASEEXCEPTIONSES)
                .add(Restrictions.and(Restrictions.le(Calendarbaseexceptions.STARTDATE, day),
                        Restrictions.ge(Calendarbaseexceptions.FINISHDATE, day)));

        isException = ((Integer) crit.uniqueResult()) > 0;
    }

    if (!isException && projCal != null) {
        Query query = getSession().createQuery("select count(calendar) " + "from Projectcalendar as calendar "
                + "left join calendar.projectcalendarexceptionses as exceptionsp "
                + "left join calendar.calendarbase as calendarb "
                + "left join calendarb.calendarbaseexceptionses as exceptionsb "
                + "where calendar.idProjectCalendar = :idProjectCalendar "
                + "and (:day between exceptionsp.startDate and exceptionsp.finishDate "
                + "or :day between exceptionsb.startDate and exceptionsb.finishDate)");

        query.setInteger("idProjectCalendar", projCal.getIdProjectCalendar());
        query.setDate("day", day);

        Long count = (Long) query.uniqueResult();

        isException = (count > 0);
    }
    return isException;
}