Rename findSatisfyingCriterionsAtSomePoint to findSatisfyingAllCriterionsAtSomePoint and modify behaviour accordingly
The former function was used incorrectly. The new function has the right behaviour. FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
parent
7b0e0b59b1
commit
bc35014aa0
10 changed files with 37 additions and 15 deletions
|
|
@ -507,7 +507,7 @@ public class GenericResourceAllocation extends
|
|||
|
||||
@Override
|
||||
public List<Resource> querySuitableResources(IResourceDAO resourceDAO) {
|
||||
return resourceDAO.findSatisfyingCriterionsAtSomePoint(getCriterions());
|
||||
return resourceDAO.findSatisfyingAllCriterionsAtSomePoint(getCriterions());
|
||||
}
|
||||
|
||||
public static Map<Criterion, List<GenericResourceAllocation>> byCriterion(
|
||||
|
|
|
|||
|
|
@ -60,12 +60,12 @@ public interface IResourceDAO extends IIntegrationEntityDAO<Resource> {
|
|||
boolean limitingResource);
|
||||
|
||||
/**
|
||||
* Returns a list of {@link Resource} satisfying at least one criterion from criterions
|
||||
*
|
||||
* Returns a list of {@link Resource} satisfying all criteria at some point
|
||||
* in time
|
||||
* @param criterions
|
||||
* @return
|
||||
*/
|
||||
List<Resource> findSatisfyingCriterionsAtSomePoint(Collection<? extends Criterion> criterions);
|
||||
List<Resource> findSatisfyingAllCriterionsAtSomePoint(Collection<? extends Criterion> criterions);
|
||||
|
||||
/**
|
||||
* Returns all {@link Machine}
|
||||
|
|
|
|||
|
|
@ -92,14 +92,27 @@ public class ResourceDAO extends IntegrationEntityDAO<Resource> implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> findSatisfyingCriterionsAtSomePoint(
|
||||
public List<Resource> findSatisfyingAllCriterionsAtSomePoint(
|
||||
Collection<? extends Criterion> criterions) {
|
||||
Validate.notNull(criterions);
|
||||
Validate.noNullElements(criterions);
|
||||
if (criterions.isEmpty()) {
|
||||
return list(Resource.class);
|
||||
}
|
||||
return findRelatedWithSomeOfTheCriterions(criterions);
|
||||
return selectSatisfiyingAllAtSomePoint(
|
||||
findRelatedWithSomeOfTheCriterions(criterions), criterions);
|
||||
}
|
||||
|
||||
private List<Resource> selectSatisfiyingAllAtSomePoint(
|
||||
List<Resource> resources,
|
||||
Collection<? extends Criterion> criterions) {
|
||||
List<Resource> result = new ArrayList<Resource>();
|
||||
for (Resource each : resources) {
|
||||
if (each.satisfiesCriterionsAtSomePoint(criterions)) {
|
||||
result.add(each);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -107,8 +120,8 @@ public class ResourceDAO extends IntegrationEntityDAO<Resource> implements
|
|||
Collection<? extends Criterion> criterions) {
|
||||
String strQuery = "SELECT DISTINCT resource "
|
||||
+ "FROM Resource resource "
|
||||
+ "LEFT OUTER JOIN resource.criterionSatisfactions criterionSatisfactions "
|
||||
+ "LEFT OUTER JOIN criterionSatisfactions.criterion criterion "
|
||||
+ "JOIN resource.criterionSatisfactions criterionSatisfactions "
|
||||
+ "JOIN criterionSatisfactions.criterion criterion "
|
||||
+ "WHERE criterion IN (:criterions)";
|
||||
Query query = getSession().createQuery(strQuery);
|
||||
query.setParameterList("criterions", criterions);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ import org.hibernate.validator.InvalidValue;
|
|||
import org.hibernate.validator.Valid;
|
||||
import org.joda.time.Days;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.calendars.entities.AvailabilityTimeLine;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.ICalendar;
|
||||
import org.navalplanner.business.calendars.entities.ResourceCalendar;
|
||||
|
|
@ -54,6 +55,7 @@ import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
|||
import org.navalplanner.business.common.exceptions.MultipleInstancesException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.costcategories.entities.ResourcesCostCategoryAssignment;
|
||||
import org.navalplanner.business.planner.entities.AvailabilityCalculator;
|
||||
import org.navalplanner.business.planner.entities.DayAssignment;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
|
|
@ -967,6 +969,13 @@ public abstract class Resource extends IntegrationEntity {
|
|||
return compositedCriterion.isSatisfiedBy(this);
|
||||
}
|
||||
|
||||
public boolean satisfiesCriterionsAtSomePoint(
|
||||
Collection<? extends Criterion> criterions) {
|
||||
AvailabilityTimeLine availability = AvailabilityCalculator
|
||||
.getCriterionsAvailabilityFor(criterions, this);
|
||||
return !availability.getValidPeriods().isEmpty();
|
||||
}
|
||||
|
||||
@Valid
|
||||
public Set<ResourcesCostCategoryAssignment> getResourcesCostCategoryAssignments() {
|
||||
return resourcesCostCategoryAssignments;
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ abstract class QueueTaskGenerator {
|
|||
private List<Resource> findResources(final Criterion criterion,
|
||||
final IResourceDAO resourcesDAO) {
|
||||
return resourcesDAO
|
||||
.findSatisfyingCriterionsAtSomePoint(Collections
|
||||
.findSatisfyingAllCriterionsAtSomePoint(Collections
|
||||
.singletonList(criterion));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class GenericAllocationRow extends AllocationRow {
|
|||
.getNonConsolidatedResourcePerDay());
|
||||
|
||||
result.criterions = resourceAllocation.getCriterions();
|
||||
result.resources = resourceDAO.findSatisfyingCriterionsAtSomePoint(result.criterions);
|
||||
result.resources = resourceDAO.findSatisfyingAllCriterionsAtSomePoint(result.criterions);
|
||||
result.setName(Criterion.getNames(result.criterions));
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
for (AggregatedHoursGroup each : hoursGroups) {
|
||||
hours[i++] = each.getHours();
|
||||
List<Resource> resourcesFound = resourceDAO
|
||||
.findSatisfyingCriterionsAtSomePoint(each.getCriterions());
|
||||
.findSatisfyingAllCriterionsAtSomePoint(each.getCriterions());
|
||||
allocationRowsHandler.addGeneric(each.getCriterions(),
|
||||
reloadResources(resourcesFound), each.getHours());
|
||||
}
|
||||
|
|
@ -259,7 +259,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
List<Resource> allSatisfyingCriterions;
|
||||
if (!requiredCriterions.isEmpty()) {
|
||||
allSatisfyingCriterions = resourceDAO
|
||||
.findSatisfyingCriterionsAtSomePoint(requiredCriterions);
|
||||
.findSatisfyingAllCriterionsAtSomePoint(requiredCriterions);
|
||||
} else {
|
||||
allSatisfyingCriterions = new ArrayList<Resource>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ abstract class LoadPeriodGenerator {
|
|||
private List<Resource> findResources(final Criterion criterion,
|
||||
final IResourceDAO resourcesDAO) {
|
||||
return resourcesDAO
|
||||
.findSatisfyingCriterionsAtSomePoint(Collections
|
||||
.findSatisfyingAllCriterionsAtSomePoint(Collections
|
||||
.singletonList(criterion));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -919,7 +919,7 @@ public class ResourceLoadModel implements IResourceLoadModel {
|
|||
}
|
||||
else {
|
||||
resources =resourcesDAO
|
||||
.findSatisfyingCriterionsAtSomePoint(criteriaToShow());
|
||||
.findSatisfyingAllCriterionsAtSomePoint(criteriaToShow());
|
||||
}
|
||||
for (Resource resource : resources) {
|
||||
resourcesDAO.reattach(resource);
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public class ResourceSearchModel implements IResourceSearchModel {
|
|||
List<Criterion> criteria, boolean limitingResource) {
|
||||
Set<Resource> result = new HashSet<Resource>();
|
||||
for (Resource each : resourceDAO
|
||||
.findSatisfyingCriterionsAtSomePoint(criteria)) {
|
||||
.findSatisfyingAllCriterionsAtSomePoint(criteria)) {
|
||||
if (each.isLimitingResource() == limitingResource) {
|
||||
result.add(each);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue