From c81c5eede86894512f88b35322b2ed9d62cc8eb5 Mon Sep 17 00:00:00 2001
From: vermeul <swen@ethz.ch>
Date: Thu, 22 Aug 2019 16:36:04 +0200
Subject: [PATCH] creating entity entity types, ongoing work

---
 pybis/src/python/pybis/entity_type.py | 35 +++++++++++++++------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/pybis/src/python/pybis/entity_type.py b/pybis/src/python/pybis/entity_type.py
index 70e35ee7c4d..bd2244d7854 100644
--- a/pybis/src/python/pybis/entity_type.py
+++ b/pybis/src/python/pybis/entity_type.py
@@ -97,6 +97,9 @@ class EntityType:
 
         """
         pas = self.__dict__['_propertyAssignments']
+
+        # assign property type
+        property_type = self.openbis.get_property_type(property)
         new_assignment = {
             "section": section,
             "ordinal": ordinal,
@@ -104,26 +107,16 @@ class EntityType:
             "initialValueForExistingEntities": initialValueForExistingEntities,
             "showInEditView": showInEditView,
             "showRawValueInForms": showRawValueInForms,
-            "propertyType" : {
-                "permId": property.upper(),
-                "@type": "as.dto.property.id.PropertyTypePermId"
-            },
+            "propertyType": property_type.data,
             "@type": "as.dto.property.create.PropertyAssignmentCreation",
         }
-        if plugin is not None:
-            new_assignment['pluginId'] = {
-                "permId": plugin.upper(),
-                "@type": "as.dto.plugin.id.PluginPermId"
-            }
-        pas.append(new_assignment)
 
-    @property
-    def validationPlugin(self):
-        try:
-            return self.openbis.get_plugin(self._validationPlugin['name'])
-        except Exception:
-            pass
+        # assign plugin
+        if plugin is not None:
+            plugin_obj = self.openbis.get_plugin(plugin)
+            new_assignment['plugin'] = plugin_obj.data
 
+        pas.append(new_assignment)
 
     def revoke_property(self, 
         property, 
@@ -138,6 +131,16 @@ class EntityType:
         raise ValueError("not implemented yet")
 
 
+    @property
+    def validationPlugin(self):
+        """Returns a validation plugin object when called.
+        Returns None when no validation plugin is defined.
+        """
+        try:
+            return self.openbis.get_plugin(self._validationPlugin['name'])
+        except Exception:
+            pass
+
     def codes(self):
         codes = []
         for pa in self.data['propertyAssignments']:
-- 
GitLab