ItEr32S12CUAsignacionGrupoRecursosAPlanificacionItEr31S15: Encapsulating Restriction creation
This commit is contained in:
parent
43e420db12
commit
ba3aaa34b2
2 changed files with 79 additions and 31 deletions
|
|
@ -39,6 +39,7 @@ import org.apache.commons.lang.Validate;
|
|||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
|
|
@ -167,12 +168,39 @@ public class AdvancedAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public abstract static class Restriction {
|
||||
public static Restriction onlyAssignOnInterval(LocalDate start,
|
||||
|
||||
public interface IRestrictionSource {
|
||||
int getTotalHours();
|
||||
|
||||
LocalDate getStart();
|
||||
|
||||
LocalDate getEnd();
|
||||
|
||||
CalculatedValue getCalculatedValue();
|
||||
|
||||
}
|
||||
|
||||
public static Restriction build(IRestrictionSource restrictionSource) {
|
||||
switch (restrictionSource.getCalculatedValue()) {
|
||||
case END_DATE:
|
||||
return Restriction
|
||||
.fixedHours(restrictionSource
|
||||
.getTotalHours());
|
||||
case NUMBER_OF_HOURS:
|
||||
return Restriction.onlyAssignOnInterval(restrictionSource
|
||||
.getStart(), restrictionSource.getEnd());
|
||||
default:
|
||||
throw new RuntimeException("unhandled case: "
|
||||
+ restrictionSource.getCalculatedValue());
|
||||
}
|
||||
}
|
||||
|
||||
private static Restriction onlyAssignOnInterval(LocalDate start,
|
||||
LocalDate end){
|
||||
return new OnlyOnIntervalRestriction(start, end);
|
||||
}
|
||||
|
||||
public static Restriction fixedHours(int hours) {
|
||||
private static Restriction fixedHours(int hours) {
|
||||
return new FixedHoursRestriction(hours);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import org.navalplanner.web.common.ViewSwitcher;
|
|||
import org.navalplanner.web.common.components.WorkerSearch;
|
||||
import org.navalplanner.web.planner.allocation.AdvancedAllocationController.IAdvanceAllocationResultReceiver;
|
||||
import org.navalplanner.web.planner.allocation.AdvancedAllocationController.Restriction;
|
||||
import org.navalplanner.web.planner.allocation.AdvancedAllocationController.Restriction.IRestrictionSource;
|
||||
import org.navalplanner.web.planner.order.PlanningState;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -210,6 +211,53 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
private final class AdvanceAllocationResultReceiver implements
|
||||
IAdvanceAllocationResultReceiver {
|
||||
|
||||
private final AllocationResult allocation;
|
||||
|
||||
private AdvanceAllocationResultReceiver(AllocationResult allocation) {
|
||||
this.allocation = allocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
showWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accepted(AggregateOfResourceAllocations aggregate) {
|
||||
resourceAllocationModel.accept(allocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction createRestriction() {
|
||||
return Restriction.build(new IRestrictionSource() {
|
||||
|
||||
@Override
|
||||
public int getTotalHours() {
|
||||
return allocation.getAggregate().getTotalHours();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getStart() {
|
||||
return allocation.getStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getEnd() {
|
||||
return getStart()
|
||||
.plusDays(allocation.getDaysDuration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
return allocation.getCalculatedValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public enum CalculationTypeRadio {
|
||||
|
||||
NUMBER_OF_HOURS(CalculatedValue.NUMBER_OF_HOURS) {
|
||||
|
|
@ -344,35 +392,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
|
||||
private IAdvanceAllocationResultReceiver createResultReceiver(
|
||||
final AllocationResult allocation) {
|
||||
return new IAdvanceAllocationResultReceiver() {
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
showWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accepted(AggregateOfResourceAllocations aggregate) {
|
||||
resourceAllocationModel.accept(allocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction createRestriction() {
|
||||
switch (allocation.getCalculatedValue()) {
|
||||
case END_DATE:
|
||||
return Restriction.fixedHours(allocation.getAggregate()
|
||||
.getTotalHours());
|
||||
case NUMBER_OF_HOURS:
|
||||
LocalDate start = allocation.getStart();
|
||||
LocalDate end = start
|
||||
.plusDays(allocation.getDaysDuration());
|
||||
return Restriction.onlyAssignOnInterval(start, end);
|
||||
default:
|
||||
throw new RuntimeException("unhandled case: "
|
||||
+ allocation.getCalculatedValue());
|
||||
}
|
||||
}
|
||||
};
|
||||
return new AdvanceAllocationResultReceiver(allocation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue