Example usage for org.hibernate.criterion Restrictions isNull

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

Introduction

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

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

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

License:Open Source License

/**
 * Search Employee By filter/*from   w w w .  j  a v a2 s.c  om*/
 * @param name
 * @param jobTitle
 * @param idProfile
 * @param idPerfOrg
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> searchByFilter(String name, String jobTitle, Integer idProfile, Integer idPerfOrg,
        Company company) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).add(
            Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true)));

    crit.createCriteria(Employee.CONTACT).add(Restrictions.ilike(Contact.FULLNAME, "%" + name + "%"))
            .add(Restrictions.ilike(Contact.JOBTITLE, "%" + jobTitle + "%"))
            .add(Restrictions.eq(Contact.COMPANY, company))
            .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true)))
            .createCriteria(Contact.COMPANY)
            .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

    if (idProfile != -1) {
        crit.add(Restrictions.eq(Employee.RESOURCEPROFILES, new Resourceprofiles(idProfile)));
    }
    if (idPerfOrg != -1) {
        crit.add(Restrictions.eq(Employee.PERFORMINGORG, new Performingorg(idPerfOrg)));
    }

    crit.setFetchMode(Employee.CONTACT, FetchMode.JOIN);
    crit.setFetchMode(Employee.CONTACT + "." + Contact.COMPANY, FetchMode.JOIN);
    crit.setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN);

    return crit.list();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Employee> consEmployeesByUser(Contact contact) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).add(
            Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true)));

    crit.createCriteria(Employee.RESOURCEPROFILES).addOrder(Order.asc(Resourceprofiles.PROFILENAME));

    crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN).setFetchMode(Employee.PERFORMINGORG,
            FetchMode.JOIN);// w  ww  .  j  a v  a  2s .  c om

    crit.createCriteria(Employee.CONTACT).add(Restrictions.idEq(contact.getIdContact()))
            .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true)))
            .createCriteria(Contact.COMPANY)
            .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

    return crit.list();
}

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

License:Open Source License

/**
 * Find Approvals Time Sheets by Functional Manager
 * //w  w  w . ja v a  2  s  .  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

/**
 * Cons employees for login and profile//w ww .j a v a  2s .  c om
 * 
 * @param contact
 * @param profile
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> consEmployeesByUserAndRol(Contact contact, int profile) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).add(
            Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true)));

    crit.createCriteria(Employee.RESOURCEPROFILES).add(Restrictions.eq(Resourceprofiles.IDPROFILE, profile));

    crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN).setFetchMode(Employee.PERFORMINGORG,
            FetchMode.JOIN);

    crit.createCriteria(Employee.CONTACT).add(Restrictions.idEq(contact.getIdContact()))
            .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true)))
            .createCriteria(Contact.COMPANY)
            .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

    return crit.list();
}

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

License:Open Source License

/**
 * Employees by profile and company/*from  ww  w.  j a  v a 2s. c  o  m*/
 * 
 * @param profile
 * @param company 
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> consEmployeesByRol(int profile, Company company) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).add(
            Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true)));

    crit.createCriteria(Employee.RESOURCEPROFILES).add(Restrictions.eq(Resourceprofiles.IDPROFILE, profile));

    crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN).setFetchMode(Employee.PERFORMINGORG,
            FetchMode.JOIN);

    Criteria critContact = crit.createCriteria(Employee.CONTACT);

    critContact.createCriteria(Contact.COMPANY).add(Restrictions.and(
            Restrictions.eq(Company.IDCOMPANY, company.getIdCompany()),
            Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))));

    return crit.list();
}

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

License:Open Source License

/**
 * Consult resource managers by employee
 * /*from w  ww  .ja  va 2 s .c o m*/
 * @param employee
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> consResourceManagers(Employee employee) {

    List<Employee> listEmployee = null;

    if (employee != null && employee.getResourcepool() != null) {

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

        crit.createCriteria(Employee.MANAGEPOOLS)
                .add(Restrictions.eq(Managepool.RESOURCEPOOL, employee.getResourcepool()));

        Criteria critContact = crit.createCriteria(Employee.CONTACT);

        critContact.createCriteria(Contact.COMPANY).add(
                Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

        listEmployee = crit.list();
    }

    return listEmployee;
}

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

License:Open Source License

/**
 * Find Management operations/*from  www  .ja 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.MetrickpiDAO.java

License:Open Source License

/**
 * Search metricKpis by filter/*from ww w .j  av a 2  s  .c  o  m*/
 *
 * @param name
 * @param type
 *@param company  @return
 */
@SuppressWarnings("unchecked")
public List<Metrickpi> searchByFilter(String name, Integer idBSCDimension, String type, Project project,
        Company company, List<String> joins) {

    Metrickpi example = new Metrickpi();
    example.setName(name);

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .add(Example.create(example).ignoreCase().enableLike(MatchMode.ANYWHERE));

    // Add joins
    if (joins != null && !joins.isEmpty()) {
        for (String join : joins) {
            crit.setFetchMode(join, FetchMode.JOIN);
        }
    }

    // by company
    crit.createCriteria(Metrickpi.COMPANY).add(Restrictions.idEq(company.getIdCompany()))
            .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

    // By bsc dimension
    if (!idBSCDimension.equals(-1)) {
        crit.add(Restrictions.eq(Metrickpi.BSCDIMENSION, new Bscdimension(idBSCDimension)));
    }

    // By type
    if (ValidateUtil.isNotNull(type)) {
        crit.add(Restrictions.eq(Metrickpi.TYPE, type));
    }

    // By project
    if (project.getIdProject() != -1) {
        crit.createCriteria(Projectkpi.PROJECT).add(Restrictions.idEq(project.getIdProject()));
    }

    return crit.list();
}

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

License:Open Source License

/**
 * Return Milestones without activity//from ww  w. j a  va  2 s .  co m
 * @param project
 * @return
 */
@SuppressWarnings("unchecked")
public List<Milestones> findMilestoneWithoutActivity(Project project) {
    Criteria crit = getSession().createCriteria(getPersistentClass());
    crit.add(Restrictions.isNull("projectactivity.idActivity"));
    crit.add(Restrictions.eq("project.idProject", project.getIdProject()));
    return crit.list();
}

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  www .  ja  va  2s  .  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;
}