[Bug #645] Change interface INewAllocationsAdder to require the resource type
This causes the selectors to need to provide a ResourceEnum (resource type). By now it's infered from the criteria, but this solution is ambigous for when the criteria is empty. Several FIXMEs left to remember this issue. FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
parent
72506c6bd8
commit
60c9b6ea9b
5 changed files with 27 additions and 26 deletions
|
|
@ -22,6 +22,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;
|
||||
|
|
@ -47,9 +48,11 @@ public class NewAllocationSelector extends AllocationSelector {
|
|||
@Override
|
||||
public void addTo(NewAllocationSelectorController controller,
|
||||
INewAllocationsAdder allocationsAdder) {
|
||||
allocationsAdder.addGeneric(new HashSet<Criterion>(controller
|
||||
.getSelectedCriterions()), controller
|
||||
.getSelectedWorkers());
|
||||
Set<Criterion> criteria = new HashSet<Criterion>(
|
||||
controller
|
||||
.getSelectedCriterions());
|
||||
allocationsAdder.addGeneric(ResourceEnum.WORKER, criteria,
|
||||
controller.getSelectedWorkers());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -68,9 +71,11 @@ public class NewAllocationSelector extends AllocationSelector {
|
|||
public void addTo(
|
||||
NewAllocationSelectorController controller,
|
||||
INewAllocationsAdder allocationsAdder) {
|
||||
allocationsAdder.addGeneric(new HashSet<Criterion>(controller
|
||||
.getSelectedCriterions()), controller
|
||||
.getSelectedWorkers());
|
||||
List<Criterion> criteria = controller.getSelectedCriterions();
|
||||
allocationsAdder.addGeneric(
|
||||
ResourceEnum.MACHINE,
|
||||
new HashSet<Criterion>(criteria),
|
||||
controller.getSelectedWorkers());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.Set;
|
|||
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.ResourceEnum;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
|
|
@ -33,6 +34,7 @@ public interface INewAllocationsAdder {
|
|||
|
||||
public void addSpecific(Collection<? extends Resource> resources);
|
||||
|
||||
public void addGeneric(Set<Criterion> criterions,
|
||||
public void addGeneric(ResourceEnum resourceType,
|
||||
Set<Criterion> criterions,
|
||||
Collection<? extends Resource> resourcesMatched);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,25 +138,15 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void addGeneric(Set<Criterion> criterions,
|
||||
public void addGeneric(ResourceEnum resourceType,
|
||||
Set<Criterion> criterions,
|
||||
Collection<? extends Resource> resourcesMatched) {
|
||||
reassociateResourcesWithSession();
|
||||
List<Resource> reloadResources = reloadResources(resourcesMatched);
|
||||
// TODO infer the type proviosionally. It must be explicitly specified
|
||||
// to avoid confusions when the criteria is empty
|
||||
allocationRowsHandler.addGeneric(inferType(criterions), criterions,
|
||||
allocationRowsHandler.addGeneric(resourceType, criterions,
|
||||
reloadResources);
|
||||
}
|
||||
|
||||
private static ResourceEnum inferType(
|
||||
Collection<? extends Criterion> criterions) {
|
||||
if (criterions.isEmpty()) {
|
||||
return ResourceEnum.WORKER;
|
||||
}
|
||||
Criterion first = criterions.iterator().next();
|
||||
return first.getType().getResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (currentStartDate != null) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.navalplanner.business.resources.daos.IResourceDAO;
|
|||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.ResourceEnum;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.planner.order.PlanningState;
|
||||
|
|
@ -101,21 +102,22 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
|
|||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void addGeneric(Set<Criterion> criteria,
|
||||
public void addGeneric(ResourceEnum resourceType, Set<Criterion> criteria,
|
||||
Collection<? extends Resource> resources) {
|
||||
if (resources.isEmpty()) {
|
||||
getMessagesForUser()
|
||||
.showMessage(Level.ERROR,
|
||||
_("there are no resources for required criteria: {0}. " +
|
||||
"So the generic allocation can't be added",
|
||||
Criterion.getCaptionFor(criteria)));
|
||||
Criterion.getCaptionFor(resourceType, criteria)));
|
||||
}
|
||||
|
||||
if (resources.size() >= 1) {
|
||||
if (planningState != null) {
|
||||
planningState.reassociateResourcesWithSession();
|
||||
}
|
||||
addGenericResourceAllocation(criteria, reloadResources(resources));
|
||||
addGenericResourceAllocation(resourceType, criteria,
|
||||
reloadResources(resources));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +134,8 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
|
|||
return limitingResourceAllocationController.getMessagesForUser();
|
||||
}
|
||||
|
||||
private void addGenericResourceAllocation(Set<Criterion> criteria,
|
||||
private void addGenericResourceAllocation(ResourceEnum resourceType,
|
||||
Set<Criterion> criteria,
|
||||
Collection<? extends Resource> resources) {
|
||||
|
||||
if (isNew(criteria, resources)) {
|
||||
|
|
|
|||
|
|
@ -125,8 +125,9 @@ public class NewAllocationSelectorComboController extends
|
|||
if (isGeneric()) {
|
||||
List<Criterion> criteria = getSelectedCriterions();
|
||||
List<? extends Resource> resources = searchResources(criteria);
|
||||
allocationsAdder.addGeneric(new HashSet<Criterion>(criteria),
|
||||
resources);
|
||||
ResourceEnum type = inferType(criteria);
|
||||
allocationsAdder.addGeneric(type, new HashSet<Criterion>(
|
||||
criteria), resources);
|
||||
} else {
|
||||
allocationsAdder.addSpecific(getSelectedResources());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue