Remove method.
It was dangerous because it returned only the resources at the present time. It looks like an usual functionality but a lot of times is mistakenly used when findSatisfyingAllCriterionsAtSomePoint should be used instead. FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
parent
bc35014aa0
commit
873d3b6311
3 changed files with 4 additions and 40 deletions
|
|
@ -49,16 +49,6 @@ public interface IResourceDAO extends IIntegrationEntityDAO<Resource> {
|
|||
*/
|
||||
List<Resource> findResourcesRelatedTo(List<Task> tasks);
|
||||
|
||||
/**
|
||||
* Returns a list of {@link Resource} satisfying all criterions
|
||||
*
|
||||
* @param criterions
|
||||
* @return
|
||||
*/
|
||||
List<Resource> findSatisfyingAllCriterions(
|
||||
Collection<? extends Criterion> criterions,
|
||||
boolean limitingResource);
|
||||
|
||||
/**
|
||||
* Returns a list of {@link Resource} satisfying all criteria at some point
|
||||
* in time
|
||||
|
|
|
|||
|
|
@ -128,32 +128,6 @@ public class ResourceDAO extends IntegrationEntityDAO<Resource> implements
|
|||
return (List<Resource>) query.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> findSatisfyingAllCriterions(
|
||||
Collection<? extends Criterion> criteria,
|
||||
boolean limitingResource) {
|
||||
// FIXME don't query all resources. One possible solution is to do a
|
||||
// query for the first criteria and then filter in memory for the
|
||||
// remaining
|
||||
return selectSatisfiyingAllCriterions(new ArrayList<Resource>(
|
||||
getResources()), criteria, limitingResource);
|
||||
}
|
||||
|
||||
private List<Resource> selectSatisfiyingAllCriterions(
|
||||
List<Resource> resources,
|
||||
Collection<? extends Criterion> criterions,
|
||||
Boolean limitingResource) {
|
||||
|
||||
List<Resource> result = new ArrayList<Resource>();
|
||||
for (Resource each : resources) {
|
||||
if (limitingResource.equals(each.isLimitingResource())
|
||||
&& each.satisfiesCriterions(criterions)) {
|
||||
result.add(each);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> findResourcesRelatedTo(List<Task> taskElements) {
|
||||
if (taskElements.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@
|
|||
package org.navalplanner.business.test.resources.daos;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
|
||||
|
|
@ -117,7 +117,7 @@ public class ResourceDAOTest {
|
|||
Collection<Criterion> criterions = createCriterions();
|
||||
createAndSaveResourceSatisfyingAllCriterions(criterions);
|
||||
List<Resource> result = resourceDAO
|
||||
.findSatisfyingAllCriterions(criterions, false);
|
||||
.findSatisfyingAllCriterionsAtSomePoint(criterions);
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
|
@ -173,9 +173,9 @@ public class ResourceDAOTest {
|
|||
criterions.add(createCriterion("criterion3"));
|
||||
|
||||
List<Resource> result = resourceDAO
|
||||
.findSatisfyingAllCriterions(criterions, false);
|
||||
.findSatisfyingAllCriterionsAtSomePoint(criterions);
|
||||
assertNotNull(result);
|
||||
assertTrue(result.size() != 1);
|
||||
assertThat(result.size(), not(equalTo(1)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue