Do not require to provide a set of criterions for INewAllocationsAdder#addGeneric

Now any criterion collection can work

FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
Óscar González Fernández 2010-09-20 16:38:04 +02:00
parent 60c9b6ea9b
commit 6fed0b1dcb
9 changed files with 30 additions and 34 deletions

View file

@ -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<Criterion> criteria = new HashSet<Criterion>(
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<Criterion> criteria = controller.getSelectedCriterions();
allocationsAdder.addGeneric(
ResourceEnum.MACHINE,
new HashSet<Criterion>(criteria),
controller.getSelectedWorkers());
criteria, controller.getSelectedWorkers());
}
@Override

View file

@ -85,24 +85,24 @@ public class AllocationRowsHandler {
}
public void addGeneric(ResourceEnum resourceType,
Set<Criterion> criterions,
Collection<? extends Criterion> criteria,
Collection<? extends Resource> resourcesMatched) {
addGeneric(resourceType, criterions, resourcesMatched, null);
addGeneric(resourceType, criteria, resourcesMatched, null);
}
public void addGeneric(ResourceEnum resourceType,
Set<Criterion> criterions,
Collection<? extends Criterion> criteria,
Collection<? extends Resource> 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<Criterion> criterions) {
private boolean alreadyExistsAllocationFor(
Collection<? extends Criterion> criterions) {
Set<Criterion> criterionsSet = new HashSet<Criterion>(criterions);
List<GenericAllocationRow> generic = AllocationRow
.getGeneric(getCurrentRows());
for (GenericAllocationRow each : generic) {
if (each.hasSameCriterions(criterions)) {
if (each.hasSameCriterions(criterionsSet)) {
return true;
}
}

View file

@ -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<Criterion> criterions) {
public void markThereisAlreadyAssignmentWith(
Collection<? extends Criterion> criterions) {
messagesForUser.showMessage(Level.ERROR, _(
"already exists an allocation for criteria {0}",
Criterion.getCaptionFor(criterions)));

View file

@ -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<Criterion> criterions,
Collection<? extends Criterion> criterions,
Collection<? extends Resource> resources) {
Validate.isTrue(!resources.isEmpty());
Validate.notNull(criterions);
GenericAllocationRow result = createDefault(resourceType);
result.criterions = criterions;
result.criterions = new HashSet<Criterion>(criterions);
result.resources = new ArrayList<Resource>(resources);
result.setName(Criterion.getCaptionFor(resourceType, criterions));
return result;

View file

@ -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<? extends Resource> resources);
public void addGeneric(ResourceEnum resourceType,
Set<Criterion> criterions,
Collection<? extends Criterion> criteria,
Collection<? extends Resource> resourcesMatched);
}

View file

@ -139,11 +139,11 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
@Override
@Transactional(readOnly = true)
public void addGeneric(ResourceEnum resourceType,
Set<Criterion> criterions,
Collection<? extends Criterion> criteria,
Collection<? extends Resource> resourcesMatched) {
reassociateResourcesWithSession();
List<Resource> reloadResources = reloadResources(resourcesMatched);
allocationRowsHandler.addGeneric(resourceType, criterions,
allocationRowsHandler.addGeneric(resourceType, criteria,
reloadResources);
}

View file

@ -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<Criterion> criteria,
public static LimitingAllocationRow create(
Collection<? extends Criterion> criteria,
Collection<? extends Resource> resources, Task task, int priority) {
LimitingAllocationRow result = new LimitingAllocationRow(
GenericResourceAllocation.create(task, criteria), task,

View file

@ -102,7 +102,8 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
@Override
@Transactional(readOnly = true)
public void addGeneric(ResourceEnum resourceType, Set<Criterion> criteria,
public void addGeneric(ResourceEnum resourceType,
Collection<? extends Criterion> criteria,
Collection<? extends Resource> resources) {
if (resources.isEmpty()) {
getMessagesForUser()
@ -135,7 +136,7 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
}
private void addGenericResourceAllocation(ResourceEnum resourceType,
Set<Criterion> criteria,
Collection<? extends Criterion> criteria,
Collection<? extends Resource> resources) {
if (isNew(criteria, resources)) {
@ -146,7 +147,8 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
}
}
private boolean isNew(Set<Criterion> criteria, Collection<? extends Resource> resources) {
private boolean isNew(Collection<? extends Criterion> criteria,
Collection<? extends Resource> resources) {
LimitingAllocationRow allocationRow = getLimitingAllocationRow();
if (allocationRow == null || allocationRow.isSpecific()) {

View file

@ -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<Criterion> criteria = getSelectedCriterions();
List<? extends Resource> resources = searchResources(criteria);
ResourceEnum type = inferType(criteria);
allocationsAdder.addGeneric(type, new HashSet<Criterion>(
criteria), resources);
allocationsAdder.addGeneric(type, criteria, resources);
} else {
allocationsAdder.addSpecific(getSelectedResources());
}