ItEr20S04ArquitecturaServidorItEr19S04: Removing makeTransient from ResourceAllocations.

This commit is contained in:
Manuel Rego Casasnovas 2009-08-04 13:05:12 +02:00 committed by Óscar González Fernández
parent 8976b8ed42
commit 963dd7dbb3
6 changed files with 18 additions and 54 deletions

View file

@ -6,17 +6,14 @@ package org.navalplanner.business.planner.entities;
import java.math.BigDecimal;
import org.hibernate.validator.NotNull;
import org.navalplanner.business.common.BaseEntity;
/**
* Resources are allocated to planner tasks.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public abstract class ResourceAllocation {
private Long id;
private Long version;
public abstract class ResourceAllocation extends BaseEntity {
@NotNull
private Task task;
@ -38,14 +35,6 @@ public abstract class ResourceAllocation {
this.task = task;
}
public Long getId() {
return id;
}
public Long getVersion() {
return version;
}
public Task getTask() {
return task;
}
@ -62,13 +51,4 @@ public abstract class ResourceAllocation {
this.percentage = proportion;
}
public boolean isTransient() {
return id == null;
}
public void makeTransientAgain() {
id = null;
version = null;
}
}

View file

@ -10,6 +10,12 @@ import org.navalplanner.business.resources.entities.Worker;
*/
public class SpecificResourceAllocation extends ResourceAllocation {
public static SpecificResourceAllocation create(Task task) {
SpecificResourceAllocation result = new SpecificResourceAllocation(task);
result.setNewObject(true);
return result;
}
@NotNull
private Worker worker;
@ -19,7 +25,7 @@ public class SpecificResourceAllocation extends ResourceAllocation {
public SpecificResourceAllocation() {
}
public SpecificResourceAllocation(Task task) {
private SpecificResourceAllocation(Task task) {
super(task);
}

View file

@ -6,7 +6,7 @@
<id name="id" column="id" type="long">
<generator class="native" />
</id>
<version name="version" type="long" />
<version name="version" access="property" type="long" />
<property name="percentage" />

View file

@ -51,8 +51,7 @@ public class TaskTest {
public void taskAddResourceAllocation() {
assertThat(task.getResourceAllocations().size(), equalTo(0));
SpecificResourceAllocation resourceAllocation = new SpecificResourceAllocation(
task);
SpecificResourceAllocation resourceAllocation = SpecificResourceAllocation.create(task);
task.addResourceAllocation(resourceAllocation);
assertThat(task.getResourceAllocations().size(), equalTo(1));
@ -65,8 +64,7 @@ public class TaskTest {
public void taskRemoveResourceAllocation() {
assertThat(task.getResourceAllocations().size(), equalTo(0));
SpecificResourceAllocation resourceAllocation = new SpecificResourceAllocation(
task);
SpecificResourceAllocation resourceAllocation = SpecificResourceAllocation.create(task);
task.addResourceAllocation(resourceAllocation);
assertThat(task.getResourceAllocations().size(), equalTo(1));

View file

@ -76,8 +76,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
@Override
public void addResourceAllocation() {
ResourceAllocation resourceAllocation = new SpecificResourceAllocation(
task);
ResourceAllocation resourceAllocation = SpecificResourceAllocation.create(task);
task.addResourceAllocation(resourceAllocation);
}
@ -121,8 +120,6 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
@Override
@Transactional(readOnly = true)
public void setResourceAllocation(ResourceAllocation resourceAllocation) {
boolean wasTransient = resourceAllocation.isTransient();
resourceAllocationDAO.save(resourceAllocation);
Worker worker = ((SpecificResourceAllocation) resourceAllocation)
@ -137,10 +134,6 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
}
}
if (wasTransient) {
resourceAllocation.makeTransientAgain();
}
this.resourceAllocation = resourceAllocation;
}
@ -188,27 +181,9 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
@Override
@Transactional(readOnly = true)
public void updateGanttTaskDuration() {
// A set of resourceAllocation objects of the task with the ones which
// are transiet is filled
Set<ResourceAllocation> transietResourceAllocations = new HashSet<ResourceAllocation>();
for (ResourceAllocation resourceAllocation : task
.getResourceAllocations()) {
if (resourceAllocation.isTransient()) {
transietResourceAllocations.add(resourceAllocation);
}
}
taskElementDAO.save(task);
task.getDuration();
ganttTask.setEndDate(task.getEndDate());
// The set of resourceAllocation objects which are previously transiet
// are put to transiet again
for (ResourceAllocation resourceAllocation : transietResourceAllocations) {
resourceAllocation.makeTransientAgain();
}
}
}

View file

@ -1,5 +1,6 @@
package org.navalplanner.web.planner;
import org.navalplanner.business.planner.entities.ResourceAllocation;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.business.planner.services.ITaskElementService;
@ -40,6 +41,10 @@ public class SaveCommand implements ISaveCommand {
+ taskElement.getName()
+ "' has some repeated Worker assigned");
}
for (ResourceAllocation resourceAllocation : ((Task) taskElement)
.getResourceAllocations()) {
resourceAllocation.dontPoseAsTransientObjectAnymore();
}
}
}
for (TaskElement taskElement : state.getToRemove()) {