From cd5beb8d0087d93a2cda8da3ee8d70ff893f9532 Mon Sep 17 00:00:00 2001
From: vermeul <swen@ethz.ch>
Date: Wed, 23 Oct 2019 17:25:23 +0200
Subject: [PATCH] handling of boolean attributes in update of entity types.
 Bugfix of validationPlugin when updating entity types

---
 pybis/src/python/pybis/attribute.py | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/pybis/src/python/pybis/attribute.py b/pybis/src/python/pybis/attribute.py
index 6e1befcc4ee..c9c5fc7d94a 100644
--- a/pybis/src/python/pybis/attribute.py
+++ b/pybis/src/python/pybis/attribute.py
@@ -61,9 +61,15 @@ class AttrHolder():
                 if isinstance(self.__dict__['_' + attr], dict):
                     self.__dict__['_' + attr].pop('@id')
 
-            elif attr == 'vocabularyCode':
+            elif attr in ['vocabularyCode']:
                 self.__dict__['_'+attr] = data.get('permId', {}).get(attr, None)
 
+            elif attr in ['validationPlugin']:
+                d = data.get(attr, None)
+                if d is not None:
+                    d = d['permId']
+                self.__dict__['_' + attr] = d
+
             elif attr in ["space"]:
                 d = data.get(attr, None)
                 if d is not None:
@@ -237,9 +243,10 @@ class AttrHolder():
                     "@type": "as.dto.common.update.IdListUpdateValue" 
                 }
 
-            elif attr in 'description label official ordinal'.split():
+            elif attr in 'description label official ordinal autoGeneratedCode subcodeUnique listable showContainer showParents showParentMetadata disallowDeletion validationPlugin'.split():
                 # alway update common fields
-                up_obj[attr] = {
+                key = attr2ids.get(attr, attr)
+                up_obj[key] = {
                     "value": self.__dict__['_'+attr],
                     "isModified": True,
                     "@type": "as.dto.common.update.FieldUpdateValue"
@@ -268,13 +275,8 @@ class AttrHolder():
                     if value is None:
                         pass
                     elif isinstance(value, bool):
-                        # for boolean values no type is needed
+                        # for boolean values where no type is needed
                         up_obj[attr] = value
-                        #{
-                        #    "value": value,
-                        #    "isModified": True,
-                        #    "@type": "as.dto.common.update.FieldUpdateValue"
-                        #}
                     elif isinstance(value, dict) and len(value) == 0:
                         # value is {}: it means that we want this attribute to be
                         # deleted, not updated.
@@ -325,6 +327,7 @@ class AttrHolder():
         if name in name_map:
             name = name_map[name]
 
+
         int_name = '_' + name
         if int_name in self.__dict__:
             if int_name == '_attachments':
@@ -471,6 +474,14 @@ class AttrHolder():
                 "@type": "as.dto.vocabulary.id.VocabularyPermId",
                 "permId": value.upper()
             }
+        elif name in ["validationPlugin"]:
+            if value is None or value == '':
+                self.__dict__['_validationPlugin'] = None
+            else:
+                self.__dict__['_validationPlugin'] = {
+                    "@type": "as.dto.plugin.id.PluginPermId",
+                    "permId": value
+                }
 
         elif name in ["materialType"]:
             self.__dict__['_materialType'] = {
-- 
GitLab