From 8357c60ca7eb6fd8646dd78ceeaf73a66cdc71bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Sun, 23 May 2010 13:34:28 +0200 Subject: [PATCH] ItEr58S14RecalculosConexionEscenariosItEr57S15: Fix bug. When a tasks is removed its dependencies must be removed too. Otherwise when the task is not preexistent a TransientObjectException happens. --- .../business/orders/entities/TaskSource.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/orders/entities/TaskSource.java b/navalplanner-business/src/main/java/org/navalplanner/business/orders/entities/TaskSource.java index d80f89d91..e35e7d177 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/orders/entities/TaskSource.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/orders/entities/TaskSource.java @@ -20,6 +20,7 @@ package org.navalplanner.business.orders.entities; import java.util.ArrayList; +import java.util.ConcurrentModificationException; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -32,6 +33,7 @@ import org.navalplanner.business.common.exceptions.InstanceNotFoundException; import org.navalplanner.business.orders.entities.SchedulingState.Type; import org.navalplanner.business.planner.daos.ITaskElementDAO; import org.navalplanner.business.planner.daos.ITaskSourceDAO; +import org.navalplanner.business.planner.entities.Dependency; import org.navalplanner.business.planner.entities.Task; import org.navalplanner.business.planner.entities.TaskElement; import org.navalplanner.business.planner.entities.TaskGroup; @@ -223,6 +225,7 @@ public class TaskSource extends BaseEntity { public TaskElement apply(ITaskSourceDAO taskSourceDAO, boolean preexistent) { if (!preexistent) { + removeDependenciesFor(taskSource.getTask()); return null; } try { @@ -240,6 +243,30 @@ public class TaskSource extends BaseEntity { return null; } + private void removeDependenciesFor(TaskElement task) { + for (Dependency each : copy(task + .getDependenciesWithThisDestination())) { + removeDependency(each); + } + for (Dependency each : copy(task.getDependenciesWithThisOrigin())) { + removeDependency(each); + } + } + + private void removeDependency(Dependency each) { + each.getOrigin().removeDependencyWithDestination( + each.getDestination(), + each.getType()); + } + + /** + * Copy the dependencies to a list in order to avoid + * {@link ConcurrentModificationException} + */ + private List copy(Set dependencies) { + return new ArrayList(dependencies); + } + } public static TaskSource withHoursGroupOf(