From 35f7fca342cd4a5206e2fe82dd0adbad1b87eaa7 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 26 Sep 2012 22:04:20 +0200 Subject: [PATCH] Bug #1537: Fix issue getting allocations from memory and not from database Without this patch the generic allocations were gotten from database, and only for the criteria in an already stored allocation a replacement for the allocations in memory was done. From now on, for each possible criterion, the allocations from database are recovered, and they are replaced if needed by the new ones in memory. FEA: ItEr77S04BugFixing --- .../planner/daos/IResourceAllocationDAO.java | 7 ++--- .../planner/daos/ResourceAllocationDAO.java | 20 ++++++------- .../web/resourceload/ResourceLoadModel.java | 30 +++++++++++++------ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java index 45e61b0d0..74207aea1 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/IResourceAllocationDAO.java @@ -63,10 +63,9 @@ public interface IResourceAllocationDAO extends Scenario onScenario, Date intervalFilterStartDate, Date intervalFilterEndDate); - Map> findGenericAllocationsBySomeCriterion( - Scenario onScenario, - List criterions, Date intervalFilterStartDate, - Date intervalFilterEndDate); + List findGenericAllocationsRelatedToCriterion( + Scenario onScenario, Criterion criterion, + Date intervalFilterStartDate, Date intervalFilterEndDate); /** *

diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java index f7d2eff22..2d291053f 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/daos/ResourceAllocationDAO.java @@ -23,6 +23,7 @@ package org.libreplan.business.planner.daos; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -238,20 +239,19 @@ public class ResourceAllocationDAO extends } @Override - public Map> findGenericAllocationsBySomeCriterion( - final Scenario onScenario, - final List criterions, + @SuppressWarnings("unchecked") + public List findGenericAllocationsRelatedToCriterion( + final Scenario onScenario, final Criterion criterion, final Date intervalFilterStartDate, final Date intervalFilterEndDate) { - - if (criterions.isEmpty()) { - return new HashMap>(); + if (criterion == null) { + return Collections.emptyList(); } QueryBuilder queryBuilder = new QueryBuilder() { @Override protected String getBaseQuery() { - return "select generic, criterion " + return "select generic " + "from GenericResourceAllocation as generic " + "join generic.task as task " + "join generic.criterions as criterion "; @@ -259,12 +259,12 @@ public class ResourceAllocationDAO extends @Override protected String getBaseConditions() { - return "where criterion in(:criterions) "; + return "where criterion = :criterion "; } @Override protected void setBaseParameters(Query query) { - query.setParameterList("criterions", criterions); + query.setParameter("criterion", criterion); } @Override @@ -276,7 +276,7 @@ public class ResourceAllocationDAO extends } }; Query q = queryBuilder.build(getSession()); - return toCriterionMapFrom(q); + return q.list(); } @SuppressWarnings("unchecked") diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java index b558a54b8..f33fdb256 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java @@ -455,20 +455,32 @@ public class ResourceLoadModel implements IResourceLoadModel { scenarioManager.getCurrent(), criterions)); } - private Map> findAllocationsGroupedByCriteria( + private Map>> findAllocationsGroupedByCriteria( Scenario onScenario, List relatedWith) { - Map> result = resourceAllocationDAO - .findGenericAllocationsBySomeCriterion(onScenario, - relatedWith, - asDate(parameters.getInitDateFilter()), - asDate(parameters.getEndDateFilter())); - return doReplacementsIfNeeded(result); + Map>> result = new LinkedHashMap>>(); + for (Criterion criterion : relatedWith) { + IAllocationCriteria criteria = and(onInterval(), + new RelatedWith(criterion)); + result.put( + criterion, + ResourceAllocation.sortedByStartDate(doReplacementsIfNeeded( + resourceAllocationDAO + .findGenericAllocationsRelatedToCriterion( + getCurrentScenario(), + criterion, asDate(parameters + .getInitDateFilter()), + asDate(parameters + .getEndDateFilter())), + criteria))); + + } + return result; } private Map>> withAssociatedSpecific( - Map> genericAllocationsByCriterion) { + Map>> genericAllocationsByCriterion) { Map>> result = new HashMap>>(); - for (Entry> each : genericAllocationsByCriterion + for (Entry>> each : genericAllocationsByCriterion .entrySet()) { List> both = new ArrayList>(); both.addAll(each.getValue());