From 184499d3cc8e300e44eaaa6c3241405003792fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Fri, 18 Feb 2011 14:01:31 +0100 Subject: [PATCH] [Bug #865] Fix bug If the recommended alloation cannot be done, no operations are disabled. FEA: ItEr70S04BugFixing --- .../allocation/AllocationRowsHandler.java | 11 +++++--- .../web/planner/allocation/FormBinder.java | 26 +++++++++++-------- .../allocation/IResourceAllocationModel.java | 4 +++ .../allocation/ResourceAllocationModel.java | 8 ++++-- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java index 07f287b63..63ad238f9 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java @@ -31,11 +31,11 @@ import org.joda.time.LocalDate; import org.navalplanner.business.calendars.entities.ThereAreHoursOnWorkHoursCalculator.CapacityResult; import org.navalplanner.business.orders.entities.HoursGroup; import org.navalplanner.business.planner.entities.CalculatedValue; -import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder; import org.navalplanner.business.planner.entities.ResourceAllocation; -import org.navalplanner.business.planner.entities.ResourceAllocation.AllocationsSpecified.INotFulfilledReceiver; -import org.navalplanner.business.planner.entities.ResourceAllocation.Direction; import org.navalplanner.business.planner.entities.Task; +import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder; +import org.navalplanner.business.planner.entities.ResourceAllocation.Direction; +import org.navalplanner.business.planner.entities.ResourceAllocation.AllocationsSpecified.INotFulfilledReceiver; import org.navalplanner.business.planner.entities.allocationalgorithms.HoursModification; import org.navalplanner.business.planner.entities.allocationalgorithms.ResourcesPerDayModification; import org.navalplanner.business.resources.entities.Criterion; @@ -94,12 +94,13 @@ public class AllocationRowsHandler { addGeneric(resourceType, criteria, resourcesMatched, null); } - public void addGeneric(ResourceEnum resourceType, + public boolean addGeneric(ResourceEnum resourceType, Collection criteria, Collection resourcesMatched, Integer hours) { if (resourcesMatched.isEmpty()) { formBinder.markNoResourcesMatchedByCriterions(resourceType, criteria); + return false; } else { GenericAllocationRow genericAllocationRow = GenericAllocationRow .create(resourceType, criteria, resourcesMatched); @@ -111,9 +112,11 @@ public class AllocationRowsHandler { if (alreadyExistsAllocationFor(resourceType, criteria)) { formBinder.markThereisAlreadyAssignmentWith(resourceType, criteria); + return false; } else { currentRows.add(genericAllocationRow); formBinder.newAllocationAdded(); + return true; } } } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java index 6e8e96700..4c7281596 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/FormBinder.java @@ -680,18 +680,22 @@ public class FormBinder { private void activatingRecommendedAllocation() { allocationRowsHandler.removeAll(); - hoursDistributorForRecommendedAllocation = resourceAllocationModel + ProportionalDistributor distributor = resourceAllocationModel .addDefaultAllocations(); - resourcesPerDayDistributorForRecommendedAllocation = ResourcesPerDay - .distributor(hoursDistributorForRecommendedAllocation); - this.recommendedAllocation = true; - disableIfNeededWorkerSearch(); - applyDisabledRules(); - allHoursInput.addEventListener(Events.ON_CHANGE, - allHoursInputChange); - allResourcesPerDay.addEventListener(Events.ON_CHANGE, - allResourcesPerDayChange); - sumResourcesPerDayOrSetToZero(); + boolean recommendAllocationSuccessful = distributor != null; + if (recommendAllocationSuccessful) { + hoursDistributorForRecommendedAllocation = distributor; + resourcesPerDayDistributorForRecommendedAllocation = ResourcesPerDay + .distributor(hoursDistributorForRecommendedAllocation); + this.recommendedAllocation = true; + disableIfNeededWorkerSearch(); + applyDisabledRules(); + allHoursInput.addEventListener(Events.ON_CHANGE, + allHoursInputChange); + allResourcesPerDay.addEventListener(Events.ON_CHANGE, + allResourcesPerDayChange); + sumResourcesPerDayOrSetToZero(); + } Util.reloadBindings(allocationsGrid); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java index 7360cab1f..ef90b7405 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java @@ -72,6 +72,10 @@ public interface IResourceAllocationModel extends INewAllocationsAdder { T onAllocationContext( IResourceAllocationContext resourceAllocationContext); + /** + * Adds the default allocations, also known as recommended allocation. If it + * can't be done null is returned + */ ProportionalDistributor addDefaultAllocations(); Date getTaskEnd(); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java index c74c54152..50354eade 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java @@ -39,11 +39,11 @@ import org.navalplanner.business.planner.daos.ITaskElementDAO; import org.navalplanner.business.planner.daos.ITaskSourceDAO; import org.navalplanner.business.planner.entities.DayAssignment; import org.navalplanner.business.planner.entities.DerivedAllocation; -import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder; import org.navalplanner.business.planner.entities.GenericResourceAllocation; import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.Task; import org.navalplanner.business.planner.entities.TaskElement; +import org.navalplanner.business.planner.entities.DerivedAllocationGenerator.IWorkerFinder; import org.navalplanner.business.resources.daos.ICriterionDAO; import org.navalplanner.business.resources.daos.IResourceDAO; import org.navalplanner.business.resources.entities.Criterion; @@ -137,9 +137,13 @@ public class ResourceAllocationModel implements IResourceAllocationModel { List resourcesFound = searchModel .searchBy(each.getResourceType()) .byCriteria(each.getCriterions()).execute(); - allocationRowsHandler.addGeneric(each.getResourceType(), + boolean added = allocationRowsHandler.addGeneric(each + .getResourceType(), each.getCriterions(), reloadResources(resourcesFound), each.getHours()); + if (!added) { + return null; + } } return ProportionalDistributor.create(hours); }