[Bug #784] Sort results of add criterion combo in resource edition

FEA : ItEr67S04BugFixing
This commit is contained in:
Susana Montes Pedreira 2011-01-09 18:56:38 +01:00
parent 3047b32a0b
commit 1b637c7513
5 changed files with 43 additions and 14 deletions

View file

@ -26,6 +26,7 @@ import java.util.List;
import org.apache.commons.lang.Validate;
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;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
@ -194,7 +195,8 @@ public class CriterionTypeDAO extends IntegrationEntityDAO<CriterionType>
public List<CriterionType> getCriterionTypesByResources(
Collection<ResourceEnum> resources) {
return getSession().createCriteria(CriterionType.class).add(
Restrictions.in("resource", resources)).list();
Restrictions.in("resource", resources)).addOrder(
Order.asc("name")).list();
}
}

View file

@ -298,6 +298,18 @@ public class Criterion extends IntegrationEntity implements ICriterion {
return children;
}
@Valid
public List<Criterion> getSortedChildren() {
List<Criterion> children = new ArrayList<Criterion>(getChildren());
Collections.sort(children, new Comparator<Criterion>() {
@Override
public int compare(Criterion o1, Criterion o2) {
return o1.getName().compareTo(o2.getName());
}
});
return children;
}
public void setChildren(Set<Criterion> children) {
this.children = children;
}

View file

@ -20,7 +20,11 @@
package org.navalplanner.business.resources.entities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
@ -220,6 +224,17 @@ public class CriterionType extends IntegrationEntity implements
return criterions;
}
public List<Criterion> getSortCriterions() {
List<Criterion> criterions = new ArrayList<Criterion>(getCriterions());
Collections.sort(criterions, new Comparator<Criterion>() {
@Override
public int compare(Criterion o1, Criterion o2) {
return o1.getName().compareTo(o2.getName());
}
});
return criterions;
}
public void setCriterions(Set<Criterion> criterions) {
this.criterions = criterions;
}

View file

@ -212,7 +212,7 @@ public class AssignedMachineCriterionsModel extends IntegrationEntityModel
criterionsWithItsTypes = new ArrayList<CriterionWithItsType>();
List<CriterionType> listTypes = getCriterionTypes();
for (CriterionType criterionType : listTypes) {
Set<Criterion> listCriterion = getDirectCriterions(criterionType);
List<Criterion> listCriterion = getDirectCriterions(criterionType);
getCriterionWithItsType(criterionType, listCriterion);
}
return criterionsWithItsTypes;
@ -224,7 +224,7 @@ public class AssignedMachineCriterionsModel extends IntegrationEntityModel
criterionsWithItsTypes = new ArrayList<CriterionWithItsType>();
List<CriterionType> listTypes = getCriterionWorkersTypes();
for (CriterionType criterionType : listTypes) {
Set<Criterion> listCriterion = getDirectCriterions(criterionType);
List<Criterion> listCriterion = getDirectCriterions(criterionType);
getCriterionWithItsType(criterionType, listCriterion);
}
return criterionsWithItsTypes;
@ -244,7 +244,7 @@ public class AssignedMachineCriterionsModel extends IntegrationEntityModel
}
private void getCriterionWithItsType(CriterionType type,
Set<Criterion> children) {
List<Criterion> children) {
for (Criterion criterion : children) {
// Create the criterion with its criterionType and its Hierarchy
// label
@ -253,14 +253,14 @@ public class AssignedMachineCriterionsModel extends IntegrationEntityModel
// Add to the list
criterionsWithItsTypes.add(criterionAndType);
getCriterionWithItsType(type, criterion.getChildren());
getCriterionWithItsType(type, criterion.getSortedChildren());
}
}
private static Set<Criterion> getDirectCriterions(
private static List<Criterion> getDirectCriterions(
CriterionType criterionType) {
Set<Criterion> criterions = new HashSet<Criterion>();
for (Criterion criterion : criterionType.getCriterions()) {
List<Criterion> criterions = new ArrayList<Criterion>();
for (Criterion criterion : criterionType.getSortCriterions()) {
if (criterion.getParent() == null) {
criterions.add(criterion);
}

View file

@ -182,7 +182,7 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements
List<CriterionType> listTypes = getCriterionTypes();
for (CriterionType criterionType : listTypes) {
if (criterionType.isEnabled()) {
Set<Criterion> listCriterion = getDirectCriterions(criterionType);
List<Criterion> listCriterion = getDirectCriterions(criterionType);
getCriterionWithItsType(criterionType, listCriterion);
}
}
@ -201,7 +201,7 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements
}
private void getCriterionWithItsType(CriterionType type,
Set<Criterion> children) {
List<Criterion> children) {
for (Criterion criterion : children) {
if (criterion.isActive()) {
// Create the criterion with its criterionType and its Hierarchy
@ -210,15 +210,15 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements
type, criterion);
// Add to the list
criterionsWithItsTypes.add(criterionAndType);
getCriterionWithItsType(type, criterion.getChildren());
getCriterionWithItsType(type, criterion.getSortedChildren());
}
}
}
private static Set<Criterion> getDirectCriterions(
private static List<Criterion> getDirectCriterions(
CriterionType criterionType) {
Set<Criterion> criterions = new HashSet<Criterion>();
for (Criterion criterion : criterionType.getCriterions()) {
List<Criterion> criterions = new ArrayList<Criterion>();
for (Criterion criterion : criterionType.getSortCriterions()) {
if (criterion.getParent() == null) {
criterions.add(criterion);
}