diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java index c9348077f..83c3b3a2d 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/StretchesFunction.java @@ -352,7 +352,7 @@ public class StretchesFunction extends AssignmentFunction { return type == null ? Type.DEFAULT : type; } - private Type getDesiredType() { + public Type getDesiredType() { return desiredType == null ? getType() : desiredType; } @@ -462,4 +462,8 @@ public class StretchesFunction extends AssignmentFunction { return left; } + public boolean ifInterpolatedMustHaveAtLeastTwoStreches() { + return getDesiredType() != Type.INTERPOLATED || stretches.size() >= 2; + } + } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/IStretchesFunctionModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/IStretchesFunctionModel.java index 8197e9796..a50983511 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/IStretchesFunctionModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/IStretchesFunctionModel.java @@ -31,6 +31,7 @@ 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.Type; @@ -45,7 +46,7 @@ public interface IStretchesFunctionModel { * Initial conversation steps */ - void init(StretchesFunction stretchesFunction, Task task); + void init(StretchesFunction stretchesFunction, Task task, Type type); /* * Intermediate conversation steps diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java index 964dc0db0..336e5e076 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StrechesFunctionConfiguration.java @@ -49,7 +49,9 @@ public abstract class StrechesFunctionConfiguration implements "/planner/stretches_function.zul", getParentOnWhichOpenWindow(), args); Util.createBindingsFor(window); - stretchesFunctionController.setResourceAllocation(getAllocation()); + ResourceAllocation allocation = getAllocation(); + stretchesFunctionController + .setResourceAllocation(allocation, getType()); stretchesFunctionController.showWindow(); getAllocation().setAssignmentFunction( stretchesFunctionController.getAssignmentFunction()); @@ -83,7 +85,7 @@ public abstract class StrechesFunctionConfiguration implements public void applyDefaultFunction(ResourceAllocation resourceAllocation) { StretchesFunction stretchesFunction = StretchesFunctionModel .createDefaultStretchesFunction(resourceAllocation.getTask() - .getEndDate(), getType()); + .getEndDate()); resourceAllocation.setAssignmentFunction(stretchesFunction); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java index 6e1a6696b..72467eeae 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionController.java @@ -36,6 +36,7 @@ import org.navalplanner.business.planner.entities.ResourceAllocation; 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.Type; import org.navalplanner.web.common.Util; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.SuspendNotAllowedException; @@ -77,12 +78,13 @@ public class StretchesFunctionController extends GenericForwardComposer { return stretchesFunctionModel.getStretchesFunction(); } - public void setResourceAllocation(ResourceAllocation resourceAllocation) { + public void setResourceAllocation(ResourceAllocation resourceAllocation, + Type type) { AssignmentFunction assignmentFunction = resourceAllocation .getAssignmentFunction(); Task task = resourceAllocation.getTask(); stretchesFunctionModel.init((StretchesFunction) assignmentFunction, - task); + task, type); reloadStretchesListAndCharts(); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java index 10531d705..16309dc2a 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/streches/StretchesFunctionModel.java @@ -38,7 +38,6 @@ 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.Type; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; @@ -54,16 +53,13 @@ import org.springframework.transaction.annotation.Transactional; @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class StretchesFunctionModel implements IStretchesFunctionModel { - public static StretchesFunction createDefaultStretchesFunction( - Date endDate, Type type) { + public static StretchesFunction createDefaultStretchesFunction(Date endDate) { StretchesFunction stretchesFunction = StretchesFunction.create(); - stretchesFunction.changeTypeTo(type); Stretch stretch = new Stretch(); stretch.setDate(new LocalDate(endDate)); stretch.setLengthPercentage(BigDecimal.ONE); stretch.setAmountWorkPercentage(BigDecimal.ONE); stretchesFunction.addStretch(stretch); - return stretchesFunction; } @@ -89,12 +85,15 @@ public class StretchesFunctionModel implements IStretchesFunctionModel { @Override @Transactional(readOnly = true) - public void init(StretchesFunction stretchesFunction, Task task) { + public void init( + StretchesFunction stretchesFunction, + Task task, + org.navalplanner.business.planner.entities.StretchesFunction.Type type) { if (stretchesFunction != null) { assignmentFunctionDAO.reattach(stretchesFunction); this.originalStretchesFunction = stretchesFunction; this.stretchesFunction = stretchesFunction.copy(); - + this.stretchesFunction.changeTypeTo(type); this.task = task; forceLoadTask(); this.taskEndDate = task.getEndDate(); @@ -133,10 +132,16 @@ public class StretchesFunctionModel implements IStretchesFunctionModel { _("Last stretch should have one hundred percent for " + "length and amount of work percentage")); } + if (!stretchesFunction.ifInterpolatedMustHaveAtLeastTwoStreches()) { + throw new ValidationException( + _("For interpolation at least two streches needed")); + } if (originalStretchesFunction != null) { originalStretchesFunction .resetToStrechesFrom(stretchesFunction); + originalStretchesFunction.changeTypeTo(stretchesFunction + .getDesiredType()); stretchesFunction = originalStretchesFunction; } }