ItEr25S07CUAsignacionGrupoRecursosAPlanificacionItEr24S08: The SpecificResourceAllocation is related to resource instead of worker.

This commit is contained in:
Óscar González Fernández 2009-09-16 11:35:45 +02:00
parent 7d61c709cb
commit 19176d73a9
7 changed files with 24 additions and 22 deletions

View file

@ -8,6 +8,7 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.NotNull;
import org.joda.time.LocalDate;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
/**
@ -23,7 +24,7 @@ public class SpecificResourceAllocation extends ResourceAllocation implements
}
@NotNull
private Worker worker;
private Resource resource;
private Set<SpecificDayAssigment> specificDaysAssigment = new HashSet<SpecificDayAssigment>();
@ -49,12 +50,12 @@ public class SpecificResourceAllocation extends ResourceAllocation implements
super(task);
}
public Worker getWorker() {
return worker;
public Resource getResource() {
return resource;
}
public void setWorker(Worker worker) {
this.worker = worker;
public void setResource(Resource resource) {
this.resource = resource;
}
@Override
@ -70,14 +71,14 @@ public class SpecificResourceAllocation extends ResourceAllocation implements
@Override
public void allocate(ResourcesPerDay resourcesPerDay) {
Validate.notNull(resourcesPerDay);
Validate.notNull(worker);
Validate.notNull(resource);
AssignmentsAllocation<SpecificDayAssigment> assignmentsAllocation = new AssignmentsAllocation<SpecificDayAssigment>() {
@Override
protected List<SpecificDayAssigment> distributeForDay(
LocalDate day, int totalHours) {
return Arrays.asList(SpecificDayAssigment.create(day,
totalHours, worker));
totalHours, resource));
}
@Override

View file

@ -12,6 +12,7 @@ import org.joda.time.DateTime;
import org.joda.time.Days;
import org.navalplanner.business.orders.entities.HoursGroup;
import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
/**
@ -122,13 +123,13 @@ public class Task extends TaskElement {
for (ResourceAllocation resourceAllocation : resourceAllocations) {
if (resourceAllocation instanceof SpecificResourceAllocation) {
Worker worker = ((SpecificResourceAllocation) resourceAllocation)
.getWorker();
if (worker != null) {
if (workers.contains(worker.getId())) {
Resource resource = ((SpecificResourceAllocation) resourceAllocation)
.getResource();
if (resource != null) {
if (workers.contains(resource.getId())) {
return false;
} else {
workers.add(worker.getId());
workers.add(resource.getId());
}
}
}

View file

@ -21,8 +21,8 @@
<joined-subclass name="SpecificResourceAllocation" table="SPECIFIC_RESOURCE_ALLOCATION">
<key column="RESOURCE_ALLOCATION_ID" />
<many-to-one name="worker"
class="org.navalplanner.business.resources.entities.Worker" />
<many-to-one name="resource"
class="org.navalplanner.business.resources.entities.Resource" />
</joined-subclass>
<joined-subclass name="GenericResourceAllocation" table="GENERIC_RESOURCE_ALLOCATION">

View file

@ -98,7 +98,7 @@ public class ResourceAllocationDAOTest {
.createForTesting(ResourcesPerDay.amount(1), task);
Worker worker = (Worker) createValidWorker();
resourceDAO.save(worker);
specificResourceAllocation.setWorker(worker);
specificResourceAllocation.setResource(worker);
return specificResourceAllocation;
}

View file

@ -56,7 +56,7 @@ public class SpecificResourceAllocationTest {
givenWorker();
givenTask(start, end);
specificResourceAllocation = SpecificResourceAllocation.create(task);
specificResourceAllocation.setWorker(worker);
specificResourceAllocation.setResource(worker);
}
private void givenSpecificResourceAllocation(LocalDate start, int days) {

View file

@ -163,8 +163,8 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
private void reattachSpecificResourceAllocation(
SpecificResourceAllocation resourceAllocation) {
resourceAllocation.getWorker().getName();
reattachCriterionSatisfactions(resourceAllocation.getWorker()
resourceAllocation.getResource().getDescription();
reattachCriterionSatisfactions(resourceAllocation.getResource()
.getCriterionSatisfactions());
}

View file

@ -46,15 +46,15 @@ public class SpecificAllocationDTO extends AllocationDTO {
}
public static SpecificAllocationDTO from(SpecificResourceAllocation specific) {
SpecificAllocationDTO result = forResource(specific.getWorker());
SpecificAllocationDTO result = forResource(specific.getResource());
result.setResourcesPerDay(specific.getResourcesPerDay());
return result;
}
public static SpecificAllocationDTO forResource(Worker worker) {
public static SpecificAllocationDTO forResource(Resource resource) {
SpecificAllocationDTO result = new SpecificAllocationDTO();
result.setName(worker.getName());
result.setResource(worker);
result.setName(resource.getDescription());
result.setResource(resource);
result.setResourcesPerDay(ResourcesPerDay.amount(1));
return result;
}