C++: new Group class, modifications to Offering
authorjani <jani@asema.com>
Mon, 9 Sep 2019 14:10:27 +0000 (17:10 +0300)
committerjani <jani@asema.com>
Mon, 9 Sep 2019 14:10:27 +0000 (17:10 +0300)
Common/C++/SmartAPI/smartapi.pro
Common/C++/SmartAPI/smartapi/common/PROPERTY.h
Common/C++/SmartAPI/smartapi/common/RESOURCE.h
Common/C++/SmartAPI/smartapi/model/Group.cpp [new file with mode: 0755]
Common/C++/SmartAPI/smartapi/model/Group.h [new file with mode: 0644]
Common/C++/SmartAPI/smartapi/model/Offering.cpp
Common/C++/SmartAPI/smartapi/model/Offering.h
Common/C++/SmartAPI/smartapi/model/Voucher.cpp
Common/C++/SmartAPI/smartapi/model/Voucher.h

index 7c9dd851643effc8bba83f01d19d248f9176f9af..8c93955fa23d01912635b69507728445bb637bc9 100644 (file)
@@ -104,6 +104,7 @@ SOURCES += smartapi/agents/Agent.cpp \
         smartapi/model/Evaluation.cpp \
         smartapi/model/Grading.cpp \
         smartapi/model/GrObj.cpp \
+        smartapi/model/Group.cpp \
         smartapi/model/HeartBeat.cpp \
         smartapi/model/Input.cpp \
         smartapi/model/InterfaceAddress.cpp \
@@ -247,6 +248,7 @@ HEADERS += smartapi/agents/Agent.h \
         smartapi/model/Evaluation.h \
         smartapi/model/Grading.h \
         smartapi/model/GrObj.h \
+        smartapi/model/Group.h \
         smartapi/model/HeartBeat.h \
         smartapi/model/Input.h \
         smartapi/model/InterfaceAddress.h \
index 7c32ecf072c3ae478d178759212978ab777cdfb0..005ebefd6010f1727ef81393b960e75048851a3c 100644 (file)
 #define PROPERTY__ZONEROUTE            "http://smart-api.io/ontology/1.0/smartapi#zoneRoute"
 
 #define PROPERTY__VOUCHER              "http://smart-api.io/ontology/1.0/smartapi#voucher"
+#define PROPERTY__ORGANIZATION         "http://smart-api.io/ontology/1.0/smartapi#organization"
+#define PROPERTY__GROUP                "http://smart-api.io/ontology/1.0/smartapi#group"
+#define PROPERTY__PROMOCODE            "http://smart-api.io/ontology/1.0/smartapi#promoCode"
 
 #endif //__PROPERTY_H__
index e44f08e723676b7b3fadec7ee35419f29c0efd59..c5b6b60b9496b07011f481451e12fcd4482755f6 100644 (file)
 #define RESOURCE__ZONETRAVELDURATIONDEPENDENTPRICESPECIFICATION                "http://smart-api.io/ontology/1.0/smartapi#ZoneTravelDurationDependentPriceSpecification"
 
 #define RESOURCE__VOUCHER              "http://smart-api.io/ontology/1.0/smartapi#Voucher"
+#define RESOURCE__PROMOCODE            "http://smart-api.io/ontology/1.0/smartapi#PromoCode"
 
 #endif //__RESOURCE_H__
diff --git a/Common/C++/SmartAPI/smartapi/model/Group.cpp b/Common/C++/SmartAPI/smartapi/model/Group.cpp
new file mode 100755 (executable)
index 0000000..e9bbc92
--- /dev/null
@@ -0,0 +1,14 @@
+#include "Group.h"
+
+Resource* Group::serialize(Model* model)
+{
+       INIT_SERIALIZE(Entity,model)
+       FINISH_SERIALIZE(Entity)
+}
+
+
+void Group::parse(Statement* statement)
+{
+       INIT_PARSE(statement)
+       FINISH_PARSE(Entity)
+}
diff --git a/Common/C++/SmartAPI/smartapi/model/Group.h b/Common/C++/SmartAPI/smartapi/model/Group.h
new file mode 100644 (file)
index 0000000..b0983e7
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _GROUP_H_
+#define _GROUP_H_
+
+#include "smartapi/common/RESOURCE.h"
+#include "smartapi/model/Entity.h"
+
+#include <QString>
+
+class Group : public Entity
+{
+public:
+       Group() : Entity() { setType(RESOURCE__GROUP); }
+       Group(QString uri) : Entity(uri) { setType(RESOURCE__GROUP); }
+       Group(Group* r) : Entity(r) {}
+
+       Resource* serialize(Model* model);
+       void parse(Statement* statement);
+};
+
+#endif // _GROUP_H_
index ee270f6ae6fc121917d9c1cf1f1c6ec1f7772cb1..bf8284ef624ce2831ff2768e0e5f8aa9a270f6f9 100755 (executable)
@@ -5,6 +5,9 @@
 #include "smartapi/common/Tools.h"
 #include "smartapi/model/UnitPriceSpecification.h"
 #include "smartapi/model/SomeItems.h"
+#include "smartapi/model/Organization.h"
+#include "smartapi/model/Group.h"
+#include "smartapi/model/Person.h"
 
 
 Offering::Offering(QString identifierUri)
@@ -12,9 +15,12 @@ Offering::Offering(QString identifierUri)
 {
        setType(RESOURCE__OFFERING);
        INIT_PROPERTY(mBusinessFunction)
-       INIT_PROPERTYLIST(mPriceSpecifications,PROPERTY__HASPRICESPECIFICATION);
-       INIT_PROPERTYLIST(mIncludes,PROPERTY__INCLUDES);
-       INIT_PROPERTYLIST(mTypeAndQuantityNodes,PROPERTY__INCLUDESOBJECT);
+       INIT_PROPERTYLIST(mPriceSpecifications, PROPERTY__HASPRICESPECIFICATION);
+       INIT_PROPERTYLIST(mIncludes, PROPERTY__INCLUDES);
+       INIT_PROPERTYLIST(mTypeAndQuantityNodes, PROPERTY__INCLUDESOBJECT);
+       INIT_PROPERTYLIST(mOrganizations, PROPERTY__ORGANIZATION);
+       INIT_PROPERTYLIST(mGroups, PROPERTY__GROUP);
+       INIT_PROPERTYLIST(mPersons, PROPERTY__PERSON);
 }
 
 Offering::Offering(QString identifierUri, QString name, QString description)
@@ -30,6 +36,9 @@ Offering::Offering(Offering* o) : GrObj(o)
        SET_PROPERTY_REFERENCE(PROPERTY__HASBUSINESSFUNCTION,mBusinessFunction,Variant);
        SET_PROPERTYLIST_REFERENCE(PROPERTY__INCLUDES,mIncludes,SomeItems)
        SET_PROPERTYLIST_REFERENCE(PROPERTY__INCLUDESOBJECT,mTypeAndQuantityNodes,TypeAndQuantityNode)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__ORGANIZATION,mOrganizations,Organization)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__GROUP,mGroups,Group)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__PERSON,mPersons,Person)
        COPY_PROPERTYLIST(PROPERTY__HASPRICESPECIFICATION,mPriceSpecifications,PriceSpecification)
        setType(RESOURCE__OFFERING);
 }
@@ -40,13 +49,13 @@ Offering::~Offering()
 
 void Offering::clearReferences(QSet<GraphItem*>* trash)
 {
-       INIT_CLEAR(GrObj,trash);
-       FINISH_CLEAR(GrObj,trash);
+       INIT_CLEAR(GrObj, trash);
+       FINISH_CLEAR(GrObj, trash);
 }
 
 Resource* Offering::serialize(Model *model)
 {
-       INIT_SERIALIZE(GrObj,model)
+       INIT_SERIALIZE(GrObj, model)
        FINISH_SERIALIZE(GrObj)
 }
 
@@ -57,6 +66,10 @@ void Offering::parse(Statement* statement)
        PARSE_PROPERTY(PROPERTY__HASPRICESPECIFICATION, addPriceSpecification, PriceSpecification)
        PARSE_PROPERTY(PROPERTY__INCLUDES, addIncludes, SomeItems)
        PARSE_PROPERTY(PROPERTY__INCLUDESOBJECT, addTypeAndQuantityNode, TypeAndQuantityNode)
+       PARSE_PROPERTY(PROPERTY__ORGANIZATION, addOrganization, Organization)
+       PARSE_PROPERTY(PROPERTY__GROUP, addGroup, Group)
+       PARSE_PROPERTY(PROPERTY__PERSON, addPerson, Person)
+
        FINISH_PARSE(GrObj)
 }
 
index bee6f1d5c619e69b406386379173df26dd8d7b17..f998dcda289f024c22ab824409b39a8e402d2419 100644 (file)
@@ -8,6 +8,9 @@
 class SomeItems;
 class PriceSpecification;
 class UnitPriceSpecification;
+class Person;
+class Organization;
+class Group;
 
 class Offering : public GrObj
 {
@@ -41,11 +44,26 @@ public:
        void addTypeAndQuantityNode(TypeAndQuantityNode* t)                                     { mTypeAndQuantityNodes.append(t); }
        PropertyList<TypeAndQuantityNode*> getTypeAndQuantityNodes()            { return mTypeAndQuantityNodes; }
 
+       bool hasPerson()                                                                                                        { return !mPersons.isEmpty(); }
+       void addPerson(Person* p)                                                                                       { mPersons.append(p); }
+       PropertyList<Person*> getPersons()                                                                      { return mPersons; }
+
+       bool hasGroup()                                                                                                         { return !mGroups.isEmpty(); }
+       void addGroup(Group* g)                                                                                         { mGroups.append(g); }
+       PropertyList<Group*> getGroups()                                                                        { return mGroups; }
+
+       bool hasOrganization()                                                                                          { return !mOrganizations.isEmpty(); }
+       void addOrganization(Organization* p)                                                           { mOrganizations.append(p); }
+       PropertyList<Organization*> getOrganizations()                                          { return mOrganizations; }
+
        void addItem(Obj* item, float amount, QString unitOfMeasurement,
                                QString name, QString description)                                              { addTypeAndQuantityNode(new TypeAndQuantityNode(item, amount, unitOfMeasurement, name, description)); }
 
 protected:
        Variant* mBusinessFunction;
+       PropertyList<Organization*> mOrganizations;
+       PropertyList<Group*> mGroups;
+       PropertyList<Person*> mPersons;
        PropertyList<PriceSpecification*> mPriceSpecifications;
        PropertyList<SomeItems*> mIncludes;
        PropertyList<TypeAndQuantityNode*> mTypeAndQuantityNodes;
index 4ce684cbd89dc0e0745e6742dfd14ec74be3a325..398fbaddb5b3f9c2894e924721bcf4d3e4e0a55b 100755 (executable)
@@ -9,6 +9,7 @@ Voucher::Voucher(QString identifierUri)
 {
        setType(RESOURCE__VOUCHER);
        INIT_PROPERTY(mMaxAvailable)
+       INIT_PROPERTY(mPromoCode)
 }
 
 Voucher::Voucher(QString identifierUri, QString name, QString description)
@@ -43,5 +44,6 @@ void Voucher::parse(Statement* statement)
 {
        INIT_PARSE(statement)
        PARSE_PROPERTY(PROPERTY__MAXAVAILABLE, setMaxAvailable, Variant)
+       PARSE_PROPERTY(PROPERTY__PROMOCODE, setPromoCode, Variant)
        FINISH_PARSE(Offering)
 }
index 1515af0444ed1be17180761798f2330d57281fbd..5f401c8c6a2aeec42934b2b0736115e6d8bbbc85 100644 (file)
@@ -17,11 +17,17 @@ public:
 
        bool hasMaxAvailable()                                                                                          { return mMaxAvailable != NULL; }
        void setMaxAvailable(Variant* m)                                                                        { add(PROPERTY__MAXAVAILABLE, m); mMaxAvailable = m; }
-       void setMaxAvailable(int m)                                                                                     { setBusinessFunction(new Variant(m)); }
+       void setMaxAvailable(int m)                                                                                     { setMaxAvailable(new Variant(m)); }
        int getMaxAvailable()                                                                                           { PROPERTYVAL(mMaxAvailable, asInt, -1); }
 
+       bool hasPromoCode()                                                                                                     { return mPromoCode != NULL; }
+       void setPromoCode(Variant* c)                                                                           { add(PROPERTY__PROMOCODE, c); mPromoCode = c; }
+       void setPromoCode(QString c)                                                                            { setPromoCode(new Variant(c)); }
+       QString getPromoCode()                                                                                          { PROPERTYVAL(mPromoCode, asString, QString()); }
+
 private:
        Variant* mMaxAvailable;
+       Variant* mPromoCode;
 };
 
 #endif // _VOUCHER_H_