The criterions tree must be ordered by criterion type name and criterion name

FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
Óscar González Fernández 2010-09-21 18:02:42 +02:00
parent 0d7cd79ebc
commit d37657ea03
3 changed files with 17 additions and 3 deletions

View file

@ -27,6 +27,7 @@ import org.apache.commons.lang.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.navalplanner.business.common.daos.IntegrationEntityDAO;
@ -169,4 +170,14 @@ public class CriterionDAO extends IntegrationEntityDAO<Criterion>
return (List<Criterion>) c.list();
}
@Override
public List<Criterion> getAllSortedByTypeAndName() {
Query query = getSession()
.createQuery(
"select criterion from Criterion criterion "
+ "JOIN criterion.type type "
+ "order by type.name asc, criterion.name asc");
return (List<Criterion>) query.list();
}
}

View file

@ -50,6 +50,8 @@ public interface ICriterionDAO extends IIntegrationEntityDAO<Criterion> {
List<Criterion> getAll();
List<Criterion> getAllSortedByTypeAndName();
List<Criterion> getAllSorted();
boolean thereIsOtherWithSameNameAndType(Criterion criterion);

View file

@ -28,7 +28,7 @@ import static org.hibernate.criterion.Restrictions.or;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -254,8 +254,9 @@ public class ResourceSearchModel implements IResourceSearchModel {
return new IOnTransaction<Map<CriterionType, Set<Criterion>>>() {
@Override
public Map<CriterionType, Set<Criterion>> execute() {
Map<CriterionType, Set<Criterion>> result = new HashMap<CriterionType, Set<Criterion>>();
for (Criterion criterion : criterionDAO.getAllSorted()) {
Map<CriterionType, Set<Criterion>> result = new LinkedHashMap<CriterionType, Set<Criterion>>();
for (Criterion criterion : criterionDAO
.getAllSortedByTypeAndName()) {
CriterionType key = criterion.getType();
if (klassTheCriterionTypeMustBeRelatedWith
.isAssignableFrom(key.getResource().asClass())) {