Example usage for org.hibernate.criterion Restrictions ne

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

Introduction

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

Prototype

public static SimpleExpression ne(String propertyName, Object value) 

Source Link

Document

Apply a "not equal" constraint to the named property

Usage

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

License:Open Source License

/**
 * Find Management operations/* w ww . j  a va 2  s. c  om*/
 *
 * @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.ExpensesDAO.java

License:Open Source License

/**
 * Check if budget account is in use in project and expense
 * @param project/*from   w  ww .  jav a  2  s.  c  om*/
 * @param expenses
 * @param budgetaccounts
 * @return
 */
public boolean isBudgetInUse(Project project, Expenses expenses, Budgetaccounts budgetaccounts) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.eq(Expenses.BUDGETACCOUNTS, budgetaccounts));

    if (expenses.getIdExpense() != -1) {
        crit.add(Restrictions.ne(Expenses.IDEXPENSE, expenses.getIdExpense()));
    }

    crit.createCriteria(Expenses.PROJECTCOSTS).add(Restrictions.eq(Projectcosts.PROJECT, project));

    Integer count = (Integer) crit.uniqueResult();

    return (count != null && count > 0);
}

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

License:Open Source License

/**
 * Find labels enabled by company/*from  www. ja va 2 s. co  m*/
 * 
 * @param company
 * @return
 */
@SuppressWarnings("unchecked")
public List<Label> findEnabledByCompany(Company company) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Label.COMPANY, company)).add(Restrictions.ne(Label.DISABLE, true))
            .addOrder(Order.asc(Label.NAME));

    return crit.list();
}

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

License:Open Source License

/**
 * Search metricKpis by filter//  w  w  w.ja v a  2s .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.PerformingOrgDAO.java

License:Open Source License

/**
 * Find other POs by company//from  w  w w. j a  v  a  2  s. com
 * @param company
 * @param performingorg
 * @return
 */
@SuppressWarnings("unchecked")
public List<Performingorg> findOtherPOs(Company company, Integer idPerfOrg) {
    Criteria crit = getSession().createCriteria(getPersistentClass());

    crit.add(Restrictions.ne(Performingorg.IDPERFORG, idPerfOrg))
            .add(Restrictions.eq(Performingorg.COMPANY, company));

    addOrder(crit, Performingorg.NAME, Constants.ASCENDENT);

    return crit.list();
}

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

License:Open Source License

/**
 * Find restriction type/*w  w w.j a v  a 2s  .  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
 * /*from  www.  j a v  a 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

/**
 * Update Planned Dates of root activity
 * /*w w  w  .  jav  a  2 s.c om*/
 * @param project
 * @param rootActivity
 */
public void updatePlannedDates(Project project, Projectactivity rootActivity) {

    // Num of activities of project
    int numActivities = rowCountEq(Projectactivity.PROJECT, project);

    // Get max and min project activity dates
    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.projectionList().add(Projections.min(Projectactivity.PLANINITDATE))
                    .add(Projections.max(Projectactivity.PLANENDDATE)))
            .add(Restrictions.eq(Projectactivity.PROJECT, project));

    // Exclude root activities
    if (numActivities > 1) {
        crit.add(Restrictions.ne(Projectactivity.IDACTIVITY, rootActivity.getIdActivity()));
    }

    Object[] row = (Object[]) crit.uniqueResult();

    // Init calculated plan dates
    Date calculatedPlanStartDate = null;
    Date calculatedPlanFinishDate = null;

    // If there is result set root activity
    if (row != null && row.length > 0) {

        Date planInitDate = (Date) row[0];
        Date planEndDate = (Date) row[1];

        rootActivity.setPlanInitDate(planInitDate);
        rootActivity.setPlanEndDate(planEndDate);
        rootActivity = makePersistent(rootActivity);

        // Set calculated plan dates 
        calculatedPlanStartDate = planInitDate == null ? project.getPlannedInitDate() : planInitDate;
        calculatedPlanFinishDate = planEndDate == null ? project.getPlannedFinishDate() : planEndDate;
    } else {

        // Set calculated plan dates 
        calculatedPlanStartDate = project.getPlannedInitDate();
        calculatedPlanFinishDate = project.getPlannedFinishDate();
    }

    // Update calculated planning dates
    Query query = getSession().createQuery("update Project p "
            + " set p.calculatedPlanStartDate = :calculatedPlanStartDate,"
            + " p.calculatedPlanFinishDate = :calculatedPlanFinishDate" + " where p.idProject = :idProject");
    query.setInteger("idProject", project.getIdProject());
    query.setDate("calculatedPlanStartDate", calculatedPlanStartDate);
    query.setDate("calculatedPlanFinishDate", calculatedPlanFinishDate);
    query.executeUpdate();
}

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

License:Open Source License

/**
 * Update Actual Dates of root activity//from  www.  ja  va  2  s . c  om
 * 
 * @param project
 * @param rootActivity
 */
@SuppressWarnings("unchecked")
public void updateActualDates(Project project, Projectactivity rootActivity) {

    // Find activities by project, exclude root activity
    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Projectactivity.PROJECT, project))
            .add(Restrictions.ne(Projectactivity.IDACTIVITY, rootActivity.getIdActivity()));

    List<Projectactivity> activities = crit.list();

    Date initDate = null;
    Date endDate = null;

    for (Projectactivity activity : activities) {

        // Update init date
        //
        if (activity.getActualInitDate() != null
                && (initDate == null || initDate.after(activity.getActualInitDate()))) {

            initDate = activity.getActualInitDate();
        } else if (activity.getActualInitDate() == null && activity.getPlanInitDate() != null
                && (initDate == null || initDate.after(activity.getPlanInitDate()))) {

            initDate = activity.getPlanInitDate();
        }

        // Update end Date
        //
        if (activity.getActualEndDate() != null
                && (endDate == null || endDate.before(activity.getActualEndDate()))) {

            endDate = activity.getActualEndDate();
        } else if (activity.getActualEndDate() == null && activity.getPlanEndDate() != null
                && (endDate == null || endDate.before(activity.getPlanEndDate()))) {

            endDate = activity.getPlanEndDate();
        }
    }

    // Update dates with project dates if not has been assigned in activities
    if (initDate == null) {
        initDate = project.getPlannedInitDate();
    }
    if (endDate == null) {
        endDate = project.getPlannedFinishDate();
    }

    // Set dates in root activity
    rootActivity.setActualInitDate(initDate);
    rootActivity.setActualEndDate(endDate);

    // Save changes
    makePersistent(rootActivity);
}

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

License:Open Source License

/**
 *
 * Find activity with greater date/*from  ww  w .java  2s.  co  m*/
 * The activity can not be the same activity nor the parent node
  *
 * @param project
 * @param projectactivity
 * @param rootActivity
 * @return
 */
public Projectactivity findActivityMaxEndDate(Project project, Projectactivity projectactivity,
        Projectactivity rootActivity) {

    List<Projectactivity> list = null;

    if (project != null && projectactivity != null && rootActivity != null) {
        // Control activity is not the same you are updating and is not the parent activity
        Criteria crit = getSession().createCriteria(getPersistentClass())
                .add(Restrictions.eq(Projectactivity.PROJECT, project))
                .add(Restrictions.ne(Projectactivity.IDACTIVITY, projectactivity.getIdActivity()))
                .add(Restrictions.ne(Projectactivity.IDACTIVITY, rootActivity.getIdActivity()))
                .addOrder(Order.desc(Projectactivity.PLANENDDATE));

        list = crit.list();
    }

    return (list.isEmpty() ? null : list.get(0));
}