Replace attribute TaskElement.sumOfHoursAllocated with an equivalent attribute

measured in EffortDuration.

FEA: ItEr75S04BugFixing
This commit is contained in:
Jacobo Aragunde Pérez 2011-12-21 12:40:00 +01:00
parent 3aeea3808a
commit 3d1a5c1aa8
6 changed files with 71 additions and 54 deletions

View file

@ -32,6 +32,7 @@ import org.libreplan.business.common.daos.GenericDAOHibernate;
import org.libreplan.business.planner.entities.ResourceAllocation;
import org.libreplan.business.planner.entities.TaskElement;
import org.libreplan.business.planner.entities.TaskGroup;
import org.libreplan.business.workingday.EffortDuration;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
@ -69,45 +70,51 @@ public class TaskElementDAO extends GenericDAOHibernate<TaskElement, Long>
}
private void updateSumOfAllocatedHours(TaskElement taskElement) {
Integer allocatedHours = 0;
Integer oldAllocatedHours = taskElement.getSumOfHoursAllocated();
EffortDuration assignedEffort = EffortDuration.hours(0);
EffortDuration oldAssignedEffort = taskElement.getSumOfAssignedEffort();
for(ResourceAllocation<?> allocation : taskElement.getAllResourceAllocations()) {
allocatedHours += allocation.getAssignedHours();
assignedEffort = assignedEffort.plus(allocation.getAssignedEffort());
}
if(allocatedHours != oldAllocatedHours) {
taskElement.setSumOfHoursAllocated(allocatedHours);
if(assignedEffort.compareTo(oldAssignedEffort) != 0) {
taskElement.setSumOfAssignedEffort(assignedEffort);
updateSumOfAllocatedHoursToParent(taskElement.getParent(),
allocatedHours - oldAllocatedHours);
updateSumOfAllocatedHoursToChildren(taskElement,
allocatedHours - oldAllocatedHours);
oldAssignedEffort, assignedEffort);
updateSumOfAllocatedHoursToChildren(taskElement);
}
}
private void updateSumOfAllocatedHoursToChildren(
TaskElement parent, Integer differenceOfHours) {
private void updateSumOfAllocatedHoursToChildren(TaskElement parent) {
if(parent instanceof TaskGroup) {
for(TaskElement child : parent.getChildren()) {
Integer allocatedHours = 0;
Integer oldAllocatedHours = child.getSumOfHoursAllocated();
EffortDuration assignedEffort = EffortDuration.hours(0);
EffortDuration oldAssignedEffort = child.getSumOfAssignedEffort();
for(ResourceAllocation<?> allocation : child.getAllResourceAllocations()) {
allocatedHours += allocation.getAssignedHours();
assignedEffort = assignedEffort.plus(allocation.getAssignedEffort());
}
if(allocatedHours != oldAllocatedHours) {
child.setSumOfHoursAllocated(allocatedHours);
updateSumOfAllocatedHoursToChildren(child,
allocatedHours - oldAllocatedHours);
if(assignedEffort.compareTo(oldAssignedEffort) != 0) {
child.setSumOfAssignedEffort(assignedEffort);
updateSumOfAllocatedHoursToChildren(child);
}
}
}
}
private void updateSumOfAllocatedHoursToParent(TaskGroup taskGroup, Integer differenceOfHours) {
private void updateSumOfAllocatedHoursToParent(TaskGroup taskGroup,
EffortDuration oldAssignedEffort, EffortDuration newAssignedEffort) {
if (taskGroup != null) {
if (!Hibernate.isInitialized(taskGroup)) {
reattach(taskGroup);
}
taskGroup.addSumOfHoursAllocated(differenceOfHours);
updateSumOfAllocatedHoursToParent(taskGroup.getParent(), differenceOfHours);
if(newAssignedEffort.compareTo(oldAssignedEffort) < 0) {
taskGroup.setSumOfAssignedEffort(taskGroup.getSumOfAssignedEffort().minus(
oldAssignedEffort.minus(newAssignedEffort)));
}
else {
taskGroup.setSumOfAssignedEffort(taskGroup.getSumOfAssignedEffort().plus(
newAssignedEffort.minus(oldAssignedEffort)));
}
updateSumOfAllocatedHoursToParent(taskGroup.getParent(),
oldAssignedEffort, newAssignedEffort);
}
}

View file

@ -603,7 +603,7 @@ public abstract class TaskElement extends BaseEntity {
//simplified calculation has only two states:
//unassigned, when hours allocated is zero, and
//assigned otherwise
if (getSumOfHoursAllocated() == 0) {
if (getSumOfAssignedEffort().isZero()) {
return "unassigned";
}
return "assigned";
@ -658,24 +658,20 @@ public abstract class TaskElement extends BaseEntity {
this.advancePercentage = advancePercentage;
}
private Integer sumOfHoursAllocated = 0;
private EffortDuration sumOfAssignedEffort = EffortDuration.hours(0);
public void setSumOfHoursAllocated(Integer sumOfHoursAllocated) {
this.sumOfHoursAllocated = sumOfHoursAllocated;
public void setSumOfAssignedEffort(EffortDuration sumOfAssignedEffort) {
this.sumOfAssignedEffort = sumOfAssignedEffort;
}
public void addSumOfHoursAllocated(Integer sumOfHoursAllocated) {
this.sumOfHoursAllocated += sumOfHoursAllocated;
public EffortDuration getSumOfAssignedEffort() {
return sumOfAssignedEffort;
}
public Integer getSumOfHoursAllocated() {
return sumOfHoursAllocated;
}
public Integer getSumOfHoursAllocatedCalculated() {
int result = 0;
public EffortDuration getSumOfAssignedEffortCalculated() {
EffortDuration result = EffortDuration.hours(0);
for(ResourceAllocation<?> allocation : getAllResourceAllocations()) {
result += allocation.getAssignedHours();
result = result.plus(allocation.getAssignedEffort());
}
return result;
}

View file

@ -17,4 +17,19 @@
defaultValueNumeric="0" />
</changeSet>
<changeSet id="change-sum_of_hours_allocated-to-sum_of_assigned_effort" author="jaragunde">
<comment>Changing sum_of_hours_allocated to sum_of_assigned_effort</comment>
<renameColumn tableName="task_element"
oldColumnName="sum_of_hours_allocated"
newColumnName="sum_of_assigned_effort"
columnDataType="INTEGER" />
</changeSet>
<changeSet id="update-effort-values-in-sum_charged_effort" author="jaragunde">
<comment>Updating effort values (hours to seconds) in task_element table</comment>
<sql>
UPDATE task_element
SET sum_of_assigned_effort = sum_of_assigned_effort*3600
</sql>
</changeSet>
</databaseChangeLog>

View file

@ -27,7 +27,8 @@
<property name="deadline" type="org.joda.time.contrib.hibernate.PersistentLocalDate" />
<property name="advancePercentage" column="advance_percentage" access="field" scale="4"/>
<property name="sumOfHoursAllocated" column="sum_of_hours_allocated" />
<property name="sumOfAssignedEffort" column="sum_of_assigned_effort" access="field"
type="org.libreplan.business.workingday.hibernate.EffortDurationType"/>
<!-- Indexed -->
<many-to-one name="parent" class="TaskGroup" cascade="none" column="parent"

View file

@ -581,8 +581,8 @@ public class TaskElementDAOTest {
fail();
return null;
}
assertTrue(task1.getSumOfHoursAllocated() == 24);
assertTrue(task1.getParent().getSumOfHoursAllocated() == 24);
assertTrue(task1.getSumOfAssignedEffort().getHours() == 24);
assertTrue(task1.getParent().getSumOfAssignedEffort().getHours() == 24);
return null;
}

View file

@ -557,17 +557,15 @@ public class TaskElementAdapter {
}
if (result == null) {
Integer hours = taskElement.getSumOfHoursAllocated();
EffortDuration effort = taskElement.getSumOfAssignedEffort();
if (hours == 0) {
hours = orderElement.getWorkHours();
if (hours == 0) {
if (effort.isZero()) {
effort = EffortDuration.hours(orderElement.getWorkHours());
if (effort.isZero()) {
return getBeginDate();
}
}
BigDecimal percentage = assignedEffort
.toHoursAsDecimalWithScale(2).divide(
new BigDecimal(hours), RoundingMode.DOWN);
BigDecimal percentage = new BigDecimal(assignedEffort.divideBy(effort));
result = calculateLimitDateByPercentage(percentage);
}
@ -589,17 +587,15 @@ public class TaskElementAdapter {
BigDecimal assignedHours = totalChargedEffort
.toHoursAsDecimalWithScale(2);
BigDecimal estimatedHours = new BigDecimal(
taskElement.getSumOfHoursAllocated()).setScale(2);
EffortDuration estimatedEffort = taskElement.getSumOfAssignedEffort();
if (estimatedHours.compareTo(BigDecimal.ZERO) <= 0) {
estimatedHours = new BigDecimal(orderElement.getWorkHours())
.setScale(2);
if (estimatedHours.compareTo(BigDecimal.ZERO) <= 0) {
if(estimatedEffort.isZero()) {
estimatedEffort = EffortDuration.hours(orderElement.getWorkHours());
if(estimatedEffort.isZero()) {
return BigDecimal.ZERO;
}
}
return assignedHours.divide(estimatedHours, RoundingMode.DOWN);
return new BigDecimal(totalChargedEffort.divideBy(estimatedEffort));
}
@Override
@ -638,14 +634,16 @@ public class TaskElementAdapter {
}
private GanttDate getAdvanceEndDate(BigDecimal advancePercentage) {
Integer hours = Integer.valueOf(0);
BigDecimal hours = BigDecimal.ZERO;
if (taskElement.getOrderElement() != null) {
if(taskElement.getParent() == null){
//it's an order, we use the cached value
hours = taskElement.getSumOfHoursAllocated();
hours = taskElement.getSumOfAssignedEffort()
.toHoursAsDecimalWithScale(2);
}
else {
hours = taskElement.getSumOfHoursAllocatedCalculated();
hours = taskElement.getSumOfAssignedEffortCalculated()
.toHoursAsDecimalWithScale(2);;
}
}
@ -655,7 +653,7 @@ public class TaskElementAdapter {
// Calculate date according to advanceHours or advancePercentage
final Integer advanceHours = advancePercentage.multiply(
new BigDecimal(hours)).intValue();
hours).intValue();
GanttDate result = calculateLimitDateByHours(advanceHours);
if (result == null) {
result = calculateLimitDateByPercentage(advancePercentage);