From a9bc372692cac70da50e4f6ac692c08934c78406 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Tue, 18 Jan 2011 10:28:46 +0000
Subject: [PATCH] LMS-1949 Fixed order of execution of translation to managed
 entity property.

SVN: 19462
---
 .../translator/EntityPropertyTranslator.java  | 32 ++++++++++++++-----
 .../translator/PropertyTranslatorUtils.java   | 18 ++++++-----
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityPropertyTranslator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityPropertyTranslator.java
index 4af3b63e2cb..d62bcd0b42e 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityPropertyTranslator.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/EntityPropertyTranslator.java
@@ -42,24 +42,40 @@ public final class EntityPropertyTranslator
     public final static IEntityProperty translate(final EntityPropertyPE propertyPE,
             Map<PropertyTypePE, PropertyType> cacheOrNull)
     {
-        final IEntityProperty result = PropertyTranslatorUtils.createEntityProperty(propertyPE);
-        result.setPropertyType(PropertyTypeTranslator.translate(propertyPE
-                .getEntityTypePropertyType().getPropertyType(), cacheOrNull));
-        result.setOrdinal(propertyPE.getEntityTypePropertyType().getOrdinal());
+        final IEntityProperty basicProperty =
+                PropertyTranslatorUtils.createEntityProperty(propertyPE);
+        final PropertyType propertyType =
+                PropertyTypeTranslator.translate(propertyPE.getEntityTypePropertyType()
+                        .getPropertyType(), cacheOrNull);
+        final Long ordinal = propertyPE.getEntityTypePropertyType().getOrdinal();
+
+        PropertyTranslatorUtils.initializeEntityProperty(basicProperty, propertyType, ordinal);
+       
         final DataTypeCode typeCode = PropertyTranslatorUtils.getDataTypeCode(propertyPE);
         switch (typeCode)
         {
             case CONTROLLEDVOCABULARY:
-                result.setVocabularyTerm(VocabularyTermTranslator.translate(propertyPE
+                basicProperty.setVocabularyTerm(VocabularyTermTranslator.translate(propertyPE
                         .getVocabularyTerm()));
                 break;
             case MATERIAL:
-                result.setMaterial(MaterialTranslator.translate(propertyPE.getMaterialValue(),
-                        false));
+                basicProperty.setMaterial(MaterialTranslator.translate(
+                        propertyPE.getMaterialValue(), false));
                 break;
             default:
-                result.setValue(propertyPE.tryGetUntypedValue());
+                basicProperty.setValue(propertyPE.tryGetUntypedValue());
+        }
+
+        final IEntityProperty result;
+        if (propertyPE.getEntityTypePropertyType().isManaged())
+        {
+            result = PropertyTranslatorUtils.createManagedEntityProperty(propertyPE, basicProperty);
+            PropertyTranslatorUtils.initializeEntityProperty(result, propertyType, ordinal);
+        } else
+        {
+            result = basicProperty;
         }
+
         return result;
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java
index 4b538da1fa7..896dd11e9ab 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/translator/PropertyTranslatorUtils.java
@@ -21,6 +21,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialEntityProperty;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ScriptType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.dto.EntityPropertyPE;
@@ -63,19 +64,13 @@ final class PropertyTranslatorUtils
     {
         final DataTypeCode typeCode = PropertyTranslatorUtils.getDataTypeCode(propertyPE);
         final IEntityProperty basicProperty = createEntityProperty(typeCode);
-        if (propertyPE.getEntityTypePropertyType().isManaged())
-        {
-            return createManagedEntityProperty(propertyPE, basicProperty);
-        } else
-        {
-            return basicProperty;
-        }
+        return basicProperty;
     }
 
     /**
      * Creates a managed {@link IEntityProperty} wrapping given <var>basicProperty</var>.
      */
-    private static IEntityProperty createManagedEntityProperty(EntityPropertyPE property,
+    static IEntityProperty createManagedEntityProperty(EntityPropertyPE property,
             IEntityProperty basicProperty)
     {
         final ScriptPE script = property.getEntityTypePropertyType().getScript();
@@ -87,6 +82,13 @@ final class PropertyTranslatorUtils
         return result;
     }
 
+    static void initializeEntityProperty(IEntityProperty property, PropertyType propertyType,
+            Long ordinal)
+    {
+        property.setPropertyType(propertyType);
+        property.setOrdinal(ordinal);
+    }
+
     /**
      * Creates an appropriate {@link IEntityProperty} for the given <var>dataTypeCode</var>.
      */
-- 
GitLab