Fixed issues with DependentPriceSpecification
authorjani <jani@asema.com>
Sat, 3 Aug 2019 18:00:47 +0000 (21:00 +0300)
committerjani <jani@asema.com>
Sat, 3 Aug 2019 18:00:47 +0000 (21:00 +0300)
Common/C++/SmartAPI/smartapi/model/DependentPriceSpecification.cpp
Common/Java/SmartAPI/build.xml
Common/Java/SmartAPI/runtests.sh
Common/Java/SmartAPI/src/smartapi/tests/TestSequence.java
Common/Python/SmartAPI/model/DependentPriceSpecification.py
Examples/Python/AdaptDataService/AdaptDataService.py

index 67b19c81e19c523a04829fa51581e69fee423f69..68350afe7d972846ac609dc5c6a6b80fee4b52c4 100644 (file)
@@ -24,7 +24,7 @@ DependentPriceSpecification::DependentPriceSpecification(QString unit, QString s
 DependentPriceSpecification::DependentPriceSpecification(DependentPriceSpecification* o) :
        PriceSpecification(o)
 {
-       SET_PROPERTYLIST_REFERENCE(PROPERTY__LIST,mConditions,Condition);
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__LIST, mConditions, Condition);
 }
 
 DependentPriceSpecification::~DependentPriceSpecification()
index b3acaf56a98c553d1dd3ebd3b72fc13bc376912a..3e99344148a2bef7e811aadde69cdb6f3dae0432 100644 (file)
@@ -46,7 +46,7 @@
     <pathelement location="lib/spin-2.0.0.jar"/>
   </path>
   <target name ="jar" description="Create a jar for the smartapi project" depends='compile'>
-    <jar jarfile="dist/smartapi.jar" includes="**/**" excludes="*.class" basedir="smartapi/"/>
+    <jar jarfile="dist/smartapi-1.0.jar" includes="**/**" excludes="*.class" basedir="smartapi/"/>
   </target>
   <target name ="compile" description="Compile smartapi code">
     <javac srcdir="src/" destdir="smartapi/"
@@ -62,7 +62,7 @@
   </target>
   <target name ="deploy" description="Deploy the Smart API to Tomcat" depends='jar'>
     <property name="tomcat.local" value="/usr/share/tomcat" />
-    <delete verbose='true' dir='${tomcat.local}/lib/smartapi.jar'/>
-    <copy todir='${tomcat.local}/lib/' file='dist/smartapi.jar'/>
+    <delete verbose='true' dir='${tomcat.local}/lib/smartapi-1.0.jar'/>
+    <copy todir='${tomcat.local}/lib/' file='dist/smartapi-1.0.jar'/>
   </target>    
 </project>
index 62d8f62835464fea0d9751881969dfd7da61f95a..25c69e68e7270e1b771fbd8705bc5fc1572d51b1 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/bash
 
-java -cp dist/smartapi.jar:lib/* smartapi.tests.TestSequence
+java -cp dist/smartapi-1.0.jar:lib/* smartapi.tests.TestSequence
index 722422e7b411547214b9e3836ceb0ff770ffa612..0275d5832165c3ea3f23e90c14ae74082b4d5878 100644 (file)
@@ -49,6 +49,7 @@ import smartapi.model.Activity;
 import smartapi.model.Address;
 import smartapi.model.Availability;
 import smartapi.model.Capacity;
+import smartapi.model.Condition;
 import smartapi.model.Coordinates;
 import smartapi.model.Device;
 import smartapi.model.Entity;
@@ -66,6 +67,7 @@ import smartapi.model.Output;
 import smartapi.model.Parameter;
 import smartapi.model.PhysicalEntity;
 import smartapi.model.PriceSpecification;
+import smartapi.model.PropertyDependentPriceSpecification;
 import smartapi.model.Request;
 import smartapi.model.Response;
 import smartapi.model.Route;
@@ -2983,22 +2985,6 @@ public class TestSequence {
                return true;
        }
        
-       public void temp()
-       {
-               String myId = "http://blank-entity-and-offering-test.com";
-               SharingAgent sAgent = new SharingAgent(myId);
-               sAgent.setHTTPBasicAccessAuthenticationCredentials("senni", "12345");
-
-               // fetch shared by me
-               java.util.List<Entity> shared = sAgent.fetchSharings();
-               if ( shared.size() != 1 ) {
-                       System.out.println("BlankEntityAndOfferingTest FAILED to fetch all shared entities. Shared 1, found " + shared.size() + ".");                   
-               }
-               for ( Entity e : shared ) {
-                       e.turtlePrint();
-               }
-       }
-       
        public void storeObjToNotaryTest()
        {
                try {
@@ -3057,7 +3043,7 @@ public class TestSequence {
                } catch ( Exception e ) {
                        e.printStackTrace();
                        return false;
-               }               
+               }
        }
        
        public boolean tradingAgentAccountTest()
@@ -3156,13 +3142,48 @@ public class TestSequence {
                }
        }
 
+       public boolean conditionalPriceSpecificationTest()
+       {
+               Offering offering = new Offering();
+               PropertyDependentPriceSpecification priceSpec = new PropertyDependentPriceSpecification();
+
+               Condition c1 = new Condition();
+               c1.addGreater(new Variant(0));
+               c1.addAction(10);
+               priceSpec.addCondition(c1);
+               
+               Condition c2 = new Condition();
+               c2.addGreater(new Variant(10));
+               c2.addAction(20);
+               priceSpec.addCondition(c2);
+               
+               Condition c3 = new Condition();
+               c3.addGreater(new Variant(30));
+               c3.addAction(40);
+               priceSpec.addCondition(c3);
+               
+               Condition c4 = new Condition();
+               c4.addGreater(new Variant(40));
+               c4.addAction(55);
+               priceSpec.addCondition(c4);
+               
+               offering.addPriceSpecification(priceSpec);
+               
+               offering.turtlePrint();
+               
+               Offering o2 = (Offering)Tools.serializeParse(offering);
+               
+               o2.turtlePrint();
+               
+               return true;
+       }
+       
+               
        public void runSequence()
        {
                //TestConverter.converterTest();
                //serializeRequestTest();
                //longSerializeParseTest();
-               //SeasObjects.setValidationMode(ValidationMode.REALTIME_VALIDATION);
-               //System.out.println("test ConceptValidator: "+ConceptValidator.isValidConcept(RESOURCE.ABCOULOMB));
                //simpleSerializeParseTest();
                //classSerializeParseTest();
                //commandTest();
@@ -3206,11 +3227,11 @@ public class TestSequence {
                //baseObjectTest();
                //fetchSharingsByOfferingTest();
                //blankEntityAndOfferingTest();
-               //temp();
                //entityTypeRegistrationTest();
                //fetchMyharingsTest();
                //storeObjToNotaryTest();
-               hasChangedTest();
+               //hasChangedTest();
                //tradingAgentAccountTest();
+               conditionalPriceSpecificationTest();
        }
 }
index 379364d09844536d144f40b3cd9da9957f3dd4fb..7bb0710fecf78aa64cd31364ad4f6302c14dd03e 100644 (file)
@@ -2,23 +2,30 @@ from SmartAPI.common.PROPERTY import PROPERTY
 
 from SmartAPI.model.PriceSpecification import PriceSpecification
 from SmartAPI.model.Condition import Condition
+from SmartAPI.rdf.LinkedList import LinkedList
 
 
 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_property(PROPERTY.LIST, 'conditions', self.hasCondition, self.getConditions, islist = True)
+               self.init_propertylist(PROPERTY.LIST, 'conditions', LinkedList, self.hasCondition, self.getConditionsContainer)
        
        def hasCondition(self):
-               return len(self.conditions) > 0
+               return self.conditions is not None and not self.conditions.isEmpty()
                
-       def getConditions(self):
+       def getConditionsContainer(self):
                return self.conditions
-
+       
+       def getConditions(self):
+               return self.conditions.get_items()
+       
        def addCondition(self, c):
                self.conditions.append(c)
-
+       
+       def setConditions(self, cs):
+               self.conditions = cs
+               
        def _parseStatement(self, statement, custom_classes = None):
-               self.parse_property(statement, PROPERTY.LIST, self.addCondition, Condition, custom_classes = custom_classes)
+               self.parse_propertylist(statement, PROPERTY.LIST, self.setConditions, Condition, custom_classes = custom_classes)
                super(DependentPriceSpecification, self)._parseStatement(statement, custom_classes = custom_classes)
\ No newline at end of file
index 54493772ac7a7d97f0bbd584705a0354e4c28a33..3270e2f457f4a5a6582e795b88d99367e432aafc 100755 (executable)
@@ -91,6 +91,8 @@ class SampleRegistration(object):
                        
                        offering = Offering()
                        priceSpec = PropertyDependentPriceSpecification()
+                       priceSpec.setName("Sample pricing")
+                       priceSpec.addType(RESOURCE.PRICETYPEDISCOUNT)
                        
                        c1 = Condition()
                        c1.addGreater(0)