Author: tchemit Date: 2014-05-01 14:21:24 +0200 (Thu, 01 May 2014) New Revision: 3090 Url: http://forge.nuiton.org/projects/topia/repository/revisions/3090 Log: fixes #3184: Fix generation of entity.getXXX(index) for ordered but not unique attribute Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2014-04-30 13:56:22 UTC (rev 3089) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2014-05-01 12:21:24 UTC (rev 3090) @@ -25,6 +25,7 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaException; @@ -127,6 +128,23 @@ } /** + * Get entity at {@code index} position in the collection is not null. + * + * @param entities collection of entities (can be null) + * @param index position to get + * @param <E> type of entity + * @return the entity at the given index, or {@code null} if entities are null + * @throws IndexOutOfBoundsException if index is out of bounds + * @since 3.0 + */ + public static <E extends TopiaEntity> E getEntityByIndex(Collection<E> entities, int index) throws IndexOutOfBoundsException { + if (entities != null) { + return Iterables.get(entities, index); + } + return null; + } + + /** * Teste si une entité possède un topiaId. * * @param paramName le nom du paramètre à afficher en casd'erreur Modified: trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java =================================================================== --- trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java 2014-04-30 13:56:22 UTC (rev 3089) +++ trunk/topia-templates/src/main/java/org/nuiton/topia/templates/EntityTransformer.java 2014-05-01 12:21:24 UTC (rev 3090) @@ -736,6 +736,12 @@ // getXXX addMultipleGetOperation(attribute, collectionInterface); + if (TopiaGeneratorUtil.isOrdered(attribute)) { + + // getXXX(index) + addMultipleGetByIndexOperation(attribute); + } + if (TopiaGeneratorUtil.isEntity(attribute, model)) { // getXXXByTopiaId @@ -746,12 +752,6 @@ } - if (TopiaGeneratorUtil.isOrdered(attribute)) { - - // getXXX(index) - addMultipleGetByIndexOperation(attribute); - } - // sizeXXX addMultipleSizeOperation(attribute); @@ -1151,7 +1151,7 @@ addOperation(outputInterface, getJavaBeanMethodName("get", attrName), attrType, ObjectModelJavaModifier.PACKAGE); ObjectModelParameter param = - addParameter(interfaceOperation, Integer.class, "index"); + addParameter(interfaceOperation, int.class, "index"); // Implementation ObjectModelOperation implOperation = @@ -1161,7 +1161,7 @@ setOperationBody(implOperation, "" /*{ - return <%=attrName%>.get(index); + return TopiaEntityHelper.getEntityByIndex(<%=attrName%>, index); }*/ ); }