ItEr19S11CUAsignacionRecursosEspecificosAPlanificacionItEr18S14: Checking if the same Worker is not assigned more than one time to the same Task.
This commit is contained in:
parent
91668fba1b
commit
9909aef738
3 changed files with 42 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import java.util.Set;
|
|||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.navalplanner.business.orders.entities.HoursGroup;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
|
|
@ -65,4 +66,31 @@ public class Task extends TaskElement {
|
|||
resourceAllocations.remove(resourceAllocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there isn't any {@link Worker} repeated in the {@link Set} of
|
||||
* {@link ResourceAllocation} of this {@link Task}.
|
||||
*
|
||||
* @return <code>true</code> if the {@link Task} is valid, that means there
|
||||
* isn't any {@link Worker} repeated.
|
||||
*/
|
||||
public boolean isValidResourceAllocationWorkers() {
|
||||
Set<Long> workers = new HashSet<Long>();
|
||||
|
||||
for (ResourceAllocation resourceAllocation : resourceAllocations) {
|
||||
if (resourceAllocation instanceof SpecificResourceAllocation) {
|
||||
Worker worker = ((SpecificResourceAllocation) resourceAllocation)
|
||||
.getWorker();
|
||||
if (worker != null) {
|
||||
if (workers.contains(worker.getId())) {
|
||||
return false;
|
||||
} else {
|
||||
workers.add(worker.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,12 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
if (!resourceAllocationModel.getTask()
|
||||
.isValidResourceAllocationWorkers()) {
|
||||
throw new WrongValueException(window.getFellow("resourcesList"),
|
||||
"There is some Worker assigned twice (or more)");
|
||||
}
|
||||
|
||||
Clients.closeErrorBox(window.getFellow("resourcesList"));
|
||||
window.setVisible(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.navalplanner.web.planner;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.planner.services.ITaskElementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -36,6 +37,13 @@ public class SaveCommand implements ISaveCommand {
|
|||
public void doAction(IContext<TaskElement> context) {
|
||||
for (TaskElement taskElement : taskElements) {
|
||||
taskElementService.save(taskElement);
|
||||
if (taskElement instanceof Task) {
|
||||
if (!((Task) taskElement).isValidResourceAllocationWorkers()) {
|
||||
throw new RuntimeException("The Task '"
|
||||
+ taskElement.getName()
|
||||
+ "' has some repeated Worker assigned");
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO redirect to another page or show message
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue