ItEr45S10CUAsignacionRecursosEspecificosAPlanificacionItEr44S16: Checking there are the necessary number of streches

This commit is contained in:
Óscar González Fernández 2010-01-25 13:42:06 +01:00
parent 6bc707eb67
commit 8a6ca7c51e
5 changed files with 27 additions and 13 deletions

View file

@ -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;
}
}

View file

@ -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

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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;
}
}