Add new query for searching for specific allocations interfering with a criterion
FEA: ItEr70S08CriteriaLoadRefinementItEr69S10
This commit is contained in:
parent
57c10052c1
commit
efb28b8404
3 changed files with 94 additions and 0 deletions
|
|
@ -31,6 +31,7 @@ import org.navalplanner.business.common.daos.IGenericDAO;
|
|||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.SpecificDayAssignment;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
|
@ -74,4 +75,33 @@ public interface IResourceAllocationDAO extends
|
|||
List<Criterion> criterions, Date intervalFilterStartDate,
|
||||
Date intervalFilterEndDate);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* It searches for the {@link SpecificResourceAllocation specific
|
||||
* allocations} that have an assigned resource such that interferes with the
|
||||
* provided criterion. This means that the assigned resource for the
|
||||
* specific allocation satisfies the provided criterion in part or all the
|
||||
* specific allocation.
|
||||
* </p>
|
||||
* <p>
|
||||
* It only returns the allocations for which their tasks overlap
|
||||
* intervalFilterStartDate and intervalFilterEndDate. If any of these
|
||||
* interval parameters is null it's considered that the interval is open
|
||||
* ended. So if you provide both interval filter values as null, all
|
||||
* allocations satisfying the first requirement are returned.
|
||||
* </p>
|
||||
*
|
||||
* @param criterion
|
||||
* must be not <code>null</code>
|
||||
* @param intervalFilterStartDate
|
||||
* It can be <code>null</code>
|
||||
* @param intervalFilterEndDate
|
||||
* It can be <code>null</code>
|
||||
* @return the list of {@link SpecificResourceAllocation specific
|
||||
* allocations} found
|
||||
*/
|
||||
List<SpecificResourceAllocation> findSpecificAllocationsRelatedTo(
|
||||
Criterion criterion, Date intervalFilterStartDate,
|
||||
Date intervalFilterEndDate);
|
||||
|
||||
}
|
||||
|
|
@ -310,4 +310,61 @@ public class ResourceAllocationDAO extends
|
|||
Restrictions.between("day", start, end))).list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpecificResourceAllocation> findSpecificAllocationsRelatedTo(
|
||||
Criterion criterion, Date intervalFilterStartDate,
|
||||
Date intervalFilterEndDate) {
|
||||
String queryString = "select distinct s from SpecificResourceAllocation s "
|
||||
+ "join s.resource r "
|
||||
+ "join r.criterionSatisfactions satisfaction "
|
||||
+ "join satisfaction.criterion c";
|
||||
if (intervalFilterStartDate != null || intervalFilterEndDate != null) {
|
||||
queryString += " inner join s.task t";
|
||||
}
|
||||
queryString += " where c = :criterion";
|
||||
if (intervalFilterEndDate != null) {
|
||||
queryString += " and t.startDate.date <= :intervalFilterEndDate";
|
||||
}
|
||||
if (intervalFilterStartDate != null) {
|
||||
queryString += " and t.endDate.date >= :intervalFilterStartDate";
|
||||
}
|
||||
|
||||
Query query = getSession().createQuery(queryString);
|
||||
query.setParameter("criterion", criterion);
|
||||
|
||||
if (intervalFilterStartDate != null) {
|
||||
query.setParameter("intervalFilterStartDate",
|
||||
asLocalDate(intervalFilterStartDate));
|
||||
}
|
||||
if (intervalFilterEndDate != null) {
|
||||
query.setParameter("intervalFilterEndDate",
|
||||
asLocalDate(intervalFilterEndDate));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<SpecificResourceAllocation> result = query.list();
|
||||
return onlyAllocationsWithActiveCriterion(criterion, result,
|
||||
asLocalDate(intervalFilterStartDate),
|
||||
asLocalDate(intervalFilterEndDate));
|
||||
}
|
||||
|
||||
private static LocalDate asLocalDate(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return LocalDate.fromDateFields(date);
|
||||
}
|
||||
|
||||
private List<SpecificResourceAllocation> onlyAllocationsWithActiveCriterion(
|
||||
Criterion criterion, List<SpecificResourceAllocation> allocations,
|
||||
LocalDate startInclusive, LocalDate endExclusive) {
|
||||
List<SpecificResourceAllocation> result = new ArrayList<SpecificResourceAllocation>();
|
||||
for (SpecificResourceAllocation each : allocations) {
|
||||
if (each.interferesWith(criterion, startInclusive, endExclusive)) {
|
||||
result.add(each);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -388,4 +388,11 @@ public class SpecificResourceAllocation extends
|
|||
return availability.getValidPeriods();
|
||||
}
|
||||
|
||||
public boolean interferesWith(ICriterion criterion,
|
||||
LocalDate startInclusive, LocalDate endExclusive) {
|
||||
List<Interval> intervalsRelatedWith = getIntervalsRelatedWith(
|
||||
criterion, startInclusive, endExclusive);
|
||||
return !intervalsRelatedWith.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue