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
This commit is contained in:
Manuel Rego Casasnovas 2012-09-26 22:04:20 +02:00
parent 519ac2a5aa
commit 35f7fca342
3 changed files with 34 additions and 23 deletions

View file

@ -63,10 +63,9 @@ public interface IResourceAllocationDAO extends
Scenario onScenario,
Date intervalFilterStartDate, Date intervalFilterEndDate);
Map<Criterion, List<GenericResourceAllocation>> findGenericAllocationsBySomeCriterion(
Scenario onScenario,
List<Criterion> criterions, Date intervalFilterStartDate,
Date intervalFilterEndDate);
List<GenericResourceAllocation> findGenericAllocationsRelatedToCriterion(
Scenario onScenario, Criterion criterion,
Date intervalFilterStartDate, Date intervalFilterEndDate);
/**
* <p>

View file

@ -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<Criterion, List<GenericResourceAllocation>> findGenericAllocationsBySomeCriterion(
final Scenario onScenario,
final List<Criterion> criterions,
@SuppressWarnings("unchecked")
public List<GenericResourceAllocation> findGenericAllocationsRelatedToCriterion(
final Scenario onScenario, final Criterion criterion,
final Date intervalFilterStartDate, final Date intervalFilterEndDate) {
if (criterions.isEmpty()) {
return new HashMap<Criterion, List<GenericResourceAllocation>>();
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")

View file

@ -455,20 +455,32 @@ public class ResourceLoadModel implements IResourceLoadModel {
scenarioManager.getCurrent(), criterions));
}
private Map<Criterion, List<GenericResourceAllocation>> findAllocationsGroupedByCriteria(
private Map<Criterion, List<ResourceAllocation<?>>> findAllocationsGroupedByCriteria(
Scenario onScenario, List<Criterion> relatedWith) {
Map<Criterion, List<GenericResourceAllocation>> result = resourceAllocationDAO
.findGenericAllocationsBySomeCriterion(onScenario,
relatedWith,
asDate(parameters.getInitDateFilter()),
asDate(parameters.getEndDateFilter()));
return doReplacementsIfNeeded(result);
Map<Criterion, List<ResourceAllocation<?>>> result = new LinkedHashMap<Criterion, List<ResourceAllocation<?>>>();
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<Criterion, List<ResourceAllocation<?>>> withAssociatedSpecific(
Map<Criterion, List<GenericResourceAllocation>> genericAllocationsByCriterion) {
Map<Criterion, List<ResourceAllocation<?>>> genericAllocationsByCriterion) {
Map<Criterion, List<ResourceAllocation<?>>> result = new HashMap<Criterion, List<ResourceAllocation<?>>>();
for (Entry<Criterion, List<GenericResourceAllocation>> each : genericAllocationsByCriterion
for (Entry<Criterion, List<ResourceAllocation<?>>> each : genericAllocationsByCriterion
.entrySet()) {
List<ResourceAllocation<?>> both = new ArrayList<ResourceAllocation<?>>();
both.addAll(each.getValue());