Fix criteria filtering discounting children with invalidated criteria

If any child has the filtering criteria invalidated, it's not taken into account
in order to calculate the values in the parent task that is part of the report.

FEA: ItEr77S09WBSReport
This commit is contained in:
Manuel Rego Casasnovas 2012-10-22 17:57:19 +02:00
parent 242cfa8e35
commit 535d2e3423
3 changed files with 109 additions and 4 deletions

View file

@ -945,7 +945,7 @@ public abstract class OrderElement extends IntegrationEntity implements
newRequirement);
}
protected Set<IndirectCriterionRequirement> getIndirectCriterionRequirement() {
public Set<IndirectCriterionRequirement> getIndirectCriterionRequirement() {
return criterionRequirementHandler.getIndirectCriterionRequirement(criterionRequirements);
}

View file

@ -66,6 +66,16 @@ public class ProjectStatusReportDTO {
this.totalCost = totalCost;
}
public ProjectStatusReportDTO(String code, String name,
EffortDuration estimatedHours, EffortDuration plannedHours,
EffortDuration imputedHours, BigDecimal budget,
BigDecimal hoursCost, BigDecimal expensesCost, BigDecimal totalCost) {
this(estimatedHours, plannedHours, imputedHours, budget, hoursCost,
expensesCost, totalCost);
this.code = code;
this.name = name;
}
public ProjectStatusReportDTO(OrderElement orderElement) {
code = orderElement.getCode();
name = Util.getPrefixSpacesDependingOnDepth(orderElement)

View file

@ -33,6 +33,7 @@ import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
import org.libreplan.business.reports.dtos.ProjectStatusReportDTO;
import org.libreplan.business.requirements.entities.IndirectCriterionRequirement;
import org.libreplan.business.resources.daos.ICriterionDAO;
import org.libreplan.business.resources.entities.Criterion;
import org.libreplan.business.scenarios.IScenarioManager;
@ -114,9 +115,80 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
dto.setExpensesCost(moneyCostCalculator
.getExpensesMoneyCost(orderElement));
dto.setTotalCost(moneyCostCalculator.getTotalMoneyCost(orderElement));
if (!isNotFilteringByCriteria()) {
dto = discountChildrenWithInvalidatedCriteria(orderElement, dto);
}
return dto;
}
private ProjectStatusReportDTO discountChildrenWithInvalidatedCriteria(
OrderElement orderElement, ProjectStatusReportDTO dto) {
List<ProjectStatusReportDTO> dtosToDiscount = new ArrayList<ProjectStatusReportDTO>();
for (OrderElement child : orderElement.getChildren()) {
for (IndirectCriterionRequirement criterionRequirement : child
.getIndirectCriterionRequirement()) {
if (isCriterionSelected(criterionRequirement.getCriterion()
.getCode())) {
if (!criterionRequirement.isValid()) {
dtosToDiscount.add(calculateDTO(child));
}
}
}
}
return discount(dto, dtosToDiscount);
}
private ProjectStatusReportDTO discount(ProjectStatusReportDTO originalDto,
List<ProjectStatusReportDTO> toDiscount) {
if (toDiscount.isEmpty()) {
return originalDto;
}
EffortDuration estimatedHours = originalDto.getEstimatedHoursAsEffortDuration();
EffortDuration plannedHours = originalDto.getPlannedHoursAsEffortDuration();
EffortDuration imputedHours = originalDto.getImputedHoursAsEffortDuration();
BigDecimal budget = originalDto.getBudget();
BigDecimal hoursCost = originalDto.getHoursCost();
BigDecimal expensesCost = originalDto.getExpensesCost();
BigDecimal totalCost = originalDto.getTotalCost();
for (ProjectStatusReportDTO each : toDiscount) {
estimatedHours = subtractIfNotNull(estimatedHours,
each.getEstimatedHoursAsEffortDuration());
plannedHours = subtractIfNotNull(plannedHours,
each.getPlannedHoursAsEffortDuration());
imputedHours = subtractIfNotNull(imputedHours,
each.getImputedHoursAsEffortDuration());
budget = subtractIfNotNull(budget, each.getBudget());
hoursCost = subtractIfNotNull(hoursCost, each.getHoursCost());
expensesCost = subtractIfNotNull(expensesCost,
each.getExpensesCost());
totalCost = subtractIfNotNull(totalCost, each.getTotalCost());
}
ProjectStatusReportDTO projectStatusReportDTO = new ProjectStatusReportDTO(
originalDto.getCode(), originalDto.getName(), estimatedHours,
plannedHours, imputedHours, budget, hoursCost, expensesCost,
totalCost);
return projectStatusReportDTO;
}
public boolean isCriterionSelected(String code) {
for (Criterion criterion : selectedCriteria) {
if (criterion.getCode().equals(code)) {
return true;
}
}
return false;
}
private void calculateTotalDTO(Order order,
List<ProjectStatusReportDTO> dtos) {
if (isNotFiltering()) {
@ -151,12 +223,20 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
}
private boolean isNotFiltering() {
return selectedLabels.isEmpty() && selectedCriteria.isEmpty();
return isNotFilteringByLabels() && isNotFilteringByCriteria();
}
private boolean isNotFilteringByLabels() {
return selectedLabels.isEmpty();
}
private boolean isNotFilteringByCriteria() {
return selectedCriteria.isEmpty();
}
private List<OrderElement> filterBySelectedLabels(
List<OrderElement> orderElements) {
if (selectedLabels.isEmpty()) {
if (isNotFilteringByLabels()) {
return orderElements;
}
@ -171,7 +251,7 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
private List<OrderElement> filterBySelectedCriteria(
List<OrderElement> orderElements) {
if (selectedCriteria.isEmpty()) {
if (isNotFilteringByCriteria()) {
return orderElements;
}
@ -192,6 +272,14 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
return total.plus(other);
}
private EffortDuration subtractIfNotNull(EffortDuration total,
EffortDuration other) {
if (other == null) {
return total;
}
return total.minus(other);
}
private BigDecimal addIfNotNull(BigDecimal total, BigDecimal other) {
if (other == null) {
return total;
@ -199,6 +287,13 @@ public class ProjectStatusReportModel implements IProjectStatusReportModel {
return total.add(other);
}
private BigDecimal subtractIfNotNull(BigDecimal total, BigDecimal other) {
if (other == null) {
return total;
}
return total.subtract(other);
}
@Override
@Transactional(readOnly = true)
public BigDecimal getHoursCost(Order order) {