Example usage for org.hibernate.criterion Restrictions isNotNull

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

Introduction

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

Prototype

public static Criterion isNotNull(String propertyName) 

Source Link

Document

Apply an "is not null" constraint to the named property

Usage

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

License:Open Source License

public Projectfollowup findLastWithDataByProject(Project proj) {
    Projectfollowup followup = null;//  w w w .  j  a v  a  2  s.  co  m
    if (proj != null) {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        crit.add(Restrictions.eq("project.idProject", proj.getIdProject()))
                .add(Restrictions.disjunction().add(Restrictions.isNotNull("generalFlag"))
                        .add(Restrictions.isNotNull("riskFlag")).add(Restrictions.isNotNull("costFlag"))
                        .add(Restrictions.isNotNull("scheduleFlag")))
                .addOrder(Order.desc("followupDate")).setMaxResults(1);

        followup = (Projectfollowup) crit.uniqueResult();
    }
    return followup;
}

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

License:Open Source License

/**
 * Get EV from program projects until a date
 * @param program//from ww w .ja v  a 2  s.  c om
 * @param tempDate
 * @return
 */
public Double getProgramEV(Program program, Date date, boolean projectsDisabled) {
    Double ev = 0D;

    if (program != null) {
        ProjectDAO projectDAO = new ProjectDAO(getSession());

        List<Project> projects = projectDAO.findByProgramAndProjectsDisabled(program, projectsDisabled);

        for (Project p : projects) {
            Criteria crit = getSession().createCriteria(getPersistentClass());
            crit.add(Restrictions.eq("project.idProject", p.getIdProject()));
            crit.add(Restrictions.lt("followupDate", date));
            crit.add(Restrictions.isNotNull("ev"));
            crit.addOrder(Order.desc("followupDate"));
            crit.setMaxResults(1);

            Projectfollowup followup = (Projectfollowup) crit.uniqueResult();
            if (followup != null) {
                ev += followup.getEv();
            }
        }
    }

    return ev;
}

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

License:Open Source License

/**
 * Consult backlog for a program in a month
 * CurrentMonth is for calculate number of months of a project to end
 * @param program/*from   w  ww.  j a v a 2  s .c o  m*/
 * @param date
 * @return
 */
public Double getProgramBacklog(Program program, Date date, Date currentMonth, boolean projectsDisabled) {
    Double backlog = 0D;

    if (program != null) {
        ProjectDAO projectDAO = new ProjectDAO(getSession());

        List<Project> projects = projectDAO.findByProgramAndProjectsDisabled(program, projectsDisabled);

        for (Project p : projects) {
            if (p.getPlannedFinishDate() != null && p.getPlannedFinishDate().after(date)) {
                Integer months = DateUtil.monthsBetween(currentMonth, p.getPlannedFinishDate());
                if (months <= 0)
                    months = 1;

                Criteria crit = getSession().createCriteria(getPersistentClass());
                crit.add(Restrictions.eq("project.idProject", p.getIdProject()));
                crit.add(Restrictions.lt("followupDate", date));
                crit.add(Restrictions.isNotNull("ev"));
                crit.addOrder(Order.desc("followupDate"));
                crit.setMaxResults(1);

                Projectfollowup followup = (Projectfollowup) crit.uniqueResult();

                if (followup != null) {
                    //Extra is project pending incomes divided by months pending to close project
                    double netIncome = (p.getNetIncome() == null ? 0 : p.getNetIncome());
                    backlog += (netIncome - followup.getEv()) / months;
                }
            }
        }
    }

    return backlog;
}

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

License:Open Source License

/**
 * Find last followup of month/*from   w  w  w  . java2  s  .co m*/
 * @param project
 * @param firstMonthDay
 * @param lastMonthDay
 * @return
 */
public Projectfollowup findLasInMonth(Project project, Date firstMonthDay, Date lastMonthDay) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Projectfollowup.PROJECT, project))
            .add(Restrictions.between(Projectfollowup.FOLLOWUPDATE, firstMonthDay, lastMonthDay))
            .add(Restrictions.isNotNull(Projectfollowup.PV)).setMaxResults(1)
            .addOrder(Order.desc(Projectfollowup.FOLLOWUPDATE));

    return (Projectfollowup) crit.uniqueResult();
}

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

License:Open Source License

/**
 * Find by project and contains metrickpi type
 *
 * @param project//from  w w w . j a  v a2 s.  c  o  m
 * @return
 */
public List<Projectkpi> findByProjectAndMetricType(Project project) {

    // Find by project
    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Projectkpi.PROJECT, project));

    // Find by metrickpi contains type
    crit.createCriteria(Projectkpi.METRICKPI).add(Restrictions.isNotNull(Metrickpi.TYPE));

    return crit.list();
}

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

License:Open Source License

/**
 * Find Time Sheets operations// w  ww  .j ava  2 s . com
 * @param employee
 * @param initDate
 * @param endDate
 * @param joins
 * @return
 */
@SuppressWarnings("unchecked")
public List<Timesheet> findByOperation(Employee employee, Date initDate, Date endDate, List<String> joins,
        String minStatus, String maxStatus) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Timesheet.EMPLOYEE, employee)).add(Restrictions.isNotNull(Timesheet.OPERATION))
            .add(Restrictions.eq(Timesheet.INITDATE, initDate))
            .add(Restrictions.eq(Timesheet.ENDDATE, endDate));

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

        Disjunction disjunction = Restrictions.disjunction();
        disjunction.add(Restrictions.eq(Timesheet.STATUS, minStatus));
        disjunction.add(Restrictions.eq(Timesheet.STATUS, maxStatus));

        if (Constants.TIMESTATUS_APP0.equals(minStatus) && (Constants.TIMESTATUS_APP2.equals(maxStatus)
                || Constants.TIMESTATUS_APP3.equals(maxStatus))) {

            disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1));
        }

        if (Constants.TIMESTATUS_APP3.equals(maxStatus) && (Constants.TIMESTATUS_APP0.equals(minStatus)
                || Constants.TIMESTATUS_APP1.equals(minStatus))) {

            disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2));
        }

        crit.add(disjunction);
    }

    addJoins(crit, joins);

    return crit.list();
}

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

License:Open Source License

/**
 * Is time status//ww  w . j a v a2s  . com
 * @param idEmployee
 * @param initDate
 * @param endDate
 * @param status
 * @param filterUser
 * @param inOperation
 * @return
 */
public boolean isTimeStatus(Integer idEmployee, Date initDate, Date endDate, String status, Employee filterUser,
        boolean inOperation) {

    boolean isStatus = false;

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.eq(Timesheet.STATUS, status)).add(Restrictions.eq(Timesheet.INITDATE, initDate))
            .add(Restrictions.eq(Timesheet.ENDDATE, endDate))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee)));

    if (inOperation) {
        crit.add(Restrictions.isNotNull(Timesheet.OPERATION));
    } else {
        Resourceprofiles profile = filterUser.getResourceprofiles();

        Criterion restriction = null;

        if (profile.getIdProfile() == Constants.ROLE_FM) {
            restriction = Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser);
        } else if (profile.getIdProfile() == Constants.ROLE_PM) {
            restriction = Restrictions.eq(Project.EMPLOYEEBYPROJECTMANAGER, filterUser);
        } else {
            restriction = Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg());
        }

        Criteria critFilter = crit.createCriteria(Timesheet.PROJECTACTIVITY)
                .createCriteria(Projectactivity.PROJECT);
        critFilter.add(restriction);
    }

    isStatus = (Integer) crit.uniqueResult() > 0;

    if (!isStatus && !inOperation) {
        isStatus = isTimeStatus(idEmployee, initDate, endDate, status, filterUser, true);
    }

    return isStatus;
}

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

License:Open Source License

/**
 * Get Hours resource by operation/*  ww  w.  ja  va2s.co  m*/
 * @param idEmployee
 * @param initDate
 * @param endDate
 * @return
 */
public double getHoursResourceOpeartion(Integer idEmployee, Date initDate, Date endDate) {

    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.sum(Timesheet.HOURSDAY1));
    proList.add(Projections.sum(Timesheet.HOURSDAY2));
    proList.add(Projections.sum(Timesheet.HOURSDAY3));
    proList.add(Projections.sum(Timesheet.HOURSDAY4));
    proList.add(Projections.sum(Timesheet.HOURSDAY5));
    proList.add(Projections.sum(Timesheet.HOURSDAY6));
    proList.add(Projections.sum(Timesheet.HOURSDAY7));

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList)
            .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1))
                    .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2))
                    .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)))
            .add(Restrictions.eq(Timesheet.INITDATE, initDate)).add(Restrictions.eq(Timesheet.ENDDATE, endDate))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee)))
            .add(Restrictions.isNotNull(Timesheet.OPERATION));

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

    double hours = 0;

    if (hoursList != null) {
        hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]);
        hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]);
        hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]);
        hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]);
        hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]);
        hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]);
        hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]);
    }

    return hours;
}

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

License:Open Source License

/**
 * Calculate Fte for inputed hours in project
 * // w w w  . j av  a  2s .co  m
 * @param project
 * @param member
 * @param firstWeekDay
 * @param lastWeekDay
 * @return
 */
public double getHoursResource(Project project, Employee member, Date firstWeekDay, Date lastWeekDay) {

    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.sum(Timesheet.HOURSDAY1));
    proList.add(Projections.sum(Timesheet.HOURSDAY2));
    proList.add(Projections.sum(Timesheet.HOURSDAY3));
    proList.add(Projections.sum(Timesheet.HOURSDAY4));
    proList.add(Projections.sum(Timesheet.HOURSDAY5));
    proList.add(Projections.sum(Timesheet.HOURSDAY6));
    proList.add(Projections.sum(Timesheet.HOURSDAY7));

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList)
            .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, member));

    if (firstWeekDay != null && lastWeekDay != null) {

        crit.add(Restrictions.eq(Timesheet.INITDATE, firstWeekDay))
                .add(Restrictions.eq(Timesheet.ENDDATE, lastWeekDay));
    }

    // Aliases 
    //
    crit.createAlias(Timesheet.PROJECTACTIVITY, "pa", CriteriaSpecification.LEFT_JOIN);

    // Projects or operations
    crit.add(Restrictions.disjunction().add(Restrictions.isNotNull(Timesheet.OPERATION))
            .add(Restrictions.eq("pa." + Projectactivity.PROJECT, project)));

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

    double hours = 0;

    if (hoursList != null) {
        hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]);
        hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]);
        hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]);
        hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]);
        hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]);
        hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]);
        hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]);
    }

    return hours;
}

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

License:Open Source License

/**
 * Retrun all WBSNodes of a project except the parent node
 * @param project//from w  w  w .j a  v  a2 s  .c  om
 * @return
 */
@SuppressWarnings("unchecked")
public List<Wbsnode> findChildsByProject(Project project) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).addOrder(Order.asc(Wbsnode.NAME))
            .add(Restrictions.isNotNull(Wbsnode.WBSNODE)).add(Restrictions.eq(Wbsnode.PROJECT, project));

    return crit.list();
}