diff --git a/ganttzk/pom.xml b/ganttzk/pom.xml index 5c068c08f..d273872c6 100644 --- a/ganttzk/pom.xml +++ b/ganttzk/pom.xml @@ -137,7 +137,7 @@ org.jgrapht - jgrapht-jdk1.5 + jgrapht-core diff --git a/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java b/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java index 8f00ba385..36ecb37a7 100644 --- a/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java +++ b/ganttzk/src/main/java/org/zkoss/ganttz/data/GanttDiagramGraph.java @@ -61,6 +61,7 @@ import org.zkoss.ganttz.util.ReentranceGuard.IReentranceCases; * This class contains a graph with the {@link Task tasks} as vertexes and the * {@link Dependency dependency} as arcs. It enforces the rules embodied in the * dependencies and in the duration of the tasks using listeners.
+ * * @author Óscar González Fernández */ public class GanttDiagramGraph> implements ICriticalPathCalculable { @@ -75,8 +76,7 @@ public class GanttDiagramGraph> implements ICritical } @Override - public void setStartDate(GanttDate previousStart, - GanttDate previousEnd, GanttDate newStart) { + public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) { } @Override @@ -98,8 +98,7 @@ public class GanttDiagramGraph> implements ICritical boolean isContainer(V task); - void registerDependenciesEnforcerHookOn(V task, - IDependenciesEnforcerHookFactory hookFactory); + void registerDependenciesEnforcerHookOn(V task, IDependenciesEnforcerHookFactory hookFactory); GanttDate getStartDate(V task); @@ -109,9 +108,8 @@ public class GanttDiagramGraph> implements ICritical void setEndDateFor(V task, GanttDate newEnd); - public List> getConstraints( - ConstraintCalculator calculator, Set withDependencies, - Point point); + List> getConstraints(ConstraintCalculator calculator, Set withDependencies, + Point point); List> getStartConstraintsFor(V task); @@ -142,10 +140,11 @@ public class GanttDiagramGraph> implements ICritical @Override public Task getOwner(Task task) { - if (task instanceof Milestone) { + if ( task instanceof Milestone ) { Milestone milestone = (Milestone) task; return milestone.getOwner(); } + return null; } @@ -165,14 +164,12 @@ public class GanttDiagramGraph> implements ICritical } @Override - public void registerDependenciesEnforcerHookOn(Task task, - IDependenciesEnforcerHookFactory hookFactory) { + public void registerDependenciesEnforcerHookOn(Task task, IDependenciesEnforcerHookFactory hookFactory) { task.registerDependenciesEnforcerHook(hookFactory); } @Override - public Dependency createInvisibleDependency(Task origin, - Task destination, DependencyType type) { + public Dependency createInvisibleDependency(Task origin, Task destination, DependencyType type) { return new Dependency(origin, destination, type, false); } @@ -225,11 +222,10 @@ public class GanttDiagramGraph> implements ICritical } @Override - public List> getConstraints( - ConstraintCalculator calculator, - Set withDependencies, Point pointBeingModified) { - return Dependency.getConstraintsFor(calculator, withDependencies, - pointBeingModified); + public List> getConstraints(ConstraintCalculator calculator, + Set withDependencies, Point pointBeingModified) { + + return Dependency.getConstraintsFor(calculator, withDependencies, pointBeingModified); } @Override @@ -249,31 +245,28 @@ public class GanttDiagramGraph> implements ICritical } - public static class GanttZKDiagramGraph extends - GanttDiagramGraph { + public static class GanttZKDiagramGraph extends GanttDiagramGraph { - private GanttZKDiagramGraph(boolean scheduleBackwards, - List> globalStartConstraints, - List> globalEndConstraints, - boolean dependenciesConstraintsHavePriority) { - super(scheduleBackwards, GANTTZK_ADAPTER, globalStartConstraints, - globalEndConstraints, + private GanttZKDiagramGraph(boolean scheduleBackwards, List> globalStartConstraints, + List> globalEndConstraints, boolean dependenciesConstraintsHavePriority) { + + super(scheduleBackwards, GANTTZK_ADAPTER, globalStartConstraints, globalEndConstraints, dependenciesConstraintsHavePriority); } } public interface IGraphChangeListener { - public void execute(); + void execute(); } public static GanttZKDiagramGraph create(boolean scheduleBackwards, - List> globalStartConstraints, - List> globalEndConstraints, - boolean dependenciesConstraintsHavePriority) { - return new GanttZKDiagramGraph(scheduleBackwards, - globalStartConstraints, - globalEndConstraints, dependenciesConstraintsHavePriority); + List> globalStartConstraints, + List> globalEndConstraints, + boolean dependenciesConstraintsHavePriority) { + + return new GanttZKDiagramGraph(scheduleBackwards, globalStartConstraints, globalEndConstraints, + dependenciesConstraintsHavePriority); } private final IAdapter adapter; @@ -282,9 +275,9 @@ public class GanttDiagramGraph> implements ICritical private final TopologicalSorter topologicalSorter; - private List topLevelTasks = new ArrayList(); + private List topLevelTasks = new ArrayList<>(); - private Map fromChildToParent = new HashMap(); + private Map fromChildToParent = new HashMap<>(); private final List> globalStartConstraints; @@ -302,14 +295,12 @@ public class GanttDiagramGraph> implements ICritical @Override protected void postAction() { - executeGraphChangeListeners(new ArrayList( - postGraphChangeListeners)); + executeGraphChangeListeners(new ArrayList<>(postGraphChangeListeners)); } @Override protected void preAction() { - executeGraphChangeListeners(new ArrayList( - preGraphChangeListeners)); + executeGraphChangeListeners(new ArrayList<>(preGraphChangeListeners)); } private void executeGraphChangeListeners(List graphChangeListeners) { @@ -323,9 +314,9 @@ public class GanttDiagramGraph> implements ICritical } }; - private List preGraphChangeListeners = new ArrayList(); + private List preGraphChangeListeners = new ArrayList<>(); - private List postGraphChangeListeners = new ArrayList(); + private List postGraphChangeListeners = new ArrayList<>(); public void addPreGraphChangeListener(IGraphChangeListener preGraphChangeListener) { preGraphChangeListeners.add(preGraphChangeListener); @@ -343,15 +334,13 @@ public class GanttDiagramGraph> implements ICritical postGraphChangeListeners.remove(postGraphChangeListener); } - public void addPreChangeListeners( - Collection preChangeListeners) { + public void addPreChangeListeners(Collection preChangeListeners) { for (IGraphChangeListener each : preChangeListeners) { addPreGraphChangeListener(each); } } - public void addPostChangeListeners( - Collection postChangeListeners) { + public void addPostChangeListeners(Collection postChangeListeners) { for (IGraphChangeListener each : postChangeListeners) { addPostGraphChangeListener(each); } @@ -363,22 +352,22 @@ public class GanttDiagramGraph> implements ICritical List> globalStartConstraints, List> globalEndConstraints, boolean dependenciesConstraintsHavePriority) { - return new GanttDiagramGraph(scheduleBackwards, adapter, - globalStartConstraints, - globalEndConstraints, dependenciesConstraintsHavePriority); + + return new GanttDiagramGraph<>(scheduleBackwards, adapter, globalStartConstraints, globalEndConstraints, + dependenciesConstraintsHavePriority); } - protected GanttDiagramGraph(boolean scheduleBackwards, - IAdapter adapter, - List> globalStartConstraints, - List> globalEndConstraints, - boolean dependenciesConstraintsHavePriority) { + protected GanttDiagramGraph(boolean scheduleBackwards, IAdapter adapter, + List> globalStartConstraints, + List> globalEndConstraints, + boolean dependenciesConstraintsHavePriority) { + this.scheduleBackwards = scheduleBackwards; this.adapter = adapter; this.globalStartConstraints = globalStartConstraints; this.globalEndConstraints = globalEndConstraints; this.dependenciesConstraintsHavePriority = dependenciesConstraintsHavePriority; - this.graph = new SimpleDirectedGraph(adapter.getDependencyType()); + this.graph = new SimpleDirectedGraph<>(adapter.getDependencyType()); this.topologicalSorter = new TopologicalSorter(); } @@ -386,24 +375,28 @@ public class GanttDiagramGraph> implements ICritical enforcer.enforceRestrictionsOn(withoutVisibleIncomingDependencies(getTopLevelTasks())); } - private List withoutVisibleIncomingDependencies( - Collection tasks) { - List result = new ArrayList(); + private List withoutVisibleIncomingDependencies(Collection tasks) { + List result = new ArrayList<>(); for (V each : tasks) { - if (noVisibleDependencies(isScheduleForward() ? graph - .incomingEdgesOf(each) : graph.outgoingEdgesOf(each))) { + + boolean condition = noVisibleDependencies(isScheduleForward() ? graph.incomingEdgesOf(each) + : graph.outgoingEdgesOf(each)); + + if ( condition ) { result.add(each); } } + return result; } private boolean noVisibleDependencies(Collection dependencies) { for (D each : dependencies) { - if (adapter.isVisible(each)) { + if ( adapter.isVisible(each) ) { return false; } } + return true; } @@ -429,12 +422,12 @@ public class GanttDiagramGraph> implements ICritical private Map taskPointsByDepthCached = null; private Map taskPointsByDepth() { - if (taskPointsByDepthCached != null) { + if ( taskPointsByDepthCached != null ) { return taskPointsByDepthCached; } - Map result = new HashMap(); - Map> visitedBy = new HashMap>(); + Map result = new HashMap<>(); + Map> visitedBy = new HashMap<>(); Queue withoutIncoming = getInitial(withoutVisibleIncomingDependencies(getTopLevelTasks())); for (TaskPoint each : withoutIncoming) { @@ -443,36 +436,35 @@ public class GanttDiagramGraph> implements ICritical while (!withoutIncoming.isEmpty()) { TaskPoint current = withoutIncoming.poll(); + for (TaskPoint each : current.getImmediateSuccessors()) { - initializeIfNeededForKey(visitedBy, each, - new HashSet()); + + initializeIfNeededForKey(visitedBy, each, new HashSet()); Set visitors = visitedBy.get(each); visitors.add(current); - Set predecessorsRequired = each - .getImmediatePredecessors(); - if (visitors.containsAll(predecessorsRequired)) { - initializeIfNeededForKey(result, each, - result.get(current) + 1); + Set predecessorsRequired = each.getImmediatePredecessors(); + + if ( visitors.containsAll(predecessorsRequired) ) { + initializeIfNeededForKey(result, each, result.get(current) + 1); withoutIncoming.offer(each); } } } - return taskPointsByDepthCached = Collections - .unmodifiableMap(result); + return taskPointsByDepthCached = Collections.unmodifiableMap(result); } - private void initializeIfNeededForKey(Map map, K key, - T initialValue) { - if (!map.containsKey(key)) { + private void initializeIfNeededForKey(Map map, K key, T initialValue) { + if ( !map.containsKey(key) ) { map.put(key, initialValue); } } private LinkedList getInitial(List initial) { - LinkedList result = new LinkedList(); + LinkedList result = new LinkedList<>(); for (V each : initial) { result.add(allPointsPotentiallyModified(each)); } + return result; } @@ -480,11 +472,9 @@ public class GanttDiagramGraph> implements ICritical taskPointsByDepthCached = null; } - public List sort( - Collection recalculationsToBeSorted) { + public List sort(Collection recalculationsToBeSorted) { - List result = new ArrayList( - recalculationsToBeSorted); + List result = new ArrayList<>(recalculationsToBeSorted); final Map taskPointsByDepth = taskPointsByDepth(); Collections.sort(result, new Comparator() { @@ -492,17 +482,18 @@ public class GanttDiagramGraph> implements ICritical public int compare(Recalculation o1, Recalculation o2) { int o1Depth = onNullDefault( taskPointsByDepth.get(o1.taskPoint), - Integer.MAX_VALUE, "no depth value for " - + o1.taskPoint); + Integer.MAX_VALUE, "no depth value for " + o1.taskPoint); + int o2Depth = onNullDefault( taskPointsByDepth.get(o2.taskPoint), - Integer.MAX_VALUE, "no depth value for " - + o2.taskPoint); + Integer.MAX_VALUE, "no depth value for " + o2.taskPoint); + int result = o1Depth - o2Depth; - if (result == 0) { - return asInt(o1.parentRecalculation) - - asInt(o2.parentRecalculation); + + if ( result == 0 ) { + return asInt(o1.parentRecalculation) - asInt(o2.parentRecalculation); } + return result; } @@ -510,59 +501,62 @@ public class GanttDiagramGraph> implements ICritical return b ? 1 : 0; } }); + return result; } } - private static T onNullDefault(T value, T defaultValue, - String warnMessage) { - if (value == null) { - if (warnMessage != null) { + private static T onNullDefault(T value, T defaultValue, String warnMessage) { + if ( value == null ) { + if ( warnMessage != null ) { LOG.warn(warnMessage); } + return defaultValue; } + return value; } public void addTask(V original) { - List stack = new LinkedList(); + List stack = new LinkedList<>(); stack.add(original); - List dependenciesToAdd = new ArrayList(); + List dependenciesToAdd = new ArrayList<>(); + while (!stack.isEmpty()){ + V task = stack.remove(0); graph.addVertex(task); topologicalSorter.recalculationNeeded(); adapter.registerDependenciesEnforcerHookOn(task, enforcer); - if (adapter.isContainer(task)) { + + if ( adapter.isContainer(task) ) { + for (V child : adapter.getChildren(task)) { fromChildToParent.put(child, task); stack.add(0, child); - dependenciesToAdd.add(adapter.createInvisibleDependency( - child, task, DependencyType.END_END)); - dependenciesToAdd.add(adapter.createInvisibleDependency( - task, child, DependencyType.START_START)); + dependenciesToAdd.add(adapter.createInvisibleDependency(child, task, DependencyType.END_END)); + dependenciesToAdd.add(adapter.createInvisibleDependency(task, child, DependencyType.START_START)); } + } else { V owner = adapter.getOwner(task); - if(owner != null) { - dependenciesToAdd.add(adapter.createInvisibleDependency( - task, owner, DependencyType.END_END)); - dependenciesToAdd.add(adapter.createInvisibleDependency( - owner, task, DependencyType.START_START)); + if( owner != null ) { + dependenciesToAdd.add(adapter.createInvisibleDependency(task, owner, DependencyType.END_END)); + dependenciesToAdd.add(adapter.createInvisibleDependency(owner, task, DependencyType.START_START)); } } } + for (D each : dependenciesToAdd) { add(each, false); } } private interface IDependenciesEnforcer { - public void setStartDate(GanttDate previousStart, - GanttDate previousEnd, GanttDate newStart); + void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart); - public void setNewEnd(GanttDate previousEnd, GanttDate newEnd); + void setNewEnd(GanttDate previousEnd, GanttDate newEnd); } /** @@ -592,7 +586,7 @@ public class GanttDiagramGraph> implements ICritical *

*/ public interface IDependenciesEnforcerHook extends IDependenciesEnforcer { - public void positionPotentiallyModified(); + void positionPotentiallyModified(); } public interface IDependenciesEnforcerHookFactory { @@ -601,24 +595,22 @@ public class GanttDiagramGraph> implements ICritical * {@link INotificationAfterDependenciesEnforcement notifier} to notify * the changes that have happened due to the algorithm. */ - public IDependenciesEnforcerHook create(T task, - INotificationAfterDependenciesEnforcement notifier); + IDependenciesEnforcerHook create(T task, INotificationAfterDependenciesEnforcement notifier); - public IDependenciesEnforcerHook create(T task); + IDependenciesEnforcerHook create(T task); } public interface INotificationAfterDependenciesEnforcement { - public void onStartDateChange(GanttDate previousStart, - GanttDate previousEnd, GanttDate newStart); + void onStartDateChange(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart); - public void onEndDateChange(GanttDate previousEnd, GanttDate newEnd); + void onEndDateChange(GanttDate previousEnd, GanttDate newEnd); } - private static final INotificationAfterDependenciesEnforcement EMPTY_NOTIFICATOR = new INotificationAfterDependenciesEnforcement() { + private static final INotificationAfterDependenciesEnforcement EMPTY_NOTIFICATOR = + new INotificationAfterDependenciesEnforcement() { @Override - public void onStartDateChange(GanttDate previousStart, - GanttDate previousEnd, GanttDate newStart) { + public void onStartDateChange(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) { } @Override @@ -633,7 +625,7 @@ public class GanttDiagramGraph> implements ICritical */ public class DeferedNotifier { - private Map notificationsPending = new LinkedHashMap(); + private Map notificationsPending = new LinkedHashMap<>(); public void add(V task, StartDateNofitication notification) { retrieveOrCreateFor(task).setStartDateNofitication(notification); @@ -641,10 +633,11 @@ public class GanttDiagramGraph> implements ICritical private NotificationPendingForTask retrieveOrCreateFor(V task) { NotificationPendingForTask result = notificationsPending.get(task); - if (result == null) { + if ( result == null ) { result = new NotificationPendingForTask(); notificationsPending.put(task, result); } + return result; } @@ -653,8 +646,7 @@ public class GanttDiagramGraph> implements ICritical } public void doNotifications() { - for (NotificationPendingForTask each : notificationsPending - .values()) { + for (NotificationPendingForTask each : notificationsPending.values()) { each.doNotification(); } notificationsPending.clear(); @@ -667,23 +659,24 @@ public class GanttDiagramGraph> implements ICritical private LengthNotification lengthNofitication; - void setStartDateNofitication( - StartDateNofitication startDateNofitication) { - this.startDateNofitication = this.startDateNofitication == null ? startDateNofitication - : this.startDateNofitication - .coalesce(startDateNofitication); + void setStartDateNofitication(StartDateNofitication startDateNofitication) { + + this.startDateNofitication = (this.startDateNofitication == null) ? startDateNofitication : + this.startDateNofitication.coalesce(startDateNofitication); } void setLengthNofitication(LengthNotification lengthNofitication) { - this.lengthNofitication = this.lengthNofitication == null ? lengthNofitication - : this.lengthNofitication.coalesce(lengthNofitication); + + this.lengthNofitication = (this.lengthNofitication == null) ? lengthNofitication : + this.lengthNofitication.coalesce(lengthNofitication); } void doNotification() { - if (startDateNofitication != null) { + if ( startDateNofitication != null ) { startDateNofitication.doNotification(); } - if (lengthNofitication != null) { + + if ( lengthNofitication != null ) { lengthNofitication.doNotification(); } } @@ -696,25 +689,23 @@ public class GanttDiagramGraph> implements ICritical private final GanttDate previousEnd; private final GanttDate newStart; - public StartDateNofitication( - INotificationAfterDependenciesEnforcement notification, - GanttDate previousStart, GanttDate previousEnd, - GanttDate newStart) { + public StartDateNofitication(INotificationAfterDependenciesEnforcement notification, + GanttDate previousStart, + GanttDate previousEnd, + GanttDate newStart) { + this.notification = notification; this.previousStart = previousStart; this.previousEnd = previousEnd; this.newStart = newStart; } - public StartDateNofitication coalesce( - StartDateNofitication startDateNofitication) { - return new StartDateNofitication(notification, previousStart, - previousEnd, startDateNofitication.newStart); + public StartDateNofitication coalesce(StartDateNofitication startDateNofitication) { + return new StartDateNofitication(notification, previousStart, previousEnd, startDateNofitication.newStart); } void doNotification() { - notification - .onStartDateChange(previousStart, previousEnd, newStart); + notification.onStartDateChange(previousStart, previousEnd, newStart); } } @@ -724,9 +715,10 @@ public class GanttDiagramGraph> implements ICritical private final GanttDate previousEnd; private final GanttDate newEnd; - public LengthNotification( - INotificationAfterDependenciesEnforcement notification, - GanttDate previousEnd, GanttDate newEnd) { + public LengthNotification(INotificationAfterDependenciesEnforcement notification, + GanttDate previousEnd, + GanttDate newEnd) { + this.notification = notification; this.previousEnd = previousEnd; this.newEnd = newEnd; @@ -734,8 +726,7 @@ public class GanttDiagramGraph> implements ICritical } public LengthNotification coalesce(LengthNotification lengthNofitication) { - return new LengthNotification(notification, previousEnd, - lengthNofitication.newEnd); + return new LengthNotification(notification, previousEnd, lengthNofitication.newEnd); } void doNotification() { @@ -743,10 +734,9 @@ public class GanttDiagramGraph> implements ICritical } } - private class DependenciesEnforcer implements - IDependenciesEnforcerHookFactory { + private class DependenciesEnforcer implements IDependenciesEnforcerHookFactory { - private ThreadLocal deferedNotifier = new ThreadLocal(); + private ThreadLocal deferedNotifier = new ThreadLocal<>(); /** * It creates a {@link IDependenciesEnforcerHook} that starts the @@ -754,12 +744,10 @@ public class GanttDiagramGraph> implements ICritical * modifications records the changes onNotification. */ @Override - public IDependenciesEnforcerHook create(V task, - INotificationAfterDependenciesEnforcement notificator) { + public IDependenciesEnforcerHook create(V task, INotificationAfterDependenciesEnforcement notificator) { return withPositionPotentiallyModified( task, - onlyEnforceDependenciesOnEntrance(onEntrance(task), - onNotification(task, notificator))); + onlyEnforceDependenciesOnEntrance(onEntrance(task), onNotification(task, notificator))); } @Override @@ -774,8 +762,7 @@ public class GanttDiagramGraph> implements ICritical private IDependenciesEnforcer onEntrance(final V task) { return new IDependenciesEnforcer() { - public void setStartDate(GanttDate previousStart, - GanttDate previousEnd, GanttDate newStart) { + public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) { taskPositionModified(task); } @@ -792,23 +779,22 @@ public class GanttDiagramGraph> implements ICritical * dependencies enforcement algorithm. */ private IDependenciesEnforcer onNotification(final V task, - final INotificationAfterDependenciesEnforcement notification) { + final INotificationAfterDependenciesEnforcement notification) { return new IDependenciesEnforcer() { @Override - public void setStartDate(GanttDate previousStart, - GanttDate previousEnd, GanttDate newStart) { - StartDateNofitication startDateNotification = new StartDateNofitication( - notification, previousStart, previousEnd, - newStart); + public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) { + + StartDateNofitication startDateNotification = + new StartDateNofitication(notification, previousStart, previousEnd, newStart); + deferedNotifier.get().add(task, startDateNotification); } @Override public void setNewEnd(GanttDate previousEnd, GanttDate newEnd) { - LengthNotification lengthNotification = new LengthNotification( - notification, previousEnd, newEnd); + LengthNotification lengthNotification = new LengthNotification(notification, previousEnd, newEnd); deferedNotifier.get().add(task, lengthNotification); } }; @@ -819,13 +805,12 @@ public class GanttDiagramGraph> implements ICritical * Enrich {@link IDependenciesEnforcer} with * {@link IDependenciesEnforcerHook#positionPotentiallyModified()}. */ - private IDependenciesEnforcerHook withPositionPotentiallyModified( - final V task, final IDependenciesEnforcer enforcer) { + private IDependenciesEnforcerHook withPositionPotentiallyModified(final V task, + final IDependenciesEnforcer enforcer) { return new IDependenciesEnforcerHook() { @Override - public void setStartDate(GanttDate previousStart, - GanttDate previousEnd, GanttDate newStart) { + public void setStartDate(GanttDate previousStart, GanttDate previousEnd, GanttDate newStart) { enforcer.setStartDate(previousStart, previousEnd, newStart); } @@ -850,74 +835,64 @@ public class GanttDiagramGraph> implements ICritical * onEntrance. Otherwise it delegates to * notifier. */ - private IDependenciesEnforcer onlyEnforceDependenciesOnEntrance( - final IDependenciesEnforcer onEntrance, - final IDependenciesEnforcer notifier) { + private IDependenciesEnforcer onlyEnforceDependenciesOnEntrance(final IDependenciesEnforcer onEntrance, + final IDependenciesEnforcer notifier) { return new IDependenciesEnforcer() { @Override public void setStartDate(final GanttDate previousStart, - final GanttDate previousEnd, final GanttDate newStart) { - positionsUpdatingGuard - .entranceRequested(new IReentranceCases() { + final GanttDate previousEnd, + final GanttDate newStart) { + + positionsUpdatingGuard.entranceRequested(new IReentranceCases() { + @Override + public void ifNewEntrance() { + onNewEntrance(new IAction() { @Override - public void ifNewEntrance() { - onNewEntrance(new IAction() { - - @Override - public void doAction() { - notifier.setStartDate( - previousStart, - previousEnd, newStart); - onEntrance.setStartDate( - previousStart, previousEnd, - newStart); - } - }); - } - - @Override - public void ifAlreadyInside() { - notifier.setStartDate(previousStart, - previousEnd, newStart); - + public void doAction() { + notifier.setStartDate(previousStart, previousEnd, newStart); + onEntrance.setStartDate(previousStart, previousEnd, newStart); } }); + } + + @Override + public void ifAlreadyInside() { + notifier.setStartDate(previousStart, previousEnd, newStart); + + } + }); } @Override - public void setNewEnd(final GanttDate previousEnd, - final GanttDate newEnd) { - positionsUpdatingGuard - .entranceRequested(new IReentranceCases() { + public void setNewEnd(final GanttDate previousEnd, final GanttDate newEnd) { + positionsUpdatingGuard.entranceRequested(new IReentranceCases() { + + @Override + public void ifNewEntrance() { + onNewEntrance(new IAction() { @Override - public void ifNewEntrance() { - onNewEntrance(new IAction() { - - @Override - public void doAction() { - notifier.setNewEnd(previousEnd, - newEnd); - onEntrance.setNewEnd(previousEnd, - newEnd); - } - }); - } - - @Override - public void ifAlreadyInside() { + public void doAction() { notifier.setNewEnd(previousEnd, newEnd); + onEntrance.setNewEnd(previousEnd, newEnd); } }); + } + + @Override + public void ifAlreadyInside() { + notifier.setNewEnd(previousEnd, newEnd); + } + }); } }; } void enforceRestrictionsOn(Collection tasks) { - List allRecalculations = new ArrayList(); + List allRecalculations = new ArrayList<>(); for (V each : tasks) { allRecalculations.addAll(getRecalculationsNeededFrom(each)); } @@ -925,12 +900,12 @@ public class GanttDiagramGraph> implements ICritical } void enforceRestrictionsOn(V task) { - enforceRestrictionsOn(getRecalculationsNeededFrom(task), - Collections.singleton(task)); + enforceRestrictionsOn(getRecalculationsNeededFrom(task), Collections.singleton(task)); } void enforceRestrictionsOn(final List recalculations, final Collection initiallyModified) { + executeWithPreAndPostActionsOnlyIfNewEntrance(new IAction() { @Override public void doAction() { @@ -939,8 +914,7 @@ public class GanttDiagramGraph> implements ICritical }); } - private void executeWithPreAndPostActionsOnlyIfNewEntrance( - final IAction action) { + private void executeWithPreAndPostActionsOnlyIfNewEntrance(final IAction action) { positionsUpdatingGuard.entranceRequested(new IReentranceCases() { @Override @@ -1011,6 +985,7 @@ public class GanttDiagramGraph> implements ICritical }); } }); + return result; } @@ -1019,22 +994,24 @@ public class GanttDiagramGraph> implements ICritical @Override public void doAction() { List recalculationsNeededFrom = getRecalculationsNeededFrom(task); - doRecalculations(recalculationsNeededFrom, - Collections.singletonList(task)); + doRecalculations(recalculationsNeededFrom, Collections.singletonList(task)); } }); } private void doRecalculations(List recalculationsNeeded, Collection initiallyModified) { - Set allModified = new HashSet(); + + Set allModified = new HashSet<>(); allModified.addAll(initiallyModified); + for (Recalculation each : recalculationsNeeded) { boolean modified = each.doRecalculation(); if ( modified ) { allModified.add(each.taskPoint.task); } } + List shrunkContainers = shrunkContainersOfModified(allModified); for (V each : getTaskAffectedByShrinking(shrunkContainers)) { doRecalculations(getRecalculationsNeededFrom(each), @@ -1043,59 +1020,65 @@ public class GanttDiagramGraph> implements ICritical } private List getTaskAffectedByShrinking(List shrunkContainers) { - List tasksAffectedByShrinking = new ArrayList(); + List tasksAffectedByShrinking = new ArrayList<>(); for (V each : shrunkContainers) { + for (D eachDependency : graph.outgoingEdgesOf(each)) { - if (adapter.getType(eachDependency) == DependencyType.START_START - && adapter.isVisible(eachDependency)) { - tasksAffectedByShrinking.add(adapter - .getDestination(eachDependency)); + + boolean condition = adapter.getType(eachDependency) == DependencyType.START_START && + adapter.isVisible(eachDependency); + + if ( condition ) { + tasksAffectedByShrinking.add(adapter.getDestination(eachDependency)); } } } + return tasksAffectedByShrinking; } - private List shrunkContainersOfModified( - Set allModified) { + private List shrunkContainersOfModified(Set allModified) { Set topmostToShrink = getTopMostThatCouldPotentiallyNeedShrinking(allModified); - List allToShrink = new ArrayList(); + List allToShrink = new ArrayList<>(); + for (V each : topmostToShrink) { allToShrink.addAll(getContainersBottomUp(each)); } - List result = new ArrayList(); + + List result = new ArrayList<>(); for (V each : allToShrink) { boolean modified = enforceParentShrinkage(each); - if (modified) { + if ( modified ) { result.add(each); } } + return result; } - private Set getTopMostThatCouldPotentiallyNeedShrinking( - Collection modified) { - Set result = new HashSet(); + private Set getTopMostThatCouldPotentiallyNeedShrinking(Collection modified) { + Set result = new HashSet<>(); for (V each : modified) { V t = getTopmostFor(each); - if (adapter.isContainer(t)) { + if ( adapter.isContainer(t) ) { result.add(t); } } + return result; } - private Collection getContainersBottomUp( - V container) { + private Collection getContainersBottomUp(V container) { List result = new ArrayList(); List tasks = adapter.getChildren(container); for (V each : tasks) { - if (adapter.isContainer(each)) { + if ( adapter.isContainer(each) ) { result.addAll(getContainersBottomUp(each)); result.add(each); } } result.add(container); + return result; } @@ -1104,13 +1087,13 @@ public class GanttDiagramGraph> implements ICritical GanttDate firstStart = getSmallestBeginDateFromChildrenFor(container); GanttDate lastEnd = getBiggestEndDateFromChildrenFor(container); GanttDate previousEnd = adapter.getEndDateFor(container); - if (firstStart.after(oldBeginDate) || previousEnd.after(lastEnd)) { - adapter.setStartDateFor(container, - GanttDate.max(firstStart, oldBeginDate)); - adapter.setEndDateFor(container, - GanttDate.min(lastEnd, previousEnd)); + + if ( firstStart.after(oldBeginDate) || previousEnd.after(lastEnd) ) { + adapter.setStartDateFor(container, GanttDate.max(firstStart, oldBeginDate)); + adapter.setEndDateFor(container, GanttDate.min(lastEnd, previousEnd)); return true; } + return false; } } @@ -1125,18 +1108,21 @@ public class GanttDiagramGraph> implements ICritical private List getChildrenDates(V container, Point point) { List children = adapter.getChildren(container); - List result = new ArrayList(); - if (children.isEmpty()) { + List result = new ArrayList<>(); + + if ( children.isEmpty() ) { result.add(getDateFor(container, point)); } + for (V each : children) { result.add(getDateFor(each, point)); } + return result; } GanttDate getDateFor(V task, Point point) { - if (point.equals(Point.START)) { + if ( point.equals(Point.START) ) { return adapter.getStartDate(task); } else { return adapter.getEndDateFor(task); @@ -1144,29 +1130,33 @@ public class GanttDiagramGraph> implements ICritical } List getRecalculationsNeededFrom(V task) { - List result = new ArrayList(); - Set parentRecalculationsAlreadyDone = new HashSet(); + List result = new ArrayList<>(); + Set parentRecalculationsAlreadyDone = new HashSet<>(); Recalculation first = recalculationFor(allPointsPotentiallyModified(task)); first.couldHaveBeenModifiedBeforehand(); - result.addAll(getParentsRecalculations(parentRecalculationsAlreadyDone, - first.taskPoint)); + result.addAll(getParentsRecalculations(parentRecalculationsAlreadyDone, first.taskPoint)); result.add(first); - Queue pendingOfVisit = new LinkedList(); + Queue pendingOfVisit = new LinkedList<>(); pendingOfVisit.offer(first); - Map alreadyVisited = new HashMap(); + Map alreadyVisited = new HashMap<>(); alreadyVisited.put(first, first); while (!pendingOfVisit.isEmpty()) { + Recalculation current = pendingOfVisit.poll(); + for (TaskPoint each : current.taskPoint.getImmediateSuccessors()) { + if ( each.isImmediatelyDerivedFrom(current.taskPoint) ) { continue; } + Recalculation recalculationToAdd = getRecalcualtionToAdd(each, alreadyVisited); recalculationToAdd.comesFromPredecessor(current); + if ( !alreadyVisited.containsKey(recalculationToAdd) ) { result.addAll(getParentsRecalculations(parentRecalculationsAlreadyDone, each)); result.add(recalculationToAdd); @@ -1175,62 +1165,71 @@ public class GanttDiagramGraph> implements ICritical } } } + return topologicalSorter.sort(result); } - private Recalculation getRecalcualtionToAdd(TaskPoint taskPoint, - Map alreadyVisited) { + private Recalculation getRecalcualtionToAdd(TaskPoint taskPoint, Map alreadyVisited) { Recalculation result = recalculationFor(taskPoint); - if (alreadyVisited.containsKey(result)) { + + if ( alreadyVisited.containsKey(result) ) { return alreadyVisited.get(result); } else { return result; } } - private List getParentsRecalculations( - Set parentRecalculationsAlreadyDone, - TaskPoint taskPoint) { - List result = new ArrayList(); + private List getParentsRecalculations(Set parentRecalculationsAlreadyDone, + TaskPoint taskPoint) { + List result = new ArrayList<>(); + for (TaskPoint eachParent : parentsRecalculationsNeededFor(taskPoint)) { + Recalculation parentRecalculation = parentRecalculation(eachParent.task); - if (!parentRecalculationsAlreadyDone - .contains(parentRecalculation)) { + + if ( !parentRecalculationsAlreadyDone.contains(parentRecalculation) ) { parentRecalculationsAlreadyDone.add(parentRecalculation); result.add(parentRecalculation); } } + return result; } private Set parentsRecalculationsNeededFor(TaskPoint current) { - Set result = new LinkedHashSet(); - if (current.areAllPointsPotentiallyModified()) { + Set result = new LinkedHashSet<>(); + + if ( current.areAllPointsPotentiallyModified() ) { List path = fromTaskToTop(current.task); - if (path.size() > 1) { + + if ( path.size() > 1 ) { path = path.subList(1, path.size()); Collections.reverse(path); result.addAll(asBothPoints(path)); } } + return result; } private Collection asBothPoints(List parents) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (V each : parents) { result.add(allPointsPotentiallyModified(each)); } + return result; } private List fromTaskToTop(V task) { - List result = new ArrayList(); + List result = new ArrayList<>(); V current = task; - while (current != null) { + + while ( current != null ) { result.add(current); current = fromChildToParent.get(current); } + return result; } @@ -1248,7 +1247,7 @@ public class GanttDiagramGraph> implements ICritical private final TaskPoint taskPoint; - private Set recalculationsCouldAffectThis = new HashSet(); + private Set recalculationsCouldAffectThis = new HashSet<>(); private boolean recalculationCalled = false; @@ -1277,8 +1276,7 @@ public class GanttDiagramGraph> implements ICritical } private boolean haveToDoCalculation() { - return recalculationsCouldAffectThis.isEmpty() - || predecessorsHaveBeenModified(); + return recalculationsCouldAffectThis.isEmpty() || predecessorsHaveBeenModified(); } private boolean predecessorsHaveBeenModified() { @@ -1296,19 +1294,20 @@ public class GanttDiagramGraph> implements ICritical private boolean taskChangesPosition() { ChangeTracker tracker = trackTaskChanges(); - Constraint.initialValue(noRestrictions()) - .withConstraints(getConstraintsToApply()) - .apply(); + Constraint.initialValue(noRestrictions()).withConstraints(getConstraintsToApply()).apply(); return tracker.taskHasChanged(); } @SuppressWarnings("unchecked") private List> getConstraintsToApply() { - Constraint weakForces = scheduleBackwards ? new WeakForwardForces() - : new WeakBackwardsForces(); - Constraint dominatingForces = scheduleBackwards ? new DominatingBackwardForces() - : new DominatingForwardForces(); - if (dependenciesConstraintsHavePriority) { + + Constraint weakForces = + scheduleBackwards ? new WeakForwardForces() : new WeakBackwardsForces(); + + Constraint dominatingForces = + scheduleBackwards ? new DominatingBackwardForces() : new DominatingForwardForces(); + + if ( dependenciesConstraintsHavePriority ) { return asList(weakForces, dominatingForces); } else { return asList(weakForces, dominatingForces, weakForces); @@ -1346,8 +1345,7 @@ public class GanttDiagramGraph> implements ICritical private final class NoRestrictions extends PositionRestrictions { public NoRestrictions(TaskPoint taskPoint) { - super(adapter.getStartDate(taskPoint.task), adapter - .getEndDateFor(taskPoint.task)); + super(adapter.getStartDate(taskPoint.task), adapter.getEndDateFor(taskPoint.task)); } @Override @@ -1372,14 +1370,18 @@ public class GanttDiagramGraph> implements ICritical } DatesBasedPositionRestrictions biggerThan(GanttDate start, GanttDate end) { - ComparisonType type = isScheduleForward() ? ComparisonType.BIGGER_OR_EQUAL_THAN - : ComparisonType.BIGGER_OR_EQUAL_THAN_LEFT_FLOATING; + + ComparisonType type = isScheduleForward() ? ComparisonType.BIGGER_OR_EQUAL_THAN : + ComparisonType.BIGGER_OR_EQUAL_THAN_LEFT_FLOATING; + return new DatesBasedPositionRestrictions(type, start, end); } DatesBasedPositionRestrictions lessThan(GanttDate start, GanttDate end) { - ComparisonType type = isScheduleForward() ? ComparisonType.LESS_OR_EQUAL_THAN_RIGHT_FLOATING - : ComparisonType.LESS_OR_EQUAL_THAN; + + ComparisonType type = isScheduleForward() ? ComparisonType.LESS_OR_EQUAL_THAN_RIGHT_FLOATING : + ComparisonType.LESS_OR_EQUAL_THAN; + return new DatesBasedPositionRestrictions(type, start, end); } @@ -1388,27 +1390,22 @@ public class GanttDiagramGraph> implements ICritical private Constraint startConstraint; private Constraint endConstraint; - public DatesBasedPositionRestrictions( - ComparisonType comparisonType, GanttDate start, - GanttDate end) { + public DatesBasedPositionRestrictions(ComparisonType comparisonType, GanttDate start, GanttDate end) { super(start, end); - this.startConstraint = ConstraintOnComparableValues - .instantiate(comparisonType, start); - this.endConstraint = ConstraintOnComparableValues.instantiate( - comparisonType, end); + this.startConstraint = ConstraintOnComparableValues.instantiate(comparisonType, start); + this.endConstraint = ConstraintOnComparableValues.instantiate(comparisonType, end); } boolean satisfies(PositionRestrictions other) { - if (DatesBasedPositionRestrictions.class.isInstance(other)) { - return satisfies(DatesBasedPositionRestrictions.class - .cast(other)); + if ( DatesBasedPositionRestrictions.class.isInstance(other) ) { + return satisfies(DatesBasedPositionRestrictions.class.cast(other)); } + return false; } private boolean satisfies(DatesBasedPositionRestrictions other) { - return startConstraint.isSatisfiedBy(other.getStart()) - && endConstraint.isSatisfiedBy(other.getEnd()); + return startConstraint.isSatisfiedBy(other.getStart()) && endConstraint.isSatisfiedBy(other.getEnd()); } @Override @@ -1435,8 +1432,8 @@ public class GanttDiagramGraph> implements ICritical } public boolean taskHasChanged() { - return areNotEqual(adapter.getStartDate(task), this.start) - || areNotEqual(adapter.getEndDateFor(task), this.end); + return areNotEqual(adapter.getStartDate(task), this.start) || + areNotEqual(adapter.getEndDateFor(task), this.end); } } @@ -1460,11 +1457,11 @@ public class GanttDiagramGraph> implements ICritical private PositionRestrictions resultingRestrictions = noRestrictions(); - protected PositionRestrictions applyConstraintTo( - PositionRestrictions restrictions) { - if (adapter.isFixed(task)) { + protected PositionRestrictions applyConstraintTo(PositionRestrictions restrictions) { + if ( adapter.isFixed(task) ) { return restrictions; } + resultingRestrictions = enforceUsingPreviousRestrictions(restrictions); return resultingRestrictions; } @@ -1480,8 +1477,7 @@ public class GanttDiagramGraph> implements ICritical } private void checkStartConstraints(GanttDate finalStart) { - Constraint - .checkSatisfyResult(getStartConstraints(), finalStart); + Constraint.checkSatisfyResult(getStartConstraints(), finalStart); } private void checkEndConstraints(GanttDate finalEnd) { @@ -1492,8 +1488,7 @@ public class GanttDiagramGraph> implements ICritical abstract List> getEndConstraints(); - abstract PositionRestrictions enforceUsingPreviousRestrictions( - PositionRestrictions restrictions); + abstract PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions); } abstract class Dominating extends Forces { @@ -1524,32 +1519,31 @@ public class GanttDiagramGraph> implements ICritical } @Override - PositionRestrictions enforceUsingPreviousRestrictions( - PositionRestrictions restrictions) { - if (parentRecalculation) { + PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions) { + if ( parentRecalculation ) { // avoid interference from task containers shrinking return enforcePrimaryPoint(restrictions); - } else if (taskPoint.areAllPointsPotentiallyModified()) { + } else if ( taskPoint.areAllPointsPotentiallyModified() ) { return enforceBoth(restrictions); - } else if (taskPoint.somePointPotentiallyModified()) { + } else if ( taskPoint.somePointPotentiallyModified() ) { return enforceSecondaryPoint(restrictions); } + return restrictions; } - private PositionRestrictions enforceBoth( - PositionRestrictions restrictions) { + private PositionRestrictions enforceBoth(PositionRestrictions restrictions) { ChangeTracker changeTracker = trackTaskChanges(); PositionRestrictions currentRestrictions = enforcePrimaryPoint(restrictions); - if (changeTracker.taskHasChanged() || parentRecalculation - || couldHaveBeenModifiedBeforehand) { + + if ( changeTracker.taskHasChanged() || parentRecalculation || couldHaveBeenModifiedBeforehand ) { return enforceSecondaryPoint(currentRestrictions); } + return currentRestrictions; } - private PositionRestrictions enforcePrimaryPoint( - PositionRestrictions originalRestrictions) { + private PositionRestrictions enforcePrimaryPoint(PositionRestrictions originalRestrictions) { GanttDate newDominatingPointDate = calculatePrimaryPointDate(originalRestrictions); return enforceRestrictionsFor(primary, newDominatingPointDate); } @@ -1560,78 +1554,75 @@ public class GanttDiagramGraph> implements ICritical * return the existent commanding point date * @param originalRestrictions */ - private GanttDate calculatePrimaryPointDate( - PositionRestrictions originalRestrictions) { - GanttDate newDate = Constraint - . initialValue(null) - .withConstraints( - getConstraintsFrom(originalRestrictions, - getPrimaryPoint())) + private GanttDate calculatePrimaryPointDate(PositionRestrictions originalRestrictions) { + + GanttDate newDate = Constraint. initialValue(null) + .withConstraints(getConstraintsFrom(originalRestrictions, getPrimaryPoint())) .withConstraints(getConstraintsFor(getPrimaryPoint())) .applyWithoutFinalCheck(); - if (newDate == null) { + + if ( newDate == null ) { return getTaskDateFor(getPrimaryPoint()); } + return newDate; } private List> getConstraintsFor(Point point) { Validate.isTrue(isSupportedPoint(point)); switch (point) { + case START: return getStartConstraints(); + case END: return getEndConstraints(); + default: throw new RuntimeException("shouldn't happen"); } } - private PositionRestrictions enforceSecondaryPoint( - PositionRestrictions restrictions) { + private PositionRestrictions enforceSecondaryPoint(PositionRestrictions restrictions) { GanttDate newSecondaryPointDate = calculateSecondaryPointDate(restrictions); - if (newSecondaryPointDate == null) { + if ( newSecondaryPointDate == null ) { return restrictions; } - restrictions = enforceRestrictionsFor(getSecondaryPoint(), - newSecondaryPointDate); - if (taskPoint.onlyModifies(getSecondaryPoint())) { - // primary point constraints could be the ones "commanding" - // now + + restrictions = enforceRestrictionsFor(getSecondaryPoint(), newSecondaryPointDate); + + if ( taskPoint.onlyModifies(getSecondaryPoint()) ) { + + // primary point constraints could be the ones "commanding" now GanttDate potentialPrimaryDate = calculatePrimaryPointDate(restrictions); - if (!doSatisfyOrderCondition(potentialPrimaryDate, - getTaskDateFor(getPrimaryPoint()))) { - return enforceRestrictionsFor(getPrimaryPoint(), - potentialPrimaryDate); + + if ( !doSatisfyOrderCondition(potentialPrimaryDate, getTaskDateFor(getPrimaryPoint())) ) { + return enforceRestrictionsFor(getPrimaryPoint(), potentialPrimaryDate); } } + return restrictions; } - private GanttDate calculateSecondaryPointDate( - PositionRestrictions restrictions) { - GanttDate newEnd = Constraint - . initialValue(null) - .withConstraints( - getConstraintsFrom(restrictions, - getSecondaryPoint())) + private GanttDate calculateSecondaryPointDate(PositionRestrictions restrictions) { + + GanttDate newEnd = Constraint. initialValue(null) + .withConstraints(getConstraintsFrom(restrictions, getSecondaryPoint())) .withConstraints(getConstraintsFor(getSecondaryPoint())) .applyWithoutFinalCheck(); + return newEnd; } - protected abstract boolean doSatisfyOrderCondition( - GanttDate supposedlyBefore, GanttDate supposedlyAfter); + protected abstract boolean doSatisfyOrderCondition(GanttDate supposedlyBefore, GanttDate supposedlyAfter); - private PositionRestrictions enforceRestrictionsFor(Point point, - GanttDate newDate) { + private PositionRestrictions enforceRestrictionsFor(Point point, GanttDate newDate) { GanttDate old = getTaskDateFor(point); - if (areNotEqual(old, newDate)) { + if ( areNotEqual(old, newDate) ) { setTaskDateFor(point, newDate); } - return createRestrictionsFor(getTaskDateFor(Point.START), - getTaskDateFor(Point.END)); + return createRestrictionsFor(getTaskDateFor(Point.START), getTaskDateFor(Point.END)); } GanttDate getTaskDateFor(Point point) { @@ -1639,55 +1630,62 @@ public class GanttDiagramGraph> implements ICritical return getDateFor(task, point); } - protected abstract PositionRestrictions createRestrictionsFor( - GanttDate start, GanttDate end); + protected abstract PositionRestrictions createRestrictionsFor(GanttDate start, GanttDate end); private void setTaskDateFor(Point point, GanttDate date) { Validate.isTrue(isSupportedPoint(point)); switch (point) { + case START: adapter.setStartDateFor(task, date); break; + case END: adapter.setEndDateFor(task, date); } } - private List> getConstraintsFrom( - PositionRestrictions restrictions, Point point) { + private List> getConstraintsFrom(PositionRestrictions restrictions, Point point) { Validate.isTrue(isSupportedPoint(point)); switch (point) { + case START: return restrictions.getStartConstraints(); + case END: return restrictions.getEndConstraints(); + default: throw new RuntimeException("shouldn't happen"); } } protected List> getConstraintsForPrimaryPoint() { - List> result = new ArrayList>(); - if (dependenciesConstraintsHavePriority) { + List> result = new ArrayList<>(); + + if ( dependenciesConstraintsHavePriority ) { result.addAll(getTaskConstraints(getPrimaryPoint())); result.addAll(getDependenciesConstraintsFor(getPrimaryPoint())); - } else { result.addAll(getDependenciesConstraintsFor(getPrimaryPoint())); result.addAll(getTaskConstraints(getPrimaryPoint())); } + result.addAll(getGlobalConstraintsToApply(getPrimaryPoint())); + return result; } - private Collection> getGlobalConstraintsToApply( - Point point) { + private Collection> getGlobalConstraintsToApply(Point point) { Validate.isTrue(isSupportedPoint(point)); switch (point) { + case START: return globalStartConstraints; + case END: return globalEndConstraints; + default: throw new RuntimeException("shouldn't happen"); } @@ -1697,11 +1695,9 @@ public class GanttDiagramGraph> implements ICritical return getDependenciesConstraintsFor(getSecondaryPoint()); } - private List> getDependenciesConstraintsFor( - Point point) { + private List> getDependenciesConstraintsFor(Point point) { final Set withDependencies = getDependenciesAffectingThisTask(); - return adapter.getConstraints(getCalculator(), - withDependencies, point); + return adapter.getConstraints(getCalculator(), withDependencies, point); } protected abstract Set getDependenciesAffectingThisTask(); @@ -1709,10 +1705,13 @@ public class GanttDiagramGraph> implements ICritical private List> getTaskConstraints(Point point) { Validate.isTrue(isSupportedPoint(point)); switch (point) { + case START: return adapter.getStartConstraintsFor(task); + case END: return adapter.getEndConstraintsFor(task); + default: throw new RuntimeException("shouldn't happen"); } @@ -1772,15 +1771,12 @@ public class GanttDiagramGraph> implements ICritical } @Override - protected PositionRestrictions createRestrictionsFor( - GanttDate start, GanttDate end) { + protected PositionRestrictions createRestrictionsFor(GanttDate start, GanttDate end) { return biggerThan(start, end); } @Override - protected boolean doSatisfyOrderCondition( - GanttDate supposedlyBefore, - GanttDate supposedlyAfter) { + protected boolean doSatisfyOrderCondition(GanttDate supposedlyBefore, GanttDate supposedlyAfter) { return supposedlyBefore.compareTo(supposedlyAfter) <= 0; } @@ -1813,15 +1809,12 @@ public class GanttDiagramGraph> implements ICritical } @Override - protected PositionRestrictions createRestrictionsFor( - GanttDate start, GanttDate end) { + protected PositionRestrictions createRestrictionsFor(GanttDate start, GanttDate end) { return lessThan(start, end); } @Override - protected boolean doSatisfyOrderCondition( - GanttDate supposedlyBefore, - GanttDate supposedlyAfter) { + protected boolean doSatisfyOrderCondition(GanttDate supposedlyBefore, GanttDate supposedlyAfter) { return supposedlyBefore.compareTo(supposedlyAfter) >= 0; } @@ -1840,21 +1833,23 @@ public class GanttDiagramGraph> implements ICritical } @Override - PositionRestrictions enforceUsingPreviousRestrictions( - PositionRestrictions restrictions) { + PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions) { + GanttDate result = Constraint. initialValue(null) .withConstraints(restrictions.getStartConstraints()) .withConstraints(getStartConstraints()) .applyWithoutFinalCheck(); - if (result != null) { + + if ( result != null ) { enforceRestrictions(result); return biggerThan(result, adapter.getEndDateFor(task)); } + return restrictions; } private void enforceRestrictions(GanttDate result) { - if (!result.equals(getStartDate(task))) { + if ( !result.equals(getStartDate(task)) ) { adapter.setStartDateFor(task, result); } } @@ -1864,16 +1859,18 @@ public class GanttDiagramGraph> implements ICritical class WeakBackwardsForces extends Forces { @Override - PositionRestrictions enforceUsingPreviousRestrictions( - PositionRestrictions restrictions) { + PositionRestrictions enforceUsingPreviousRestrictions(PositionRestrictions restrictions) { + GanttDate result = Constraint. initialValue(null) .withConstraints(restrictions.getEndConstraints()) .withConstraints(getEndConstraints()) .applyWithoutFinalCheck(); - if (result != null) { + + if ( result != null ) { enforceRestrictions(result); return lessThan(adapter.getStartDate(task), result); } + return restrictions; } @@ -1888,7 +1885,7 @@ public class GanttDiagramGraph> implements ICritical } private void enforceRestrictions(GanttDate newEnd) { - if (!newEnd.equals(getEndDateFor(task))) { + if ( !newEnd.equals(getEndDateFor(task)) ) { adapter.setEndDateFor(task, newEnd); } } @@ -1906,29 +1903,33 @@ public class GanttDiagramGraph> implements ICritical public String toString() { return String.format( "%s, parentRecalculation: %s, predecessors: %s", - taskPoint, parentRecalculation, + taskPoint, + parentRecalculation, asSimpleString(recalculationsCouldAffectThis)); } - private String asSimpleString( - Collection recalculations) { + private String asSimpleString(Collection recalculations) { StringBuilder result = new StringBuilder(); result.append("["); + for (Recalculation each : recalculations) { result.append(each.taskPoint).append(", "); } result.append("]"); + return result.toString(); } @Override public boolean equals(Object obj) { - if (Recalculation.class.isInstance(obj)) { + if ( Recalculation.class.isInstance(obj) ) { Recalculation other = Recalculation.class.cast(obj); + return new EqualsBuilder().append(parentRecalculation, other.parentRecalculation) .append(taskPoint, other.taskPoint) .isEquals(); } + return false; } } @@ -1938,11 +1939,13 @@ public class GanttDiagramGraph> implements ICritical graph.removeVertex(task); topLevelTasks.remove(task); fromChildToParent.remove(task); - if (adapter.isContainer(task)) { + + if ( adapter.isContainer(task) ) { for (V t : adapter.getChildren(task)) { remove(t); } } + topologicalSorter.recalculationNeeded(); enforcer.enforceRestrictionsOn(needingEnforcing); } @@ -1961,24 +1964,20 @@ public class GanttDiagramGraph> implements ICritical } private boolean isForbidden(D dependency) { - if (!adapter.isVisible(dependency)) { - // the invisible dependencies, the ones used to implement container - // behavior are not forbidden + if ( !adapter.isVisible(dependency) ) { + // the invisible dependencies, the ones used to implement container behavior are not forbidden return false; } - boolean endEndDependency = DependencyType.END_END == dependency - .getType(); - boolean startStartDependency = DependencyType.START_START == dependency - .getType(); + boolean endEndDependency = DependencyType.END_END == dependency.getType(); + boolean startStartDependency = DependencyType.START_START == dependency.getType(); V source = adapter.getSource(dependency); V destination = adapter.getDestination(dependency); boolean destinationIsContainer = adapter.isContainer(destination); boolean sourceIsContainer = adapter.isContainer(source); - return (destinationIsContainer && endEndDependency) - || (sourceIsContainer && startStartDependency); + return (destinationIsContainer && endEndDependency) || (sourceIsContainer && startStartDependency); } @@ -1991,14 +1990,15 @@ public class GanttDiagramGraph> implements ICritical } private void add(D dependency, boolean enforceRestrictions) { - if (isForbidden(dependency)) { + if ( isForbidden(dependency) ) { return; } + V source = adapter.getSource(dependency); V destination = adapter.getDestination(dependency); graph.addEdge(source, destination, dependency); topologicalSorter.recalculationNeeded(); - if (enforceRestrictions) { + if ( enforceRestrictions ) { enforceRestrictions(destination); } } @@ -2016,16 +2016,17 @@ public class GanttDiagramGraph> implements ICritical } public List getTasks() { - return new ArrayList(graph.vertexSet()); + return new ArrayList<>(graph.vertexSet()); } public List getVisibleDependencies() { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); for (D dependency : graph.edgeSet()) { - if (adapter.isVisible(dependency)) { + if ( adapter.isVisible(dependency) ) { result.add(dependency); } } + return result; } @@ -2038,15 +2039,17 @@ public class GanttDiagramGraph> implements ICritical } public List getInitialTasks() { - List result = new ArrayList(); + List result = new ArrayList<>(); for (V task : graph.vertexSet()) { int dependencies = graph.inDegreeOf(task); - if ((dependencies == 0) - || (dependencies == getNumberOfIncomingDependenciesByType( - task, DependencyType.END_END))) { + + if ( (dependencies == 0) || + (dependencies == getNumberOfIncomingDependenciesByType(task, DependencyType.END_END)) ) { + result.add(task); } } + return result; } @@ -2055,18 +2058,20 @@ public class GanttDiagramGraph> implements ICritical } public Set getOutgoingTasksFor(V task) { - Set result = new HashSet(); + Set result = new HashSet<>(); for (D dependency : graph.outgoingEdgesOf(task)) { result.add(adapter.getDestination(dependency)); } + return result; } public Set getIncomingTasksFor(V task) { - Set result = new HashSet(); + Set result = new HashSet<>(); for (D dependency : graph.incomingEdgesOf(task)) { result.add(adapter.getSource(dependency)); } + return result; } @@ -2076,11 +2081,11 @@ public class GanttDiagramGraph> implements ICritical private boolean isSomeVisibleAndNotEndEnd(Set dependencies) { for (D each : dependencies) { - if (!each.getType().equals(DependencyType.END_END) - && adapter.isVisible(each)) { + if ( !each.getType().equals(DependencyType.END_END) && adapter.isVisible(each) ) { return true; } } + return false; } @@ -2090,22 +2095,23 @@ public class GanttDiagramGraph> implements ICritical private boolean isSomeVisibleAndNotStartStart(Set dependencies) { for (D each : dependencies) { - if (!each.getType().equals(DependencyType.START_START) - && adapter.isVisible(each)) { + if ( !each.getType().equals(DependencyType.START_START) && adapter.isVisible(each) ) { return true; } } + return false; } public List getLatestTasks() { - List tasks = new ArrayList(); + List tasks = new ArrayList<>(); for (V task : graph.vertexSet()) { int dependencies = graph.outDegreeOf(task); - if ((dependencies == 0) - || (dependencies == getNumberOfOutgoingDependenciesByType( - task, DependencyType.START_START))) { + + if ( (dependencies == 0) || + (dependencies == getNumberOfOutgoingDependenciesByType(task, DependencyType.START_START)) ) { + tasks.add(task); } } @@ -2113,60 +2119,63 @@ public class GanttDiagramGraph> implements ICritical return tasks; } - private int getNumberOfIncomingDependenciesByType(V task, - DependencyType dependencyType) { + private int getNumberOfIncomingDependenciesByType(V task, DependencyType dependencyType) { int count = 0; for (D dependency : graph.incomingEdgesOf(task)) { - if (adapter.getType(dependency).equals(dependencyType)) { + if ( adapter.getType(dependency).equals(dependencyType) ) { count++; } } + return count; } - private int getNumberOfOutgoingDependenciesByType(V task, - DependencyType dependencyType) { + private int getNumberOfOutgoingDependenciesByType(V task, DependencyType dependencyType) { int count = 0; for (D dependency : graph.outgoingEdgesOf(task)) { - if (adapter.getType(dependency).equals(dependencyType)) { + if ( adapter.getType(dependency).equals(dependencyType) ) { count++; } } + return count; } public boolean isContainer(V task) { - if (task == null) { + if ( task == null ) { return false; } + return adapter.isContainer(task); } public boolean contains(V container, V task) { - if ((container == null) || (task == null)) { + if ( (container == null) || (task == null) ) { return false; } - if (adapter.isContainer(container)) { + + if ( adapter.isContainer(container) ) { return adapter.getChildren(container).contains(task); } + return false; } public boolean doesNotProvokeLoop(D dependency) { - Set reachableFromDestination = destinationPoint(dependency) - .getReachable(); + Set reachableFromDestination = destinationPoint(dependency).getReachable(); for (TaskPoint each : reachableFromDestination) { - if (each.sendsModificationsThrough(dependency)) { + + if ( each.sendsModificationsThrough(dependency) ) { return false; } } + return true; } TaskPoint destinationPoint(D dependency) { V destination = getDependencyDestination(dependency); - return new TaskPoint(destination, - getDestinationPoint(dependency.getType())); + return new TaskPoint(destination, getDestinationPoint(dependency.getType())); } private Point getDestinationPoint(DependencyType type) { @@ -2196,13 +2205,11 @@ public class GanttDiagramGraph> implements ICritical } private V getDependencySource(D dependency) { - return isScheduleForward() ? adapter.getSource(dependency) : adapter - .getDestination(dependency); + return isScheduleForward() ? adapter.getSource(dependency) : adapter.getDestination(dependency); } private V getDependencyDestination(D dependency) { - return isScheduleForward() ? adapter.getDestination(dependency) - : adapter.getSource(dependency); + return isScheduleForward() ? adapter.getDestination(dependency) : adapter.getSource(dependency); } TaskPoint allPointsPotentiallyModified(V task) { @@ -2224,8 +2231,10 @@ public class GanttDiagramGraph> implements ICritical Validate.notNull(entryPoint); this.task = task; this.entryPoint = entryPoint; - this.pointsModified = isDominatingPoint(entryPoint) ? EnumSet.of( - Point.START, Point.END) : EnumSet.of(entryPoint); + + this.pointsModified = + isDominatingPoint(entryPoint) ? EnumSet.of(Point.START, Point.END) : EnumSet.of(entryPoint); + this.isContainer = adapter.isContainer(task); } @@ -2237,19 +2246,21 @@ public class GanttDiagramGraph> implements ICritical @Override public boolean equals(Object obj) { - if (TaskPoint.class.isInstance(obj)) { + if ( TaskPoint.class.isInstance(obj) ) { TaskPoint other = TaskPoint.class.cast(obj); - return new EqualsBuilder().append(task, other.task) + + return new EqualsBuilder() + .append(task, other.task) .append(pointsModified, other.pointsModified) .isEquals(); } + return false; } @Override public int hashCode() { - return new HashCodeBuilder().append(task).append(pointsModified) - .toHashCode(); + return new HashCodeBuilder().append(task).append(pointsModified).toHashCode(); } public boolean areAllPointsPotentiallyModified() { @@ -2257,8 +2268,7 @@ public class GanttDiagramGraph> implements ICritical } public boolean somePointPotentiallyModified() { - return pointsModified.contains(Point.START) - || pointsModified.contains(Point.END); + return pointsModified.contains(Point.START) || pointsModified.contains(Point.END); } public boolean onlyModifies(Point point) { @@ -2266,110 +2276,109 @@ public class GanttDiagramGraph> implements ICritical } Set getReachable() { - Set result = new HashSet(); - Queue pending = new LinkedList(); + Set result = new HashSet<>(); + Queue pending = new LinkedList<>(); result.add(this); pending.offer(this); + while (!pending.isEmpty()) { TaskPoint current = pending.poll(); Set immendiate = current.getImmediateSuccessors(); + for (TaskPoint each : immendiate) { - if (!result.contains(each)) { + if ( !result.contains(each) ) { result.add(each); pending.offer(each); } } } + return result; } public boolean isImmediatelyDerivedFrom(TaskPoint other) { - return this.task.equals(other.task) - && other.pointsModified.containsAll(this.pointsModified); + return this.task.equals(other.task) && other.pointsModified.containsAll(this.pointsModified); } private Set cachedInmmediateSuccesors = null; public Set getImmediateSuccessors() { - if (cachedInmmediateSuccesors != null) { + if ( cachedInmmediateSuccesors != null ) { return cachedInmmediateSuccesors; } - Set result = new HashSet(); + Set result = new HashSet<>(); result.addAll(getImmediatelyDerivedOnSameTask()); Set candidates = immediateDependencies(); for (D each : candidates) { - if (this.sendsModificationsThrough(each)) { + if ( this.sendsModificationsThrough(each) ) { result.add(destinationPoint(each)); } } - return cachedInmmediateSuccesors = Collections - .unmodifiableSet(result); + + return cachedInmmediateSuccesors = Collections.unmodifiableSet(result); } private Set cachedImmediatePredecessors = null; public Set getImmediatePredecessors() { - if (cachedImmediatePredecessors != null) { + if ( cachedImmediatePredecessors != null ) { return cachedImmediatePredecessors; } - Set result = new HashSet(); - if (!isDominatingPoint(entryPoint)) { + + Set result = new HashSet<>(); + if ( !isDominatingPoint(entryPoint) ) { TaskPoint dominating = allPointsPotentiallyModified(task); assert isDominatingPoint(dominating.entryPoint); assert this.isImmediatelyDerivedFrom(dominating); result.add(dominating); } + for (D each : immediateIncomingDependencies()) { - if (this.receivesModificationsThrough(each)) { + if ( this.receivesModificationsThrough(each) ) { TaskPoint sourcePoint = sourcePoint(each); result.add(sourcePoint); } } - return cachedImmediatePredecessors = Collections - .unmodifiableSet(result); + + return cachedImmediatePredecessors = Collections.unmodifiableSet(result); } private Collection getImmediatelyDerivedOnSameTask() { for (Point each : pointsModified) { - if (isDominatingPoint(each)) { - return Collections.singletonList(new TaskPoint(task, each - .getOther())); + if ( isDominatingPoint(each) ) { + return Collections.singletonList(new TaskPoint(task, each.getOther())); } } + return Collections.emptyList(); } private Set immediateDependencies() { - return isScheduleForward() ? graph.outgoingEdgesOf(this.task) - : graph.incomingEdgesOf(this.task); + return isScheduleForward() ? graph.outgoingEdgesOf(this.task) : graph.incomingEdgesOf(this.task); } private Set immediateIncomingDependencies() { - return isScheduleForward() ? graph.incomingEdgesOf(this.task) - : graph.outgoingEdgesOf(this.task); + return isScheduleForward() ? graph.incomingEdgesOf(this.task) : graph.outgoingEdgesOf(this.task); } public boolean sendsModificationsThrough(D dependency) { V source = getDependencySource(dependency); - Point dependencySourcePoint = getSourcePoint(adapter - .getType(dependency)); + Point dependencySourcePoint = getSourcePoint(adapter.getType(dependency)); - return source.equals(task) - && (!isContainer || pointsModified - .contains(dependencySourcePoint)); + return source.equals(task) && (!isContainer || pointsModified.contains(dependencySourcePoint)); } private Point getSourcePoint(DependencyType type) { Point[] sourceAndDestination = type.getSourceAndDestination(); + return sourceAndDestination[isScheduleForward() ? 0 : 1]; } private boolean receivesModificationsThrough(D dependency) { V destination = getDependencyDestination(dependency); - Point destinationPoint = getDestinationPoint(adapter - .getType(dependency)); + Point destinationPoint = getDestinationPoint(adapter.getType(dependency)); return destination.equals(task) && entryPoint == destinationPoint; } @@ -2383,6 +2392,7 @@ public class GanttDiagramGraph> implements ICritical while (fromChildToParent.containsKey(result)) { result = fromChildToParent.get(result); } + return result; } @@ -2416,9 +2426,10 @@ public class GanttDiagramGraph> implements ICritical @Override public List getChildren(V task) { - if (!isContainer(task)) { + if ( !isContainer(task) ) { return Collections.emptyList(); } + return adapter.getChildren(task); } diff --git a/libreplan-webapp/pom.xml b/libreplan-webapp/pom.xml index edb76d9f7..3da9ba644 100644 --- a/libreplan-webapp/pom.xml +++ b/libreplan-webapp/pom.xml @@ -444,6 +444,7 @@ javax.servlet-api
+ javax.mail @@ -488,7 +489,7 @@ org.jgrapht - jgrapht-jdk1.5 + jgrapht-core diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java b/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java index 861d6e590..ed73cdc73 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/I18nHelper.java @@ -40,23 +40,21 @@ public class I18nHelper { private static Locale defaultLang = Locale.ENGLISH; - private static HashMap localesCache = new HashMap(); + private static HashMap localesCache = new HashMap<>(); public static I18n getI18n() { setPreferredLocale(); Locale locale = Locales.getCurrent(); - if (localesCache.keySet().contains(locale)) { + if ( localesCache.keySet().contains(locale) ) { return localesCache.get(locale); } - I18n i18n = I18nFactory.getI18n(I18nHelper.class, locale, - org.xnap.commons.i18n.I18nFactory.FALLBACK); + I18n i18n = I18nFactory.getI18n(I18nHelper.class, locale, org.xnap.commons.i18n.I18nFactory.FALLBACK); // The language returned is not the same as the requested by the user - if (!locale.getLanguage().equals( - i18n.getResources().getLocale().getLanguage())) { + if ( !locale.getLanguage().equals(i18n.getResources().getLocale().getLanguage()) ) { // Force it to be default language i18n = getDefaultI18n(); } @@ -67,11 +65,10 @@ public class I18nHelper { private static void setPreferredLocale() { Execution execution = Executions.getCurrent(); - if (execution != null) { + if ( execution != null ) { Locale userLocale = getUserLocale(); - Charsets.setPreferredLocale((HttpSession) execution.getSession() - .getNativeSession(), userLocale); - if (userLocale != null) { + Charsets.setPreferredLocale((HttpSession) execution.getSession().getNativeSession(), userLocale); + if ( userLocale != null ) { Locales.setThreadLocal(userLocale); } } @@ -79,18 +76,17 @@ public class I18nHelper { private static Locale getUserLocale() { User user = UserUtil.getUserFromSession(); - if (user != null) { - return user.getApplicationLanguage().getLocale(); - } - return null; + + return (user != null) ? user.getApplicationLanguage().getLocale() : null; } private static I18n getDefaultI18n() { I18n i18n = localesCache.get(defaultLang); - if (i18n == null) { - i18n = I18nFactory.getI18n(I18nHelper.class, defaultLang, - org.xnap.commons.i18n.I18nFactory.FALLBACK); + + if ( i18n == null ) { + i18n = I18nFactory.getI18n(I18nHelper.class, defaultLang, org.xnap.commons.i18n.I18nFactory.FALLBACK); } + return i18n; } @@ -114,8 +110,7 @@ public class I18nHelper { return getI18n().tr(text, o1, o2, o3); } - public static String _(String text, Object o1, Object o2, Object o3, - Object o4) { + public static String _(String text, Object o1, Object o2, Object o3, Object o4) { return getI18n().tr(text, o1, o2, o3, o4); } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java index b048af54a..d0d437025 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/CustomMenuController.java @@ -111,8 +111,7 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { this.disabled = disabled; } - public CustomMenuItem(String name, String url, - List children) { + public CustomMenuItem(String name, String url, List children) { this.name = name; this.unencodedURL = url; this.encodedURL = Executions.getCurrent().encodeURL(url); @@ -135,20 +134,22 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { public boolean contains(String requestPath) { for (CustomMenuItem item : thisAndChildren()) { - if (requestContains(requestPath, item.unencodedURL)) { + if ( requestContains(requestPath, item.unencodedURL) ) { return true; } } + return false; } private List thisAndChildren() { - List items = new ArrayList(); + List items = new ArrayList<>(); items.add(this); items.addAll(children); for (CustomMenuItem child : children) { items.addAll(child.children); } + return items; } @@ -167,14 +168,12 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { } private static IGlobalViewEntryPoints findGlobalViewEntryPoints() { - return (IGlobalViewEntryPoints) getSpringContext().getBean( - "globalView", IGlobalViewEntryPoints.class); + return getSpringContext().getBean("globalView", IGlobalViewEntryPoints.class); } private static WebApplicationContext getSpringContext() { Execution current = Executions.getCurrent(); - HttpServletRequest request = (HttpServletRequest) current - .getNativeRequest(); + HttpServletRequest request = (HttpServletRequest) current.getNativeRequest(); ServletContext context = request.getSession().getServletContext(); return WebApplicationContextUtils.getWebApplicationContext(context); @@ -185,7 +184,7 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { private IGlobalViewEntryPoints globalView; public CustomMenuController() { - this.firstLevel = new ArrayList(); + this.firstLevel = new ArrayList<>(); this.globalView = findGlobalViewEntryPoints(); initializeMenu(); activateCurrentOne(); @@ -193,28 +192,38 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { } private void activateCurrentOne() { - String requestPath = Executions.getCurrent().getDesktop() - .getRequestPath(); + String requestPath = Executions.getCurrent().getDesktop().getRequestPath(); + for (CustomMenuItem ci : this.firstLevel) { - if (ci.contains(requestPath)) { + + if ( ci.contains(requestPath) ) { + ci.setActive(true); + for (CustomMenuItem child : ci.children) { - if (child.contains(requestPath)) { + + if ( child.contains(requestPath) ) { + child.setActive(true); + for (CustomMenuItem c : child.children) { - if (c.contains(requestPath)) { + + if ( c.contains(requestPath) ) { + c.setActive(true); return; } } + return; } } + return; } } - if (requestPath.isEmpty()) { + if ( requestPath.isEmpty() ) { CustomMenuItem item = this.firstLevel.get(0); item.setActive(true); item.children.get(0).setActive(true); @@ -225,27 +234,26 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { return OnZKDesktopRegistry.getLocatorFor(IMenuItemsRegister.class); } - private CustomMenuController topItem(String name, String url, - String helpUri, Collection items) { - return topItem(name, url, helpUri, - items.toArray(new CustomMenuItem[items.size()])); + private CustomMenuController topItem(String name, String url, String helpUri, + Collection items) { + + return topItem(name, url, helpUri, items.toArray(new CustomMenuItem[items.size()])); } - private CustomMenuController topItem(String name, String url, - String helpUri, - CustomMenuItem... items) { + private CustomMenuController topItem(String name, String url, String helpUri, CustomMenuItem... items) { return topItem(name, url, helpUri, false, items); } - private CustomMenuController topItem(String name, String url, - String helpLink, - boolean disabled, CustomMenuItem... items) { + private CustomMenuController topItem(String name, String url, String helpLink, boolean disabled, + CustomMenuItem... items) { + CustomMenuItem parent = new CustomMenuItem(name, url, disabled); parent.setHelpLink(helpLink); this.firstLevel.add(parent); for (CustomMenuItem child : items) { parent.appendChildren(child); } + return this; } @@ -253,296 +261,316 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { return new CustomMenuItem(name, url, helpLink); } - private CustomMenuItem subItem(String name, ICapture urlCapture, - String helpLink) { - return new CustomMenuItem(name, EntryPointsHandler.capturePath(urlCapture), - helpLink); + private CustomMenuItem subItem(String name, ICapture urlCapture, String helpLink) { + return new CustomMenuItem(name, EntryPointsHandler.capturePath(urlCapture), helpLink); } public void initializeMenu() { - List planningItems = new ArrayList(); - if (SecurityUtils.isSuperuserOrRolePlanningOrHasAnyAuthorization()) { - planningItems.add(subItem(_("Company view"), new ICapture() { - @Override - public void capture() { - globalView.goToCompanyScheduling(); - } - }, "01-introducion.html")); - planningItems.add(subItem(_("Projects"), new ICapture() { - @Override - public void capture() { - globalView.goToOrdersList(); - } - }, "01-introducion.html#id2")); + List planningItems = new ArrayList<>(); + if ( SecurityUtils.isSuperuserOrRolePlanningOrHasAnyAuthorization() ) { + + planningItems.add( + subItem( + _("Company view"), + new ICapture() { + @Override + public void capture() { + globalView.goToCompanyScheduling(); + } + }, + "01-introducion.html")); + + planningItems.add(subItem( + _("Projects"), + new ICapture() { + @Override + public void capture() { + globalView.goToOrdersList(); + } + }, + "01-introducion.html#id2")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING)) { - planningItems.add(subItem(_("Resources Load"), new ICapture() { - @Override - public void capture() { - globalView.goToCompanyLoad(); - } - }, "01-introducion.html#id1")); - planningItems.add(subItem(_("Queue-based Resources"), new ICapture() { - @Override - public void capture() { - globalView.goToLimitingResources(); - } - }, "01-introducion.html")); + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PLANNING) ) { + planningItems.add(subItem( + _("Resources Load"), + new ICapture() { + @Override + public void capture() { + globalView.goToCompanyLoad(); + } + }, + "01-introducion.html#id1")); + + planningItems.add(subItem( + _("Queue-based Resources"), + new ICapture() { + @Override + public void capture() { + globalView.goToLimitingResources(); + } + }, + "01-introducion.html")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TEMPLATES)) { - planningItems.add(subItem(_("Templates"), - "/templates/templates.zul", "")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TEMPLATES) ) { + planningItems.add(subItem(_("Templates"), "/templates/templates.zul", "")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_IMPORT_PROJECTS)) { + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_IMPORT_PROJECTS) ) { // In order of see the Import project option in the menu - planningItems.add(subItem(_("Import project"), - "/orders/imports/projectImport.zul", "")); + planningItems.add(subItem(_("Import project"), "/orders/imports/projectImport.zul", "")); } - //TODO There is some problem here! - /*planningItems.add(subItem(_("Logs"), new ICapture() { - @Override - public void capture() { - globalView.goToLogs(); - } - }, "01-asd"));*/ - - if (!planningItems.isEmpty()) { + if ( !planningItems.isEmpty() ) { topItem(_("Planning"), "/planner/index.zul", "", planningItems); } - List resourcesItems = new ArrayList(); - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_WORKERS)) { - resourcesItems.add(subItem(_("Workers"), + List resourcesItems = new ArrayList<>(); + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_WORKERS) ) { + resourcesItems.add(subItem( + _("Workers"), "/resources/worker/worker.zul", "05-recursos.html#xesti-n-de-traballadores")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MACHINES)) { - resourcesItems.add(subItem(_("Machines"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MACHINES) ) { + resourcesItems.add(subItem( + _("Machines"), "/resources/machine/machines.zul", "05-recursos.html#xesti-n-de-m-quinas")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_VIRTUAL_WORKERS)) { - resourcesItems.add(subItem(_("Virtual Workers"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_VIRTUAL_WORKERS) ) { + resourcesItems.add(subItem( + _("Virtual Workers"), "/resources/worker/virtualWorkers.zul", "05-recursos.html#xesti-n-de-traballadores")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CALENDARS)) { - resourcesItems.add(subItem(_("Calendars"), - "/calendars/calendars.zul", "03-calendarios.html")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CALENDARS) ) { + resourcesItems.add(subItem(_("Calendars"), "/calendars/calendars.zul", "03-calendarios.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_CALENDAR_EXCEPTION_DAYS)) { - resourcesItems.add(subItem(_("Calendar Exception Days"), - "/excetiondays/exceptionDays.zul", "")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CALENDAR_EXCEPTION_DAYS) ) { + resourcesItems.add(subItem(_("Calendar Exception Days"), "/excetiondays/exceptionDays.zul", "")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CRITERIA)) { - resourcesItems.add(subItem(_("Criteria"), - "/resources/criterions/criterions.zul", - "02-criterios.html#id1")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_CRITERIA) ) { + resourcesItems.add(subItem(_("Criteria"), "/resources/criterions/criterions.zul", "02-criterios.html#id1")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_PROGRESS_TYPES)) { - resourcesItems.add(subItem(_("Progress Types"), - "/advance/advanceTypes.zul", "04-avances.html#id1")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROGRESS_TYPES) ) { + resourcesItems.add(subItem(_("Progress Types"), "/advance/advanceTypes.zul", "04-avances.html#id1")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_LABELS)) { - resourcesItems.add(subItem(_("Labels"), "/labels/labelTypes.zul", - "10-etiquetas.html")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_LABELS) ) { + resourcesItems.add(subItem(_("Labels"), "/labels/labelTypes.zul", "10-etiquetas.html")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MATERIALS)) { - resourcesItems.add(subItem(_("Materials"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MATERIALS) ) { + resourcesItems.add(subItem( + _("Materials"), "/materials/materials.zul", "11-materiales.html#administraci-n-de-materiais")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_MATERIAL_UNITS)) { - resourcesItems.add(subItem(_("Material Units"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MATERIAL_UNITS) ) { + resourcesItems.add(subItem( + _("Material Units"), "/unittypes/unitTypes.zul", "11-materiales.html#administraci-n-de-materiais")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_QUALITY_FORMS)) { - resourcesItems - .add(subItem(_("Quality Forms"), - "/qualityforms/qualityForms.zul", - "12-formularios-calidad.html#administraci-n-de-formularios-de-calidade")); - } - if (!resourcesItems.isEmpty()) { - topItem(_("Resources"), "/resources/worker/worker.zul", "", - resourcesItems); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_QUALITY_FORMS) ) { + resourcesItems.add(subItem( + _("Quality Forms"), + "/qualityforms/qualityForms.zul", + "12-formularios-calidad.html#administraci-n-de-formularios-de-calidade")); } - List costItems = new ArrayList(); - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS)) { - costItems.add(subItem(_("Timesheets"), - "/workreports/workReport.zul", "09-partes.html#id3")); + if ( !resourcesItems.isEmpty() ) { + topItem(_("Resources"), "/resources/worker/worker.zul", "", resourcesItems); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS_TEMPLATES)) { - costItems.add(subItem(_("Timesheets Templates"), - "/workreports/workReportTypes.zul", "09-partes.html#id2")); + + List costItems = new ArrayList<>(); + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS) ) { + costItems.add(subItem(_("Timesheets"), "/workreports/workReport.zul", "09-partes.html#id3")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEET_LINES_LIST)) { - costItems.add(subItem(_("Timesheet Lines List"), - "/workreports/workReportQuery.zul", "09-partes.html#id4")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEETS_TEMPLATES) ) { + costItems.add(subItem( + _("Timesheets Templates"), + "/workreports/workReportTypes.zul", + "09-partes.html#id2")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EXPENSES)) { - costItems.add(subItem(_("Expenses"), - "/expensesheet/expenseSheet.zul", "")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TIMESHEET_LINES_LIST) ) { + costItems.add(subItem( + _("Timesheet Lines List"), + "/workreports/workReportQuery.zul", + "09-partes.html#id4")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_COST_CATEGORIES)) { - costItems.add(subItem(_("Cost Categories"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EXPENSES) ) { + costItems.add(subItem(_("Expenses"), "/expensesheet/expenseSheet.zul", "")); + } + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_COST_CATEGORIES) ) { + costItems.add(subItem( + _("Cost Categories"), "/costcategories/costCategory.zul", "14-custos.html#categor-as-de-custo")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_HOURS_TYPES)) { - costItems.add(subItem(_("Hours Types"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_HOURS_TYPES) ) { + costItems.add(subItem( + _("Hours Types"), "/typeofworkhours/typeOfWorkHours.zul", "14-custos.html#administraci-n-de-horas-traballadas")); } - if (!costItems.isEmpty()) { + + if ( !costItems.isEmpty() ) { topItem(_("Cost"), "/workreports/workReport.zul", "", costItems); } - List configurationItems = new ArrayList(); - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MAIN_SETTINGS)) { - configurationItems - .add(subItem(_("Main Settings"), - "/common/configuration.zul", - "16-ldap-authentication.html")); + List configurationItems = new ArrayList<>(); + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MAIN_SETTINGS) ) { + configurationItems.add(subItem( + _("Main Settings"), + "/common/configuration.zul", + "16-ldap-authentication.html")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS)) { - configurationItems.add(subItem(_("User Accounts"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS) ) { + configurationItems.add(subItem( + _("User Accounts"), "/users/users.zul", "13-usuarios.html#administraci-n-de-usuarios")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROFILES)) { - configurationItems.add(subItem(_("Profiles"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROFILES) ) { + configurationItems.add(subItem( + _("Profiles"), "/profiles/profiles.zul", "13-usuarios.html#administraci-n-de-perfiles")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_JOB_SCHEDULING)) { - configurationItems.add(subItem(_("Job Scheduling"), - "/common/job_scheduling.zul", - "19-scheduler.html")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_JOB_SCHEDULING) ) { + configurationItems.add(subItem(_("Job Scheduling"), "/common/job_scheduling.zul", "19-scheduler.html")); } - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EDIT_EMAIL_TEMPLATES)) { - configurationItems.add(subItem(_("Edit E-mail Templates"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_EDIT_EMAIL_TEMPLATES) ) { + configurationItems.add(subItem( + _("Edit E-mail Templates"), "/email/email_templates.zul", "email-templates.html")); } - if (!configurationItems.isEmpty()) { - topItem(_("Configuration"), "/common/configuration.zul", "", - configurationItems); + if ( !configurationItems.isEmpty() ) { + topItem(_("Configuration"), "/common/configuration.zul", "", configurationItems); } - List communicationsItems = new ArrayList(); - if (SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_COMPANIES)) { - communicationsItems.add(subItem(_("Companies"), - "/externalcompanies/externalcompanies.zul", "")); + List communicationsItems = new ArrayList<>(); + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_COMPANIES) ) { + communicationsItems.add(subItem(_("Companies"), "/externalcompanies/externalcompanies.zul", "")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_SUBCONTRACTORS)) { - communicationsItems.add(subItem(_("Send To Subcontractors"), - "/subcontract/subcontractedTasks.zul", "")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_SUBCONTRACTORS) ) { + communicationsItems.add(subItem(_("Send To Subcontractors"), "/subcontract/subcontractedTasks.zul", "")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_SUBCONTRACTORS)) { - communicationsItems.add(subItem(_("Received From Subcontractors"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_SUBCONTRACTORS) ) { + communicationsItems.add(subItem( + _("Received From Subcontractors"), "/subcontract/subcontractorCommunications.zul", "")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_CUSTOMERS)) { - communicationsItems.add(subItem(_("Send To Customers"), - "/subcontract/reportAdvances.zul", "")); - } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_CUSTOMERS)) { - communicationsItems.add(subItem(_("Received From Customers"), - "/subcontract/customerCommunications.zul", "")); - } - if (!communicationsItems.isEmpty()) { - topItem(_("Communications"), - "/externalcompanies/externalcompanies.zul", "", - communicationsItems); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_SEND_TO_CUSTOMERS) ) { + communicationsItems.add(subItem(_("Send To Customers"), "/subcontract/reportAdvances.zul", "")); } - List reportsItems = new ArrayList(); - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_HOURS_WORKED_PER_RESOURCE_REPORT)) { - reportsItems.add(subItem(_("Hours Worked Per Resource"), + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_RECEIVED_FROM_CUSTOMERS) ) { + communicationsItems.add(subItem( + _("Received From Customers"), + "/subcontract/customerCommunications.zul", "")); + } + + if ( !communicationsItems.isEmpty() ) { + topItem(_("Communications"), "/externalcompanies/externalcompanies.zul", "", communicationsItems); + } + + List reportsItems = new ArrayList<>(); + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_HOURS_WORKED_PER_RESOURCE_REPORT) ) { + reportsItems.add(subItem( + _("Hours Worked Per Resource"), "/reports/hoursWorkedPerWorkerReport.zul", "15-1-report-hours-worked-by-resource.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_TOTAL_WORKED_HOURS_BY_RESOURCE_IN_A_MONTH_REPORT)) { + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TOTAL_WORKED_HOURS_BY_RESOURCE_IN_A_MONTH_REPORT) ) { reportsItems.add(subItem( _("Total Worked Hours By Resource In A Month"), "/reports/hoursWorkedPerWorkerInAMonthReport.zul", "15-2-total-hours-by-resource-month.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_WORK_AND_PROGRESS_PER_PROJECT_REPORT)) { - reportsItems.add(subItem(_("Work And Progress Per Project"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_WORK_AND_PROGRESS_PER_PROJECT_REPORT) ) { + reportsItems.add(subItem( + _("Work And Progress Per Project"), "/reports/schedulingProgressPerOrderReport.zul", "15-3-work-progress-per-project.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_WORK_AND_PROGRESS_PER_TASK_REPORT)) { - reportsItems.add(subItem(_("Work And Progress Per Task"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_WORK_AND_PROGRESS_PER_TASK_REPORT) ) { + reportsItems.add(subItem( + _("Work And Progress Per Task"), "/reports/workingProgressPerTaskReport.zul", "15-informes.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_ESTIMATED_PLANNED_HOURS_PER_TASK_REPORT)) { - reportsItems.add(subItem(_("Estimated/Planned Hours Per Task"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_ESTIMATED_PLANNED_HOURS_PER_TASK_REPORT) ) { + reportsItems.add(subItem( + _("Estimated/Planned Hours Per Task"), "/reports/completedEstimatedHoursPerTask.zul", "15-informes.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_PROJECT_COSTS_REPORT)) { - reportsItems.add(subItem(_("Project Costs"), - "/reports/orderCostsPerResource.zul", "15-informes.html")); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROJECT_COSTS_REPORT) ) { + reportsItems.add(subItem(_("Project Costs"), "/reports/orderCostsPerResource.zul", "15-informes.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_TASK_SCHEDULING_STATUS_IN_PROJECT_REPORT)) { - reportsItems.add(subItem(_("Task Scheduling Status In Project"), + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_TASK_SCHEDULING_STATUS_IN_PROJECT_REPORT) ) { + reportsItems.add(subItem( + _("Task Scheduling Status In Project"), "/reports/workingArrangementsPerOrderReport.zul", "15-informes.html")); } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_MATERIALS_NEED_AT_DATE_REPORT)) { - reportsItems.add(subItem(_("Materials Needed At Date"), - "/reports/timeLineMaterialReport.zul", "15-informes.html")); - } - if (SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_PROJECT_STATUS_REPORT)) { - reportsItems.add(subItem(_("Project Status"), - "/reports/projectStatusReport.zul", "15-informes.html")); - } - if (!reportsItems.isEmpty()) { - topItem(_("Reports"), "/reports/hoursWorkedPerWorkerReport.zul", - "", reportsItems); + + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_MATERIALS_NEED_AT_DATE_REPORT) ) { + reportsItems.add(subItem( + _("Materials Needed At Date"), + "/reports/timeLineMaterialReport.zul", + "15-informes.html")); } - List personalAreaItems = new ArrayList(); - if (SecurityUtils.isUserInRole(UserRole.ROLE_BOUND_USER)) { - personalAreaItems.add(subItem(_("Home"), - "/myaccount/userDashboard.zul", "")); + if ( SecurityUtils.isSuperuserOrUserInRoles(UserRole.ROLE_PROJECT_STATUS_REPORT) ) { + reportsItems.add(subItem(_("Project Status"), "/reports/projectStatusReport.zul", "15-informes.html")); } - personalAreaItems.add(subItem(_("Preferences"), - "/myaccount/settings.zul", "")); - personalAreaItems.add(subItem(_("Change Password"), - "/myaccount/changePassword.zul", "")); - topItem(_("Personal area"), "/myaccount/userDashboard.zul", "", - personalAreaItems); + + if ( !reportsItems.isEmpty() ) { + topItem(_("Reports"), "/reports/hoursWorkedPerWorkerReport.zul", "", reportsItems); + } + + List personalAreaItems = new ArrayList<>(); + if ( SecurityUtils.isUserInRole(UserRole.ROLE_BOUND_USER) ) { + personalAreaItems.add(subItem(_("Home"), "/myaccount/userDashboard.zul", "")); + } + + personalAreaItems.add(subItem(_("Preferences"), "/myaccount/settings.zul", "")); + personalAreaItems.add(subItem(_("Change Password"), "/myaccount/changePassword.zul", "")); + topItem(_("Personal area"), "/myaccount/userDashboard.zul", "", personalAreaItems); } private Vbox getRegisteredItemsInsertionPoint() { @@ -554,16 +582,25 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { } public List getBreadcrumbsPath() { - List breadcrumbsPath = new ArrayList(); + List breadcrumbsPath = new ArrayList<>(); + for (CustomMenuItem ci : this.firstLevel) { - if (ci.isActiveParent()) { - if ((ci.name != null) && (ci.name != _("Planning"))) { + + if ( ci.isActiveParent() ) { + + if ( (ci.name != null) && (ci.name != _("Planning")) ) { + breadcrumbsPath.add(ci); + for (CustomMenuItem child : ci.children) { - if (child.isActiveParent()) { + + if ( child.isActiveParent() ) { + breadcrumbsPath.add(child); + for (CustomMenuItem c : child.children) { - if (c.isActiveParent()) { + + if ( c.isActiveParent() ) { breadcrumbsPath.add(c); } } @@ -572,53 +609,60 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { } } } + return breadcrumbsPath; } public String getHelpLink() { String helpLink = "index.html"; for (CustomMenuItem ci : this.firstLevel) { - if (ci.isActiveParent()) { - if ((ci.name != null)) { + + if ( ci.isActiveParent() ) { + + if ( (ci.name != null) ) { + for (CustomMenuItem child : ci.children) { - if (child.isActiveParent() - && !child.helpLink.equals("")) { + + if ( child.isActiveParent() && !child.helpLink.equals("") ) { helpLink = child.helpLink; } } } } } + return helpLink; } public List getCustomMenuSecondaryItems() { for (CustomMenuItem ci : this.firstLevel) { - if (ci.isActiveParent()) { + if ( ci.isActiveParent() ) { return ci.getChildren(); } } - return Collections. emptyList(); + + return Collections.emptyList(); } private Button currentOne = null; @Override - public Object addMenuItem(String name, String cssClass, - org.zkoss.zk.ui.event.EventListener eventListener) { + public Object addMenuItem(String name, String cssClass, org.zkoss.zk.ui.event.EventListener eventListener) { Vbox insertionPoint = getRegisteredItemsInsertionPoint(); Button button = new Button(); button.setLabel(_(name)); - if (cssClass != null) { + + if ( cssClass != null ) { toggleDomainCssClass(cssClass, button); } + setDeselectedClass(button); - button.addEventListener(Events.ON_CLICK, doNotCallTwice(button, - eventListener)); + button.addEventListener(Events.ON_CLICK, doNotCallTwice(button, eventListener)); button.setMold("trendy"); insertionPoint.appendChild(button); insertionPoint.appendChild(separator()); + return button; } @@ -631,20 +675,22 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { public void renameMenuItem(Object key, String name, String cssClass) { Button button = (Button) key; button.setLabel(name); - if (cssClass != null) { + + if ( cssClass != null ) { toggleDomainCssClass(cssClass, button); } } private void toggleDomainCssClass(String cssClass, Button button) { - Matcher matcher = perspectiveCssClass - .matcher(button.getSclass() == null ? "" : button.getSclass()); + Matcher matcher = perspectiveCssClass.matcher(button.getSclass() == null ? "" : button.getSclass()); String previousPerspectiveClass; - if (matcher.find()) { + + if ( matcher.find() ) { previousPerspectiveClass = matcher.group(); } else { previousPerspectiveClass = ""; } + button.setSclass(previousPerspectiveClass + " " + cssClass); } @@ -663,36 +709,33 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { togglePerspectiveClassTo(button, "perspective"); } - private static final Pattern perspectiveCssClass = Pattern - .compile("\\bperspective(-\\w+)?\\b"); + private static final Pattern perspectiveCssClass = Pattern.compile("\\bperspective(-\\w+)?\\b"); - private void togglePerspectiveClassTo(final Button button, - String newPerspectiveClass) { - button - .setSclass(togglePerspectiveCssClass(newPerspectiveClass, - button)); + private void togglePerspectiveClassTo(final Button button, String newPerspectiveClass) { + button.setSclass(togglePerspectiveCssClass(newPerspectiveClass, button)); } - private String togglePerspectiveCssClass(String newPerspectiveClass, - Button button) { + private String togglePerspectiveCssClass(String newPerspectiveClass, Button button) { String sclass = button.getSclass(); - if (!perspectiveCssClass.matcher(sclass).find()) { + if ( !perspectiveCssClass.matcher(sclass).find() ) { return newPerspectiveClass + " " + sclass; } else { Matcher matcher = perspectiveCssClass.matcher(sclass); + return matcher.replaceAll(newPerspectiveClass); } } private EventListener doNotCallTwice(final Button button, - final org.zkoss.zk.ui.event.EventListener originalListener) { + final org.zkoss.zk.ui.event.EventListener originalListener) { return new EventListener() { @Override public void onEvent(Event event) throws Exception { - if (currentOne == button) { + if ( currentOne == button ) { return; } + switchCurrentButtonTo(button); originalListener.onEvent(event); } @@ -710,10 +753,10 @@ public class CustomMenuController extends Div implements IMenuItemsRegister { } private void switchCurrentButtonTo(final Button button) { - if (currentOne == button) { + if ( currentOne == button ) { return; } - if (currentOne != null) { + if ( currentOne != null ) { setDeselectedClass(currentOne); } setSelectClass(button); diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/LimitingResourceQueueModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/LimitingResourceQueueModel.java index f5b8d561c..1bb5a1dbf 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/LimitingResourceQueueModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/LimitingResourceQueueModel.java @@ -131,16 +131,16 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { private LimitingResourceQueueElement beingEdited; - private Set toBeRemoved = new HashSet(); + private Set toBeRemoved = new HashSet<>(); - private Set toBeSaved = new HashSet(); + private Set toBeSaved = new HashSet<>(); - private Set parentElementsToBeUpdated = new HashSet(); + private Set parentElementsToBeUpdated = new HashSet<>(); private Scenario master; private Map> toBeSavedDependencies = - new HashMap>(); + new HashMap<>(); @Override @Transactional(readOnly = true) @@ -155,21 +155,18 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { List queues = loadLimitingResourceQueues(); queuesState = new QueuesState(queues, unassigned); final Date startingDate = getEarliestDate(); - Date endDate = (new LocalDate(startingDate)).plusYears(2) - .toDateTimeAtCurrentTime().toDate(); + Date endDate = (new LocalDate(startingDate)).plusYears(2).toDateTimeAtCurrentTime().toDate(); viewInterval = new Interval(startingDate, endDate); Date currentDate = new Date(); - viewInterval = new Interval( - startingDate.after(currentDate) ? currentDate : startingDate, - endDate); + viewInterval = new Interval(startingDate.after(currentDate) ? currentDate : startingDate, endDate); } private Date getEarliestDate() { final LimitingResourceQueueElement element = getEarliestQueueElement(); - return (element != null) ? element.getStartDate() - .toDateTimeAtCurrentTime().toDate() : new Date(); + + return (element != null) ? element.getStartDate().toDateTimeAtCurrentTime().toDate() : new Date(); } private LimitingResourceQueueElement getEarliestQueueElement() { @@ -177,29 +174,27 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { for (LimitingResourceQueue each : queuesState.getQueues()) { LimitingResourceQueueElement element = getFirstLimitingResourceQueueElement(each); - if (element == null) { + if ( element == null ) { continue; } - if (earliestQueueElement == null - || isEarlier(element, earliestQueueElement)) { + + if ( earliestQueueElement == null || isEarlier(element, earliestQueueElement) ) { earliestQueueElement = element; } } + return earliestQueueElement; } - private boolean isEarlier(LimitingResourceQueueElement arg1, - LimitingResourceQueueElement arg2) { + private boolean isEarlier(LimitingResourceQueueElement arg1, LimitingResourceQueueElement arg2) { return (arg1.getStartDate().isBefore(arg2.getStartDate())); } - private LimitingResourceQueueElement getFirstLimitingResourceQueueElement( - LimitingResourceQueue queue) { + private LimitingResourceQueueElement getFirstLimitingResourceQueueElement(LimitingResourceQueue queue) { return getFirstChild(queue.getLimitingResourceQueueElements()); } - private LimitingResourceQueueElement getFirstChild( - SortedSet elements) { + private LimitingResourceQueueElement getFirstChild(SortedSet elements) { return (elements.isEmpty()) ? null : elements.iterator().next(); } @@ -209,22 +204,21 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { * @return */ private List findUnassignedLimitingResourceQueueElements() { - return initializeLimitingResourceQueueElements(limitingResourceQueueElementDAO - .getUnassigned()); + return initializeLimitingResourceQueueElements(limitingResourceQueueElementDAO.getUnassigned()); } private List initializeLimitingResourceQueueElements( List elements) { + for (LimitingResourceQueueElement each : elements) { initializeLimitingResourceQueueElement(each); } + return elements; } - private void initializeLimitingResourceQueueElement( - LimitingResourceQueueElement element) { - ResourceAllocation resourceAllocation = element - .getResourceAllocation(); + private void initializeLimitingResourceQueueElement(LimitingResourceQueueElement element) { + ResourceAllocation resourceAllocation = element.getResourceAllocation(); resourceAllocation.switchToScenario(master); resourceAllocation = initializeResourceAllocationIfNecessary(resourceAllocation); element.setResourceAllocation(resourceAllocation); @@ -233,15 +227,20 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } private void initializeTask(Task task) { - if (hasResourceAllocation(task)) { - ResourceAllocation resourceAllocation = initializeResourceAllocationIfNecessary(getResourceAllocation(task)); + if ( hasResourceAllocation(task) ) { + + ResourceAllocation resourceAllocation = + initializeResourceAllocationIfNecessary(getResourceAllocation(task)); + task.setResourceAllocation(resourceAllocation); } Hibernate.initialize(task); + for (ResourceAllocation each: task.getAllResourceAllocations()) { Hibernate.initialize(each); } + initializeDependencies(task); initializeTaskSource(task.getTaskSource()); initializeRootOrder(task); @@ -251,6 +250,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { for (Dependency each: task.getDependenciesWithThisOrigin()) { Hibernate.initialize(each.getDestination()); } + for (Dependency each: task.getDependenciesWithThisDestination()) { Hibernate.initialize(each.getOrigin()); } @@ -272,11 +272,11 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } // FIXME: Needed to fetch order.name in QueueComponent.composeTooltiptext. - // Try to replace it with a HQL query instead of iterating all the way up - // through order + // Try to replace it with a HQL query instead of iterating all the way up through order private void initializeRootOrder(Task task) { Hibernate.initialize(task.getOrderElement()); OrderElement order = task.getOrderElement(); + do { Hibernate.initialize(order.getParent()); order = order.getParent(); @@ -284,7 +284,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } private void initializeCalendarIfAny(BaseCalendar calendar) { - if (calendar != null) { + if ( calendar != null ) { Hibernate.initialize(calendar); initializeCalendarAvailabilities(calendar); initializeCalendarExceptions(calendar); @@ -313,18 +313,21 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } } - private ResourceAllocation initializeResourceAllocationIfNecessary( - ResourceAllocation resourceAllocation) { - if (resourceAllocation instanceof HibernateProxy) { + private ResourceAllocation initializeResourceAllocationIfNecessary(ResourceAllocation resourceAllocation) { + if ( resourceAllocation instanceof HibernateProxy ) { + resourceAllocation = (ResourceAllocation) ((HibernateProxy) resourceAllocation) .getHibernateLazyInitializer().getImplementation(); - if (resourceAllocation instanceof GenericResourceAllocation) { + + if ( resourceAllocation instanceof GenericResourceAllocation ) { GenericResourceAllocation generic = (GenericResourceAllocation) resourceAllocation; initializeCriteria(generic.getCriterions()); } + Hibernate.initialize(resourceAllocation.getAssignments()); Hibernate.initialize(resourceAllocation.getLimitingResourceQueueElement()); } + return resourceAllocation; } @@ -340,33 +343,31 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } private List loadLimitingResourceQueues() { - return initializeLimitingResourceQueues(limitingResourceQueueDAO - .getAll()); + return initializeLimitingResourceQueues(limitingResourceQueueDAO.getAll()); } - private List initializeLimitingResourceQueues( - List queues) { + private List initializeLimitingResourceQueues(List queues) { for (LimitingResourceQueue each : queues) { initializeLimitingResourceQueue(each); } + return queues; } private void initializeLimitingResourceQueue(LimitingResourceQueue queue) { initializeResourceIfAny(queue.getResource()); - for (LimitingResourceQueueElement each : queue - .getLimitingResourceQueueElements()) { + for (LimitingResourceQueueElement each : queue.getLimitingResourceQueueElements()) { initializeLimitingResourceQueueElement(each); } } private void initializeResourceIfAny(Resource resource) { - if (resource != null) { + if ( resource != null ) { Hibernate.initialize(resource); initializeCalendarIfAny(resource.getCalendar()); resource.getAssignments(); - for (CriterionSatisfaction each : resource - .getCriterionSatisfactions()) { + + for (CriterionSatisfaction each : resource.getCriterionSatisfactions()) { Hibernate.initialize(each); initializeCriterion(each.getCriterion()); } @@ -387,25 +388,28 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { @Override @Transactional(readOnly = true) public boolean userCanRead(Order order, String loginName) { - if (SecurityUtils.isSuperuserOrUserInRoles( + if ( SecurityUtils.isSuperuserOrUserInRoles( UserRole.ROLE_READ_ALL_PROJECTS, UserRole.ROLE_EDIT_ALL_PROJECTS)) { + return true; } + try { User user = userDAO.findByLoginName(loginName); - for (OrderAuthorization authorization : orderAuthorizationDAO - .listByOrderUserAndItsProfiles(order, user)) { - if (authorization.getAuthorizationType() == OrderAuthorizationType.READ_AUTHORIZATION - || authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION) { + for (OrderAuthorization authorization : orderAuthorizationDAO.listByOrderUserAndItsProfiles(order, user)) { + + if ( authorization.getAuthorizationType() == OrderAuthorizationType.READ_AUTHORIZATION || + authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION ) { return true; } } } catch (InstanceNotFoundException e) { // this case shouldn't happen, because it would mean that there // isn't a logged user - // anyway, if it happenned we don't allow the user to pass + // anyway, if it happened we don't allow the user to pass } + return false; } @@ -422,30 +426,31 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { @Override public ZoomLevel calculateInitialZoomLevel() { Interval interval = getViewInterval(); - return ZoomLevel.getDefaultZoomByDates(new LocalDate(interval - .getStart()), new LocalDate(interval.getFinish())); + return ZoomLevel.getDefaultZoomByDates(new LocalDate(interval.getStart()), new LocalDate(interval.getFinish())); } @Override public List assignLimitingResourceQueueElement( LimitingResourceQueueElement externalQueueElement) { - InsertionRequirements requirements = queuesState - .getRequirementsFor(externalQueueElement); + InsertionRequirements requirements = queuesState.getRequirementsFor(externalQueueElement); AllocationSpec allocation = insertAtGap(requirements); - if (allocation == null) { + + if ( allocation == null ) { return Collections.emptyList(); } + applyAllocation(allocation); assert allocation.isValid(); - List result = new ArrayList(); + List result = new ArrayList<>(); result.add(requirements.getElement()); List moved = shift( - queuesState - .getPotentiallyAffectedByInsertion(externalQueueElement), - requirements.getElement(), allocation); + queuesState.getPotentiallyAffectedByInsertion(externalQueueElement), + requirements.getElement(), + allocation); + result.addAll(rescheduleAffectedElementsToSatisfyDependencies(allocation, moved)); return result; @@ -466,19 +471,21 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { private Collection rescheduleAffectedElementsToSatisfyDependencies( AllocationSpec allocation, List moved) { - List result = new ArrayList(); - List toReschedule = new ArrayList(); + List result = new ArrayList<>(); + List toReschedule = new ArrayList<>(); checkAllocationIsAppropriative(false); for (LimitingResourceQueueElement each: moved) { toReschedule.add(unschedule(each)); } - if (allocation.isAppropriative()) { + if ( allocation.isAppropriative() ) { toReschedule.addAll(allocation.getUnscheduledElements()); } + for (LimitingResourceQueueElement each: queuesState.inTopologicalOrder(toReschedule)) { result.addAll(assignLimitingResourceQueueElement(each)); } + checkAllocationIsAppropriative(true); return result; @@ -498,9 +505,11 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { AllocationSpec allocationAlreadyDone) { List allocationsToBeDone = getAllocationsToBeDone( - potentiallyAffectedByInsertion, elementInserted, - allocationAlreadyDone); - List result = new ArrayList(); + potentiallyAffectedByInsertion, + elementInserted, + allocationAlreadyDone); + + List result = new ArrayList<>(); for (AllocationSpec each : allocationsToBeDone) { applyAllocation(each); @@ -515,31 +524,36 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { DirectedGraph potentiallyAffectedByInsertion, LimitingResourceQueueElement elementInserted, AllocationSpec allocationAlreadyDone) { - List result = new ArrayList(); - Map allocationsToBeDoneByElement = new HashMap(); + + List result = new ArrayList<>(); + Map allocationsToBeDoneByElement = new HashMap<>(); allocationsToBeDoneByElement.put(elementInserted, allocationAlreadyDone); List mightNeedShift = withoutElementInserted( elementInserted, QueuesState.topologicalIterator(potentiallyAffectedByInsertion)); + for (LimitingResourceQueueElement each : mightNeedShift) { - AllocationSpec futureAllocation = getAllocationToBeDoneFor( - potentiallyAffectedByInsertion, - allocationsToBeDoneByElement, each); - if (futureAllocation != null) { + + AllocationSpec futureAllocation = + getAllocationToBeDoneFor(potentiallyAffectedByInsertion, allocationsToBeDoneByElement, each); + + if ( futureAllocation != null ) { result.add(futureAllocation); allocationsToBeDoneByElement.put(each, futureAllocation); } } + return result; } private List withoutElementInserted( LimitingResourceQueueElement elementInserted, final TopologicalOrderIterator topologicalIterator) { - List result = QueuesState - .toList(topologicalIterator); + + List result = QueuesState.toList(topologicalIterator); result.remove(elementInserted); + return result; } @@ -547,53 +561,50 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { DirectedGraph potentiallyAffectedByInsertion, Map allocationsToBeDoneByElement, LimitingResourceQueueElement current) { + Validate.isTrue(!current.isDetached()); DateAndHour newStart = current.getStartTime(); DateAndHour newEnd = current.getEndTime(); - Map> incoming = bySource(potentiallyAffectedByInsertion - .incomingEdgesOf(current)); - for (Entry> each : incoming - .entrySet()) { - AllocationSpec previous = allocationsToBeDoneByElement.get(each - .getKey()); - if (previous != null) { - newStart = DateAndHour.max(newStart, getStartFrom(previous, - each.getValue())); - newEnd = DateAndHour.max(newEnd, getEndFrom(previous, each - .getValue())); + + Map> incoming = + bySource(potentiallyAffectedByInsertion.incomingEdgesOf(current)); + + for (Entry> each : incoming.entrySet()) { + AllocationSpec previous = allocationsToBeDoneByElement.get(each.getKey()); + if ( previous != null ) { + newStart = DateAndHour.max(newStart, getStartFrom(previous, each.getValue())); + newEnd = DateAndHour.max(newEnd, getEndFrom(previous, each.getValue())); } } - if (current.getStartTime().compareTo(newStart) == 0 - && current.getEndTime().compareTo(newEnd) == 0) { + + if (current.getStartTime().compareTo(newStart) == 0 && current.getEndTime().compareTo(newEnd) == 0) { return null; } - InsertionRequirements requirements = InsertionRequirements.create( - current, newStart, newEnd); - GapOnQueue gap = Gap.untilEnd(current, newStart).onQueue( - current.getLimitingResourceQueue()); + + InsertionRequirements requirements = InsertionRequirements.create(current, newStart, newEnd); + GapOnQueue gap = Gap.untilEnd(current, newStart).onQueue(current.getLimitingResourceQueue()); AllocationSpec result = requirements.guessValidity(gap); assert result.isValid(); + return result; } - private DateAndHour getStartFrom(AllocationSpec previous, - List edges) { + private DateAndHour getStartFrom(AllocationSpec previous, List edges) { DateAndHour result = null; for (Edge each : edges) { - result = DateAndHour.max(result, - calculateStart(previous, each.type)); + result = DateAndHour.max(result, calculateStart(previous, each.type)); } + return result; } - private DateAndHour calculateStart(AllocationSpec previous, - QueueDependencyType type) { - if (!type.modifiesDestinationStart()) { + private DateAndHour calculateStart(AllocationSpec previous, QueueDependencyType type) { + if ( !type.modifiesDestinationStart() ) { return null; } - return type.calculateDateTargetFrom(previous.getStartInclusive(), previous - .getEndExclusive()); + + return type.calculateDateTargetFrom(previous.getStartInclusive(), previous.getEndExclusive()); } private DateAndHour getEndFrom(AllocationSpec previous, List edges) { @@ -601,27 +612,29 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { for (Edge each : edges) { result = DateAndHour.max(result, calculateEnd(previous, each.type)); } + return result; } - private DateAndHour calculateEnd(AllocationSpec previous, - QueueDependencyType type) { - if (!type.modifiesDestinationEnd()) { + private DateAndHour calculateEnd(AllocationSpec previous, QueueDependencyType type) { + if ( !type.modifiesDestinationEnd() ) { return null; } - return type.calculateDateTargetFrom(previous.getStartInclusive(), - previous.getEndExclusive()); + + return type.calculateDateTargetFrom(previous.getStartInclusive(), previous.getEndExclusive()); } - private Map> bySource( - Collection incomingEdgesOf) { - Map> result = new HashMap>(); + private Map> bySource(Collection incomingEdgesOf) { + Map> result = new HashMap<>(); for (Edge each : incomingEdgesOf) { - if (result.get(each.source) == null) { + + if ( result.get(each.source) == null ) { result.put(each.source, new ArrayList()); } + result.get(each.source).add(each); } + return result; } @@ -631,6 +644,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { */ private AllocationSpec insertAtGap(InsertionRequirements requirements) { AllocationSpec allocationStillNotDone = findAllocationSpecFor(requirements); + return doAppropriativeIfNecessary(allocationStillNotDone, requirements); } @@ -641,69 +655,72 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { * @return */ private AllocationSpec findAllocationSpecFor(InsertionRequirements requirements) { - List potentiallyValidGapsFor = queuesState - .getPotentiallyValidGapsFor(requirements); + List potentiallyValidGapsFor = queuesState.getPotentiallyValidGapsFor(requirements); + return findAllocationSpecFor(potentiallyValidGapsFor, requirements); } private AllocationSpec findAllocationSpecFor(List gapsOnQueue, InsertionRequirements requirements) { boolean generic = requirements.getElement().isGeneric(); for (GapOnQueue each : gapsOnQueue) { - for (GapOnQueue eachSubGap : getSubGaps(each, - requirements.getElement(), generic)) { - AllocationSpec allocation = requirements - .guessValidity(eachSubGap); - if (allocation.isValid()) { + + for (GapOnQueue eachSubGap : getSubGaps(each, requirements.getElement(), generic)) { + + AllocationSpec allocation = requirements.guessValidity(eachSubGap); + + if ( allocation.isValid() ) { return allocation; } } } + return null; } - private AllocationSpec doAppropriativeIfNecessary(AllocationSpec allocation, - InsertionRequirements requirements) { - if (allocation != null) { - if (checkAllocationIsAppropriative() - && requirements.isAppropiativeAllocation(allocation)) { + private AllocationSpec doAppropriativeIfNecessary(AllocationSpec allocation, InsertionRequirements requirements) { + if ( allocation != null ) { + if ( checkAllocationIsAppropriative() && requirements.isAppropiativeAllocation(allocation) ) { return doAppropriativeAllocation(requirements, allocation); } + return allocation; } + return null; } private AllocationSpec insertAtGap(InsertionRequirements requirements, LimitingResourceQueue queue) { AllocationSpec allocationStillNotDone = findAllocationSpecForInQueue(requirements, queue); + return doAppropriativeIfNecessary(allocationStillNotDone, requirements); } - private AllocationSpec findAllocationSpecForInQueue( - InsertionRequirements requirements, LimitingResourceQueue queue) { + private AllocationSpec findAllocationSpecForInQueue(InsertionRequirements requirements, + LimitingResourceQueue queue) { - List potentiallyValidGapsFor = new ArrayList(); + List potentiallyValidGapsFor = new ArrayList<>(); - for (GapOnQueue each : queuesState - .getPotentiallyValidGapsFor(requirements)) { - if (each.getOriginQueue().equals(queue)) { + for (GapOnQueue each : queuesState.getPotentiallyValidGapsFor(requirements)) { + if ( each.getOriginQueue().equals(queue) ) { potentiallyValidGapsFor.add(each); } } + return findAllocationSpecFor(potentiallyValidGapsFor, requirements); } private boolean checkAllocationIsAppropriative = true; - private AllocationSpec doAppropriativeAllocation( - InsertionRequirements requirements, AllocationSpec allocation) { + private AllocationSpec doAppropriativeAllocation(InsertionRequirements requirements, AllocationSpec allocation) { LimitingResourceQueueElement element = requirements.getElement(); List potentiallyValidQueues = getAssignableQueues(element); LimitingResourceQueue queue = earliestQueue(potentiallyValidQueues); - List unscheduled = new ArrayList(); + List unscheduled = new ArrayList<>(); allocation = unscheduleElementsFor(queue, requirements, unscheduled); allocation.setUnscheduledElements(queuesState.inTopologicalOrder(unscheduled)); + return allocation; } @@ -713,26 +730,28 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { * @param potentiallyValidQueues * @return */ - private LimitingResourceQueue earliestQueue( - List potentiallyValidQueues) { + private LimitingResourceQueue earliestQueue(List potentiallyValidQueues) { LimitingResourceQueue result = null; LocalDate latestDate = null; for (LimitingResourceQueue each : potentiallyValidQueues) { - SortedSet elements = each - .getLimitingResourceQueueElements(); - if (!elements.isEmpty()) { + SortedSet elements = each.getLimitingResourceQueueElements(); + + if ( !elements.isEmpty() ) { LocalDate date = elements.last().getEndDate(); - if (latestDate == null || date.isAfter(latestDate)) { + + if ( latestDate == null || date.isAfter(latestDate) ) { latestDate = date; result = each; } } } - if(result == null && !potentiallyValidQueues.isEmpty()) { + + if( result == null && !potentiallyValidQueues.isEmpty() ) { result = potentiallyValidQueues.get(0); } + return result; } @@ -744,11 +763,11 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { return checkAllocationIsAppropriative; } - private List getSubGaps(GapOnQueue each, - LimitingResourceQueueElement element, boolean generic) { - if (generic) { + private List getSubGaps(GapOnQueue each, LimitingResourceQueueElement element, boolean generic) { + if ( generic ) { return each.splitIntoGapsSatisfyingCriteria(element.getCriteria()); } + return Collections.singletonList(each); } @@ -756,15 +775,14 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { applyAllocation(allocationStillNotDone, new IDayAssignmentBehaviour() { @Override - public void allocateDayAssigments(IntraDayDate start, - IntraDayDate end) { + public void allocateDayAssigments(IntraDayDate start, IntraDayDate end) { ResourceAllocation resourceAllocation = getResourceAllocation(allocationStillNotDone); Resource resource = getResource(allocationStillNotDone); - List assignments = allocationStillNotDone.getAssignmentsFor( - resourceAllocation, resource); - resourceAllocation.allocateLimitingDayAssignments(assignments, - start, end); + List assignments = + allocationStillNotDone.getAssignmentsFor(resourceAllocation, resource); + + resourceAllocation.allocateLimitingDayAssignments(assignments, start, end); } private ResourceAllocation getResourceAllocation(AllocationSpec allocation) { @@ -776,35 +794,33 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } }); + return allocationStillNotDone; } - private void applyAllocation(AllocationSpec allocationStillNotDone, - IDayAssignmentBehaviour allocationBehaviour) { + private void applyAllocation(AllocationSpec allocationStillNotDone, IDayAssignmentBehaviour allocationBehaviour) { // Do day allocation allocationBehaviour.allocateDayAssigments( convert(allocationStillNotDone.getStartInclusive()), convert(allocationStillNotDone.getEndExclusive())); - LimitingResourceQueueElement element = allocationStillNotDone - .getElement(); + LimitingResourceQueueElement element = allocationStillNotDone.getElement(); LimitingResourceQueue queue = allocationStillNotDone.getQueue(); // Update start and end time of task - updateStartAndEndTimes(element, allocationStillNotDone - .getStartInclusive(), allocationStillNotDone - .getEndExclusive()); + updateStartAndEndTimes( + element, + allocationStillNotDone.getStartInclusive(), + allocationStillNotDone.getEndExclusive()); // Add to queue and mark as modified addLimitingResourceQueueElementIfNeeded(queue, element); markAsModified(element); } - private DateAndHour getEndsAfterBecauseOfGantt( - LimitingResourceQueueElement queueElement) { - return DateAndHour.from(LocalDate.fromDateFields(queueElement - .getEarliestEndDateBecauseOfGantt())); + private DateAndHour getEndsAfterBecauseOfGantt(LimitingResourceQueueElement queueElement) { + return DateAndHour.from(LocalDate.fromDateFields(queueElement.getEarliestEndDateBecauseOfGantt())); } private List assignLimitingResourceQueueElementToQueueAt( @@ -814,10 +830,10 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { final DateAndHour endsAfter) { // Check if allocation is possible - InsertionRequirements requirements = queuesState.getRequirementsFor( - element, startAt); + InsertionRequirements requirements = queuesState.getRequirementsFor(element, startAt); AllocationSpec allocation = insertAtGap(requirements, queue); - if (!allocation.isValid()) { + + if ( !allocation.isValid() ) { return Collections.emptyList(); } @@ -825,15 +841,13 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { applyAllocation(allocation, new IDayAssignmentBehaviour() { @Override - public void allocateDayAssigments(IntraDayDate start, - IntraDayDate end) { + public void allocateDayAssigments(IntraDayDate start, IntraDayDate end) { - List assignments = LimitingResourceAllocator - .generateDayAssignments( - element.getResourceAllocation(), - queue.getResource(), startAt, endsAfter); - element.getResourceAllocation().allocateLimitingDayAssignments( - assignments, start, end); + List assignments = LimitingResourceAllocator.generateDayAssignments( + element.getResourceAllocation(), + queue.getResource(), startAt, endsAfter); + + element.getResourceAllocation().allocateLimitingDayAssignments(assignments, start, end); } }); @@ -841,12 +855,13 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { assert allocation.isValid(); // Move other tasks to respect dependency constraints - List result = new ArrayList(); + List result = new ArrayList<>(); result.add(requirements.getElement()); List moved = shift( queuesState.getPotentiallyAffectedByInsertion(element), requirements.getElement(), allocation); + result.addAll(rescheduleAffectedElementsToSatisfyDependencies(allocation, moved)); return result; @@ -866,18 +881,18 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } private void markAsModified(LimitingResourceQueueElement element) { - if (!toBeSaved.contains(element)) { + if ( !toBeSaved.contains(element) ) { toBeSaved.add(element); } } - public Gap createGap(Resource resource, DateAndHour startTime, - DateAndHour endTime) { + public Gap createGap(Resource resource, DateAndHour startTime, DateAndHour endTime) { return Gap.create(resource, startTime, endTime); } private void updateStartAndEndTimes(LimitingResourceQueueElement element, - DateAndHour startTime, DateAndHour endTime) { + DateAndHour startTime, + DateAndHour endTime) { element.setStartDate(startTime.getDate()); element.setStartHour(startTime.getHour()); @@ -890,20 +905,19 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { } private IntraDayDate convert(DateAndHour dateAndHour) { - return IntraDayDate.create(dateAndHour.getDate(), - EffortDuration.hours(dateAndHour.getHour())); + return IntraDayDate.create(dateAndHour.getDate(), EffortDuration.hours(dateAndHour.getHour())); } - private void updateStartingAndEndingDate(Task task, IntraDayDate startDate, - IntraDayDate endDate) { + private void updateStartingAndEndingDate(Task task, IntraDayDate startDate, IntraDayDate endDate) { task.setIntraDayStartDate(startDate); task.setIntraDayEndDate(endDate); task.explicityMoved(startDate, endDate); } private void addLimitingResourceQueueElementIfNeeded(LimitingResourceQueue queue, - LimitingResourceQueueElement element) { - if (element.getLimitingResourceQueue() == null) { + LimitingResourceQueueElement element) { + + if ( element.getLimitingResourceQueue() == null ) { queuesState.assignedToQueue(element, queue); } } @@ -921,7 +935,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { private void saveQueueElements() { for (LimitingResourceQueueElement each: toBeSaved) { - if (each != null) { + if ( each != null ) { saveQueueElement(each); } } @@ -931,14 +945,16 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { parentElementsToBeUpdated.clear(); } - private List> getAllocations( - Collection elements) { - List> result = new ArrayList>(); + private List> getAllocations(Collection elements) { + List> result = new ArrayList<>(); + for (LimitingResourceQueueElement each : elements) { - if (each.getResourceAllocation() != null) { + + if ( each.getResourceAllocation() != null ) { result.add(each.getResourceAllocation()); } } + return result; } @@ -946,24 +962,30 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { Long previousId = element.getId(); limitingResourceQueueElementDAO.save(element); limitingResourceQueueDAO.flush(); - if (element.isNewObject()) { + + if ( element.isNewObject() ) { queuesState.idChangedFor(previousId, element); } + element.dontPoseAsTransientObjectAnymore(); element.getResourceAllocation().dontPoseAsTransientObjectAnymore(); + for (DayAssignment each: element.getDayAssignments()) { each.dontPoseAsTransientObjectAnymore(); } - if (toBeSavedDependencies.get(element) != null) { + + if ( toBeSavedDependencies.get(element) != null ) { saveDependencies(toBeSavedDependencies.get(element)); toBeSavedDependencies.remove(element); } + taskDAO.save(getAssociatedTask(element)); } private void updateEndDateForParentTasks() { for(TaskElement task : parentElementsToBeUpdated) { TaskElement parent = task; + while(parent != null) { parent.setIntraDayEndDate(null); parent.initializeDatesIfNeeded(); @@ -988,6 +1010,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { for (LimitingResourceQueueElement each: toBeRemoved) { removeQueueElement(each); } + toBeRemoved.clear(); } @@ -1010,6 +1033,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { for (Dependency each: task.getDependenciesWithThisOrigin()) { removeQueueDependencyIfAny(each); } + for (Dependency each: task.getDependenciesWithThisDestination()) { removeQueueDependencyIfAny(each); } @@ -1017,7 +1041,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { private void removeQueueDependencyIfAny(Dependency dependency) { LimitingResourceQueueDependency queueDependency = dependency.getQueueDependency(); - if (queueDependency != null) { + if ( queueDependency != null ) { queueDependency.getHasAsOrigin().remove(queueDependency); queueDependency.getHasAsDestiny().remove(queueDependency); dependency.setQueueDependency(null); @@ -1055,29 +1079,27 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { * */ @Override - public void removeUnassignedLimitingResourceQueueElement( - LimitingResourceQueueElement element) { + public void removeUnassignedLimitingResourceQueueElement(LimitingResourceQueueElement element) { LimitingResourceQueueElement queueElement = queuesState.getEquivalent(element); queueElement.getResourceAllocation().setLimitingResourceQueueElement(null); - queueElement.getResourceAllocation().getTask() - .removeAllResourceAllocations(); + queueElement.getResourceAllocation().getTask().removeAllResourceAllocations(); queuesState.removeUnassigned(queueElement); markAsRemoved(queueElement); } private void markAsRemoved(LimitingResourceQueueElement element) { - if (toBeSaved.contains(element)) { + if ( toBeSaved.contains(element) ) { toBeSaved.remove(element); } - if (!toBeRemoved.contains(element)) { + + if ( !toBeRemoved.contains(element) ) { toBeRemoved.add(element); } } @Override - public List getAssignableQueues( - LimitingResourceQueueElement element) { + public List getAssignableQueues(LimitingResourceQueueElement element) { return queuesState.getAssignableQueues(element); } @@ -1091,11 +1113,15 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { Validate.notNull(queue); Validate.notNull(startTime); - if (element.getLimitingResourceQueue() != null) { + if ( element.getLimitingResourceQueue() != null ) { unschedule(element); } - return assignLimitingResourceQueueElementToQueueAt(element, queue, - startTime, getEndsAfterBecauseOfGantt(element)); + + return assignLimitingResourceQueueElementToQueueAt( + element, + queue, + startTime, + getEndsAfterBecauseOfGantt(element)); } @Override @@ -1113,30 +1139,31 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { LimitingResourceQueueElement _element, LimitingResourceQueue _queue, DateAndHour allocationTime) { - Set result = new HashSet(); + Set result = new HashSet<>(); LimitingResourceQueue queue = queuesState.getEquivalent(_queue); LimitingResourceQueueElement element = queuesState.getEquivalent(_element); - InsertionRequirements requirements = queuesState - .getRequirementsFor(element, allocationTime); + InsertionRequirements requirements = queuesState.getRequirementsFor(element, allocationTime); - if (element.getLimitingResourceQueue() != null) { + if ( element.getLimitingResourceQueue() != null ) { unschedule(element); } - // Unschedule elements in queue since allocationTime and put them in - // toSchedule - List toSchedule = new ArrayList(); + // Unschedule elements in queue since allocationTime and put them in toSchedule + List toSchedule = new ArrayList<>(); unscheduleElementsFor(queue, requirements, toSchedule); - result.addAll(assignLimitingResourceQueueElementToQueueAt(element, - queue, allocationTime, getEndsAfterBecauseOfGantt(element))); + result.addAll(assignLimitingResourceQueueElementToQueueAt( + element, + queue, + allocationTime, + getEndsAfterBecauseOfGantt(element))); - for (LimitingResourceQueueElement each: queuesState - .inTopologicalOrder(toSchedule)) { + for (LimitingResourceQueueElement each: queuesState.inTopologicalOrder(toSchedule)) { result.addAll(assignLimitingResourceQueueElement(each)); } + return result; } @@ -1156,33 +1183,39 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { private AllocationSpec unscheduleElementsFor( LimitingResourceQueue queue, InsertionRequirements requirements, List result) { + DateAndHour allocationTime = requirements.getEarliestPossibleStart(); - List gapsWithQueueElements = queuesState - .getGapsWithQueueElementsOnQueueSince(queue, allocationTime); + List gapsWithQueueElements = + queuesState.getGapsWithQueueElementsOnQueueSince(queue, allocationTime); return unscheduleElementsFor(gapsWithQueueElements, requirements, result); } private AllocationSpec unscheduleElementsFor(List gaps, - InsertionRequirements requirements, - List result) { + InsertionRequirements requirements, + List result) { - if (gaps.isEmpty()) { + if ( gaps.isEmpty() ) { return null; } + GapOnQueueWithQueueElement first = gaps.get(0); GapOnQueue gapOnQueue = first.getGapOnQueue(); - if (gapOnQueue != null) { + + if ( gapOnQueue != null ) { AllocationSpec allocation = requirements.guessValidity(gapOnQueue); - if (allocation.isValid()) { + if ( allocation.isValid() ) { return allocation; } } + result.add(unschedule(first.getQueueElement())); - if (gaps.size() > 1) { + if ( gaps.size() > 1 ) { gaps.set(1, GapOnQueueWithQueueElement.coalesce(first, gaps.get(1))); } + gaps.remove(0); + return unscheduleElementsFor(gaps, requirements, result); } @@ -1192,18 +1225,20 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { // First element final LimitingResourceQueueElement first = elements.get(0); - if (isAfter(first, allocationTime)) { + + if ( isAfter(first, allocationTime) ) { return first; } // Rest of elements for (int i = 0; i < elements.size(); i++) { final LimitingResourceQueueElement each = elements.get(i); - if (isInTheMiddle(each, allocationTime) || - isAfter(each, allocationTime)) { + + if ( isInTheMiddle(each, allocationTime) || isAfter(each, allocationTime) ) { return each; } } + return null; } @@ -1213,7 +1248,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { LimitingResourceQueueElement oldElement, LimitingResourceQueueElement newElement) { - List result = new ArrayList(); + List result = new ArrayList<>(); boolean needToReassign = oldElement.hasDayAssignments(); @@ -1222,10 +1257,11 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { toBeSaved.remove(oldElement); queuesState.replaceLimitingResourceQueueElement(oldElement, newElement); - if (needToReassign) { + if ( needToReassign ) { result.addAll(assignLimitingResourceQueueElement(newElement)); } - HashSet dependencies = new HashSet(); + + HashSet dependencies = new HashSet<>(); dependencies.addAll(newElement.getDependenciesAsOrigin()); dependencies.addAll(newElement.getDependenciesAsDestiny()); toBeSavedDependencies.put(newElement, dependencies); @@ -1239,10 +1275,12 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { @Override public Set assignLimitingResourceQueueElements( List queueElements) { - Set result = new HashSet(); + + Set result = new HashSet<>(); for (LimitingResourceQueueElement each: queuesState.inTopologicalOrder(queueElements)) { result.addAll(assignLimitingResourceQueueElement(each)); } + return result; } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueuesState.java b/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueuesState.java index d7020cfb4..9f66f5d7a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueuesState.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/limitingresources/QueuesState.java @@ -73,62 +73,70 @@ public class QueuesState { private final Map queuesByResourceId; - private static Map byId( - Collection entities) { - Map result = new HashMap(); + private static Map byId(Collection entities) { + Map result = new HashMap<>(); for (T each : entities) { result.put(each.getId(), each); } + return result; } private static Map byResourceId( Collection limitingResourceQueues) { - Map result = new HashMap(); + + Map result = new HashMap<>(); for (LimitingResourceQueue each : limitingResourceQueues) { result.put(each.getResource().getId(), each); } + return result; } public QueuesState( List limitingResourceQueues, List unassignedLimitingResourceQueueElements) { - this.queues = new ArrayList( - limitingResourceQueues); - this.unassignedElements = new ArrayList( - unassignedLimitingResourceQueueElements); + + this.queues = new ArrayList<>(limitingResourceQueues); + this.unassignedElements = new ArrayList<>(unassignedLimitingResourceQueueElements); this.queuesById = byId(queues); - this.elementsById = byId(allElements(limitingResourceQueues, - unassignedLimitingResourceQueueElements)); + this.elementsById = byId(allElements(limitingResourceQueues, unassignedLimitingResourceQueueElements)); this.queuesByResourceId = byResourceId(limitingResourceQueues); this.graph = buildGraph(getAllElements(unassignedElements, queues)); } private static DirectedGraph buildGraph( List allElements) { - DirectedGraph result = instantiateDirectedGraph(); + + DirectedGraph result = + instantiateDirectedGraph(); + for (LimitingResourceQueueElement each : allElements) { result.addVertex(each); } + for (LimitingResourceQueueElement each : allElements) { - Set dependenciesAsOrigin = each - .getDependenciesAsOrigin(); + Set dependenciesAsOrigin = each.getDependenciesAsOrigin(); + for (LimitingResourceQueueDependency eachDependency : dependenciesAsOrigin) { addDependency(result, eachDependency); } } + return result; } - private static SimpleDirectedGraph instantiateDirectedGraph() { - return new SimpleDirectedGraph( - LimitingResourceQueueDependency.class); + private static SimpleDirectedGraph + instantiateDirectedGraph() { + + return new SimpleDirectedGraph<>(LimitingResourceQueueDependency.class); } private static void addDependency( - DirectedGraph result, + DirectedGraph result, LimitingResourceQueueDependency dependency) { + LimitingResourceQueueElement origin = dependency.getHasAsOrigin(); LimitingResourceQueueElement destination = dependency.getHasAsDestiny(); result.addVertex(origin); @@ -139,22 +147,27 @@ public class QueuesState { private static List getAllElements( List unassigned, List queues) { - List result = new ArrayList(); + + List result = new ArrayList<>(); result.addAll(unassigned); + for (LimitingResourceQueue each : queues) { result.addAll(each.getLimitingResourceQueueElements()); } + return result; } private List allElements( List queues, List unassigned) { - List result = new ArrayList(); + + List result = new ArrayList<>(); for (LimitingResourceQueue each : queues) { result.addAll(each.getLimitingResourceQueueElements()); } result.addAll(unassigned); + return result; } @@ -163,26 +176,26 @@ public class QueuesState { } public ArrayList getQueuesOrderedByResourceName() { - ArrayList result = new ArrayList( - queues); + ArrayList result = new ArrayList<>(queues); Collections.sort(result, new Comparator() { @Override - public int compare(LimitingResourceQueue arg0, - LimitingResourceQueue arg1) { + public int compare(LimitingResourceQueue arg0, LimitingResourceQueue arg1) { - if ((arg0 == null) || (arg0.getResource().getName() == null)) { + if ( (arg0 == null) || (arg0.getResource().getName() == null) ) { return -1; } - if ((arg1 == null) || (arg1.getResource().getName() == null)) { + if ( (arg1 == null) || (arg1.getResource().getName() == null) ) { return 1; } + return (arg0.getResource().getName().toLowerCase() .compareTo(arg1.getResource().getName().toLowerCase())); } }); + return result; } @@ -191,8 +204,7 @@ public class QueuesState { return Collections.unmodifiableList(unassignedElements); } - public void assignedToQueue(LimitingResourceQueueElement element, - LimitingResourceQueue queue) { + public void assignedToQueue(LimitingResourceQueueElement element, LimitingResourceQueue queue) { Validate.isTrue(unassignedElements.contains(element)); queue.addLimitingResourceQueueElement(element); unassignedElements.remove(element); @@ -202,15 +214,15 @@ public class QueuesState { return queuesById.get(queue.getId()); } - public LimitingResourceQueueElement getEquivalent( - LimitingResourceQueueElement element) { + public LimitingResourceQueueElement getEquivalent(LimitingResourceQueueElement element) { return elementsById.get(element.getId()); } public void unassingFromQueue(LimitingResourceQueueElement externalElement) { LimitingResourceQueueElement queueElement = getEquivalent(externalElement); LimitingResourceQueue queue = queueElement.getLimitingResourceQueue(); - if (queue != null) { + + if ( queue != null ) { queue.removeLimitingResourceQueueElement(queueElement); unassignedElements.add(queueElement); } @@ -220,20 +232,19 @@ public class QueuesState { unassignedElements.remove(queueElement); } - public List getAssignableQueues( - LimitingResourceQueueElement element) { - final ResourceAllocation resourceAllocation = element - .getResourceAllocation(); - if (resourceAllocation instanceof SpecificResourceAllocation) { - LimitingResourceQueue queue = getQueueFor(element - .getResource()); + public List getAssignableQueues(LimitingResourceQueueElement element) { + final ResourceAllocation resourceAllocation = element.getResourceAllocation(); + + if ( resourceAllocation instanceof SpecificResourceAllocation ) { + LimitingResourceQueue queue = getQueueFor(element.getResource()); Validate.notNull(queue); return Collections.singletonList(queue); - } else if (resourceAllocation instanceof GenericResourceAllocation) { - final GenericResourceAllocation generic = (GenericResourceAllocation) element - .getResourceAllocation(); + + } else if ( resourceAllocation instanceof GenericResourceAllocation ) { + final GenericResourceAllocation generic = (GenericResourceAllocation) element.getResourceAllocation(); return findQueuesMatchingCriteria(generic); } + throw new RuntimeException("unexpected type of: " + resourceAllocation); } @@ -241,34 +252,33 @@ public class QueuesState { return queuesByResourceId.get(resource.getId()); } - public InsertionRequirements getRequirementsFor( - LimitingResourceQueueElement element) { - List dependenciesStart = new ArrayList(); - List dependenciesEnd = new ArrayList(); + public InsertionRequirements getRequirementsFor(LimitingResourceQueueElement element) { + List dependenciesStart = new ArrayList<>(); + List dependenciesEnd = new ArrayList<>(); fillIncoming(element, dependenciesStart, dependenciesEnd); - return InsertionRequirements.forElement(getEquivalent(element), - dependenciesStart, dependenciesEnd); + + return InsertionRequirements.forElement(getEquivalent(element), dependenciesStart, dependenciesEnd); } - public InsertionRequirements getRequirementsFor( - LimitingResourceQueueElement element, DateAndHour startAt) { - List dependenciesStart = new ArrayList(); - List dependenciesEnd = new ArrayList(); + public InsertionRequirements getRequirementsFor(LimitingResourceQueueElement element, DateAndHour startAt) { + List dependenciesStart = new ArrayList<>(); + List dependenciesEnd = new ArrayList<>(); fillIncoming(element, dependenciesStart, dependenciesEnd); - return InsertionRequirements.forElement(getEquivalent(element), - dependenciesStart, dependenciesEnd, startAt); + + return InsertionRequirements.forElement(getEquivalent(element), dependenciesStart, dependenciesEnd, startAt); } private void fillIncoming(LimitingResourceQueueElement element, List dependenciesStart, List dependenciesEnd) { - Set incoming = graph - .incomingEdgesOf(element); + + Set incoming = graph.incomingEdgesOf(element); for (LimitingResourceQueueDependency each : incoming) { - List addingTo = each - .modifiesDestinationStart() ? dependenciesStart - : dependenciesEnd; - if (each.isOriginNotDetached()) { + + List addingTo = + each.modifiesDestinationStart() ? dependenciesStart : dependenciesEnd; + + if ( each.isOriginNotDetached() ) { addingTo.add(each); } else { fillIncoming(each, addingTo); @@ -276,13 +286,14 @@ public class QueuesState { } } - private void fillIncoming(LimitingResourceQueueDependency next, - List result) { - Set incoming = graph - .incomingEdgesOf(next.getHasAsOrigin()); + private void fillIncoming(LimitingResourceQueueDependency next, List result) { + Set incoming = graph.incomingEdgesOf(next.getHasAsOrigin()); + for (LimitingResourceQueueDependency each : incoming) { - if (each.propagatesThrough(next)) { - if (each.isOriginNotDetached()) { + + if ( each.propagatesThrough(next) ) { + + if ( each.isOriginNotDetached() ) { result.add(each); } else { fillIncoming(each, result); @@ -295,36 +306,36 @@ public class QueuesState { * @return all the gaps that could potentially fit element * ordered by start date */ - public List getPotentiallyValidGapsFor( - InsertionRequirements requirements) { - List assignableQueues = getAssignableQueues(requirements - .getElement()); + public List getPotentiallyValidGapsFor(InsertionRequirements requirements) { + List assignableQueues = getAssignableQueues(requirements.getElement()); List> allGaps = gapsFor(assignableQueues, requirements); + return GapsMergeSort.sort(allGaps); } - private List> gapsFor( - List assignableQueues, - InsertionRequirements requirements) { - List> result = new ArrayList>(); + private List> gapsFor(List assignableQueues, + InsertionRequirements requirements) { + + List> result = new ArrayList<>(); for (LimitingResourceQueue each : assignableQueues) { result.add(each.getGapsPotentiallyValidFor(requirements)); } + return result; } private List findQueuesMatchingCriteria(GenericResourceAllocation generic) { - List result = new ArrayList(); + List result = new ArrayList<>(); ResourceEnum resourceType = generic.getResourceType(); Set criteria = generic.getCriterions(); for (LimitingResourceQueue each : queues) { Resource resource = each.getResource(); - if (resource.getType().equals(resourceType) - && resource.satisfiesCriterionsAtSomePoint(criteria)) { + if ( resource.getType().equals(resourceType) && resource.satisfiesCriterionsAtSomePoint(criteria) ) { result.add(each); } } + return result; } @@ -336,19 +347,19 @@ public class QueuesState { public final QueueDependencyType type; public static Edge from(LimitingResourceQueueDependency dependency) { - return new Edge(dependency.getHasAsOrigin(), - dependency.getHasAsDestiny(), dependency.getType()); + return new Edge(dependency.getHasAsOrigin(), dependency.getHasAsDestiny(), dependency.getType()); } - public static Edge insertionOrder( - LimitingResourceQueueElement element, - LimitingResourceQueueElement contiguousNext) { - return new Edge(element, contiguousNext, - QueueDependencyType.END_START); + public static Edge insertionOrder(LimitingResourceQueueElement element, + LimitingResourceQueueElement contiguousNext) { + + return new Edge(element, contiguousNext, QueueDependencyType.END_START); } private Edge(LimitingResourceQueueElement source, - LimitingResourceQueueElement target, QueueDependencyType type) { + LimitingResourceQueueElement target, + QueueDependencyType type) { + Validate.notNull(source); Validate.notNull(target); Validate.notNull(type); @@ -359,18 +370,20 @@ public class QueuesState { @Override public int hashCode() { - return new HashCodeBuilder().append(source).append(target) - .append(type).toHashCode(); + return new HashCodeBuilder().append(source).append(target).append(type).toHashCode(); } @Override public boolean equals(Object obj) { - if (obj instanceof Edge) { + if ( obj instanceof Edge ) { Edge another = (Edge) obj; - return new EqualsBuilder().append(source, another.source) + + return new EqualsBuilder() + .append(source, another.source) .append(target, another.target) .append(type, another.type).isEquals(); } + return false; } @@ -378,36 +391,41 @@ public class QueuesState { public DirectedGraph getPotentiallyAffectedByInsertion( LimitingResourceQueueElement element) { + DirectedMultigraph result; result = asEdges(onQueues(buildOutgoingGraphFor(getEquivalent(element)))); - Map earliestForEachQueue = earliest(byQueue(result - .vertexSet())); - for (Entry each : earliestForEachQueue - .entrySet()) { + + Map earliestForEachQueue = + earliest(byQueue(result.vertexSet())); + + for (Entry each : earliestForEachQueue.entrySet()) { LimitingResourceQueue queue = each.getKey(); LimitingResourceQueueElement earliest = each.getValue(); - addInsertionOrderOnQueueEdges(result, earliest, - queue.getElementsAfter(earliest)); + addInsertionOrderOnQueueEdges(result, earliest, queue.getElementsAfter(earliest)); } + return result; } private DirectedGraph onQueues( DirectedGraph graph) { + SimpleDirectedGraph result; result = instantiateDirectedGraph(); + for (LimitingResourceQueueDependency each : graph.edgeSet()) { - if (!each.getHasAsOrigin().isDetached() - && !each.getHasAsDestiny().isDetached()) { + if ( !each.getHasAsOrigin().isDetached() && !each.getHasAsDestiny().isDetached() ) { addDependency(result, each); } } + return result; } private DirectedMultigraph asEdges( DirectedGraph graph) { + DirectedMultigraph result = instantiateMultiGraph(); for (LimitingResourceQueueDependency each : graph.edgeSet()) { Edge edge = Edge.from(each); @@ -415,48 +433,53 @@ public class QueuesState { result.addVertex(edge.target); result.addEdge(edge.source, edge.target, edge); } + return result; } private DirectedMultigraph instantiateMultiGraph() { - return new DirectedMultigraph( - Edge.class); + return new DirectedMultigraph<>(Edge.class); } private Map> byQueue( Collection vertexSet) { - Map> result = new HashMap>(); + + Map> result = new HashMap<>(); for (LimitingResourceQueueElement each : vertexSet) { assert each.getLimitingResourceQueue() != null; forQueue(result, each.getLimitingResourceQueue()).add(each); } + return result; } private List forQueue( Map> map, LimitingResourceQueue queue) { + List result = map.get(queue); - if (result == null) { - result = new ArrayList(); + if ( result == null ) { + result = new ArrayList<>(); map.put(queue, result); } + return result; } private static Map earliest( Map> byQueue) { - Map result = new HashMap(); - for (Entry> each : byQueue - .entrySet()) { + + Map result = new HashMap<>(); + for (Entry> each : byQueue.entrySet()) { result.put(each.getKey(), earliest(each.getValue())); } + return result; } - private static LimitingResourceQueueElement earliest( - List list) { + private static LimitingResourceQueueElement earliest(List list) { Validate.isTrue(!list.isEmpty()); + return Collections.min(list, LimitingResourceQueueElement.byStartTimeComparator()); } @@ -464,16 +487,17 @@ public class QueuesState { DirectedGraph result, LimitingResourceQueueElement first, List elements) { + LimitingResourceQueueElement previous = first; for (LimitingResourceQueueElement each : elements) { - // FIXME: Fixs bug #553, "No such vertex in graph". It seems that - // , for some reason, some of the vertexs (queue elements) are not in graph - // at this point - if (!result.containsVertex(previous)) { + // Fixes bug #553, "No such vertex in graph". + // It seems that, for some reason, some of the vertexes (queue elements) are not in graph at this point + if ( !result.containsVertex(previous) ) { result.addVertex(previous); } - if (!result.containsVertex(each)) { + + if ( !result.containsVertex(each) ) { result.addVertex(each); } @@ -490,32 +514,45 @@ public class QueuesState { */ public List getInsertionsToBeDoneFor( LimitingResourceQueueElement externalQueueElement) { + LimitingResourceQueueElement queueElement = getEquivalent(externalQueueElement); - DirectedGraph subGraph = buildOutgoingGraphFor(queueElement); - CycleDetector cycleDetector = cycleDetector(subGraph); - if (cycleDetector.detectCycles()) { + + DirectedGraph subGraph = + buildOutgoingGraphFor(queueElement); + + CycleDetector cycleDetector = + cycleDetector(subGraph); + + if ( cycleDetector.detectCycles() ) { throw new IllegalStateException("subgraph has cycles"); } - List result = new ArrayList(); + + List result = new ArrayList<>(); result.add(queueElement); result.addAll(getElementsOrderedTopologically(subGraph)); unassignFromQueues(result); + return result; } private DirectedGraph buildOutgoingGraphFor( LimitingResourceQueueElement queueElement) { - SimpleDirectedGraph result = instantiateDirectedGraph(); + + SimpleDirectedGraph result = + instantiateDirectedGraph(); + buildOutgoingGraphFor(result, queueElement); + return result; } private void buildOutgoingGraphFor( DirectedGraph result, LimitingResourceQueueElement element) { - Set outgoingEdgesOf = graph - .outgoingEdgesOf(element); + + Set outgoingEdgesOf = graph.outgoingEdgesOf(element); result.addVertex(element); + for (LimitingResourceQueueDependency each : outgoingEdgesOf) { addDependency(result, each); buildOutgoingGraphFor(result, each.getHasAsDestiny()); @@ -524,18 +561,18 @@ public class QueuesState { private CycleDetector cycleDetector( DirectedGraph subGraph) { - return new CycleDetector( - subGraph); + + return new CycleDetector<>(subGraph); } private List getElementsOrderedTopologically( DirectedGraph subGraph) { + return onlyAssigned(toList(topologicalIterator(subGraph))); } - public static TopologicalOrderIterator topologicalIterator( - DirectedGraph subGraph) { - return new TopologicalOrderIterator(subGraph); + public static TopologicalOrderIterator topologicalIterator(DirectedGraph subGraph) { + return new TopologicalOrderIterator<>(subGraph); } public static List toList(final Iterator iterator) { @@ -543,23 +580,24 @@ public class QueuesState { while (iterator.hasNext()) { result.add(iterator.next()); } + return result; } - private List onlyAssigned( - List list) { - List result = new ArrayList(); + private List onlyAssigned(List list) { + List result = new ArrayList<>(); for (LimitingResourceQueueElement each : list) { - if (!each.isDetached()) { + if ( !each.isDetached() ) { result.add(each); } } + return result; } private void unassignFromQueues(List result) { for (LimitingResourceQueueElement each : result) { - if (!each.isDetached()) { + if ( !each.isDetached() ) { unassingFromQueue(each); } } @@ -569,13 +607,13 @@ public class QueuesState { LimitingResourceQueueElement oldElement, LimitingResourceQueueElement newElement) { - if (oldElement.isNewObject()) { + if ( oldElement.isNewObject() ) { elementsById.put(oldElement.getId(), oldElement); } LimitingResourceQueueElement element = getEquivalent(oldElement); - if (element.hasDayAssignments()) { + if ( element.hasDayAssignments() ) { unassingFromQueue(element); } @@ -586,17 +624,18 @@ public class QueuesState { unassignedElements.add(newElement); elementsById.put(newElement.getId(), newElement); graph.addVertex(newElement); + for (LimitingResourceQueueDependency each: newElement.getDependenciesAsOrigin()) { graph.addEdge(each.getHasAsOrigin(), each.getHasAsDestiny(), each); } + for (LimitingResourceQueueDependency each: newElement.getDependenciesAsDestiny()) { graph.addEdge(each.getHasAsOrigin(), each.getHasAsDestiny(), each); } } - public void idChangedFor(Long previousId, - LimitingResourceQueueElement element) { + public void idChangedFor(Long previousId, LimitingResourceQueueElement element) { elementsById.remove(previousId); elementsById.put(element.getId(), element); } @@ -613,21 +652,25 @@ public class QueuesState { */ private DirectedGraph buildSubgraphFor( List queueElements) { - SimpleDirectedGraph result = instantiateDirectedGraph(); + + SimpleDirectedGraph result = + instantiateDirectedGraph(); // Iterate through elements and construct graph for (LimitingResourceQueueElement each : queueElements) { result.addVertex(each); - for (LimitingResourceQueueDependency dependency : each - .getDependenciesAsOrigin()) { - LimitingResourceQueueElement destiny = dependency - .getHasAsDestiny(); - if (queueElements.contains(destiny)) { + + for (LimitingResourceQueueDependency dependency : each.getDependenciesAsOrigin()) { + + LimitingResourceQueueElement destiny = dependency.getHasAsDestiny(); + + if ( queueElements.contains(destiny) ) { // Add source, destiny and edge between them addDependency(result, dependency); } } } + return result; } @@ -644,30 +687,34 @@ public class QueuesState { */ public List getGapsWithQueueElementsOnQueueSince( LimitingResourceQueue queue, DateAndHour allocationTime) { + return gapsWithQueueElementsFor(queue, allocationTime); } private List gapsWithQueueElementsFor( LimitingResourceQueue queue, DateAndHour allocationTime) { - List result = new ArrayList(); + List result = new ArrayList<>(); DateAndHour previousEnd = null; - for (LimitingResourceQueueElement each : queue - .getLimitingResourceQueueElements()) { + for (LimitingResourceQueueElement each : queue.getLimitingResourceQueueElements()) { + DateAndHour startTime = each.getStartTime(); - if (!startTime.isBefore(allocationTime)) { - if (previousEnd == null || startTime.isAfter(previousEnd)) { - Gap gap = Gap.create(queue.getResource(), previousEnd, - startTime); - result.add(GapOnQueueWithQueueElement.create( - gap.onQueue(queue), each)); + + if ( !startTime.isBefore(allocationTime) ) { + + if ( previousEnd == null || startTime.isAfter(previousEnd) ) { + Gap gap = Gap.create(queue.getResource(), previousEnd, startTime); + result.add(GapOnQueueWithQueueElement.create(gap.onQueue(queue), each)); } } + previousEnd = each.getEndTime(); } + Gap gap = Gap.create(queue.getResource(), previousEnd, null); result.add(GapOnQueueWithQueueElement.create(gap.onQueue(queue), null)); + return result; } diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/subcontract/SubcontractServiceTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/subcontract/SubcontractServiceTest.java index 1a025b0a4..22613754a 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/subcontract/SubcontractServiceTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/subcontract/SubcontractServiceTest.java @@ -68,8 +68,12 @@ import org.springframework.transaction.annotation.Transactional; * @author Manuel Rego Casasnovas */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, - WEBAPP_SPRING_CONFIG_FILE, WEBAPP_SPRING_CONFIG_TEST_FILE, +@ContextConfiguration(locations = { + BUSINESS_SPRING_CONFIG_FILE, + + WEBAPP_SPRING_CONFIG_FILE, + WEBAPP_SPRING_CONFIG_TEST_FILE, + WEBAPP_SPRING_SECURITY_CONFIG_FILE, WEBAPP_SPRING_SECURITY_CONFIG_TEST_FILE }) public class SubcontractServiceTest { @@ -106,14 +110,12 @@ public class SubcontractServiceTest { OrderLineDTO orderLineDTO = new OrderLineDTO(); orderLineDTO.name = "Test"; orderLineDTO.code = orderLineCode; - orderLineDTO.initDate = DateConverter - .toXMLGregorianCalendar(new Date()); + orderLineDTO.initDate = DateConverter.toXMLGregorianCalendar(new Date()); return orderLineDTO; } - private ExternalCompany getClientExternalCompanySaved(String name, - String nif) { + private ExternalCompany getClientExternalCompanySaved(String name, String nif) { ExternalCompany externalCompany = ExternalCompany.create(name, nif); externalCompany.setClient(true); @@ -147,8 +149,9 @@ public class SubcontractServiceTest { SubcontractedTaskDataDTO subcontractedTaskDataDTO = new SubcontractedTaskDataDTO(); subcontractedTaskDataDTO.orderElementDTO = orderElementDTO; - List instanceConstraintViolationsList = subcontractService - .subcontract(subcontractedTaskDataDTO).instanceConstraintViolationsList; + List instanceConstraintViolationsList = + subcontractService.subcontract(subcontractedTaskDataDTO).instanceConstraintViolationsList; + assertThat(instanceConstraintViolationsList.size(), equalTo(1)); assertThat(orderDAO.getOrders().size(), equalTo(previous)); @@ -159,14 +162,14 @@ public class SubcontractServiceTest { public void invalidSubcontractedTaskDataWithoutOrderElement() { int previous = orderDAO.getOrders().size(); - ExternalCompany externalCompany = getClientExternalCompanySaved( - "Company", "company-nif"); + ExternalCompany externalCompany = getClientExternalCompanySaved("Company", "company-nif"); SubcontractedTaskDataDTO subcontractedTaskDataDTO = new SubcontractedTaskDataDTO(); subcontractedTaskDataDTO.externalCompanyNif = externalCompany.getNif(); - List instanceConstraintViolationsList = subcontractService - .subcontract(subcontractedTaskDataDTO).instanceConstraintViolationsList; + List instanceConstraintViolationsList = + subcontractService.subcontract(subcontractedTaskDataDTO).instanceConstraintViolationsList; + assertThat(instanceConstraintViolationsList.size(), equalTo(1)); assertThat(orderDAO.getOrders().size(), equalTo(previous)); @@ -180,8 +183,7 @@ public class SubcontractServiceTest { String orderLineCode = "order-line-code"; OrderElementDTO orderElementDTO = givenBasicOrderLineDTO(orderLineCode); - ExternalCompany externalCompany = getClientExternalCompanySaved( - "Company", "company-nif"); + ExternalCompany externalCompany = getClientExternalCompanySaved("Company", "company-nif"); SubcontractedTaskDataDTO subcontractedTaskDataDTO = new SubcontractedTaskDataDTO(); subcontractedTaskDataDTO.orderElementDTO = orderElementDTO; @@ -194,8 +196,9 @@ public class SubcontractServiceTest { subcontractedTaskDataDTO.subcontractedCode = orderCustomerReference; subcontractedTaskDataDTO.subcontractPrice = orderBudget; - List instanceConstraintViolationsList = subcontractService - .subcontract(subcontractedTaskDataDTO).instanceConstraintViolationsList; + List instanceConstraintViolationsList = + subcontractService.subcontract(subcontractedTaskDataDTO).instanceConstraintViolationsList; + assertThat(instanceConstraintViolationsList.size(), equalTo(0)); assertThat(orderDAO.getOrders().size(), equalTo(previous + 1)); @@ -205,14 +208,11 @@ public class SubcontractServiceTest { assertTrue(order.isCodeAutogenerated()); assertNotNull(order.getExternalCode()); assertThat(order.getExternalCode(), equalTo(orderLineCode)); - assertThat(order.getState(), - equalTo(OrderStatusEnum.OUTSOURCED)); + assertThat(order.getState(), equalTo(OrderStatusEnum.OUTSOURCED)); assertThat(order.getWorkHours(), equalTo(0)); - assertThat(order.getCustomer().getId(), - equalTo(externalCompany.getId())); + assertThat(order.getCustomer().getId(), equalTo(externalCompany.getId())); assertThat(order.getName(), equalTo(orderName)); - assertThat(order.getCustomerReference(), - equalTo(orderCustomerReference)); + assertThat(order.getCustomerReference(), equalTo(orderCustomerReference)); assertThat(order.getTotalManualBudget(), equalTo(orderBudget)); List children = order.getChildren(); diff --git a/pom.xml b/pom.xml index f5934e89f..e087ff0e8 100644 --- a/pom.xml +++ b/pom.xml @@ -461,8 +461,8 @@ org.jgrapht - jgrapht-jdk1.5 - 0.7.3 + jgrapht-core + 0.9.2