ItEr45S10CUAsignacionRecursosEspecificosAPlanificacionItEr44S16: Adding check that was being done at streches at model
This commit is contained in:
parent
4ff0b3c648
commit
1e60c6bd7b
2 changed files with 32 additions and 11 deletions
|
|
@ -190,16 +190,8 @@ public abstract class GraphicForStreches implements IGraphicGenerator {
|
|||
|
||||
private boolean canComputeChartFrom(List<Stretch> stretches,
|
||||
LocalDate start) {
|
||||
return stretches.size() >= 2
|
||||
&& theFirstIntervalIsPosteriorToFirstDay(stretches, start);
|
||||
}
|
||||
|
||||
private boolean theFirstIntervalIsPosteriorToFirstDay(
|
||||
List<Stretch> stretches, LocalDate start) {
|
||||
List<Interval> intervals = StretchesFunction
|
||||
.intervalsFor(stretches);
|
||||
Interval first = intervals.get(0);
|
||||
return first.getEnd().compareTo(start) > 0;
|
||||
return StretchesFunctionModel.areValidForInterpolation(stretches,
|
||||
start);
|
||||
}
|
||||
|
||||
private int[] hoursForEachDayInterpolatedUsingSplines(
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ import org.navalplanner.business.planner.entities.AssignmentFunction;
|
|||
import org.navalplanner.business.planner.entities.Stretch;
|
||||
import org.navalplanner.business.planner.entities.StretchesFunction;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.StretchesFunction.Interval;
|
||||
import org.navalplanner.business.planner.entities.StretchesFunction.Type;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -136,7 +138,17 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
|
|||
throw new ValidationException(
|
||||
_("For interpolation at least two streches needed"));
|
||||
}
|
||||
|
||||
if (stretchesFunction.getDesiredType() == Type.INTERPOLATED) {
|
||||
if (!atLeastTwoStreches(getStretches())) {
|
||||
throw new ValidationException(
|
||||
_("There must be at least 2 streches for doing interpolation"));
|
||||
}
|
||||
if (!theFirstIntervalIsPosteriorToFirstDay(getStretches(),
|
||||
getTaskStartDate())) {
|
||||
throw new ValidationException(
|
||||
_("The first strech must be after the first day for doing interpolation"));
|
||||
}
|
||||
}
|
||||
if (originalStretchesFunction != null) {
|
||||
originalStretchesFunction
|
||||
.resetToStrechesFrom(stretchesFunction);
|
||||
|
|
@ -147,6 +159,23 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean areValidForInterpolation(List<Stretch> stretches,
|
||||
LocalDate start) {
|
||||
return atLeastTwoStreches(stretches)
|
||||
&& theFirstIntervalIsPosteriorToFirstDay(stretches, start);
|
||||
}
|
||||
|
||||
private static boolean atLeastTwoStreches(List<Stretch> stretches) {
|
||||
return stretches.size() >= 2;
|
||||
}
|
||||
|
||||
private static boolean theFirstIntervalIsPosteriorToFirstDay(
|
||||
List<Stretch> stretches, LocalDate start) {
|
||||
List<Interval> intervals = StretchesFunction.intervalsFor(stretches);
|
||||
Interval first = intervals.get(0);
|
||||
return first.getEnd().compareTo(start) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
stretchesFunction = originalStretchesFunction;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue