Example usage for org.hibernate.criterion Projections projectionList

List of usage examples for org.hibernate.criterion Projections projectionList

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections projectionList.

Prototype

public static ProjectionList projectionList() 

Source Link

Document

Create a new projection list.

Usage

From source file:es.itecban.deployment.environmentmanager.manager.EnvironmentManagerImpl.java

License:Apache License

private Object getLastEnvironmentDate(String environmentName) {

    final Session session = this.sessionFactory.openSession();
    session.beginTransaction();/*from   w  w w . j av  a  2  s  . c o m*/

    // Get the latest date for the "photos" stored in the database
    Criteria timestampCriteria = session.createCriteria(DeploymentTargetType.class);
    timestampCriteria.setProjection(Projections.projectionList().add(Projections.max("timestamp")));
    timestampCriteria.add(Restrictions.eq("name", environmentName));
    Object lastEvironmentTimestampCriteria = timestampCriteria.uniqueResult();

    session.close();
    return lastEvironmentTimestampCriteria;
}

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

License:Open Source License

/**
 * Get Procurement Budgets from Project//from w  w w.j  a  va  2 s.  c o  m
 * 
 * @param proj
 * @param joins
 * @return
 */
public List<ProcurementBudget> consProcurementBudgetsByProject(Project proj, List<String> joins) {
    Criteria crit = getSession().createCriteria(getPersistentClass());

    for (String join : joins) {
        crit.setFetchMode(join, FetchMode.JOIN);
    }

    crit.addOrder(Order.asc(Procurementpayments.SELLER))
            .setProjection(Projections.projectionList().add(Projections.sum(Procurementpayments.PLANNEDPAYMENT))
                    .add(Projections.sum(Procurementpayments.ACTUALPAYMENT)).add(Projections.rowCount())
                    .add(Projections.groupProperty(Procurementpayments.SELLER)))
            .add(Restrictions.eq(Procurementpayments.PROJECT, proj));

    List<ProcurementBudget> lista = new ArrayList<ProcurementBudget>();
    List<String> purchase = null;

    for (int i = 0; i < crit.list().size(); i++) {
        ProcurementBudget budget = new ProcurementBudget();
        Object[] row = (Object[]) crit.list().get(i);
        budget.setPlannedPayment((Double) row[0]);
        budget.setActualPayment((Double) row[1]);
        budget.setnPayments((Integer) row[2]);

        Seller seller = (Seller) row[3];
        budget.setSeller(seller.getName());

        purchase = consPruchaseOrder(seller, proj);
        String order = "";
        if (purchase != null) {
            for (String s : purchase) {
                if (!order.equals("")) {
                    order += ", ";
                }
                order += s;
            }
        }
        budget.setPurchaseOrder(order);

        lista.add(budget);
    }

    return lista;
}

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

License:Open Source License

/**
 * Find min and max actual dates of projects
 * /*from w ww . j av a2  s.  com*/
 * @param projects
 * @return
 */
public RangeDateWrap findMinAndMaxActualDatesByProjects(List<Project> projects) {

    RangeDateWrap range = null;

    if (ValidateUtil.isNotNull(projects)) {

        Criteria crit = getSession().createCriteria(getPersistentClass())
                .add(Restrictions.in(Procurementpayments.PROJECT, projects))
                .setProjection(Projections.projectionList()
                        .add(Projections.min(Procurementpayments.ACTUALDATE),
                                RangeDateWrap.Fields.MINDATE.toString())
                        .add(Projections.max(Procurementpayments.ACTUALDATE),
                                RangeDateWrap.Fields.MAXDATE.toString()))
                .setResultTransformer(Transformers.aliasToBean(RangeDateWrap.class));

        range = (RangeDateWrap) crit.uniqueResult();
    }

    return range;
}

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

License:Open Source License

/**
 * Update Planned Dates of root activity
 * /*from   ww  w  .j  a  va 2 s. c  o  m*/
 * @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

/**
 * List not assigned activities to seller
 * /*from  w ww . j  av a  2 s  .  c om*/
 * @param seller
 * @param project
 * @param order
 * @return
 */
@SuppressWarnings("unchecked")
public List<Object[]> consNoAssignedActivities(Seller seller, Project project, Order... order) {

    Criteria usedCrit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.property(Projectactivity.IDACTIVITY))
            .add(Restrictions.eq(Projectactivity.PROJECT, project));

    usedCrit.createCriteria(Projectactivity.ACTIVITYSELLERS)
            .add(Restrictions.eq(Activityseller.SELLER, seller));

    List<Projectactivity> lista = usedCrit.list();

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.projectionList().add(Projections.property(Projectactivity.IDACTIVITY))
                    .add(Projections.property(Projectactivity.ACTIVITYNAME)))
            .add(Restrictions.eq(Projectactivity.PROJECT, project));

    crit.createCriteria(Projectactivity.WBSNODE).add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true));

    if (!lista.isEmpty()) {
        crit.add(Restrictions.not(Restrictions.in(Projectactivity.IDACTIVITY, lista)));
    }

    for (Order o : order) {
        crit.addOrder(o);
    }

    return crit.list();
}

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

License:Open Source License

public double clacPocBySum(Project project) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Projectactivity.PROJECT, project)).setProjection(Projections.projectionList()
                    .add(Projections.sum(Projectactivity.POC)).add(Projections.rowCount()));

    Criteria critWBSNode = crit.createCriteria(Projectactivity.WBSNODE)
            .add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true));

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

    double poc = 0;

    if (value != null && value.length == 2) {
        double sumPoc = (Double) value[0] == null ? 0 : (Double) value[0];
        int rows = (Integer) value[1];

        if (rows > 0) {
            poc = sumPoc / new Double(rows);
        }/*from   w  w w.j  av a  2  s. c  o m*/
    }

    return poc;
}

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

License:Open Source License

/**
 * Get Hours resource//from   ww  w  .  ja v a  2  s.  c o m
 * @param idEmployee
 * @param id
 * @param initDate
 * @param endDate
 * @param minStatus
 * @param maxStatus
 * @return
 */
public double getHoursResource(Integer idEmployee, Integer id, Date initDate, Date endDate, String minStatus,
        Employee filterUser) {

    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)));

    if (Constants.TIMESTATUS_APP1.equals(minStatus)) {
        crit.createCriteria(Timesheet.PROJECTACTIVITY)
                .add(Restrictions.eq(Projectactivity.PROJECT, new Project(id)));
    } else if (Constants.TIMESTATUS_APP2.equals(minStatus)) {

        // Filter by User. Settings by company for last approval.

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

        Resourceprofiles profile = filterUser.getResourceprofiles();

        if (profile.getIdProfile() == Constants.ROLE_FM) {

            critFilter.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser));
        } else if (profile.getIdProfile() == Constants.ROLE_PMO) {

            critFilter.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg()));
        }
    }
    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

/**
 * Get Hours resource by operation//from ww w  .j a  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
 * /*from w w  w  .  jav  a2s.  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.TimesheetDAO.java

License:Open Source License

/**
 * Calculate Fte for inputed hours in project
 * @param project/* w  w  w  .  j  ava2s  .c  om*/
 * @param member
 * @param firstWeekDay
 * @param lastWeekDay
 * @return
 */
public double getHoursResource(Project project, Teammember 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));

    crit.createCriteria(Timesheet.EMPLOYEE).createCriteria(Employee.TEAMMEMBERS)
            .add(Restrictions.idEq(member.getIdTeamMember()));

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

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

    if (project == null) {
        crit.add(Restrictions.eq(Timesheet.PROJECTACTIVITY, member.getProjectactivity()));
    } else {

        crit.createCriteria(Timesheet.PROJECTACTIVITY).add(Restrictions.eq(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;
}