Fix the query DMS details with fields 19/11119/1
authorZhang Rong(Jon) <rong.zhang@windriver.com>
Wed, 17 May 2023 01:45:56 +0000 (09:45 +0800)
committerZhang Rong(Jon) <rong.zhang@windriver.com>
Wed, 17 May 2023 01:45:56 +0000 (09:45 +0800)
Issue-ID: INF-399
Signed-off-by: Zhang Rong(Jon) <rong.zhang@windriver.com>
Change-Id: Iaf194bde82409de734e9be2d22454741ddf724e8

o2common/views/route.py
o2ims/views/ocloud_dto.py

index 9776458..f152fc0 100644 (file)
@@ -195,6 +195,9 @@ class o2_marshal_with(marshal_with):
         for f in fields:
             f = f.strip()
             if '/' in f:
+                parent = f.split('/')[0]
+                if parent in selector and type(selector[parent]) is bool:
+                    selector[parent] = dict()
                 self.__update_selector_tree_value(selector, f, val)
                 continue
             if f not in self.fields:
@@ -217,6 +220,8 @@ class o2_marshal_with(marshal_with):
         for k, v in fields.items():
             if type(v) is dict:
                 s = self.__gen_mask_from_selector(v)
+                if s == '{}':
+                    continue
                 mask_li.append('%s%s' % (k, s))
                 continue
             if v:
@@ -225,12 +230,39 @@ class o2_marshal_with(marshal_with):
         return '{%s}' % ','.join(mask_li)
 
     def __set_default_mask(self, selector: dict, val: bool = True):
+        def convert_mask(mask):
+            # convert mask from {aa,bb,xxx{yyy}} structure to aa,bbxxx/yyy
+            stack = []
+            result = []
+            word = ''
+            for ch in mask:
+                if ch == '{':
+                    if word:
+                        stack.append(word)
+                        word = ''
+                elif ch == '}':
+                    if word:
+                        result.append('/'.join(stack + [word]))
+                        word = ''
+                    if stack:
+                        stack.pop()
+                elif ch == ',':
+                    if word:
+                        result.append('/'.join(stack + [word]))
+                        word = ''
+                else:
+                    word += ch
+            if word:
+                result.append(word)
+            return ','.join(result)
+
         mask = getattr(self.fields, "__mask__")
+        mask = convert_mask(str(mask))
         if not mask:
             selector_all = self.__gen_selector_from_model_with_value(
                 self.fields)
             for s in selector_all:
                 selector[s] = val
             return
-        default_selector = str(mask).strip(' {}')
+        default_selector = mask
         self.__update_selector_value(selector, default_selector, val)
index 622bc46..f283ca0 100644 (file)
@@ -486,7 +486,7 @@ class DeploymentManagerDTO:
             'extensions': fields.Nested(extensions, True, True)
         },
         mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
-        'extensions/profileName,extensions/profileData}'
+        'extensions{profileName,profileData}}'
     )