[Bug #865] Fix bug

If the recommended alloation cannot be done, no operations are
disabled.

FEA: ItEr70S04BugFixing
This commit is contained in:
Óscar González Fernández 2011-02-18 14:01:31 +01:00
parent 0cc3a2a87f
commit 184499d3cc
4 changed files with 32 additions and 17 deletions

View file

@ -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<? extends Criterion> criteria,
Collection<? extends Resource> 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;
}
}
}

View file

@ -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);
}

View file

@ -72,6 +72,10 @@ public interface IResourceAllocationModel extends INewAllocationsAdder {
<T> T onAllocationContext(
IResourceAllocationContext<T> resourceAllocationContext);
/**
* Adds the default allocations, also known as recommended allocation. If it
* can't be done <code>null</code> is returned
*/
ProportionalDistributor addDefaultAllocations();
Date getTaskEnd();

View file

@ -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<? extends Resource> 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);
}