ItEr18S08CUCreacionProxectoPlanificacionItEr17S10: When removeDependency is called, the dependency is removed.
This commit is contained in:
parent
e7dce15cb3
commit
b44346d3aa
3 changed files with 42 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -9,6 +10,7 @@ import java.util.Set;
|
|||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.planner.entities.Dependency.Type;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
|
|
@ -104,6 +106,29 @@ public abstract class TaskElement {
|
|||
return id;
|
||||
}
|
||||
|
||||
private void removeDependenciesWithThisOrigin(TaskElement origin, Type type) {
|
||||
ArrayList<Dependency> toBeRemoved = new ArrayList<Dependency>();
|
||||
for (Dependency dependency : dependenciesWithThisDestination) {
|
||||
if (dependency.getOrigin().equals(origin)
|
||||
&& dependency.getType().equals(type)) {
|
||||
toBeRemoved.add(dependency);
|
||||
}
|
||||
}
|
||||
dependenciesWithThisDestination.removeAll(toBeRemoved);
|
||||
}
|
||||
|
||||
public void removeDependencyWithDestination(TaskElement destination, Type type) {
|
||||
ArrayList<Dependency> toBeRemoved = new ArrayList<Dependency>();
|
||||
for (Dependency dependency : dependenciesWithThisOrigin) {
|
||||
if (dependency.getDestination().equals(destination)
|
||||
&& dependency.getType().equals(type)) {
|
||||
toBeRemoved.add(dependency);
|
||||
}
|
||||
}
|
||||
destination.removeDependenciesWithThisOrigin(this, type);
|
||||
dependenciesWithThisOrigin.removeAll(toBeRemoved);
|
||||
}
|
||||
|
||||
public abstract boolean isLeaf();
|
||||
|
||||
public abstract List<TaskElement> getChildren();
|
||||
|
|
|
|||
|
|
@ -73,4 +73,17 @@ public class TaskElementTest {
|
|||
task.setEndDate(now);
|
||||
assertThat(task.getEndDate(), equalTo(now));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDependencyWithThisOriginCanBeRemoved(){
|
||||
Task origin = new Task();
|
||||
Task destination = new Task();
|
||||
Type type = Type.START_END;
|
||||
Dependency dependency = Dependency.createDependency(origin, destination, type);
|
||||
assertThat(origin.getDependenciesWithThisOrigin().size(), equalTo(1));
|
||||
assertThat(destination.getDependenciesWithThisDestination().size(), equalTo(1));
|
||||
origin.removeDependencyWithDestination(destination, type);
|
||||
assertThat(origin.getDependenciesWithThisOrigin().size(), equalTo(0));
|
||||
assertThat(destination.getDependenciesWithThisDestination().size(), equalTo(0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,6 +170,9 @@ public class TaskElementAdapter implements ITaskElementAdapter {
|
|||
|
||||
@Override
|
||||
public void removeDependency(DomainDependency<TaskElement> dependency) {
|
||||
System.out.println("removing dependency: "+dependency);
|
||||
TaskElement source = dependency.getSource();
|
||||
Type type = toDomainType(dependency.getType());
|
||||
source.removeDependencyWithDestination(dependency.getDestination(),
|
||||
type);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue