ItEr26S07CUAsignacionGrupoRecursosAPlanificacionItEr25S07: The task doesn't store the duration it takes since it can be calculated substracting the end date by the start date.

This commit is contained in:
Óscar González Fernández 2009-09-15 11:04:46 +02:00
parent 988e1ae666
commit 780ef88827
4 changed files with 18 additions and 72 deletions

View file

@ -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<ResourceAllocation> resourceAllocations = new HashSet<ResourceAllocation>();
/**
@ -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<ResourceAllocation> resourceAllocations) {
BigDecimal result = new BigDecimal(0);
for (ResourceAllocation resourceAllocation : resourceAllocations) {
result = result.add(resourceAllocation.getPercentage());
}
return result;
}
}

View file

@ -36,7 +36,6 @@
<key column="TASK_ELEMENT_ID"></key>
<many-to-one name="hoursGroup" cascade="none"/>
<property name="fixedDuration" />
<property name="duration" />
<set name="resourceAllocations" cascade="all-delete-orphan">
<key column="TASK" />
<one-to-many class="ResourceAllocation" />

View file

@ -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();

View file

@ -25,7 +25,7 @@ public class EditTaskModel implements IEditTaskModel {
public Integer getDuration(Task task) {
taskElementDAO.save(task);
return task.getDuration();
return task.getDaysDuration();
}
}