From 780ef888272bda5ce5d81e02191fa0890eb58ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Tue, 15 Sep 2009 11:04:46 +0200 Subject: [PATCH] ItEr26S07CUAsignacionGrupoRecursosAPlanificacionItEr25S07: The task doesn't store the duration it takes since it can be calculated substracting the end date by the start date. --- .../business/planner/entities/Task.java | 78 +++---------------- .../business/planner/entities/Tasks.hbm.xml | 1 - .../web/planner/EditTaskController.java | 9 ++- .../web/planner/EditTaskModel.java | 2 +- 4 files changed, 18 insertions(+), 72 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java index 63a74167d..47c5c719b 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/Task.java @@ -1,6 +1,5 @@ package org.navalplanner.business.planner.entities; -import java.math.BigDecimal; import java.util.Collections; import java.util.Date; import java.util.HashSet; @@ -31,11 +30,6 @@ public class Task extends TaskElement { private Boolean fixedDuration = false; - /** - * Duration in days of the Task - */ - private Integer duration; - private Set resourceAllocations = new HashSet(); /** @@ -100,63 +94,21 @@ public class Task extends TaskElement { return fixedDuration; } - public void setDuration(Integer duration) { - this.duration = duration; - - DateTime endDate = (new DateTime(getStartDate())).plusDays(duration); + public void setDaysDuration(Integer duration) { + Validate.notNull(duration); + Validate.isTrue(duration >= 0); + DateTime endDate = toDateTime(getStartDate()).plusDays(duration); setEndDate(endDate.toDate()); } - @Override - public void setEndDate(Date endDate) { - super.setEndDate(endDate); - - DateTime startDateTime = new DateTime(getStartDate()); - DateTime endDateTime = new DateTime(endDate); - Days days = Days.daysBetween(startDateTime, endDateTime); - - this.duration = days.getDays(); + public Integer getDaysDuration() { + Days daysBetween = Days.daysBetween(toDateTime(getStartDate()), + toDateTime(getEndDate())); + return daysBetween.getDays(); } - public Integer getDuration() { - if ((isFixedDuration() == null) || !isFixedDuration()) { - // If it is not fixed, the duration is calculated - Integer duration = calculateDaysDuration(); - setDuration(duration); - return duration; - } - - return duration; - } - - /** - * Calculates the number of days needed to complete the Task taking into - * account the Resources assigned and their dedication. If the Task has not - * yet Resources assigned then a typical 8 hours day will be considered. - * @return The days of duration - */ - private Integer calculateDaysDuration() { - BigDecimal hoursPerDay = new BigDecimal(0).setScale(2); - - for (ResourceAllocation resourceAllocation : resourceAllocations) { - if (resourceAllocation instanceof SpecificResourceAllocation) { - BigDecimal percentage = resourceAllocation.getPercentage(); - Integer hours = ((SpecificResourceAllocation) resourceAllocation) - .getWorker().getDailyCapacity(); - - hoursPerDay = hoursPerDay.add(percentage - .multiply(new BigDecimal(hours).setScale(2))); - } - } - - BigDecimal taskHours = new BigDecimal(getWorkHours()).setScale(2); - - if (hoursPerDay.compareTo(new BigDecimal(0).setScale(2)) == 0) { - // FIXME Review, by default 8 hours per day - hoursPerDay = new BigDecimal(8).setScale(2); - } - - return taskHours.divide(hoursPerDay, BigDecimal.ROUND_DOWN).intValue(); + private DateTime toDateTime(Date startDate) { + return new DateTime(startDate.getTime()); } /** @@ -243,14 +195,4 @@ public class Task extends TaskElement { return result; } - public BigDecimal getSumPercentage( - List resourceAllocations) { - BigDecimal result = new BigDecimal(0); - - for (ResourceAllocation resourceAllocation : resourceAllocations) { - result = result.add(resourceAllocation.getPercentage()); - } - - return result; - } } diff --git a/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/Tasks.hbm.xml b/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/Tasks.hbm.xml index 1d7a0214b..eda7e3f96 100644 --- a/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/Tasks.hbm.xml +++ b/navalplanner-business/src/main/resources/org/navalplanner/business/planner/entities/Tasks.hbm.xml @@ -36,7 +36,6 @@ - diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskController.java index b35a44483..efb9e2063 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskController.java @@ -103,14 +103,19 @@ public class EditTaskController extends GenericForwardComposer { } public void onChange$duration(Event event) { - if (currentTaskElement instanceof Task) { + if ((currentTaskElement instanceof Task) + && isValidDuration(duration.getValue())) { Task task = (Task) currentTaskElement; - task.setDuration(duration.getValue()); + task.setDaysDuration(duration.getValue()); } updateComponentValuesForTask(); } + private boolean isValidDuration(Integer duration) { + return duration != null && duration > 0; + } + public void onChange$endDateBox(Event event) { currentTaskElement.setEndDate(endDateBox.getValue()); updateComponentValuesForTask(); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskModel.java index 50d88ff56..bbc2d3a6c 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/EditTaskModel.java @@ -25,7 +25,7 @@ public class EditTaskModel implements IEditTaskModel { public Integer getDuration(Task task) { taskElementDAO.save(task); - return task.getDuration(); + return task.getDaysDuration(); } }