From 6fed0b1dcbdac3147a00f36b0e30a3e34e68ec60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Mon, 20 Sep 2010 16:38:04 +0200 Subject: [PATCH] Do not require to provide a set of criterions for INewAllocationsAdder#addGeneric Now any criterion collection can work FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04 --- .../components/NewAllocationSelector.java | 11 +++------- .../allocation/AllocationRowsHandler.java | 20 ++++++++++--------- .../web/planner/allocation/FormBinder.java | 4 ++-- .../allocation/GenericAllocationRow.java | 5 +++-- .../allocation/INewAllocationsAdder.java | 3 +-- .../allocation/ResourceAllocationModel.java | 4 ++-- .../allocation/LimitingAllocationRow.java | 5 ++--- .../LimitingResourceAllocationModel.java | 8 +++++--- .../NewAllocationSelectorComboController.java | 4 +--- 9 files changed, 30 insertions(+), 34 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/NewAllocationSelector.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/NewAllocationSelector.java index a41081cd9..7dcded557 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/NewAllocationSelector.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/NewAllocationSelector.java @@ -20,9 +20,7 @@ package org.navalplanner.web.common.components; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.navalplanner.business.resources.entities.Criterion; import org.navalplanner.business.resources.entities.ResourceEnum; @@ -48,10 +46,8 @@ public class NewAllocationSelector extends AllocationSelector { @Override public void addTo(NewAllocationSelectorController controller, INewAllocationsAdder allocationsAdder) { - Set criteria = new HashSet( - controller - .getSelectedCriterions()); - allocationsAdder.addGeneric(ResourceEnum.WORKER, criteria, + allocationsAdder.addGeneric(ResourceEnum.WORKER, + controller.getSelectedCriterions(), controller.getSelectedWorkers()); } @@ -74,8 +70,7 @@ public class NewAllocationSelector extends AllocationSelector { List criteria = controller.getSelectedCriterions(); allocationsAdder.addGeneric( ResourceEnum.MACHINE, - new HashSet(criteria), - controller.getSelectedWorkers()); + criteria, controller.getSelectedWorkers()); } @Override 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 3b816b907..a4e460921 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 @@ -85,24 +85,24 @@ public class AllocationRowsHandler { } public void addGeneric(ResourceEnum resourceType, - Set criterions, + Collection criteria, Collection resourcesMatched) { - addGeneric(resourceType, criterions, resourcesMatched, null); + addGeneric(resourceType, criteria, resourcesMatched, null); } public void addGeneric(ResourceEnum resourceType, - Set criterions, + Collection criteria, Collection resourcesMatched, Integer hours) { if (resourcesMatched.isEmpty()) { - formBinder.markNoResourcesMatchedByCriterions(criterions); + formBinder.markNoResourcesMatchedByCriterions(criteria); } else { GenericAllocationRow genericAllocationRow = GenericAllocationRow - .create(resourceType, criterions, resourcesMatched); + .create(resourceType, criteria, resourcesMatched); if (hours != null) { genericAllocationRow.setHoursToInput(hours); } - if (alreadyExistsAllocationFor(criterions)) { - formBinder.markThereisAlreadyAssignmentWith(criterions); + if (alreadyExistsAllocationFor(criteria)) { + formBinder.markThereisAlreadyAssignmentWith(criteria); } else { currentRows.add(genericAllocationRow); formBinder.newAllocationAdded(); @@ -118,11 +118,13 @@ public class AllocationRowsHandler { return !getAllocationsFor(resource).isEmpty(); } - private boolean alreadyExistsAllocationFor(Set criterions) { + private boolean alreadyExistsAllocationFor( + Collection criterions) { + Set criterionsSet = new HashSet(criterions); List generic = AllocationRow .getGeneric(getCurrentRows()); for (GenericAllocationRow each : generic) { - if (each.hasSameCriterions(criterions)) { + if (each.hasSameCriterions(criterionsSet)) { 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 48f63cd16..e062654c8 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 @@ -28,7 +28,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Set; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; @@ -503,7 +502,8 @@ public class FormBinder { Criterion.getCaptionFor(criterions))); } - public void markThereisAlreadyAssignmentWith(Set criterions) { + public void markThereisAlreadyAssignmentWith( + Collection criterions) { messagesForUser.showMessage(Level.ERROR, _( "already exists an allocation for criteria {0}", Criterion.getCaptionFor(criterions))); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java index 123e70493..ca57540b1 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java @@ -24,6 +24,7 @@ import static org.navalplanner.web.I18nHelper._; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -55,12 +56,12 @@ public class GenericAllocationRow extends AllocationRow { } public static GenericAllocationRow create(ResourceEnum resourceType, - Set criterions, + Collection criterions, Collection resources) { Validate.isTrue(!resources.isEmpty()); Validate.notNull(criterions); GenericAllocationRow result = createDefault(resourceType); - result.criterions = criterions; + result.criterions = new HashSet(criterions); result.resources = new ArrayList(resources); result.setName(Criterion.getCaptionFor(resourceType, criterions)); return result; diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/INewAllocationsAdder.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/INewAllocationsAdder.java index 1a918c4a7..ca0520a1d 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/INewAllocationsAdder.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/INewAllocationsAdder.java @@ -20,7 +20,6 @@ package org.navalplanner.web.planner.allocation; import java.util.Collection; -import java.util.Set; import org.navalplanner.business.resources.entities.Criterion; import org.navalplanner.business.resources.entities.Resource; @@ -35,6 +34,6 @@ public interface INewAllocationsAdder { public void addSpecific(Collection resources); public void addGeneric(ResourceEnum resourceType, - Set criterions, + Collection criteria, Collection resourcesMatched); } 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 c79eb541b..b02cfb21b 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 @@ -139,11 +139,11 @@ public class ResourceAllocationModel implements IResourceAllocationModel { @Override @Transactional(readOnly = true) public void addGeneric(ResourceEnum resourceType, - Set criterions, + Collection criteria, Collection resourcesMatched) { reassociateResourcesWithSession(); List reloadResources = reloadResources(resourcesMatched); - allocationRowsHandler.addGeneric(resourceType, criterions, + allocationRowsHandler.addGeneric(resourceType, criteria, reloadResources); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingAllocationRow.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingAllocationRow.java index 4c2b87f1c..a8da4461f 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingAllocationRow.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingAllocationRow.java @@ -19,8 +19,6 @@ */ package org.navalplanner.web.planner.limiting.allocation; -import static org.navalplanner.business.i18n.I18nHelper._; - import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -100,7 +98,8 @@ public class LimitingAllocationRow { } } - public static LimitingAllocationRow create(Set criteria, + public static LimitingAllocationRow create( + Collection criteria, Collection resources, Task task, int priority) { LimitingAllocationRow result = new LimitingAllocationRow( GenericResourceAllocation.create(task, criteria), task, diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingResourceAllocationModel.java index ce575e727..ad5802c82 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/limiting/allocation/LimitingResourceAllocationModel.java @@ -102,7 +102,8 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat @Override @Transactional(readOnly = true) - public void addGeneric(ResourceEnum resourceType, Set criteria, + public void addGeneric(ResourceEnum resourceType, + Collection criteria, Collection resources) { if (resources.isEmpty()) { getMessagesForUser() @@ -135,7 +136,7 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat } private void addGenericResourceAllocation(ResourceEnum resourceType, - Set criteria, + Collection criteria, Collection resources) { if (isNew(criteria, resources)) { @@ -146,7 +147,8 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat } } - private boolean isNew(Set criteria, Collection resources) { + private boolean isNew(Collection criteria, + Collection resources) { LimitingAllocationRow allocationRow = getLimitingAllocationRow(); if (allocationRow == null || allocationRow.isSpecific()) { diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/search/NewAllocationSelectorComboController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/search/NewAllocationSelectorComboController.java index a65802fcb..1fd0d4fb0 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/search/NewAllocationSelectorComboController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/search/NewAllocationSelectorComboController.java @@ -21,7 +21,6 @@ package org.navalplanner.web.resources.search; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import org.navalplanner.business.resources.entities.Criterion; @@ -126,8 +125,7 @@ public class NewAllocationSelectorComboController extends List criteria = getSelectedCriterions(); List resources = searchResources(criteria); ResourceEnum type = inferType(criteria); - allocationsAdder.addGeneric(type, new HashSet( - criteria), resources); + allocationsAdder.addGeneric(type, criteria, resources); } else { allocationsAdder.addSpecific(getSelectedResources()); }