From caad232fe9d321147982247849331c37f7a40a1d Mon Sep 17 00:00:00 2001 From: Susana Montes Pedreira Date: Thu, 15 Apr 2010 17:43:10 +0200 Subject: [PATCH] ItEr54S12CUVistaRecursosTempoPorProxectoItEr53S14: Breakdown the criterion information level the screen of business and order. --- .../planner/daos/IResourceAllocationDAO.java | 2 + .../planner/daos/ResourceAllocationDAO.java | 16 ++ .../entities/GenericResourceAllocation.java | 47 +++- .../planner/entities/ResourceAllocation.java | 9 +- .../web/resourceload/LoadPeriodGenerator.java | 16 +- .../web/resourceload/ResourceLoadModel.java | 218 ++++++++++++++---- 6 files changed, 247 insertions(+), 61 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/IResourceAllocationDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/IResourceAllocationDAO.java index 6ee391269..9a164dc82 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/IResourceAllocationDAO.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/IResourceAllocationDAO.java @@ -55,4 +55,6 @@ public interface IResourceAllocationDAO extends Map> findGenericAllocationsByCriterionFor( List task); + Map> findGenericAllocationsBySomeCriterion( + List criterions); } \ No newline at end of file diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/ResourceAllocationDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/ResourceAllocationDAO.java index 56ede963e..a06b9a3d5 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/ResourceAllocationDAO.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/daos/ResourceAllocationDAO.java @@ -139,6 +139,22 @@ public class ResourceAllocationDAO extends return stripAllocationsWithoutAssignations(byCriterion(list)); } + @SuppressWarnings("unchecked") + @Override + public Map> findGenericAllocationsBySomeCriterion( + List criterions) { + if (criterions.isEmpty()) { + return new HashMap>(); + } + List list = getSession().createQuery( + "select generic, criterion " + + "from GenericResourceAllocation as generic " + + "join generic.criterions as criterion " + + "where criterion in(:criterions)").setParameterList( + "criterions", criterions).list(); + return stripAllocationsWithoutAssignations(byCriterion(list)); + } + private Map> byCriterion( List results) { diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/GenericResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/GenericResourceAllocation.java index 03f5e8bf3..8c44d5526 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/GenericResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/GenericResourceAllocation.java @@ -62,7 +62,7 @@ public class GenericResourceAllocation extends } public static Map, List> byCriterions( - Collection genericAllocations) { + Collection genericAllocations) { Map, List> result = new HashMap, List>(); for (GenericResourceAllocation genericResourceAllocation : genericAllocations) { Set criterions = genericResourceAllocation.getCriterions(); @@ -74,6 +74,34 @@ public class GenericResourceAllocation extends return result; } + public static Map> byResource( + Collection allocations) { + Map> result = new HashMap>(); + for (GenericResourceAllocation resourceAllocation : allocations) { + for (Resource resource : resourceAllocation + .getAssociatedResources()) { + initializeIfNeeded_(result, resource); + result.get(resource).add(resourceAllocation); + } + } + return result; + } + + private static void initializeIfNeeded_( + Map> result, + Resource resource) { + if (!result.containsKey(resource)) { + result.put(resource, new ArrayList()); + } + } + + private static void initializeIfNeeded_( + Map> result, Task task) { + if (!result.containsKey(task)) { + result.put(task, new ArrayList()); + } + } + private Set criterions = new HashSet(); private Set genericDayAssignments = new HashSet(); @@ -316,4 +344,21 @@ public class GenericResourceAllocation extends return resourceDAO.findSatisfyingCriterionsAtSomePoint(getCriterions()); } + public static Map> byCriterion( + List generics) { + Map> result = new HashMap>(); + for (GenericResourceAllocation genericResourceAllocation : generics) { + Set criterions = genericResourceAllocation + .getCriterions(); + for (Criterion criterion : criterions) { + if (!result.containsKey(criterion)) { + result.put(criterion, + new ArrayList()); + } + result.get(criterion).add(genericResourceAllocation); + } + } + return result; + } + } 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 2d6061e26..cf858f85a 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 @@ -90,7 +90,7 @@ public abstract class ResourceAllocation extends } public static Map>> byTask( - Collection> allocations) { + List> allocations) { Map>> result = new HashMap>>(); for (ResourceAllocation resourceAllocation : allocations) { if (resourceAllocation.getTask() != null) { @@ -102,11 +102,10 @@ public abstract class ResourceAllocation extends return result; } - private static void initializeIfNeeded( - Map>> result, Task task) { + private static > void initializeIfNeeded( + Map> result, Task task) { if (!result.containsKey(task)) { - result.put(task, - new ArrayList>()); + result.put(task, new ArrayList()); } } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/LoadPeriodGenerator.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/LoadPeriodGenerator.java index c0000bda3..5571ae369 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/LoadPeriodGenerator.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/resourceload/LoadPeriodGenerator.java @@ -339,21 +339,7 @@ class LoadPeriodGeneratorOnCriterion extends LoadPeriodGenerator { @Override protected int getHoursAssigned() { - return sumAllocations() + calculateSumOfSpecific(); - } - - private int calculateSumOfSpecific() { - List specific = new ArrayList(); - for (Resource each : resourcesSatisfyingCriterionAtSomePoint) { - specific.addAll(specificAssignmentsAtInterval(each)); - } - return sum(specific); - } - - private List specificAssignmentsAtInterval( - Resource each) { - return DayAssignment.getAtInterval( - getSpecificOrderedAssignmentsFor(each), start, end); + return sumAllocations(); } private Map> specificByResourceCached = new HashMap>(); 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 e5e095cb9..47de0e872 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 @@ -48,6 +48,7 @@ import org.navalplanner.business.planner.entities.Task; import org.navalplanner.business.planner.entities.TaskElement; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; @@ -126,9 +127,20 @@ public class ResourceLoadModel implements IResourceLoadModel { private Map> genericAllocationsByCriterion() { if (filter()) { + List criterions = new ArrayList(); + List generics = new ArrayList(); + List tasks = justTasks(filterBy + .getAllChildrenAssociatedTaskElements()); + for (Task task : tasks) { + + List> listAllocations = new ArrayList>( + task.getSatisfiedResourceAllocations()); + for (GenericResourceAllocation generic : (onlyGeneric(listAllocations))) { + criterions.addAll(generic.getCriterions()); + } + } return resourceAllocationDAO - .findGenericAllocationsByCriterionFor(justTasks(filterBy - .getAllChildrenAssociatedTaskElements())); + .findGenericAllocationsBySomeCriterion(criterions); } else { return resourceAllocationDAO.findGenericAllocationsByCriterion(); } @@ -165,6 +177,10 @@ public class ResourceLoadModel implements IResourceLoadModel { return resourcesDAO.list(Resource.class); } + /** + * @param genericAllocationsByCriterion + * @return + */ private List groupsFor( Map> genericAllocationsByCriterion) { List result = new ArrayList(); @@ -173,7 +189,8 @@ public class ResourceLoadModel implements IResourceLoadModel { List allocations = ResourceAllocation .sortedByStartDate(entry.getValue()); LoadTimeLine group = new LoadTimeLine(createPrincipal(entry - .getKey(), allocations), new ArrayList()); + .getKey(), allocations), buildSecondLevel(entry.getKey(), + allocations)); if (!group.isEmpty()) { result.add(group); } @@ -181,6 +198,124 @@ public class ResourceLoadModel implements IResourceLoadModel { return result; } + private List buildSecondLevel(Criterion criterion, + List allocations) { + List result = new ArrayList(); + Map>> byOrder = byOrder(new ArrayList>( + allocations)); + + if (filter()) { + // build time lines for current order + if (byOrder.get(filterBy) != null) { + result.addAll(buildTimeLinesForOrder(criterion, byOrder + .get(filterBy))); + } + byOrder.remove(filterBy); + // build time lines for other orders + LoadTimeLine lineOthersOrders = buildTimeLinesForOtherOrders( + criterion, byOrder); + if (lineOthersOrders != null) { + result.add(lineOthersOrders); + } + } else { + result.addAll(buildTimeLinesGroupForOrder(criterion, byOrder)); + } + return result; + } + + private List buildTimeLinesForOrder(Criterion criterion, + List> allocations) { + List result = new ArrayList(); + result.addAll(buildTimeLinesForEachTask(criterion, allocations)); + return result; + } + + private LoadTimeLine buildTimeLinesForOtherOrders(Criterion criterion, + Map>> byOrder) { + List> allocations = getAllSortedValues(byOrder); + if (allocations.isEmpty()) { + return null; + } + LoadTimeLine group = new LoadTimeLine(buildTimeLine(criterion, + "Others ordes", allocations), buildTimeLinesGroupForOrder( + criterion, byOrder)); + return group; + } + + private List buildTimeLinesGroupForOrder(Criterion criterion, + Map>> byOrder) { + List result = new ArrayList(); + for (Order order : byOrder.keySet()) { + result.add(new LoadTimeLine(buildTimeLine(criterion, order + .getName(), byOrder.get(order)), buildTimeLinesForOrder( + criterion, byOrder.get(order)))); + } + return result; + } + + private List buildTimeLinesForEachTask(Criterion criterion, + List> allocations) { + Map>> byTask = ResourceAllocation + .byTask(allocations); + + List secondLevel = new ArrayList(); + for (Entry>> entry : byTask.entrySet()) { + Task task = entry.getKey(); + Set criterions = task.getCriterions(); + LoadTimeLine timeLine = new LoadTimeLine(buildTimeLine(criterions, + task, criterion, entry.getValue()), + buildTimeLinesForEachResource(criterion, onlyGeneric(entry + .getValue()))); + if (!timeLine.isEmpty()) { + secondLevel.add(timeLine); + } + + } + return secondLevel; + } + + private List buildTimeLinesForEachResource( + Criterion criterion, List allocations) { + Map> byResource = GenericResourceAllocation + .byResource(allocations); + + List secondLevel = new ArrayList(); + for (Entry> entry : byResource + .entrySet()) { + Resource resource = entry.getKey(); + List resourceAllocations = entry + .getValue(); + String descriptionTimeLine = getDescriptionResourceWithCriterions(resource); + + LoadTimeLine timeLine = buildTimeLine(resource, + descriptionTimeLine, resourceAllocations, "resource"); + if (!timeLine.isEmpty()) { + secondLevel.add(timeLine); + } + + } + return secondLevel; + } + + private String getDescriptionResourceWithCriterions(Resource resource) { + Set criterionSatisfactions = resource + .getCriterionSatisfactions(); + return resource.getShortDescription() + + getCriterionSatisfactionDescription(criterionSatisfactions); + } + + private String getCriterionSatisfactionDescription( + Set satisfactions) { + if (satisfactions.isEmpty()) { + return _(""); + } + List criterions = new ArrayList(); + for (CriterionSatisfaction satisfaction : satisfactions) { + criterions.add(satisfaction.getCriterion()); + } + return " :: " + getName(criterions); + } + private LoadTimeLine createPrincipal(Criterion criterion, List orderedAllocations) { return new LoadTimeLine(criterion.getName(), createPeriods(criterion, @@ -209,8 +344,8 @@ public class ResourceLoadModel implements IResourceLoadModel { .sortedByStartDate(resourceAllocationDAO .findAllocationsRelatedTo(resource)); LoadTimeLine result = new LoadTimeLine(buildTimeLine(resource, resource - .getShortDescription(), sortedByStartDate), buildSecondLevel( - resource, sortedByStartDate)); + .getShortDescription(), sortedByStartDate, "resource"), + buildSecondLevel(resource, sortedByStartDate)); return result; } @@ -244,7 +379,7 @@ public class ResourceLoadModel implements IResourceLoadModel { return null; } LoadTimeLine group = new LoadTimeLine(buildTimeLine(resource, - "Others ordes", resourceAllocations), + _("Others ordes"), resourceAllocations, "resource"), buildTimeLinesGroupForOrder(resource, byOrder)); return group; } @@ -254,7 +389,7 @@ public class ResourceLoadModel implements IResourceLoadModel { List result = new ArrayList(); for (Order order : byOrder.keySet()) { result.add(new LoadTimeLine(buildTimeLine(resource, - order.getName(), byOrder.get(order)), + order.getName(), byOrder.get(order), "resource"), buildTimeLinesForOrder(resource, byOrder.get(order)))); } return result; @@ -278,10 +413,11 @@ 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.getTask() != null) { + if ((resourceAllocation.isSatisfied()) + && (resourceAllocation.getTask() != null)) { OrderElement orderElement = resourceAllocation.getTask() .getOrderElement(); Order order = orderElementDAO @@ -325,12 +461,14 @@ public class ResourceLoadModel implements IResourceLoadModel { .entrySet()) { Map>> byTask = ResourceAllocation - .byTask(entry.getValue()); + .byTask(new ArrayList>(entry + .getValue())); + for (Entry>> entryTask : byTask .entrySet()) { Task task = entryTask.getKey(); - List resouceAllocations = getGenericResourceAllocation(entryTask + List resouceAllocations = onlyGeneric(entryTask .getValue()); LoadTimeLine timeLine = buildTimeLine(entry.getKey(), task, resource, resouceAllocations); @@ -343,21 +481,14 @@ public class ResourceLoadModel implements IResourceLoadModel { return result; } - private List getGenericResourceAllocation( - List> list) { - List result = new ArrayList(); - for (ResourceAllocation resourceAllocation : list) { - if (resourceAllocation instanceof GenericResourceAllocation) { - result.add((GenericResourceAllocation) resourceAllocation); - } - } - return result; - } - private List buildTimeLinesForEachTask(Resource resource, List sortedByStartDate) { + + List> listOnlySpecific = new ArrayList>( + sortedByStartDate); Map>> byTask = ResourceAllocation - .byTask(sortedByStartDate); + .byTask(listOnlySpecific); + List secondLevel = new ArrayList(); for (Entry>> entry : byTask.entrySet()) { Task task = entry.getKey(); @@ -371,16 +502,6 @@ public class ResourceLoadModel implements IResourceLoadModel { return secondLevel; } - private LoadTimeLine buildTimeLine(Collection criterions, - Task task, Resource resource, - List allocationsSortedByStartDate) { - LoadPeriodGeneratorFactory periodGeneratorFactory = LoadPeriodGenerator - .onResourceSatisfying(resource, criterions); - return new LoadTimeLine(getName(criterions, task), PeriodsBuilder - .build(periodGeneratorFactory, allocationsSortedByStartDate), - "generic"); - } - public static String getName(Collection criterions, Task task) { String prefix = task.getName(); @@ -400,17 +521,34 @@ public class ResourceLoadModel implements IResourceLoadModel { } private LoadTimeLine buildTimeLine(Resource resource, String name, - List> sortedByStartDate) { - return new LoadTimeLine(name, PeriodsBuilder.build(LoadPeriodGenerator - .onResource(resource), sortedByStartDate), "resource"); - } - - private LoadTimeLine buildTimeLine(Resource resource, String name, - List> sortedByStartDate, String type) { + List> sortedByStartDate, String type) { return new LoadTimeLine(name, PeriodsBuilder.build(LoadPeriodGenerator .onResource(resource), sortedByStartDate), type); } + private LoadTimeLine buildTimeLine(Criterion criterion, String name, + List> allocations) { + List generics = onlyGeneric(allocations); + return new LoadTimeLine(name, createPeriods(criterion, generics), + "global-generic"); + } + + private LoadTimeLine buildTimeLine(Collection criterions, + Task task, Criterion criterion, + List> allocations) { + return buildTimeLine(criterion, getName(criterions, task), allocations); + } + + private LoadTimeLine buildTimeLine(Collection criterions, + Task task, Resource resource, + List allocationsSortedByStartDate) { + LoadPeriodGeneratorFactory periodGeneratorFactory = LoadPeriodGenerator + .onResourceSatisfying(resource, criterions); + return new LoadTimeLine(getName(criterions, task), PeriodsBuilder + .build(periodGeneratorFactory, allocationsSortedByStartDate), + "generic"); + } + @Override public List getLoadTimeLines() { return loadTimeLines;