Python: added License
authorjani <jani@asema.com>
Sat, 12 Jan 2019 22:51:52 +0000 (00:51 +0200)
committerjani <jani@asema.com>
Sat, 12 Jan 2019 22:51:52 +0000 (00:51 +0200)
17 files changed:
Common/C++/SmartAPI/smartapi/model/DistanceDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/DurationAtDistanceDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/DurationAtZoneDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/DurationDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/PriceListSpecification.cpp
Common/C++/SmartAPI/smartapi/model/PriceListSpecification.h
Common/C++/SmartAPI/smartapi/model/PriceSpecification.h
Common/C++/SmartAPI/smartapi/model/PropertyDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/SubscriptionPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/TimeDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/TravelDistanceDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/TravelDistanceDurationDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/UnitPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/ZoneDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/ZoneTravelDependentPriceSpecification.h
Common/C++/SmartAPI/smartapi/model/ZoneTravelDurationDependentPriceSpecification.h
Common/Python/SmartAPI/model/License.py [new file with mode: 0644]

index 56d0dbf61231913573d4174cb18dcf3e751d46ab..4c54874f99ec2afe9d428e02588935fef62ef632 100644 (file)
@@ -25,6 +25,8 @@ public:
        void setCoordinates(Coordinates* c)                                             { add(PROPERTY__LOCATION, c); mCoordinates = c; }
        void setCoordinates(double lat, double lon)                             { setCoordinates(new Coordinates(lat, lon)); }
 
+       bool isTimeDependent() { return false; }
+
 private:
        Coordinates* mCoordinates;
 };
index bd8f16ac3c80891da2245256d821b5f5571be294..8d25da4b6d2fc2bb2f7f59d642905d51b3a43441 100644 (file)
@@ -25,6 +25,8 @@ public:
        void setCoordinates(Coordinates* c)                                             { add(PROPERTY__LOCATION, c); mCoordinates = c; }
        void setCoordinates(double lat, double lon)                             { setCoordinates(new Coordinates(lat, lon)); }
 
+       bool isTimeDependent() { return true; }
+
 private:
        Coordinates* mCoordinates;};
 
index 8be0a1fcae6f26d74c305713cc9aea16803c6a3d..a97a64a611de119f4c2853d826b48e4cb62df249 100644 (file)
@@ -14,6 +14,9 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return false; }
+
 };
 
 #endif // DURATIONATZONEDEPENDENTPRICESPECIFICATION_H
index 75c36b9270864474d656b2505e41718453f434a3..aa72140abbdb8f82fba2a59c2714eb9c8d71c747 100644 (file)
@@ -16,6 +16,9 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return false; }
+
 };
 
 #endif // DURATIONDEPENDENTPRICESPECIFICATION_H
index bc0e573d6cca160d757bb0341d9343f33003f987..acd3272b044bcecf3801a9f2699b6b43a81aece8 100644 (file)
@@ -49,3 +49,14 @@ void PriceListSpecification::parse(Statement* statement)
        PARSE_PROPERTY(PROPERTY__HASPRICESPECIFICATION, addPriceSpecification, PriceSpecification)
        FINISH_PARSE(PriceSpecification)
 }
+
+bool PriceListSpecification::isTimeDependent()
+{
+       bool isDependent = false;
+       for (PropertyListItem<PriceSpecification*>* i = mPriceSpecifications.firstItem(); i != NULL; i = i->next()) {
+               if (i->getItem()) {
+                       isDependent = (isDependent || i->getItem()->isTimeDependent());
+               }
+       }
+       return isDependent;
+}
index 1695b482886ec64327249dc97ef8a119052ffdd0..1d5dc6b339b33a659b54f3e6869c54cce164b4d5 100644 (file)
@@ -19,6 +19,8 @@ public:
        void addPriceSpecification(PriceSpecification* priceSpecification)      { mPriceSpecifications.append(priceSpecification); }
        PropertyList<PriceSpecification*> getPriceSpecifications()                      { return mPriceSpecifications; }
 
+       bool isTimeDependent();
+
 private:
        PropertyList<PriceSpecification*> mPriceSpecifications;
 
index ac5e0206cb7ac39535d0ea6e399d1679ab1d0990..65b782cf8e8d1cb966dc2344b611e110f883fb00 100644 (file)
@@ -82,6 +82,8 @@ public:
        void setSecondaryUnit(QString unit)                                             { if (unit.length() > 0) setSecondaryUnit(QUrl(unit)); }
        void setSecondaryUnit(QUrl unit)                                                        { setSecondaryUnit(new Variant(unit)); }
 
+       virtual bool isTimeDependent() { return false; };
+
 private:
        Variant* mCurrency;
        Variant* mCurrencyValue;
index effa15f5bc7a834241b1b64b81667ab149b9c741..d4be2b2bd928217f4d53d06471a07b97d6ae5272 100644 (file)
@@ -28,6 +28,8 @@ public:
        void setProperty(QUrl property)                                                 { setProperty(new Variant(property)); }
        void setProperty(Variant* property)                                             { set(PROPERTY__SMARTAPI_PROPERTY, property); mProperty = property; }
 
+       bool isTimeDependent() { return false; }
+
 private:
        Variant* mReferenceObject;
        Variant* mProperty;
index 17830ac65bf29a102608d98e00390bcc037dcbbf..e0acc30fcd70915ddc51c2390920b4cd9d7bab2e 100644 (file)
@@ -14,6 +14,9 @@ public:
 
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return false; }
+
 };
 
 #endif // _SUBSCRIPTIONPRICESPECIFICATION_H_
index 81a01b4f79b15d922c41d660f3e5929808ab33bd..cdd3be9875fb76067de1e47c4118442bdf5710e5 100644 (file)
@@ -15,6 +15,8 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return true; }
 };
 
 #endif // TIMEDEPENDENTPRICESPECIFICATION_H
index d5aab1a9f32a22805897f9d17b3604474ef342be..f36c2d93bf8cda00abbaeab6b5c565c2860041ae 100644 (file)
@@ -29,6 +29,8 @@ public:
 
        double calculatePrice(double distance);
 
+       bool isTimeDependent() { return false; }
+
 private:
        CalculationMethod* mCalculationMethod;
 };
index edf35a3fdc8fd4122cd99295420d0df9b363d100..2660364aa73c0a29a7c0fd82d6ffc0034cd4168f 100644 (file)
@@ -14,6 +14,9 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return true; }
+
 };
 
 #endif // TRAVELDISTANCEDURATIONDEPENDENTPRICESPECIFICATION_H
index 8b8c34df84e310ea27e2aca7790b4ac31cb2e8ae..68f5e668daa6623eec0af8b085a9284c7ac0e448 100644 (file)
@@ -14,6 +14,9 @@ public:
 
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return false; }
+
 };
 
 #endif // _UNITPRICESPECIFICATION_H_
index eaedc4cf9dd296a7dd5ac35d8690eb7e690e8176..3197c2216006f1c61c305a4dbe3545c0ab67049f 100644 (file)
@@ -14,6 +14,9 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return false; }
+
 };
 
 #endif // ZONEDEPENDENTPRICESPECIFICATION_H
index ceddb34177aa10559acc8a37fb4471d642ff4725..6debdd1219b368910429358c10b9331153859f19 100644 (file)
@@ -14,6 +14,9 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return false; }
+
 };
 
 #endif // ZONETRAVELDEPENDENTPRICESPECIFICATION_H
index ac15c5d0081728ae5398b8c059f93e06527255c8..6a5cfa68165def6d7e85c65499d9cff4aea29e82 100644 (file)
@@ -15,6 +15,9 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
        Resource* serialize(Model* model);
        void parse(Statement* statement);
+
+       bool isTimeDependent() { return true; }
+
 };
 
 #endif // ZONETRAVELDURATIONDEPENDENTPRICESPECIFICATION_H
diff --git a/Common/Python/SmartAPI/model/License.py b/Common/Python/SmartAPI/model/License.py
new file mode 100644 (file)
index 0000000..4774abe
--- /dev/null
@@ -0,0 +1,52 @@
+from SmartAPI.model.Contract import Contract
+from SmartAPI.common.RESOURCE import RESOURCE
+from SmartAPI.common.PROPERTY import PROPERTY
+from SmartAPI.rdf.Variant import Variant
+from rdflib.term import URIRef
+from SmartAPI.model.PriceSpecification import PriceSpecification
+
+class License(Contract):
+    def __init__(self, identifierUri=None):
+        Obj.__init__(self, identifierUri)
+        self.setType(RESOURCE.LICENSE)
+        self.init_property(PROPERTY.LICENSEKEY, "licenseKey", self.hasLicenseKey, self.getLicenseKey)
+        self.init_property(PROPERTY.ACCOUNT, "account", self.hasAccount, self.getAccount)
+        self.init_property(PROPERTY.HASPRICESPECIFICATION, "priceSpecifications", self.hasPriceSpecification, self.getPriceSpecifications, True)
+    
+    def _parseStatement(self, statement):
+        from SmartAPI.model.Account import Account
+        
+        self.parse_property(statement, PROPERTY.LICENSEKEY, self.setLicenseKey, Variant)  
+        self.parse_property(statement, PROPERTY.ACCOUNT, self.setAccount, Acount)
+        self.parse_property(statement, PROPERTY.HASPRICESPECIFICATION, self.addPriceSpecification, PriceSpecification)
+        
+    def hasLicenseKey(self):
+        return self.licenseKey is not None
+         
+    def getLicenseKey(self):
+        return self.licenseKey
+    
+    def setLicenseKey(self, k):
+        self.licenseKey = k
+    
+    def hasAccount(self): 
+        return self.account is not None
+    
+    def getAccount(self):
+        return self.account
+    
+    def setAccount(self, acc):
+        '''
+        '''
+        self.account = acc
+    
+    def hasPriceSpecification(self): 
+        return len(self.priceSpecifications) > 0
+    
+    def getPriceSpecifications(self):
+        return self.priceSpecifications
+    
+    def addPriceSpecification(self, pc):
+        self.priceSpecifications.append(pc)
+    
\ No newline at end of file