From 58b963f30f1f6b9a65bc36a1a6b9cf8833d63ea7 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Tue, 5 Feb 2013 12:40:54 +0100 Subject: [PATCH] Include unscheduled projects in orders query When you import a project from the web service, the task elements are not created yet, so we need to return these projects in the query otherwise they will be not visible at all for the users. FEA: ItEr77S15FilteringEnhancements --- .../business/orders/daos/OrderDAO.java | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java index 1b35b5918..6a0960675 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/daos/OrderDAO.java @@ -43,6 +43,7 @@ import org.libreplan.business.labels.entities.Label; import org.libreplan.business.orders.entities.Order; import org.libreplan.business.orders.entities.OrderElement; import org.libreplan.business.orders.entities.OrderStatusEnum; +import org.libreplan.business.orders.entities.SchedulingState; import org.libreplan.business.planner.daos.ITaskSourceDAO; import org.libreplan.business.planner.entities.Task; import org.libreplan.business.reports.dtos.CostExpenseSheetDTO; @@ -231,12 +232,25 @@ public class OrderDAO extends IntegrationEntityDAO implements return Collections.emptyList(); } + List ordersIdsUnscheduled = getOrdersIdsUnscheduled(startDate, + endDate); + Criteria c = getSession().createCriteria(Order.class); - if (ordersIdsFiltered != null) { - c.add(Restrictions.in("id", ordersIdsFiltered)); - } - if (ordersIdsByDates != null) { - c.add(Restrictions.in("id", ordersIdsByDates)); + if (ordersIdsFiltered != null && ordersIdsByDates != null) { + org.hibernate.criterion.Criterion and = Restrictions.and( + Restrictions.in("id", ordersIdsFiltered), + Restrictions.in("id", ordersIdsByDates)); + c.add(Restrictions.or(and, + Restrictions.in("id", ordersIdsUnscheduled))); + } else { + if (ordersIdsFiltered != null) { + c.add(Restrictions.or(Restrictions.in("id", ordersIdsFiltered), + Restrictions.in("id", ordersIdsUnscheduled))); + } + if (ordersIdsByDates != null) { + c.add(Restrictions.or(Restrictions.in("id", ordersIdsByDates), + Restrictions.in("id", ordersIdsUnscheduled))); + } } c.addOrder(org.hibernate.criterion.Order.desc("initDate")); @@ -244,6 +258,41 @@ public class OrderDAO extends IntegrationEntityDAO implements return c.list(); } + private List getOrdersIdsUnscheduled(Date startDate, Date endDate) { + String strQuery = "SELECT s.orderElement.id " + + "FROM SchedulingDataForVersion s " + + "WHERE s.schedulingStateType = :type"; + Query query = getSession().createQuery(strQuery); + query.setParameter("type", SchedulingState.Type.NO_SCHEDULED); + + List ordersIdsUnscheduled = query.list(); + if (ordersIdsUnscheduled.isEmpty()) { + return Collections.emptyList(); + } + + String strQueryDates = "SELECT o.id " + + "FROM Order o " + + "WHERE o.id IN (:ids) "; + + if (startDate != null) { + strQueryDates += "AND o.initDate >= :startDate "; + } + if (endDate != null) { + strQueryDates += "AND o.initDate <= :endDate "; + } + + Query queryDates = getSession().createQuery(strQueryDates); + if (startDate != null) { + queryDates.setParameter("startDate", startDate); + } + if (endDate != null) { + queryDates.setParameter("endDate", endDate); + } + queryDates.setParameterList("ids", ordersIdsUnscheduled); + + return queryDates.list(); + } + /** * If both params are null it returns null. * Otherwise it filters the list of tasks to return the ones wihtout parent