ItEr54S12CUVistaRecursosTempoPorProxectoItEr53S14: Breakdown the criterion information level the screen of business and order.

This commit is contained in:
Susana Montes Pedreira 2010-04-15 17:43:10 +02:00 committed by Javier Moran Rua
parent bdea5574d1
commit caad232fe9
6 changed files with 247 additions and 61 deletions

View file

@ -55,4 +55,6 @@ public interface IResourceAllocationDAO extends
Map<Criterion, List<GenericResourceAllocation>> findGenericAllocationsByCriterionFor(
List<Task> task);
Map<Criterion, List<GenericResourceAllocation>> findGenericAllocationsBySomeCriterion(
List<Criterion> criterions);
}

View file

@ -139,6 +139,22 @@ public class ResourceAllocationDAO extends
return stripAllocationsWithoutAssignations(byCriterion(list));
}
@SuppressWarnings("unchecked")
@Override
public Map<Criterion, List<GenericResourceAllocation>> findGenericAllocationsBySomeCriterion(
List<Criterion> criterions) {
if (criterions.isEmpty()) {
return new HashMap<Criterion, List<GenericResourceAllocation>>();
}
List<Object> 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<Criterion, List<GenericResourceAllocation>> byCriterion(
List<Object> results) {

View file

@ -62,7 +62,7 @@ public class GenericResourceAllocation extends
}
public static Map<Set<Criterion>, List<GenericResourceAllocation>> byCriterions(
Collection<? extends GenericResourceAllocation> genericAllocations) {
Collection<GenericResourceAllocation> genericAllocations) {
Map<Set<Criterion>, List<GenericResourceAllocation>> result = new HashMap<Set<Criterion>, List<GenericResourceAllocation>>();
for (GenericResourceAllocation genericResourceAllocation : genericAllocations) {
Set<Criterion> criterions = genericResourceAllocation.getCriterions();
@ -74,6 +74,34 @@ public class GenericResourceAllocation extends
return result;
}
public static Map<Resource, List<GenericResourceAllocation>> byResource(
Collection<GenericResourceAllocation> allocations) {
Map<Resource, List<GenericResourceAllocation>> result = new HashMap<Resource, List<GenericResourceAllocation>>();
for (GenericResourceAllocation resourceAllocation : allocations) {
for (Resource resource : resourceAllocation
.getAssociatedResources()) {
initializeIfNeeded_(result, resource);
result.get(resource).add(resourceAllocation);
}
}
return result;
}
private static void initializeIfNeeded_(
Map<Resource, List<GenericResourceAllocation>> result,
Resource resource) {
if (!result.containsKey(resource)) {
result.put(resource, new ArrayList<GenericResourceAllocation>());
}
}
private static void initializeIfNeeded_(
Map<Task, List<GenericResourceAllocation>> result, Task task) {
if (!result.containsKey(task)) {
result.put(task, new ArrayList<GenericResourceAllocation>());
}
}
private Set<Criterion> criterions = new HashSet<Criterion>();
private Set<GenericDayAssignment> genericDayAssignments = new HashSet<GenericDayAssignment>();
@ -316,4 +344,21 @@ public class GenericResourceAllocation extends
return resourceDAO.findSatisfyingCriterionsAtSomePoint(getCriterions());
}
public static Map<Criterion, List<GenericResourceAllocation>> byCriterion(
List<GenericResourceAllocation> generics) {
Map<Criterion, List<GenericResourceAllocation>> result = new HashMap<Criterion, List<GenericResourceAllocation>>();
for (GenericResourceAllocation genericResourceAllocation : generics) {
Set<Criterion> criterions = genericResourceAllocation
.getCriterions();
for (Criterion criterion : criterions) {
if (!result.containsKey(criterion)) {
result.put(criterion,
new ArrayList<GenericResourceAllocation>());
}
result.get(criterion).add(genericResourceAllocation);
}
}
return result;
}
}

View file

@ -90,7 +90,7 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
}
public static Map<Task, List<ResourceAllocation<?>>> byTask(
Collection<? extends ResourceAllocation<?>> allocations) {
List<ResourceAllocation<?>> allocations) {
Map<Task, List<ResourceAllocation<?>>> result = new HashMap<Task, List<ResourceAllocation<?>>>();
for (ResourceAllocation<?> resourceAllocation : allocations) {
if (resourceAllocation.getTask() != null) {
@ -102,11 +102,10 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
return result;
}
private static void initializeIfNeeded(
Map<Task, List<ResourceAllocation<?>>> result, Task task) {
private static <E extends ResourceAllocation<?>> void initializeIfNeeded(
Map<Task, List<E>> result, Task task) {
if (!result.containsKey(task)) {
result.put(task,
new ArrayList<ResourceAllocation<?>>());
result.put(task, new ArrayList<E>());
}
}

View file

@ -339,21 +339,7 @@ class LoadPeriodGeneratorOnCriterion extends LoadPeriodGenerator {
@Override
protected int getHoursAssigned() {
return sumAllocations() + calculateSumOfSpecific();
}
private int calculateSumOfSpecific() {
List<SpecificDayAssignment> specific = new ArrayList<SpecificDayAssignment>();
for (Resource each : resourcesSatisfyingCriterionAtSomePoint) {
specific.addAll(specificAssignmentsAtInterval(each));
}
return sum(specific);
}
private List<SpecificDayAssignment> specificAssignmentsAtInterval(
Resource each) {
return DayAssignment.getAtInterval(
getSpecificOrderedAssignmentsFor(each), start, end);
return sumAllocations();
}
private Map<Resource, List<SpecificDayAssignment>> specificByResourceCached = new HashMap<Resource, List<SpecificDayAssignment>>();

View file

@ -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<Criterion, List<GenericResourceAllocation>> genericAllocationsByCriterion() {
if (filter()) {
List<Criterion> criterions = new ArrayList<Criterion>();
List<GenericResourceAllocation> generics = new ArrayList<GenericResourceAllocation>();
List<Task> tasks = justTasks(filterBy
.getAllChildrenAssociatedTaskElements());
for (Task task : tasks) {
List<ResourceAllocation<?>> listAllocations = new ArrayList<ResourceAllocation<?>>(
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<LoadTimeLine> groupsFor(
Map<Criterion, List<GenericResourceAllocation>> genericAllocationsByCriterion) {
List<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
@ -173,7 +189,8 @@ public class ResourceLoadModel implements IResourceLoadModel {
List<GenericResourceAllocation> allocations = ResourceAllocation
.sortedByStartDate(entry.getValue());
LoadTimeLine group = new LoadTimeLine(createPrincipal(entry
.getKey(), allocations), new ArrayList<LoadTimeLine>());
.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<LoadTimeLine> buildSecondLevel(Criterion criterion,
List<GenericResourceAllocation> allocations) {
List<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
Map<Order, List<ResourceAllocation<?>>> byOrder = byOrder(new ArrayList<ResourceAllocation<?>>(
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<LoadTimeLine> buildTimeLinesForOrder(Criterion criterion,
List<ResourceAllocation<?>> allocations) {
List<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
result.addAll(buildTimeLinesForEachTask(criterion, allocations));
return result;
}
private LoadTimeLine buildTimeLinesForOtherOrders(Criterion criterion,
Map<Order, List<ResourceAllocation<?>>> byOrder) {
List<ResourceAllocation<?>> allocations = getAllSortedValues(byOrder);
if (allocations.isEmpty()) {
return null;
}
LoadTimeLine group = new LoadTimeLine(buildTimeLine(criterion,
"Others ordes", allocations), buildTimeLinesGroupForOrder(
criterion, byOrder));
return group;
}
private List<LoadTimeLine> buildTimeLinesGroupForOrder(Criterion criterion,
Map<Order, List<ResourceAllocation<?>>> byOrder) {
List<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
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<LoadTimeLine> buildTimeLinesForEachTask(Criterion criterion,
List<ResourceAllocation<?>> allocations) {
Map<Task, List<ResourceAllocation<?>>> byTask = ResourceAllocation
.byTask(allocations);
List<LoadTimeLine> secondLevel = new ArrayList<LoadTimeLine>();
for (Entry<Task, List<ResourceAllocation<?>>> entry : byTask.entrySet()) {
Task task = entry.getKey();
Set<Criterion> 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<LoadTimeLine> buildTimeLinesForEachResource(
Criterion criterion, List<GenericResourceAllocation> allocations) {
Map<Resource, List<GenericResourceAllocation>> byResource = GenericResourceAllocation
.byResource(allocations);
List<LoadTimeLine> secondLevel = new ArrayList<LoadTimeLine>();
for (Entry<Resource, List<GenericResourceAllocation>> entry : byResource
.entrySet()) {
Resource resource = entry.getKey();
List<GenericResourceAllocation> 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<CriterionSatisfaction> criterionSatisfactions = resource
.getCriterionSatisfactions();
return resource.getShortDescription()
+ getCriterionSatisfactionDescription(criterionSatisfactions);
}
private String getCriterionSatisfactionDescription(
Set<CriterionSatisfaction> satisfactions) {
if (satisfactions.isEmpty()) {
return _("");
}
List<Criterion> criterions = new ArrayList<Criterion>();
for (CriterionSatisfaction satisfaction : satisfactions) {
criterions.add(satisfaction.getCriterion());
}
return " :: " + getName(criterions);
}
private LoadTimeLine createPrincipal(Criterion criterion,
List<GenericResourceAllocation> 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<LoadTimeLine> result = new ArrayList<LoadTimeLine>();
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<Order, List<ResourceAllocation<?>>> byOrder(
Collection<? extends ResourceAllocation<?>> allocations) {
Collection<ResourceAllocation<?>> allocations) {
Map<Order, List<ResourceAllocation<?>>> result = new HashMap<Order, List<ResourceAllocation<?>>>();
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<Task, List<ResourceAllocation<?>>> byTask = ResourceAllocation
.byTask(entry.getValue());
.byTask(new ArrayList<ResourceAllocation<?>>(entry
.getValue()));
for (Entry<Task, List<ResourceAllocation<?>>> entryTask : byTask
.entrySet()) {
Task task = entryTask.getKey();
List<GenericResourceAllocation> resouceAllocations = getGenericResourceAllocation(entryTask
List<GenericResourceAllocation> 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<GenericResourceAllocation> getGenericResourceAllocation(
List<ResourceAllocation<?>> list) {
List<GenericResourceAllocation> result = new ArrayList<GenericResourceAllocation>();
for (ResourceAllocation<?> resourceAllocation : list) {
if (resourceAllocation instanceof GenericResourceAllocation) {
result.add((GenericResourceAllocation) resourceAllocation);
}
}
return result;
}
private List<LoadTimeLine> buildTimeLinesForEachTask(Resource resource,
List<SpecificResourceAllocation> sortedByStartDate) {
List<ResourceAllocation<?>> listOnlySpecific = new ArrayList<ResourceAllocation<?>>(
sortedByStartDate);
Map<Task, List<ResourceAllocation<?>>> byTask = ResourceAllocation
.byTask(sortedByStartDate);
.byTask(listOnlySpecific);
List<LoadTimeLine> secondLevel = new ArrayList<LoadTimeLine>();
for (Entry<Task, List<ResourceAllocation<?>>> entry : byTask.entrySet()) {
Task task = entry.getKey();
@ -371,16 +502,6 @@ public class ResourceLoadModel implements IResourceLoadModel {
return secondLevel;
}
private LoadTimeLine buildTimeLine(Collection<Criterion> criterions,
Task task, Resource resource,
List<GenericResourceAllocation> allocationsSortedByStartDate) {
LoadPeriodGeneratorFactory periodGeneratorFactory = LoadPeriodGenerator
.onResourceSatisfying(resource, criterions);
return new LoadTimeLine(getName(criterions, task), PeriodsBuilder
.build(periodGeneratorFactory, allocationsSortedByStartDate),
"generic");
}
public static String getName(Collection<? extends Criterion> criterions,
Task task) {
String prefix = task.getName();
@ -400,17 +521,34 @@ public class ResourceLoadModel implements IResourceLoadModel {
}
private LoadTimeLine buildTimeLine(Resource resource, String name,
List<ResourceAllocation<?>> sortedByStartDate) {
return new LoadTimeLine(name, PeriodsBuilder.build(LoadPeriodGenerator
.onResource(resource), sortedByStartDate), "resource");
}
private LoadTimeLine buildTimeLine(Resource resource, String name,
List<ResourceAllocation<?>> sortedByStartDate, String type) {
List<? extends ResourceAllocation<?>> sortedByStartDate, String type) {
return new LoadTimeLine(name, PeriodsBuilder.build(LoadPeriodGenerator
.onResource(resource), sortedByStartDate), type);
}
private LoadTimeLine buildTimeLine(Criterion criterion, String name,
List<ResourceAllocation<?>> allocations) {
List<GenericResourceAllocation> generics = onlyGeneric(allocations);
return new LoadTimeLine(name, createPeriods(criterion, generics),
"global-generic");
}
private LoadTimeLine buildTimeLine(Collection<Criterion> criterions,
Task task, Criterion criterion,
List<ResourceAllocation<?>> allocations) {
return buildTimeLine(criterion, getName(criterions, task), allocations);
}
private LoadTimeLine buildTimeLine(Collection<Criterion> criterions,
Task task, Resource resource,
List<GenericResourceAllocation> allocationsSortedByStartDate) {
LoadPeriodGeneratorFactory periodGeneratorFactory = LoadPeriodGenerator
.onResourceSatisfying(resource, criterions);
return new LoadTimeLine(getName(criterions, task), PeriodsBuilder
.build(periodGeneratorFactory, allocationsSortedByStartDate),
"generic");
}
@Override
public List<LoadTimeLine> getLoadTimeLines() {
return loadTimeLines;