ItEr19S08CUCreacionProxectoPlanificacionItEr18S08: Adding parent relationship.

This commit is contained in:
Óscar González Fernández 2009-07-24 20:31:45 +02:00 committed by Javier Moran Rua
parent 568ace9b72
commit d15ab1f3f7
7 changed files with 37 additions and 1 deletions

View file

@ -109,6 +109,9 @@ public class Task extends TaskElement {
"the shares don't sum up the work hours");
TaskGroup result = new TaskGroup();
result.copyPropertiesFrom(this);
if (this.getParent() != null) {
this.getParent().addTaskElement(result);
}
for (int i = 0; i < shares.length; i++) {
Task task = Task.createTask(hoursGroup);
task.copyPropertiesFrom(this);

View file

@ -29,6 +29,8 @@ public abstract class TaskElement {
private String notes;
private TaskGroup parent;
@NotNull
private OrderElement orderElement;
@ -45,6 +47,10 @@ public abstract class TaskElement {
this.orderElement = task.getOrderElement();
}
public TaskGroup getParent() {
return parent;
}
public String getName() {
return name;
}
@ -142,4 +148,7 @@ public abstract class TaskElement {
public abstract List<TaskElement> getChildren();
protected void setParent(TaskGroup taskGroup) {
this.parent = taskGroup;
}
}

View file

@ -15,6 +15,7 @@ public class TaskGroup extends TaskElement {
public void addTaskElement(TaskElement task) {
Validate.notNull(task);
task.setParent(this);
taskElements.add(task);
}

View file

@ -14,6 +14,8 @@
<many-to-one name="orderElement" cascade="none" column="ORDER_ELEMENT_ID"/>
<many-to-one name="parent" class="TaskGroup" cascade="none" column="parent"/>
<set name="dependenciesWithThisOrigin" cascade="all">
<key column="ORIGIN"></key>
<one-to-many class="Dependency" />

View file

@ -141,7 +141,9 @@ public class TaskElementTest {
@Test
public void splittingATaskIntoSeveralKeepsDependencies() {
HoursGroup hoursGroup = new HoursGroup();
TaskGroup root = new TaskGroup();
Task taskBeingSplitted = Task.createTask(hoursGroup);
root.addTaskElement(taskBeingSplitted);
Task sourceDependencyTask = Task.createTask(new HoursGroup());
Task destinationDependencyTask = Task.createTask(new HoursGroup());
taskBeingSplitted.setName("prueba");
@ -158,7 +160,7 @@ public class TaskElementTest {
int[] shares = { 50, 50 };
TaskGroup taskResultOfSplit = taskBeingSplitted.split(shares);
assertThat(taskResultOfSplit.getParent(), equalTo(root));
assertThat(taskResultOfSplit.getDependenciesWithThisDestination()
.size(), equalTo(1));
Dependency withTaskResultOfSplitDestination = taskResultOfSplit

View file

@ -8,6 +8,7 @@ import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.navalplanner.business.orders.entities.HoursGroup;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.business.planner.entities.TaskGroup;
@ -38,6 +39,13 @@ public class TaskGroupTest {
child2)));
}
@Test
public void addingTaskElementToTaskGroupSetsTheParentProperty() {
Task child = Task.createTask(new HoursGroup());
taskGroup.addTaskElement(child);
assertThat(child.getParent(), equalTo(taskGroup));
}
@Test(expected = IllegalArgumentException.class)
public void cantAddNullTaskElement() {
taskGroup.addTaskElement(null);

View file

@ -114,6 +114,17 @@ public class TaskElementServiceTest {
checkProperties(taskGroup, reloaded);
}
@Test
public void theParentPropertyIsPresentWhenRetrievingTasks() {
TaskGroup taskGroup = createValidTaskGroup();
taskGroup.addTaskElement(createValidTask());
taskElementService.save(taskGroup);
flushAndEvict(taskGroup);
TaskElement reloaded = taskElementService.findById(taskGroup.getId());
TaskElement child = reloaded.getChildren().get(0);
assertThat(child.getParent(), equalTo(reloaded));
}
private TaskGroup createValidTaskGroup() {
TaskGroup result = new TaskGroup();
OrderLine orderLine = createOrderLine();