Fixing bug #4. Reattaching resource when adding specific allocation
https://naval.igalia.com/bugtracker/show_bug.cgi?id=4
This commit is contained in:
parent
311d1cbe6c
commit
7d581b1d1b
3 changed files with 18 additions and 15 deletions
|
|
@ -83,7 +83,11 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void addSpecificResourceAllocation(Worker worker) throws Exception {
|
||||
resourceAllocationsBeingEdited.addSpecificResourceAllocationFor(worker);
|
||||
planningState.reassociateResourcesWithSession(resourceDAO);
|
||||
Resource reloaded = resourceDAO.findExistingEntity(worker.getId());
|
||||
reattachResource(reloaded);
|
||||
resourceAllocationsBeingEdited
|
||||
.addSpecificResourceAllocationFor(reloaded);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import org.navalplanner.business.planner.entities.Task;
|
|||
import org.navalplanner.business.planner.entities.allocationalgorithms.ResourceAllocationWithDesiredResourcesPerDay;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
||||
public class ResourceAllocationsBeingEdited {
|
||||
|
||||
|
|
@ -82,14 +81,14 @@ public class ResourceAllocationsBeingEdited {
|
|||
this.daysDuration = task.getDaysDuration();
|
||||
}
|
||||
|
||||
public void addSpecificResourceAllocationFor(Worker worker) {
|
||||
if (alreadyExistsAllocationFor(worker)) {
|
||||
public void addSpecificResourceAllocationFor(Resource resource) {
|
||||
if (alreadyExistsAllocationFor(resource)) {
|
||||
throw new IllegalArgumentException(_(
|
||||
"{0} already assigned to resource allocation list", worker
|
||||
.getName()));
|
||||
"{0} already assigned to resource allocation list",
|
||||
resource.getDescription()));
|
||||
}
|
||||
SpecificAllocationDTO allocation = SpecificAllocationDTO
|
||||
.forResource(worker);
|
||||
.forResource(resource);
|
||||
currentAllocations.add(allocation);
|
||||
}
|
||||
|
||||
|
|
@ -97,13 +96,14 @@ public class ResourceAllocationsBeingEdited {
|
|||
return new ArrayList<AllocationDTO>(currentAllocations);
|
||||
}
|
||||
|
||||
private boolean alreadyExistsAllocationFor(Worker worker) {
|
||||
return !getAllocationsFor(worker).isEmpty();
|
||||
private boolean alreadyExistsAllocationFor(Resource resource) {
|
||||
return !getAllocationsFor(resource).isEmpty();
|
||||
}
|
||||
|
||||
private List<SpecificAllocationDTO> getAllocationsFor(Worker worker) {
|
||||
List<SpecificAllocationDTO> found = SpecificAllocationDTO.withResource(
|
||||
SpecificAllocationDTO.getSpecific(currentAllocations), worker);
|
||||
private List<SpecificAllocationDTO> getAllocationsFor(Resource resource) {
|
||||
List<SpecificAllocationDTO> found = SpecificAllocationDTO
|
||||
.withResource(SpecificAllocationDTO
|
||||
.getSpecific(currentAllocations), resource);
|
||||
return found;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.navalplanner.business.planner.entities.ResourceAllocation;
|
|||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
||||
/**
|
||||
* The information required for creating a {@link SpecificResourceAllocation}
|
||||
|
|
@ -37,10 +36,10 @@ import org.navalplanner.business.resources.entities.Worker;
|
|||
public class SpecificAllocationDTO extends AllocationDTO {
|
||||
|
||||
public static List<SpecificAllocationDTO> withResource(
|
||||
List<SpecificAllocationDTO> specific, Worker worker) {
|
||||
List<SpecificAllocationDTO> specific, Resource resource) {
|
||||
List<SpecificAllocationDTO> result = new ArrayList<SpecificAllocationDTO>();
|
||||
for (SpecificAllocationDTO specificAllocationDTO : specific) {
|
||||
if (areEquals(specificAllocationDTO.getResource(), worker)) {
|
||||
if (areEquals(specificAllocationDTO.getResource(), resource)) {
|
||||
result.add(specificAllocationDTO);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue