Example usage for org.hibernate.criterion Restrictions or

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

Introduction

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

Prototype

public static LogicalExpression or(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the disjuction of two expressions

Usage

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

License:Open Source License

/**
 * Get employee for generate token//from www  . j ava2  s .  com
 * @param contact
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> findForToken(Contact contact) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Employee.CONTACT, contact))
            .add(Restrictions.or(
                    Restrictions.eq(Employee.RESOURCEPROFILES, new Resourceprofiles(Constants.ROLE_PMO)),
                    Restrictions.eq(Employee.RESOURCEPROFILES, new Resourceprofiles(Constants.ROLE_PM))));

    List<String> joins = new ArrayList<String>();
    joins.add(Employee.PERFORMINGORG);
    joins.add(Employee.RESOURCEPROFILES);

    addJoins(crit, joins);

    crit.addOrder(Order.asc(Employee.PERFORMINGORG));
    crit.addOrder(Order.asc(Employee.RESOURCEPROFILES));

    return crit.list();
}

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

License:Open Source License

/**
 * Cons employees for login and profile//from  w  ww.jav a 2 s. 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//ww  w. j a va  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
 * //ww  w . jav a  2 s.com
 * @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   w w w  . ja  v  a  2 s  .  c o  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.ExpensesheetDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Expensesheet> findByResource(Employee employee, Date since, Date until, String minStatus,
        String maxStatus, Employee user, Project project, List<String> joins) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
            .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until));

    Criteria employeeCrit = crit.createCriteria(Expensesheet.EMPLOYEE)
            .add(Restrictions.idEq(employee.getIdEmployee()));

    if (minStatus != null && maxStatus != null) {

        crit.add(Restrictions.or(Restrictions.eq(Expensesheet.STATUS, minStatus),
                Restrictions.eq(Expensesheet.STATUS, maxStatus)));
    }//w  w w . j  a v a 2  s . c  o m

    if (project != null) {
        crit.add(Restrictions.eq(Expensesheet.PROJECT, project));
    } else if (user != null) {

        employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg()));
    }

    addJoins(crit, joins);
    return crit.list();
}

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

License:Open Source License

public double getCostResource(Integer idEmployee, Integer id, Date since, Date until, String minStatus,
        String maxStatus, Employee user) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.sum(Expensesheet.COST))
            .add(Restrictions.or(Restrictions.eq(Expensesheet.STATUS, minStatus),
                    Restrictions.eq(Expensesheet.STATUS, maxStatus)))
            .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until));

    Criteria employeeCrit = crit.createCriteria(Expensesheet.EMPLOYEE).add(Restrictions.idEq(idEmployee));

    if (Constants.EXPENSE_STATUS_APP1.equals(minStatus)) {
        crit.add(Restrictions.eq(Expensesheet.PROJECT, new Project(id)));
    } else if (Constants.EXPENSE_STATUS_APP2.equals(minStatus)) {

        employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg()));
    }// w w w.java 2s  . co  m
    double cost = (Double) (crit.uniqueResult() == null ? 0D : crit.uniqueResult());

    return cost;
}

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

License:Open Source License

/**
 * Search metricKpis by filter//w  w w  .jav a2  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.ProjectDAO.java

License:Open Source License

/**
 * Find by PO and equals Planning or Execution
 * @param performingorg//  w ww.j av a2 s. c o m
 * @return
 */
@SuppressWarnings("unchecked")
public List<Project> findByPO(Performingorg performingorg) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Project.PERFORMINGORG, performingorg))
            .add(Restrictions.or(Restrictions.eq(Project.STATUS, Constants.STATUS_CONTROL),
                    Restrictions.eq(Project.STATUS, Constants.STATUS_PLANNING)));

    return crit.list();
}

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

License:Open Source License

/**
 * /*  ww  w.ja  v  a2 s.c o  m*/
 * @param performingorg
 * @param projectsDisabled
 * @return
 */
@SuppressWarnings("unchecked")
public List<Project> findByPO(Performingorg performingorg, boolean projectsDisabled) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Project.PERFORMINGORG, performingorg))
            .add(Restrictions.or(Restrictions.eq(Project.STATUS, Constants.STATUS_CONTROL),
                    Restrictions.eq(Project.STATUS, Constants.STATUS_PLANNING)));

    // Projects not disabled
    if (projectsDisabled) {

        crit.add(Restrictions.disjunction().add(Restrictions.ne(Project.DISABLE, Constants.SELECTED))
                .add(Restrictions.isNull(Project.DISABLE)));
    }

    return crit.list();
}