ItEr37S08CUCreacionUnidadesPlanificacionItEr36S11: Being more generous receiving arguments for searching workers satisfying criterions
This commit is contained in:
parent
3583676f60
commit
b3bdbc738d
4 changed files with 12 additions and 9 deletions
|
|
@ -20,11 +20,12 @@
|
|||
|
||||
package org.navalplanner.business.resources.daos;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.ICriterion;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -49,7 +50,7 @@ public interface IWorkerDAO extends IGenericDAO<Worker, Long> {
|
|||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Worker> findByNameAndCriterions(String name, List<Criterion> criterions);
|
||||
List<Worker> findByNameAndCriterions(String name, Collection<? extends ICriterion> criterions);
|
||||
|
||||
/**
|
||||
* Returns workers which name/NIF partially matches with name
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@
|
|||
package org.navalplanner.business.resources.daos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.ICriterion;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -69,7 +69,7 @@ public class WorkerDAO extends GenericDAOHibernate<Worker, Long>
|
|||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Worker> findByNameAndCriterions(String name,
|
||||
List<Criterion> criterions) {
|
||||
Collection<? extends ICriterion> criterions) {
|
||||
|
||||
// Find workers by name
|
||||
List<Worker> workers;
|
||||
|
|
@ -87,7 +87,7 @@ public class WorkerDAO extends GenericDAOHibernate<Worker, Long>
|
|||
// Filter by criterion
|
||||
final List<Worker> result = new ArrayList<Worker>();
|
||||
for (Worker worker : workers) {
|
||||
if (worker.satisfiesCriterions(new HashSet(criterions))) {
|
||||
if (worker.satisfiesCriterions(criterions)) {
|
||||
result.add(worker);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ public class CriterionCompounder {
|
|||
return new CriterionCompounder();
|
||||
}
|
||||
|
||||
public static CriterionCompounder buildAnd(List<ICriterion> criterions) {
|
||||
public static CriterionCompounder buildAnd(
|
||||
Collection<? extends ICriterion> criterions) {
|
||||
CriterionCompounder compounder = new CriterionCompounder();
|
||||
for (ICriterion criterion : criterions) {
|
||||
compounder = compounder.and(criterion);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
package org.navalplanner.business.resources.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.hibernate.validator.NotNull;
|
||||
|
|
@ -101,7 +101,8 @@ public class Worker extends Resource {
|
|||
this.nif = nif;
|
||||
}
|
||||
|
||||
public boolean satisfiesCriterions(Set<Criterion> criterions) {
|
||||
public boolean satisfiesCriterions(
|
||||
Collection<? extends ICriterion> criterions) {
|
||||
ICriterion compositedCriterion = CriterionCompounder.buildAnd(
|
||||
new ArrayList<ICriterion>(criterions)).getResult();
|
||||
return compositedCriterion.isSatisfiedBy(this);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue