ItEr45S19CUTraspasoDeResponsabilidadesTraballoEntreUnidadesPlanificacion: Loading calendars for resources.
It was implicity loaded when the charts were first loaded, but it would throw a LazyInitializationException for resources that are not currently assigned if they are reassigned.
This commit is contained in:
parent
cb2528c544
commit
38d84cb673
1 changed files with 25 additions and 2 deletions
|
|
@ -32,6 +32,7 @@ import org.navalplanner.business.planner.entities.TaskGroup;
|
|||
import org.navalplanner.business.planner.entities.TaskMilestone;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.web.calendars.BaseCalendarModel;
|
||||
|
||||
public class PlanningState {
|
||||
private final ArrayList<TaskElement> initial;
|
||||
|
|
@ -51,7 +52,7 @@ public class PlanningState {
|
|||
this.initial = new ArrayList<TaskElement>(initialState);
|
||||
this.toSave = new HashSet<TaskElement>(initialState);
|
||||
this.toRemove = new HashSet<TaskElement>();
|
||||
this.resources = new HashSet<Resource>(initialResources);
|
||||
this.resources = doReattachments(new HashSet<Resource>(initialResources));
|
||||
}
|
||||
|
||||
public Collection<? extends TaskElement> getTasksToSave() {
|
||||
|
|
@ -70,7 +71,29 @@ public class PlanningState {
|
|||
}
|
||||
|
||||
private void addingNewlyCreated(IResourceDAO resourceDAO) {
|
||||
resources.addAll(resourceDAO.list(Resource.class));
|
||||
Set<Resource> newResources = getNewResources(resourceDAO);
|
||||
doReattachments(newResources);
|
||||
resources.addAll(newResources);
|
||||
}
|
||||
|
||||
private <T extends Collection<Resource>> T doReattachments(T result) {
|
||||
for (Resource each : result) {
|
||||
reattachCalendarFor(each);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void reattachCalendarFor(Resource each) {
|
||||
if (each.getCalendar() != null) {
|
||||
BaseCalendarModel.forceLoadBaseCalendar(each.getCalendar());
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Resource> getNewResources(IResourceDAO resourceDAO) {
|
||||
Set<Resource> result = new HashSet<Resource>(resourceDAO
|
||||
.list(Resource.class));
|
||||
result.removeAll(resources);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Collection<? extends TaskElement> getToRemove() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue