From 48717f36247c5063d167e0c46dcff041dfb7e00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Tue, 8 Feb 2011 13:38:48 +0100 Subject: [PATCH] Add related specific allocations second level FEA: ItEr70S08CriteriaLoadRefinementItEr69S10 --- .../planner/entities/ResourceAllocation.java | 8 +- .../web/resourceload/ResourceLoadModel.java | 202 +++++++++++------- 2 files changed, 124 insertions(+), 86 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java index 92663b25b..ec4a59163 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java @@ -125,10 +125,10 @@ public abstract class ResourceAllocation extends return result; } - public static Map>> byTask( - List> allocations) { - Map>> result = new HashMap>>(); - for (ResourceAllocation resourceAllocation : allocations) { + public static > Map> byTask( + List allocations) { + Map> result = new HashMap>(); + for (R resourceAllocation : allocations) { if (resourceAllocation.getTask() != null) { Task task = resourceAllocation.getTask(); initializeIfNeeded(result, task); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/ResourceLoadModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/ResourceLoadModel.java index 7e58549ef..effd96b03 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/ResourceLoadModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/ResourceLoadModel.java @@ -57,7 +57,6 @@ import org.navalplanner.business.planner.entities.TaskElement; import org.navalplanner.business.resources.daos.ICriterionDAO; import org.navalplanner.business.resources.daos.IResourceDAO; import org.navalplanner.business.resources.entities.Criterion; -import org.navalplanner.business.resources.entities.CriterionSatisfaction; import org.navalplanner.business.resources.entities.Resource; import org.navalplanner.business.scenarios.IScenarioManager; import org.navalplanner.business.users.daos.IOrderAuthorizationDAO; @@ -222,34 +221,34 @@ public class ResourceLoadModel implements IResourceLoadModel { if (filterByResources) { result.addAll(groupsFor(resourcesToShow())); } else { - calculatedGenericAllocationsByCriterion = - genericAllocationsByCriterion(); - result.addAll(groupsFor(calculatedGenericAllocationsByCriterion)); + allocationsByCriterion = allocationsByCriterion(); + result.addAll(groupsFor(allocationsByCriterion)); } return result; } - Map> calculatedGenericAllocationsByCriterion; + private Map>> allocationsByCriterion; - private Map> genericAllocationsByCriterion() { + private Map>> allocationsByCriterion() { if (!criteriaToShowList.isEmpty()) { reattachCriteriaToShow(); // reattaching criterions so the query returns the same criteria as // keys allCriteriaList = new ArrayList(criteriaToShowList); - return findAllocationsGroupedByCriteria(criteriaToShowList); + return withAssociatedSpecific(findAllocationsGroupedByCriteria(criteriaToShowList)); } - Map> result = allocationsByCriterion(); + Map> result = findAllocationsByCriterion(); allCriteriaList = Criterion.sortByTypeAndName(result.keySet()); if (pageFilterPosition == -1) { - return result; + return withAssociatedSpecific(result); } List criteriaReallyShown = allCriteriaList.subList( pageFilterPosition, getEndPositionForCriterionPageFilter()); - return onlyForThePagesShown(criteriaReallyShown, result); + return withAssociatedSpecific(onlyForThePagesShown(criteriaReallyShown, + result)); } - private Map> allocationsByCriterion() { + private Map> findAllocationsByCriterion() { if (filter()) { List tasks = justTasks(filterBy .getAllChildrenAssociatedTaskElements()); @@ -261,19 +260,36 @@ public class ResourceLoadModel implements IResourceLoadModel { private Map> findAllocationsGroupedByCriteria( List relatedWith) { - return resourceAllocationDAO.findGenericAllocationsBySomeCriterion( - relatedWith, asDate(initDateFilter), asDate(endDateFilter)); + return resourceAllocationDAO + .findGenericAllocationsBySomeCriterion( + relatedWith, asDate(initDateFilter), asDate(endDateFilter)); } private Map> findAllocationsGroupedByCriteria() { - return resourceAllocationDAO.findGenericAllocationsByCriterion( + return resourceAllocationDAO + .findGenericAllocationsByCriterion( asDate(initDateFilter), asDate(endDateFilter)); } - private Map> onlyForThePagesShown( + private Map>> withAssociatedSpecific( + Map> genericAllocationsByCriterion) { + Map>> result = new HashMap>>(); + for (Entry> each : genericAllocationsByCriterion + .entrySet()) { + List> both = new ArrayList>(); + both.addAll(each.getValue()); + both.addAll(resourceAllocationDAO.findSpecificAllocationsRelatedTo( + each.getKey(), asDate(initDateFilter), + asDate(endDateFilter))); + result.put(each.getKey(), both); + } + return result; + } + + private > Map> onlyForThePagesShown( List criteriaReallyShown, - Map> allocationsByCriteria) { - Map> result = new HashMap>(); + Map> allocationsByCriteria) { + Map> result = new HashMap>(); for (Criterion each : criteriaReallyShown) { if (allocationsByCriteria.get(each) != null) { result.put(each, allocationsByCriteria.get(each)); @@ -408,24 +424,24 @@ public class ResourceLoadModel implements IResourceLoadModel { } /** - * @param genericAllocationsByCriterion + * @param allocationsByCriterion * @return */ private List groupsFor( - Map> genericAllocationsByCriterion) { + Map>> allocationsByCriterion) { List result = new ArrayList(); for(Criterion criterion : criteriaToShow()) { - if (genericAllocationsByCriterion.get(criterion) == null) { + if (allocationsByCriterion.get(criterion) == null) { // no allocations found for criterion continue; } - List allocations = ResourceAllocation - .sortedByStartDate(genericAllocationsByCriterion + List> allocations = ResourceAllocation + .sortedByStartDate(allocationsByCriterion .get(criterion)); TimeLineRole role = getCurrentTimeLineRole(criterion); LoadTimeLine group = new LoadTimeLine(createPrincipal(criterion, - allocations, role), - buildSecondLevel(criterion, allocations)); + allocations, role), buildSecondaryLevels(criterion, + allocations)); if (!group.isEmpty()) { result.add(group); } @@ -433,8 +449,30 @@ public class ResourceLoadModel implements IResourceLoadModel { return result; } - private List buildSecondLevel(Criterion criterion, - List allocations) { + private List buildSecondaryLevels(Criterion criterion, + List> allocations) { + List result = new ArrayList(); + result.addAll(buildSubLevels(criterion, ResourceAllocation.getOfType( + GenericResourceAllocation.class, allocations))); + result.add(buildRelatedSpecificAllocations(criterion, allocations)); + return result; + } + + private LoadTimeLine buildRelatedSpecificAllocations(Criterion criterion, + List> allocations) { + List specific = ResourceAllocation + .getOfType(SpecificResourceAllocation.class, allocations); + + LoadTimeLine main = new LoadTimeLine(_("Specific Allocations"), + createPeriods(criterion, specific), "related-specific", + getCurrentTimeLineRole(criterion)); + List children = buildGroupsFor(ResourceAllocation + .byResource(new ArrayList>(specific))); + return new LoadTimeLine(main, children); + } + + private List buildSubLevels(Criterion criterion, + List> allocations) { List result = new ArrayList(); Map>> byOrder = byOrder(new ArrayList>( allocations)); @@ -443,8 +481,8 @@ public class ResourceLoadModel implements IResourceLoadModel { if (filter()) { // build time lines for current order if (byOrder.get(filterBy) != null) { - result.addAll(buildTimeLinesForOrder(criterion, byOrder - .get(filterBy))); + result.addAll(buildTimeLinesForOrder(filterBy, criterion, + byOrder.get(filterBy))); } byOrder.remove(filterBy); // build time lines for other orders @@ -459,10 +497,14 @@ public class ResourceLoadModel implements IResourceLoadModel { return result; } - private List buildTimeLinesForOrder(Criterion criterion, + private List buildTimeLinesForOrder(Order order, + Criterion criterion, List> allocations) { List result = new ArrayList(); - result.addAll(buildTimeLinesForEachTask(criterion, allocations)); + result.addAll(buildTimeLinesForEachTask(criterion, + onlyGeneric(allocations))); + result.addAll(buildTimeLinesForEachResource(criterion, + onlySpecific(allocations), getCurrentTimeLineRole(order))); return result; } @@ -490,21 +532,22 @@ public class ResourceLoadModel implements IResourceLoadModel { continue; } TimeLineRole role = getCurrentTimeLineRole(order); - result.add(new LoadTimeLine(buildTimeLine(criterion, order - .getName(), "global-generic", byOrder.get(order), role), - buildTimeLinesForOrder( - criterion, byOrder.get(order)))); + result.add(new LoadTimeLine( + buildTimeLine(criterion, order.getName(), "global-generic", + byOrder.get(order), role), buildTimeLinesForOrder( + order, criterion, byOrder.get(order)))); } return result; } private List buildTimeLinesForEachTask(Criterion criterion, - List> allocations) { - Map>> byTask = ResourceAllocation + List allocations) { + Map> byTask = ResourceAllocation .byTask(allocations); List secondLevel = new ArrayList(); - for (Entry>> entry : byTask.entrySet()) { + for (Entry> entry : byTask + .entrySet()) { Task task = entry.getKey(); @@ -537,24 +580,23 @@ public class ResourceLoadModel implements IResourceLoadModel { } private Map, List> getAllocationsWithSameCriteria( - List> genericAllocations) { - return GenericResourceAllocation - .byCriterions(onlyGeneric(genericAllocations)); + List genericAllocations) { + return GenericResourceAllocation.byCriterions(genericAllocations); } private List buildTimeLinesForEachResource( - Criterion criterion, List allocations, + Criterion criterion, + List> allocations, TimeLineRole role) { - Map> byResource = GenericResourceAllocation + Map>> byResource = ResourceAllocation .byResource(allocations); List secondLevel = new ArrayList(); - for (Entry> entry : byResource + for (Entry>> entry : byResource .entrySet()) { Resource resource = entry.getKey(); - List resourceAllocations = entry - .getValue(); - String descriptionTimeLine = getDescriptionResourceWithCriterions(resource); + List> resourceAllocations = entry.getValue(); + String descriptionTimeLine = resource.getShortDescription(); LoadTimeLine timeLine = buildTimeLine(resource, descriptionTimeLine, resourceAllocations, "generic", role); @@ -566,34 +608,16 @@ public class ResourceLoadModel implements IResourceLoadModel { return secondLevel; } - private String getDescriptionResourceWithCriterions(Resource resource) { - Set criterionSatisfactions = resource - .getCriterionSatisfactions(); - return resource.getShortDescription(); - } - - private String getCriterionSatisfactionDescription( - Set satisfactions) { - if (satisfactions.isEmpty()) { - return ""; - } - List criterions = new ArrayList(); - for (CriterionSatisfaction satisfaction : satisfactions) { - criterions.add(satisfaction.getCriterion()); - } - return " :: " + Criterion.getCaptionFor(criterions); - } - private LoadTimeLine createPrincipal(Criterion criterion, - List orderedAllocations, + List> orderedAllocations, TimeLineRole role) { return new LoadTimeLine(criterion.getType().getName() + ": " + criterion.getName(), createPeriods(criterion, orderedAllocations), "global-generic", role); } private List createPeriods(Criterion criterion, - List value) { - if(initDateFilter != null || endDateFilter != null) { + List> value) { + if (initDateFilter != null || endDateFilter != null) { return PeriodsBuilder.build( LoadPeriodGenerator.onCriterion(criterion, resourcesDAO), value, asDate(initDateFilter), asDate(endDateFilter)); @@ -604,31 +628,45 @@ public class ResourceLoadModel implements IResourceLoadModel { } private List groupsFor(List allResources) { - List result = new ArrayList(); + return buildGroupsFor(eachWithAllocations(allResources)); + } + + private Map>> eachWithAllocations( + List allResources) { + Map>> map = new HashMap>>(); for (Resource resource : allResources) { - LoadTimeLine group = buildGroup(resource); - if (!group.isEmpty()) { - result.add(group); + map.put(resource, ResourceAllocation + .sortedByStartDate(resourceAllocationDAO + .findAllocationsRelatedTo(resource, initDateFilter, + endDateFilter))); + } + return map; + } + + private List buildGroupsFor( + Map>> map) { + List result = new ArrayList(); + for (Entry>> each : map + .entrySet()) { + LoadTimeLine l = buildGroupFor(each.getKey(), each.getValue()); + if (!l.isEmpty()) { + result.add(l); } } return result; } - private LoadTimeLine buildGroup(Resource resource) { - List> sortedByStartDate = ResourceAllocation - .sortedByStartDate(resourceAllocationDAO - .findAllocationsRelatedTo(resource, initDateFilter, - endDateFilter)); + private LoadTimeLine buildGroupFor(Resource resource, + List> sortedByStartDate) { TimeLineRole role = getCurrentTimeLineRole(resource); LoadTimeLine result = new LoadTimeLine(buildTimeLine(resource, resource .getName(), sortedByStartDate, "resource", role), buildSecondLevel(resource, sortedByStartDate)); return result; - } private List buildSecondLevel(Resource resource, - List> sortedByStartDate) { + List> sortedByStartDate) { List result = new ArrayList(); Map>> byOrder = byOrder(sortedByStartDate); @@ -694,7 +732,7 @@ public class ResourceLoadModel implements IResourceLoadModel { @Transactional(readOnly = true) public Map>> byOrder( - Collection> allocations) { + Collection> allocations) { Map>> result = new HashMap>>(); for (ResourceAllocation resourceAllocation : allocations) { if ((resourceAllocation.isSatisfied()) @@ -929,10 +967,10 @@ public class ResourceLoadModel implements IResourceLoadModel { } else { List dayAssignments = new ArrayList(); - for(Entry> entry : - calculatedGenericAllocationsByCriterion.entrySet()) { + for (Entry>> entry : allocationsByCriterion + .entrySet()) { - for(GenericResourceAllocation allocation : entry.getValue()) { + for (ResourceAllocation allocation : entry.getValue()) { dayAssignments.addAll(allocation.getAssignments()); } }