Example usage for org.hibernate.criterion Restrictions idEq

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

Introduction

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

Prototype

public static Criterion idEq(Object value) 

Source Link

Document

Apply an "equal" constraint to the identifier property

Usage

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  ww  .jav a2  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()));
    }/*from  w w w  .j a  v  a2  s . co  m*/
    double cost = (Double) (crit.uniqueResult() == null ? 0D : crit.uniqueResult());

    return cost;
}

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

License:Open Source License

/**
 * Is in status/*w ww. jav  a 2 s .  c om*/
 * @param idEmployee
 * @param id
 * @param since
 * @param until
 * @param status
 * @param user 
 * @return
 */
public boolean isStatusResource(Integer idEmployee, Integer id, Date since, Date until, String status,
        Employee user) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.eq(Expensesheet.STATUS, status))
            .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until));

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

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

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

    Integer count = (Integer) crit.uniqueResult();
    return (count != null && count > 0);
}

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

License:Open Source License

/**
 * Search metricKpis by filter/*from w  w  w  .  j  av a  2 s . c  om*/
 *
 * @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.PluginDAO.java

License:Open Source License

/**
 * Get plugins enabled by contact//from   w w  w .j a  v a  2 s.  co m
 * @param contact
 * @return
 */
@SuppressWarnings("unchecked")
public List<Plugin> findByContact(Contact contact) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).add(Restrictions.eq(Plugin.ENABLED, true))
            .createCriteria(Plugin.COMPANY).createCriteria(Company.CONTACTS)
            .add(Restrictions.idEq(contact.getIdContact()));

    return crit.list();
}

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
 * /*  ww w.ja  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.ProjectcalendarDAO.java

License:Open Source License

/**
 * Check if is Exception day in project//from www .ja 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;
}

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

License:Open Source License

public boolean hasPermission(Project project, Employee user, Company company, int tab) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.idEq(project.getIdProject()));

    int rol = user.getResourceprofiles().getIdProfile();

    if (rol == Constants.ROLE_PMO || rol == Constants.ROLE_FM || rol == Constants.ROLE_LOGISTIC) {
        crit.add(Restrictions.eq(Project.PERFORMINGORG, user.getPerformingorg()));
    } else if (rol == Constants.ROLE_PM) {
        crit.add(Restrictions.eq(Project.EMPLOYEEBYPROJECTMANAGER, user));
    } else if (rol == Constants.ROLE_SPONSOR) {
        crit.add(Restrictions.eq(Project.EMPLOYEEBYSPONSOR, user));
    } else if (rol == Constants.ROLE_PORFM) {
        crit.createCriteria(Project.PERFORMINGORG).add(Restrictions.eq(Performingorg.COMPANY, company));
    } else if (rol == Constants.ROLE_IM && tab == Constants.TAB_INITIATION) {
        crit.add(Restrictions.eq(Project.EMPLOYEEBYINVESTMENTMANAGER, user));
    } else if (rol == Constants.ROLE_PROGM) {
        crit.createCriteria(Project.PROGRAM).add(Restrictions.eq(Program.EMPLOYEE, user));
    } else if (rol == Constants.ROLE_STAKEHOLDER) {
        crit.createCriteria(Project.STAKEHOLDERS).add(Restrictions.eq(Stakeholder.EMPLOYEE, user));
    } else {/*from   ww  w  .j  ava 2  s.c o m*/
        return false;
    }

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

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

License:Open Source License

/**
 * Find project by income//from  w w w  .  j  av a2  s  .c  o m
 * @param income
 * @return
 */
public Project findByIncome(Incomes income) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).createCriteria(Project.INCOMESES)
            .add(Restrictions.idEq(income.getIdIncome()));

    return (Project) crit.uniqueResult();
}

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

License:Open Source License

/**
 * Find by Project Followup//from ww w  .j av  a2  s . c  om
 * @param projectfollowup
 * @return
 */
public Project findByFollowup(Projectfollowup projectfollowup) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).createCriteria(Project.PROJECTFOLLOWUPS)
            .add(Restrictions.idEq(projectfollowup.getIdProjectFollowup()));

    return (Project) crit.uniqueResult();
}