diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/CriterionTypeDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/CriterionTypeDAO.java index a0ef2ba8d..949d00f51 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/CriterionTypeDAO.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/CriterionTypeDAO.java @@ -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 public List getCriterionTypesByResources( Collection resources) { return getSession().createCriteria(CriterionType.class).add( - Restrictions.in("resource", resources)).list(); + Restrictions.in("resource", resources)).addOrder( + Order.asc("name")).list(); } } diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Criterion.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Criterion.java index d652e20a9..f9673cf90 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Criterion.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Criterion.java @@ -298,6 +298,18 @@ public class Criterion extends IntegrationEntity implements ICriterion { return children; } + @Valid + public List getSortedChildren() { + List children = new ArrayList(getChildren()); + Collections.sort(children, new Comparator() { + @Override + public int compare(Criterion o1, Criterion o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + return children; + } + public void setChildren(Set children) { this.children = children; } diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/CriterionType.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/CriterionType.java index fca34f8c5..5ca85183d 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/CriterionType.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/CriterionType.java @@ -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 getSortCriterions() { + List criterions = new ArrayList(getCriterions()); + Collections.sort(criterions, new Comparator() { + @Override + public int compare(Criterion o1, Criterion o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + return criterions; + } + public void setCriterions(Set criterions) { this.criterions = criterions; } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/machine/AssignedMachineCriterionsModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/machine/AssignedMachineCriterionsModel.java index db681829d..559374ee7 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/machine/AssignedMachineCriterionsModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/machine/AssignedMachineCriterionsModel.java @@ -212,7 +212,7 @@ public class AssignedMachineCriterionsModel extends IntegrationEntityModel criterionsWithItsTypes = new ArrayList(); List listTypes = getCriterionTypes(); for (CriterionType criterionType : listTypes) { - Set listCriterion = getDirectCriterions(criterionType); + List listCriterion = getDirectCriterions(criterionType); getCriterionWithItsType(criterionType, listCriterion); } return criterionsWithItsTypes; @@ -224,7 +224,7 @@ public class AssignedMachineCriterionsModel extends IntegrationEntityModel criterionsWithItsTypes = new ArrayList(); List listTypes = getCriterionWorkersTypes(); for (CriterionType criterionType : listTypes) { - Set listCriterion = getDirectCriterions(criterionType); + List listCriterion = getDirectCriterions(criterionType); getCriterionWithItsType(criterionType, listCriterion); } return criterionsWithItsTypes; @@ -244,7 +244,7 @@ public class AssignedMachineCriterionsModel extends IntegrationEntityModel } private void getCriterionWithItsType(CriterionType type, - Set children) { + List 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 getDirectCriterions( + private static List getDirectCriterions( CriterionType criterionType) { - Set criterions = new HashSet(); - for (Criterion criterion : criterionType.getCriterions()) { + List criterions = new ArrayList(); + for (Criterion criterion : criterionType.getSortCriterions()) { if (criterion.getParent() == null) { criterions.add(criterion); } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/worker/AssignedCriterionsModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/worker/AssignedCriterionsModel.java index a8b63d1bb..b8d74cad4 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/worker/AssignedCriterionsModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/resources/worker/AssignedCriterionsModel.java @@ -182,7 +182,7 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements List listTypes = getCriterionTypes(); for (CriterionType criterionType : listTypes) { if (criterionType.isEnabled()) { - Set listCriterion = getDirectCriterions(criterionType); + List listCriterion = getDirectCriterions(criterionType); getCriterionWithItsType(criterionType, listCriterion); } } @@ -201,7 +201,7 @@ public class AssignedCriterionsModel extends IntegrationEntityModel implements } private void getCriterionWithItsType(CriterionType type, - Set children) { + List 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 getDirectCriterions( + private static List getDirectCriterions( CriterionType criterionType) { - Set criterions = new HashSet(); - for (Criterion criterion : criterionType.getCriterions()) { + List criterions = new ArrayList(); + for (Criterion criterion : criterionType.getSortCriterions()) { if (criterion.getParent() == null) { criterions.add(criterion); }