Bug #1384: Add validation in starting date and deadline depending on position constraints

FEA: ItEr76S04BugFixing
This commit is contained in:
Manuel Rego Casasnovas 2012-04-18 18:19:47 +02:00
parent 7c91dfb43b
commit 9632686004
7 changed files with 90 additions and 12 deletions

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -73,6 +73,7 @@ import org.libreplan.business.workingday.ResourcesPerDay;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public class Task extends TaskElement implements ITaskPositionConstrained {
@ -1218,4 +1219,10 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
public void resetStatus() {
this.currentStatus = null;
}
@Override
public boolean isAnyTaskWithConstraint(PositionConstraintType type) {
return getPositionConstraint().getConstraintType().equals(type);
}
}

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -63,6 +63,7 @@ import org.libreplan.business.workingday.ResourcesPerDay;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public abstract class TaskElement extends BaseEntity {
@ -769,4 +770,6 @@ public abstract class TaskElement extends BaseEntity {
return null;
}
public abstract boolean isAnyTaskWithConstraint(PositionConstraintType type);
}

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -44,6 +44,7 @@ import org.libreplan.business.workingday.IntraDayDate;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Javier Moran Rua <jmoran@igalia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public class TaskGroup extends TaskElement {
@ -376,4 +377,15 @@ public class TaskGroup extends TaskElement {
public void resetStatus() {
this.isFinished = this.isInProgress = null;
}
@Override
public boolean isAnyTaskWithConstraint(PositionConstraintType type) {
for (TaskElement taskElement : getChildren()) {
if (taskElement.isAnyTaskWithConstraint(type)) {
return true;
}
}
return false;
}
}

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -43,6 +43,7 @@ import org.libreplan.business.workingday.IntraDayDate;
/**
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
* @author Javier Moran Rua <jmoran@igalia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public class TaskMilestone extends TaskElement implements ITaskPositionConstrained {
@ -225,4 +226,9 @@ public class TaskMilestone extends TaskElement implements ITaskPositionConstrain
return false;
}
@Override
public boolean isAnyTaskWithConstraint(PositionConstraintType type) {
return getPositionConstraint().getConstraintType().equals(type);
}
}

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -30,6 +30,7 @@ import org.libreplan.business.labels.entities.Label;
import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.orders.entities.OrderLineGroup;
import org.libreplan.business.planner.entities.PositionConstraintType;
import org.libreplan.business.qualityforms.entities.QualityForm;
import org.libreplan.business.resources.entities.Criterion;
import org.libreplan.business.resources.entities.CriterionType;
@ -45,6 +46,7 @@ import org.zkoss.zk.ui.Desktop;
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Diego Pino García <dpino@igalia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
public interface IOrderModel extends IIntegrationEntityModel {
@ -128,4 +130,6 @@ public interface IOrderModel extends IIntegrationEntityModel {
PlanningState getPlanningState();
boolean isAnyTaskWithConstraint(PositionConstraintType type);
}

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2010-2011 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -45,6 +45,7 @@ import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.Order.SchedulingMode;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.orders.entities.OrderStatusEnum;
import org.libreplan.business.planner.entities.PositionConstraintType;
import org.libreplan.business.templates.entities.OrderTemplate;
import org.libreplan.business.users.entities.UserRole;
import org.libreplan.web.common.IMessagesForUser;
@ -108,6 +109,7 @@ import org.zkoss.zul.api.Window;
*
* @author Óscar González Fernández <ogonzalez@igalia.com>
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
* @author Manuel Rego Casasnovas <rego@igalia.com>
*/
@org.springframework.stereotype.Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@ -387,11 +389,45 @@ public class OrderCRUDController extends GenericForwardComposer {
return result;
}
private void setConstraintsFor(SchedulingMode mode) {
initDate.setConstraint(mode == SchedulingMode.FORWARD ? "no empty"
: null);
deadline.setConstraint(mode == SchedulingMode.BACKWARDS ? "no empty"
: null);
private void setConstraintsFor(final SchedulingMode mode) {
initDate.setConstraint(new Constraint() {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
if (value == null) {
if (mode == SchedulingMode.FORWARD) {
throw new WrongValueException(
comp,
_("Starting date cannot be empty in forward mode"));
}
if (orderModel
.isAnyTaskWithConstraint(PositionConstraintType.AS_SOON_AS_POSSIBLE)) {
throw new WrongValueException(comp,
_("Starting date cannot be empty because there is a task with constraint \"as soon as possible\""));
}
}
}
});
deadline.setConstraint(new Constraint() {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
if (value == null) {
if (mode == SchedulingMode.BACKWARDS) {
throw new WrongValueException(
comp,
_("Starting date cannot be empty in backwards mode"));
}
if (orderModel
.isAnyTaskWithConstraint(PositionConstraintType.AS_LATE_AS_POSSIBLE)) {
throw new WrongValueException(comp,
_("Starting date cannot be empty because there is a task with constraint \"as late as possible\""));
}
}
}
});
}
private void changeFocusAccordingTo(SchedulingMode chosen) {

View file

@ -3,7 +3,7 @@
*
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
* Copyright (C) 2012 Igalia, S.L.
* Copyright (C) 2010-2012 Igalia, S.L.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
@ -56,6 +56,7 @@ import org.libreplan.business.orders.entities.Order;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.orders.entities.OrderLineGroup;
import org.libreplan.business.planner.entities.IMoneyCostCalculator;
import org.libreplan.business.planner.entities.PositionConstraintType;
import org.libreplan.business.qualityforms.daos.IQualityFormDAO;
import org.libreplan.business.qualityforms.entities.QualityForm;
import org.libreplan.business.requirements.entities.DirectCriterionRequirement;
@ -850,4 +851,13 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
return planningState;
}
@Override
public boolean isAnyTaskWithConstraint(PositionConstraintType type) {
if ((planningState == null) || (planningState.getRootTask() == null)) {
return false;
}
return planningState.getRootTask().isAnyTaskWithConstraint(type);
}
}