Return EffortDurations instead of ints in aggregating methods
FEA: ItEr74S04BugFixing
This commit is contained in:
parent
4370fe79c0
commit
bce85384bd
4 changed files with 83 additions and 57 deletions
|
|
@ -1719,7 +1719,11 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
}
|
||||
|
||||
public int getConsolidatedHours() {
|
||||
return DayAssignment.sum(getConsolidatedAssignments()).roundToHours();
|
||||
return getConsolidatedEffort().roundToHours();
|
||||
}
|
||||
|
||||
public EffortDuration getConsolidatedEffort() {
|
||||
return DayAssignment.sum(getConsolidatedAssignments());
|
||||
}
|
||||
|
||||
public int getNonConsolidatedHours() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
package org.navalplanner.web.planner.allocation;
|
||||
|
||||
import static org.navalplanner.business.workingday.EffortDuration.hours;
|
||||
import static org.navalplanner.business.workingday.EffortDuration.zero;
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -54,6 +56,7 @@ import org.navalplanner.business.resources.daos.IResourcesSearcher;
|
|||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.ResourceEnum;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.EffortDuration.IEffortFrom;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.planner.allocation.ResourceAllocationController.DerivedAllocationColumn;
|
||||
|
|
@ -90,6 +93,50 @@ public abstract class AllocationRow {
|
|||
|
||||
private static final Log LOG = LogFactory.getLog(AllocationRow.class);
|
||||
|
||||
public static EffortDuration sumAllConsolidatedEffort(
|
||||
Collection<? extends AllocationRow> rows) {
|
||||
return EffortDuration.sum(rows, new IEffortFrom<AllocationRow>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration from(AllocationRow each) {
|
||||
return each.getConsolidatedEffort();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static EffortDuration sumAllTotalEffort(
|
||||
Collection<? extends AllocationRow> rows) {
|
||||
return EffortDuration.sum(rows, new IEffortFrom<AllocationRow>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration from(AllocationRow each) {
|
||||
return each.getTotalEffort();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static EffortDuration sumAllOriginalEffort(
|
||||
Collection<? extends AllocationRow> rows) {
|
||||
return EffortDuration.sum(rows, new IEffortFrom<AllocationRow>() {
|
||||
@Override
|
||||
public EffortDuration from(AllocationRow each) {
|
||||
return each.getOriginalEffort();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static EffortDuration sumAllEffortFromInputs(
|
||||
Collection<? extends AllocationRow> rows) {
|
||||
return EffortDuration.sum(rows, new IEffortFrom<AllocationRow>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration from(AllocationRow each) {
|
||||
return each.getEffortFromInput();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void assignHours(List<AllocationRow> rows, int[] hours) {
|
||||
int i = 0;
|
||||
for (AllocationRow each : rows) {
|
||||
|
|
@ -400,8 +447,9 @@ public abstract class AllocationRow {
|
|||
hoursInput.setValue(getHours());
|
||||
}
|
||||
|
||||
protected int getHoursFromInput() {
|
||||
return hoursInput.getValue() != null ? hoursInput.getValue() : 0;
|
||||
protected EffortDuration getEffortFromInput() {
|
||||
return hoursInput.getValue() != null ? hours(hoursInput.getValue())
|
||||
: zero();
|
||||
}
|
||||
|
||||
private Integer getHours() {
|
||||
|
|
@ -540,34 +588,34 @@ public abstract class AllocationRow {
|
|||
}
|
||||
}
|
||||
|
||||
public int getOriginalHours() {
|
||||
public EffortDuration getOriginalEffort() {
|
||||
if (temporal != null) {
|
||||
return temporal.getOriginalTotalAssigment();
|
||||
return hours(temporal.getOriginalTotalAssigment());
|
||||
}
|
||||
if (origin != null) {
|
||||
return origin.getOriginalTotalAssigment();
|
||||
return hours(origin.getOriginalTotalAssigment());
|
||||
}
|
||||
return 0;
|
||||
return zero();
|
||||
}
|
||||
|
||||
public int getTotalHours() {
|
||||
public EffortDuration getTotalEffort() {
|
||||
if (temporal != null) {
|
||||
return temporal.getAssignedHours();
|
||||
return temporal.getAssignedEffort();
|
||||
}
|
||||
if (origin != null) {
|
||||
return origin.getAssignedHours();
|
||||
return origin.getAssignedEffort();
|
||||
}
|
||||
return 0;
|
||||
return zero();
|
||||
}
|
||||
|
||||
public int getConsolidatedHours() {
|
||||
public EffortDuration getConsolidatedEffort() {
|
||||
if (temporal != null) {
|
||||
return temporal.getConsolidatedHours();
|
||||
return temporal.getConsolidatedEffort();
|
||||
}
|
||||
if (origin != null) {
|
||||
return origin.getConsolidatedHours();
|
||||
return origin.getConsolidatedEffort();
|
||||
}
|
||||
return 0;
|
||||
return zero();
|
||||
}
|
||||
|
||||
public int getNonConsolidatedHours() {
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@ public class FormBinder {
|
|||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (allHoursInput.isDisabled()) {
|
||||
allHoursInput.setValue(sumAllHoursFromHoursInputs());
|
||||
allHoursInput.setValue(AllocationRow.sumAllEffortFromInputs(
|
||||
rows).getHours());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -243,44 +244,10 @@ public class FormBinder {
|
|||
}
|
||||
|
||||
private void bindTotalHoursToHoursInputs() {
|
||||
int sum = 0;
|
||||
for (AllocationRow each : rows) {
|
||||
each.addListenerForHoursInputChange(hoursRowInputChange);
|
||||
sum += each.getHoursFromInput();
|
||||
}
|
||||
allHoursInput.setValue(sum);
|
||||
}
|
||||
|
||||
private int sumAllHoursFromHoursInputs() {
|
||||
int result = 0;
|
||||
for (AllocationRow each : rows) {
|
||||
result += each.getHoursFromInput();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int sumAllOriginalHours() {
|
||||
int result = 0;
|
||||
for (AllocationRow each : rows) {
|
||||
result += each.getOriginalHours();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int sumAllTotalHours() {
|
||||
int result = 0;
|
||||
for (AllocationRow each : rows) {
|
||||
result += each.getTotalHours();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int sumAllConsolidatedHours() {
|
||||
int result = 0;
|
||||
for (AllocationRow each : rows) {
|
||||
result += each.getConsolidatedHours();
|
||||
}
|
||||
return result;
|
||||
allHoursInput.setValue(AllocationRow.sumAllEffortFromInputs(this.rows).getHours());
|
||||
}
|
||||
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
|
|
@ -856,10 +823,12 @@ public class FormBinder {
|
|||
public void loadAggregatedCalculations() {
|
||||
// Calculate aggregated values
|
||||
if (behaviour.allowMultipleSelection()) {
|
||||
allOriginalHours.setValue(Integer.toString(sumAllOriginalHours()));
|
||||
allTotalHours.setValue(Integer.toString(sumAllTotalHours()));
|
||||
allOriginalHours.setValue(Integer.toString(AllocationRow.sumAllOriginalEffort(this.rows)
|
||||
.getHours()));
|
||||
allTotalHours.setValue(Integer.toString(AllocationRow.sumAllTotalEffort(this.rows)
|
||||
.getHours()));
|
||||
allConsolidatedHours.setValue(Integer
|
||||
.toString(sumAllConsolidatedHours()));
|
||||
.toString(AllocationRow.sumAllConsolidatedEffort(this.rows).getHours()));
|
||||
allTotalResourcesPerDay.setValue(sumAllTotalResourcesPerDay()
|
||||
.toString());
|
||||
allConsolidatedResourcesPerDay
|
||||
|
|
|
|||
|
|
@ -628,10 +628,15 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
row.setValue(data);
|
||||
append(row, data.createDetail());
|
||||
append(row, new Label(data.getName()));
|
||||
append(row, new Label(Integer.toString(data.getOriginalHours())));
|
||||
append(row, new Label(Integer.toString(data.getTotalHours())));
|
||||
append(row,
|
||||
new Label(Integer.toString(data.getConsolidatedHours())));
|
||||
new Label(Integer.toString(data.getOriginalEffort()
|
||||
.getHours())));
|
||||
append(row,
|
||||
new Label(Integer
|
||||
.toString(data.getTotalEffort().getHours())));
|
||||
append(row,
|
||||
new Label(Integer.toString(data.getConsolidatedEffort()
|
||||
.getHours())));
|
||||
append(row, data.getHoursInput());
|
||||
append(row, new Label(data.getTotalResourcesPerDay().getAmount()
|
||||
.toString()));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue