From 64c58efcd59c488bba4f5de9ee96c3fa35550966 Mon Sep 17 00:00:00 2001
From: felmer <franz-josef.elmer@id.ethz.ch>
Date: Mon, 17 Sep 2018 11:40:31 +0200
Subject: [PATCH] SSDM-7189: Bug fixed and tests fixed

---
 ...hPropertyAssignmentsOperationExecutor.java |  7 +++++-
 .../PropertyAssignmentTranslator.java         | 23 +++++++++++--------
 .../PropertyAssignmentFetchOptions.js         | 14 +++++++++++
 .../asapi/v3/AbstractGetEntityTypeTest.java   |  2 +-
 .../systemtest/asapi/v3/AbstractTest.java     |  7 ++++--
 .../v3/SearchPropertyAssignmentTest.java      |  7 +++---
 6 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/property/SearchPropertyAssignmentsOperationExecutor.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/property/SearchPropertyAssignmentsOperationExecutor.java
index e3e5a3c19a3..4bb9c297dca 100644
--- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/property/SearchPropertyAssignmentsOperationExecutor.java
+++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/property/SearchPropertyAssignmentsOperationExecutor.java
@@ -40,6 +40,7 @@ import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.property.IProperty
 import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.property.PropertyAssignmentKey;
 import ch.ethz.sis.openbis.generic.server.asapi.v3.translator.property.PropertyAssignmentRecord;
 import ch.systemsx.cisd.openbis.generic.shared.dto.EntityTypePropertyTypePE;
+import ch.systemsx.cisd.openbis.generic.shared.dto.ScriptPE;
 
 /**
  * @author pkupczyk
@@ -97,7 +98,11 @@ public class SearchPropertyAssignmentsOperationExecutor extends
             assignmentRecord.show_raw_value = assignment.getShowRawValue();
             assignmentRecord.type_code = assignment.getEntityType().getCode();
             assignmentRecord.type_id = assignment.getEntityType().getId();
-            assignmentRecord.script_id = assignment.getScript().getId();
+            ScriptPE script = assignment.getScript();
+            if (script != null)
+            {
+                assignmentRecord.script_id = script.getId();
+            }
             assignmentRecords.add(assignmentRecord);
         }
 
diff --git a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/property/PropertyAssignmentTranslator.java b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/property/PropertyAssignmentTranslator.java
index 1c45decd5e4..031ad2da473 100644
--- a/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/property/PropertyAssignmentTranslator.java
+++ b/openbis/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/translator/property/PropertyAssignmentTranslator.java
@@ -188,11 +188,11 @@ public class PropertyAssignmentTranslator implements IPropertyAssignmentTranslat
         
         if (assignmentFetchOptions.hasPlugin())
         {
-            Map<Long, List<PropertyAssignment>> assignmentsByRegistatorId = getAssignments(assignments, assignmentRecords, r -> r.script_id);
+            Map<Long, List<PropertyAssignment>> assignmentsByPluginId = getAssignments(assignments, assignmentRecords, r -> r.script_id);
             Map<Long, Plugin> registratorMap =
-                    pluginTranslator.translate(context, assignmentsByRegistatorId.keySet(), assignmentFetchOptions.withPlugin());
+                    pluginTranslator.translate(context, assignmentsByPluginId.keySet(), assignmentFetchOptions.withPlugin());
 
-            for (Map.Entry<Long, List<PropertyAssignment>> entry : assignmentsByRegistatorId.entrySet())
+            for (Map.Entry<Long, List<PropertyAssignment>> entry : assignmentsByPluginId.entrySet())
             {
                 Plugin plugin = registratorMap.get(entry.getKey());
                 for (PropertyAssignment assignment : entry.getValue())
@@ -216,15 +216,18 @@ public class PropertyAssignmentTranslator implements IPropertyAssignmentTranslat
             PropertyAssignmentKey key = new PropertyAssignmentKey(assignmentRecord.id, entityKind);
             PropertyAssignment assignment = assignments.get(key);
             Long id = extractor.apply(assignmentRecord);
-            List<PropertyAssignment> list = map.get(id);
-
-            if (list == null)
+            if (id != null)
             {
-                list = new ArrayList<PropertyAssignment>();
-                map.put(id, list);
+                List<PropertyAssignment> list = map.get(id);
+                
+                if (list == null)
+                {
+                    list = new ArrayList<PropertyAssignment>();
+                    map.put(id, list);
+                }
+                
+                list.add(assignment);
             }
-
-            list.add(assignment);
         }
 
         return map;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/property/fetchoptions/PropertyAssignmentFetchOptions.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/property/fetchoptions/PropertyAssignmentFetchOptions.js
index 169205d9021..38b3f7d2a7d 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/property/fetchoptions/PropertyAssignmentFetchOptions.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/as/dto/property/fetchoptions/PropertyAssignmentFetchOptions.js
@@ -9,6 +9,7 @@ define([ "stjs", "as/dto/common/fetchoptions/FetchOptions", "as/dto/property/fet
 		prototype.propertyType = null;
 		prototype.semanticAnnotations = null;
 		prototype.registrator = null;
+		prototype.plugin = null;
 		prototype.sort = null;
 
 		prototype.withEntityType = function() {
@@ -63,6 +64,19 @@ define([ "stjs", "as/dto/common/fetchoptions/FetchOptions", "as/dto/property/fet
 		prototype.hasRegistrator = function() {
 			return this.registrator != null;
 		};
+		prototype.withPlugin = function() {
+			if (this.plugin == null) {
+				var PluginFetchOptions = require("as/dto/plugin/fetchoptions/PluginFetchOptions");
+				this.plugin = new PluginFetchOptions();
+			}
+			return this.plugin;
+		};
+		prototype.withPluginUsing = function(fetchOptions) {
+			return this.plugin = fetchOptions;
+		};
+		prototype.hasPlugin = function() {
+			return this.plugin != null;
+		};
 		prototype.sortBy = function() {
 			if (this.sort == null) {
 				var PropertyAssignmentSortOptions = require("as/dto/property/fetchoptions/PropertyAssignmentSortOptions");
diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractGetEntityTypeTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractGetEntityTypeTest.java
index 5cd99f54549..e831dbd430f 100644
--- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractGetEntityTypeTest.java
+++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractGetEntityTypeTest.java
@@ -249,7 +249,7 @@ public abstract class AbstractGetEntityTypeTest extends AbstractTest
 
         assertEquals(((EntityTypePermId) type.getPermId()).getPermId(), permId.getPermId());
         assertEquals(type.getCode(), permId.getPermId());
-        assertPropertyAssignments(type.getPropertyAssignments(), "ENTITY_TEST_TYPE.DESCRIPTION");
+        assertPropertyAssignments(type.getPropertyAssignments(), "properties", "ENTITY_TEST_TYPE.DESCRIPTION");
 
         assertValidationPluginNotFetched(type);
     }
diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java
index 02ed8958ca6..7ce17ff5f91 100644
--- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java
+++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java
@@ -1120,14 +1120,17 @@ public class AbstractTest extends SystemTestCase
         assertCollectionContainsOnly(actualSet, expectedCodes);
     }
 
-    protected static void assertPropertyAssignments(Collection<PropertyAssignment> propertyAssignments,
+    protected static void assertPropertyAssignments(Collection<PropertyAssignment> propertyAssignments, String pluginNameOrNull,
             String... expectedEntityTypeAndPropertyTypeCodes)
     {
         Set<String> actualSet = new HashSet<String>();
         for (PropertyAssignment propertyAssignment : propertyAssignments)
         {
             actualSet.add(propertyAssignment.getEntityType().getCode() + "." + propertyAssignment.getPropertyType().getCode());
-            assertEquals(propertyAssignment.getPlugin().getName(), "properties");
+            if (pluginNameOrNull != null)
+            {
+                assertEquals(propertyAssignment.getPlugin().getName(), pluginNameOrNull);
+            }
         }
 
         assertCollectionContainsOnly(actualSet, expectedEntityTypeAndPropertyTypeCodes);
diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchPropertyAssignmentTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchPropertyAssignmentTest.java
index bc3be6513ee..286e6010596 100644
--- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchPropertyAssignmentTest.java
+++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/SearchPropertyAssignmentTest.java
@@ -149,9 +149,9 @@ public class SearchPropertyAssignmentTest extends AbstractTest
             }
         }
 
-        assertPropertyAssignments(withOwnSemanticAnnotations, "MASTER_PLATE.$PLATE_GEOMETRY", "CONTROL_LAYOUT.$PLATE_GEOMETRY",
+        assertPropertyAssignments(withOwnSemanticAnnotations, null, "MASTER_PLATE.$PLATE_GEOMETRY", "CONTROL_LAYOUT.$PLATE_GEOMETRY",
                 "CELL_PLATE.ORGANISM");
-        assertPropertyAssignments(withInheritedSemanticAnnotations, "MASTER_PLATE.DESCRIPTION", "CONTROL_LAYOUT.DESCRIPTION", "NORMAL.ORGANISM",
+        assertPropertyAssignments(withInheritedSemanticAnnotations, null, "MASTER_PLATE.DESCRIPTION", "CONTROL_LAYOUT.DESCRIPTION", "NORMAL.ORGANISM",
                 "DELETION_TEST.ORGANISM", "DELETION_TEST.DESCRIPTION");
 
         v3api.logout(sessionToken);
@@ -234,12 +234,13 @@ public class SearchPropertyAssignmentTest extends AbstractTest
         PropertyAssignmentFetchOptions fo = new PropertyAssignmentFetchOptions();
         fo.withEntityType();
         fo.withPropertyType();
+        fo.withPlugin();
 
         SearchResult<PropertyAssignment> searchResult =
                 v3api.searchPropertyAssignments(sessionToken, criteria, fo);
         List<PropertyAssignment> propertyAssignments = searchResult.getObjects();
 
-        assertPropertyAssignments(propertyAssignments, expectedEntityTypeAndPropertyTypeCodes);
+        assertPropertyAssignments(propertyAssignments, null, expectedEntityTypeAndPropertyTypeCodes);
         v3api.logout(sessionToken);
     }
 
-- 
GitLab