From ebfb2de993be4221e2bfcc8f1afa78d95da89ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Mon, 14 Sep 2009 17:50:28 +0200 Subject: [PATCH] ItEr26S07CUAsignacionGrupoRecursosAPlanificacionItEr25S07: The ResourceAllocation stores ResourcesPerUnit instead of percentage --- .../entities/GenericResourceAllocation.java | 11 +++++ .../planner/entities/ResourceAllocation.java | 41 +++++++++---------- .../entities/SpecificResourceAllocation.java | 11 +++++ .../entities/ResourceAllocations.hbm.xml | 2 +- .../daos/ResourceAllocationDAOTest.java | 5 ++- .../GenericResourceAllocationTest.java | 13 ++++++ .../web/planner/allocation/AllocationDTO.java | 12 +++--- .../allocation/GenericAllocationDTO.java | 4 +- .../ResourceAllocationController.java | 34 +++++---------- .../allocation/ResourceAllocationModel.java | 2 +- .../allocation/SpecificAllocationDTO.java | 4 +- .../src/main/webapp/planner/order.zul | 2 +- 12 files changed, 83 insertions(+), 58 deletions(-) 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 f05838edc..f8501baa9 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 @@ -33,6 +33,16 @@ public class GenericResourceAllocation extends ResourceAllocation { return (GenericResourceAllocation) create(new GenericResourceAllocation()); } + public static GenericResourceAllocation createForTesting( + ResourcesPerDay resourcesPerDay, Task task) { + return (GenericResourceAllocation) create(new GenericResourceAllocation( + resourcesPerDay, task)); + } + + private GenericResourceAllocation(ResourcesPerDay resourcesPerDay, Task task) { + super(resourcesPerDay, task); + } + public GenericResourceAllocation() { } @@ -120,6 +130,7 @@ public class GenericResourceAllocation extends ResourceAllocation { resourcesPerDay); assigmentsCreated.addAll(distributeForDay(day, totalForDay)); } + setResourcesPerDay(resourcesPerDay); setAssigments(assigmentsCreated); } 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 d3433a472..f42dee20e 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 @@ -1,9 +1,6 @@ -/** - * - */ package org.navalplanner.business.planner.entities; -import java.math.BigDecimal; + import java.util.List; import org.apache.commons.lang.Validate; @@ -22,12 +19,8 @@ public abstract class ResourceAllocation extends BaseEntity { private AssigmentFunction assigmentFunction; - /** - * Allocation percentage of the resource. - * - * It's one based, instead of one hundred based. - */ - private BigDecimal percentage = new BigDecimal(0).setScale(2); + @NotNull + private ResourcesPerDay resourcesPerDay; /** * Constructor for hibernate. Do not use! @@ -36,6 +29,11 @@ public abstract class ResourceAllocation extends BaseEntity { } + protected void setResourcesPerDay(ResourcesPerDay resourcesPerDay) { + Validate.notNull(resourcesPerDay); + this.resourcesPerDay = resourcesPerDay; + } + public ResourceAllocation(Task task) { this(task, null); } @@ -46,22 +44,16 @@ public abstract class ResourceAllocation extends BaseEntity { assigmentFunction = assignmentFunction; } + protected ResourceAllocation(ResourcesPerDay resourcesPerDay, Task task) { + this(task); + Validate.notNull(resourcesPerDay); + this.resourcesPerDay = resourcesPerDay; + } + public Task getTask() { return task; } - public BigDecimal getPercentage() { - return percentage; - } - - /** - * @param proportion - * It's one based, instead of one hundred based. - */ - public void setPercentage(BigDecimal proportion) { - this.percentage = proportion; - } - public AssigmentFunction getAssigmentFunction() { return assigmentFunction; } @@ -76,4 +68,9 @@ public abstract class ResourceAllocation extends BaseEntity { protected abstract List getAssignments(); + + public ResourcesPerDay getResourcesPerDay() { + return resourcesPerDay; + } + } diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java index 2683a4b4d..42e0544d3 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java @@ -25,6 +25,12 @@ public class SpecificResourceAllocation extends ResourceAllocation { private Set specificDaysAssigment = new HashSet(); + public static SpecificResourceAllocation createForTesting( + ResourcesPerDay resourcesPerDay, Task task) { + return (SpecificResourceAllocation) create(new SpecificResourceAllocation( + resourcesPerDay, task)); + } + /** * Constructor for hibernate. Do not use! */ @@ -32,6 +38,11 @@ public class SpecificResourceAllocation extends ResourceAllocation { } + private SpecificResourceAllocation(ResourcesPerDay resourcesPerDay, + Task task) { + super(resourcesPerDay, task); + } + private SpecificResourceAllocation(Task task) { super(task); } diff --git a/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/ResourceAllocations.hbm.xml b/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/ResourceAllocations.hbm.xml index 9a211516a..d8ef34b8e 100644 --- a/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/ResourceAllocations.hbm.xml +++ b/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/ResourceAllocations.hbm.xml @@ -12,7 +12,7 @@ - + diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/daos/ResourceAllocationDAOTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/daos/ResourceAllocationDAOTest.java index b1ffdbd52..359336e54 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/daos/ResourceAllocationDAOTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/daos/ResourceAllocationDAOTest.java @@ -21,6 +21,7 @@ import org.navalplanner.business.planner.daos.IResourceAllocationDAO; import org.navalplanner.business.planner.daos.ITaskElementDAO; import org.navalplanner.business.planner.entities.GenericResourceAllocation; import org.navalplanner.business.planner.entities.ResourceAllocation; +import org.navalplanner.business.planner.entities.ResourcesPerDay; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; import org.navalplanner.business.planner.entities.Task; import org.navalplanner.business.resources.daos.IResourceDAO; @@ -95,7 +96,7 @@ public class ResourceAllocationDAOTest { if (ResourceAllocationType.SPECIFIC_RESOURCE_ALLOCATION.equals(type)) { SpecificResourceAllocation specificResourceAllocation = SpecificResourceAllocation - .create(task); + .createForTesting(ResourcesPerDay.amount(1), task); Worker worker = (Worker) createValidWorker(); resourceDAO.save(worker); specificResourceAllocation.setWorker(worker); @@ -104,7 +105,7 @@ public class ResourceAllocationDAOTest { } if (ResourceAllocationType.GENERIC_RESOURCE_ALLOCATION.equals(type)) { GenericResourceAllocation specificResourceAllocation = GenericResourceAllocation - .create(task); + .createForTesting(ResourcesPerDay.amount(1), task); return specificResourceAllocation; } diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/GenericResourceAllocationTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/GenericResourceAllocationTest.java index 8b63a838d..d1dbd1aea 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/GenericResourceAllocationTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/GenericResourceAllocationTest.java @@ -177,6 +177,19 @@ public class GenericResourceAllocationTest { } } + @Test + public void theResourcesPerDayAreChangedWhenTheAllocationIsDone() { + givenTaskWithStartAndEnd(toInterval(new LocalDate(2006, 10, 5), Period + .days(2))); + givenGenericResourceAllocationForTask(task); + givenWorkersWithoutLoadAndWithoutCalendar(); + ResourcesPerDay assignedResourcesPerDay = ResourcesPerDay.amount(5); + genericResourceAllocation.forResources(workers).allocate( + assignedResourcesPerDay); + assertThat(genericResourceAllocation.getResourcesPerDay(), + equalTo(assignedResourcesPerDay)); + } + @Test public void allocatingSeveralResourcesPerDayHavingJustOneResourceProducesOvertime() { LocalDate start = new LocalDate(2006, 10, 5); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java index 522d80781..ebabfdee2 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java @@ -1,11 +1,11 @@ package org.navalplanner.web.planner.allocation; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.navalplanner.business.planner.entities.ResourceAllocation; +import org.navalplanner.business.planner.entities.ResourcesPerDay; /** * The information that must be introduced to create a @@ -27,7 +27,7 @@ public abstract class AllocationDTO { private String name; - private BigDecimal percentage; + private ResourcesPerDay resourcesPerDay; public String getName() { return name; @@ -37,12 +37,12 @@ public abstract class AllocationDTO { this.name = name; } - public BigDecimal getPercentage() { - return percentage; + public ResourcesPerDay getResourcesPerDay() { + return this.resourcesPerDay; } - public void setPercentage(BigDecimal percentage) { - this.percentage = percentage; + public void setResourcesPerDay(ResourcesPerDay resourcesPerDay) { + this.resourcesPerDay = resourcesPerDay; } public abstract boolean isGeneric(); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java index 158866951..e15cf0e6b 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java @@ -3,6 +3,7 @@ package org.navalplanner.web.planner.allocation; import static org.navalplanner.web.I18nHelper._; import org.navalplanner.business.planner.entities.GenericResourceAllocation; +import org.navalplanner.business.planner.entities.ResourcesPerDay; /** * The information required for creating a {@link GenericResourceAllocation} @@ -13,13 +14,14 @@ public class GenericAllocationDTO extends AllocationDTO { public static GenericAllocationDTO createDefault() { GenericAllocationDTO result = new GenericAllocationDTO(); result.setName(_("Generic")); + result.setResourcesPerDay(ResourcesPerDay.amount(0)); return result; } public static GenericAllocationDTO from( GenericResourceAllocation resourceAllocation) { GenericAllocationDTO result = createDefault(); - result.setPercentage(resourceAllocation.getPercentage()); + result.setResourcesPerDay(resourceAllocation.getResourcesPerDay()); return result; } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java index ba4e1f32e..dee9f4f2d 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java @@ -9,6 +9,7 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.navalplanner.business.planner.entities.ResourceAllocation; +import org.navalplanner.business.planner.entities.ResourcesPerDay; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; import org.navalplanner.business.planner.entities.Task; import org.navalplanner.business.resources.entities.Criterion; @@ -33,6 +34,7 @@ import org.zkoss.zul.Listbox; import org.zkoss.zul.Listcell; import org.zkoss.zul.Listitem; import org.zkoss.zul.ListitemRenderer; +import org.zkoss.zul.SimpleConstraint; import org.zkoss.zul.api.Window; /** @@ -215,9 +217,8 @@ public class ResourceAllocationController extends GenericForwardComposer { // Label fields are fixed, can only be viewed appendLabel(item, getName(data.getResource())); - // appendLabel(item, resourceAllocation.getWorker().getNif()); - // Percentage field is editable - bindPercentage(appendDecimalbox(item), data); + + bindResourcesPerDay(appendDecimalbox(item), data); // On click delete button appendButton(item, _("Delete")).addEventListener("onClick", new EventListener() { @@ -245,18 +246,9 @@ public class ResourceAllocationController extends GenericForwardComposer { private void renderGenericResourceAllocation(Listitem item, final GenericAllocationDTO data) throws Exception { item.setValue(data); - // Set name appendLabel(item, _("Generic")); - // Set percentage - BigDecimal percentage = data.getPercentage(); - if (!new BigDecimal(0).equals(data.getPercentage())) { - percentage = (percentage != null) ? percentage - : new BigDecimal(0); - percentage = percentage.scaleByPowerOfTen(2).setScale(2, - BigDecimal.ROUND_HALF_EVEN); - } - appendLabel(item, percentage.toString()); + bindResourcesPerDay(appendDecimalbox(item), data); // No buttons appendLabel(item, ""); } @@ -307,26 +299,22 @@ public class ResourceAllocationController extends GenericForwardComposer { return decimalbox; } - private void bindPercentage(final Decimalbox decimalbox, - final SpecificAllocationDTO data) { + private void bindResourcesPerDay(final Decimalbox decimalbox, + final AllocationDTO data) { + decimalbox.setConstraint(new SimpleConstraint( + SimpleConstraint.NO_NEGATIVE)); Util.bind(decimalbox, new Util.Getter() { @Override public BigDecimal get() { - return (data.getPercentage() != null) ? data - .getPercentage().scaleByPowerOfTen(2) - : new BigDecimal(0); + return data.getResourcesPerDay().getAmount(); } }, new Util.Setter() { @Override public void set(BigDecimal value) { - if (value != null) { - value = value.setScale(2).divide(new BigDecimal(100), - BigDecimal.ROUND_HALF_EVEN); - data.setPercentage(value); - } + data.setResourcesPerDay(ResourcesPerDay.amount(value)); } }); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java index 1ece93daf..8b9878cf0 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java @@ -153,7 +153,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel { Set resourceAllocations) { resourceAllocations.size(); for (ResourceAllocation resourceAllocation : resourceAllocations) { - resourceAllocation.getPercentage(); + resourceAllocation.getResourcesPerDay(); if (resourceAllocation instanceof SpecificResourceAllocation) { reattachSpecificResourceAllocation((SpecificResourceAllocation) resourceAllocation); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java index 50b26d938..d4bf944be 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.navalplanner.business.planner.entities.ResourcesPerDay; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; import org.navalplanner.business.resources.entities.Resource; import org.navalplanner.business.resources.entities.Worker; @@ -46,7 +47,7 @@ public class SpecificAllocationDTO extends AllocationDTO { public static SpecificAllocationDTO from(SpecificResourceAllocation specific) { SpecificAllocationDTO result = forResource(specific.getWorker()); - result.setPercentage(specific.getPercentage()); + result.setResourcesPerDay(specific.getResourcesPerDay()); return result; } @@ -54,6 +55,7 @@ public class SpecificAllocationDTO extends AllocationDTO { SpecificAllocationDTO result = new SpecificAllocationDTO(); result.setName(worker.getName()); result.setResource(worker); + result.setResourcesPerDay(ResourcesPerDay.amount(1)); return result; } diff --git a/navalplanner-webapp/src/main/webapp/planner/order.zul b/navalplanner-webapp/src/main/webapp/planner/order.zul index e1a45f0fe..49dfa1d7b 100644 --- a/navalplanner-webapp/src/main/webapp/planner/order.zul +++ b/navalplanner-webapp/src/main/webapp/planner/order.zul @@ -95,7 +95,7 @@ style="margin-bottom: 5px"> - +