Python: fix serialization of NudeLists when embedded within other
authorjani <jani@asema.com>
Tue, 6 Aug 2019 15:24:43 +0000 (18:24 +0300)
committerjani <jani@asema.com>
Tue, 6 Aug 2019 15:24:43 +0000 (18:24 +0300)
objects

Common/Python/SmartAPI/model/DependentPriceSpecification.py
Common/Python/SmartAPI/model/Obj.py
Common/Python/SmartAPI/rdf/List.py
Common/Python/SmartAPI/rdf/NudeList.py
Common/Python/SmartAPI/tests/TestSequences.py
Examples/Python/AdaptDataService/AdaptDataService.py

index 7bb0710fecf78aa64cd31364ad4f6302c14dd03e..348f5360a0f334caaaee42ea08941a54a2f65125 100644 (file)
@@ -10,7 +10,7 @@ class DependentPriceSpecification(PriceSpecification):
        def __init__(self, uri = None, value = None, unit = None, validFrom = None, validThrough = None):
                super(DependentPriceSpecification, self).__init__(uri = uri, value = value, unit = unit, validFrom = validFrom, validThrough = validThrough)
                self.init_propertylist(PROPERTY.LIST, 'conditions', LinkedList, self.hasCondition, self.getConditionsContainer)
-       
+               
        def hasCondition(self):
                return self.conditions is not None and not self.conditions.isEmpty()
                
index 691a2ccf7c368f34b301fa096c8c0e8a6656df58..7db4f98f054fcfad12e6491e45f99986ff500c99 100644 (file)
@@ -30,9 +30,9 @@ from SmartAPI.rdf.ItemizedList import ItemizedList
 
 
 class Obj(object):
-               
+       
        referenceUriPrefix = "http://smart-api.io/reference/1.0/smart#"
-                       
+       
        def __init__(self, seasIdentifierUri = None):
                self.seasIdentifierUri = seasIdentifierUri
                self.sameAs = None
@@ -202,7 +202,11 @@ class Obj(object):
                                        rdfList = None
                                if rdfList:  # this is an rdf list with certain format
                                        v = entry[1]()
-                                       rdfList.add_items(v) # getter
+                                       # v may now contain either an instance of a list or a list of entries. Act accordingly
+                                       if isinstance(v, List):
+                                               rdfList.add_items(v.get_items()) # getter
+                                       else:
+                                               rdfList.add_items(v)
                                        try:
                                                # wrapping this part in a try allows for the scenario where v is just a Python list for some reason
                                                rdfList.setBaseObject(v.getBaseObject())
index 47fda190a58a683c19a8726211bc43b11c7eb6e6..696ea12ae1aba6cb853695fa9e301253e0440411 100644 (file)
@@ -35,7 +35,7 @@ class List(object):
     
     def extend(self, items):
         self.elements.extend(items)
-         
+    
     def size(self):
         return len(self.elements)
     
index 77cd8871281a6fe410f855ad998d763e4c32a302..5a6cf1a083a9b0f80a29e55d70bfd408e2f748aa 100644 (file)
@@ -8,7 +8,7 @@ class NudeList(List):
     def add_items(self, items):
         
         if isinstance(items, list):
-            for i in items:               
+            for i in items:
                 try:  # objects support toNude, simple variables don't
                     self.elements.append(i.toNude())
                 except:
index 1fd733d5af4869ea3b1ddc554281229362b03c21..7baa1587c7e87f16a6a1d45272a41476cedc45e5 100755 (executable)
@@ -2154,8 +2154,8 @@ def main():
     #parameterSerializeParseTest()
     #physicalEntityTest()
     #waypointsTest()
-    #basicListSerializeParseTest()
-    #baseObjectListSerializeParseTest()
+    basicListSerializeParseTest()
+    baseObjectListSerializeParseTest()
     #timeseriesListSerializeParseTest()
     #listSpeedTestSerialize()
     #listSpeedTestSerializeAndParse()
index b5fbe294da2a81b4c0e202a48350c64accb4a954..ceece97b55086935844bd33d460dd22c3d90de2a 100755 (executable)
@@ -25,6 +25,12 @@ from SmartAPI.model.TimeSeries import TimeSeries
 from SmartAPI.model.ValueObject import ValueObject
 
 
+from SmartAPI.common.PROPERTY import PROPERTY
+from SmartAPI.rdf.OrderedList import OrderedList
+from SmartAPI.rdf.ItemizedList import ItemizedList
+from SmartAPI.rdf.NudeList import NudeList
+
+
 myIdentity = "http://adapt.asema.com/demos/python/datasource/"
 adaptServiceIdentity = "http://adapt.asema.com"
 registrationServerUri = "http://find.smart-api.io/smart/v1.0e1.0/access"
@@ -121,7 +127,22 @@ class SampleRegistration(object):
                        offering.addPriceSpecification(priceSpec)
                        dataSource.addOffering(offering)
                        dataSource.addValueObject(power)
+                       
+                       """
+                       il = ItemizedList()
+                       l = [x for x in range(10)]
+                       il.add_items(l)
+                       
+                       ol = OrderedList()
+                       ol.add_items(l)
+                       
+                       nl = NudeList()
+                       nl.add_items(l)
 
+                       dataSource.add(PROPERTY.ANGULARVELOCITYX, il)
+                       dataSource.add(PROPERTY.ANGULARVELOCITYY, ol)
+                       dataSource.add(PROPERTY.ANGULARVELOCITYZ, nl)
+                       """
                        agent.addEntity(sampleService)
                        agent.addEntity(dataSource);