C++, Python, Java: change the model to match the architecture doc
authorjani <jani@asema.com>
Fri, 4 Jan 2019 11:16:37 +0000 (13:16 +0200)
committerjani <jani@asema.com>
Fri, 4 Jan 2019 11:16:37 +0000 (13:16 +0200)
35 files changed:
Common/C++/SmartAPI/smartapi/model/Activity.cpp
Common/C++/SmartAPI/smartapi/model/Activity.h
Common/C++/SmartAPI/smartapi/model/Availability.cpp
Common/C++/SmartAPI/smartapi/model/Availability.h
Common/C++/SmartAPI/smartapi/model/Calculable.h
Common/C++/SmartAPI/smartapi/model/Condition.h
Common/C++/SmartAPI/smartapi/model/Evaluation.cpp
Common/C++/SmartAPI/smartapi/model/Evaluation.h
Common/C++/SmartAPI/smartapi/model/Input.h
Common/C++/SmartAPI/smartapi/model/License.cpp
Common/C++/SmartAPI/smartapi/model/License.h
Common/C++/SmartAPI/smartapi/model/LinearCalculation.cpp
Common/C++/SmartAPI/smartapi/model/Message.cpp
Common/C++/SmartAPI/smartapi/model/Message.h
Common/C++/SmartAPI/smartapi/model/Obj.cpp
Common/C++/SmartAPI/smartapi/model/Provenance.cpp
Common/C++/SmartAPI/smartapi/model/Provenance.h
Common/C++/SmartAPI/smartapi/model/Restriction.cpp
Common/C++/SmartAPI/smartapi/model/Restriction.h
Common/C++/SmartAPI/smartapi/model/ValueObject.cpp
Common/C++/SmartAPI/smartapi/model/ValueObject.h
Common/Java/SmartAPI/src/smartapi/common/ClassMapper.java
Common/Java/SmartAPI/src/smartapi/common/Tools.java
Common/Java/SmartAPI/src/smartapi/model/Availability.java
Common/Java/SmartAPI/src/smartapi/model/Capacity.java
Common/Java/SmartAPI/src/smartapi/model/License.java
Common/Java/SmartAPI/src/smartapi/model/Obj.java
Common/Java/SmartAPI/src/smartapi/model/Provenance.java
Common/Java/SmartAPI/src/smartapi/rdf/NudeList.java
Common/Java/SmartAPI/src/smartapi/rdf/Variant.java
Common/Java/SmartAPI/src/smartapi/tests/TestSequence.java
Common/Python/SmartAPI/model/Activity.py
Common/Python/SmartAPI/model/Availability.py
Common/Python/SmartAPI/model/Evaluation.py
Common/Python/SmartAPI/model/Provenance.py

index 7d43d43253019b7332bfc2af510acf2920063db0..9896a137c88606685ee14dc80eeb208b59c6f9b9 100755 (executable)
@@ -4,12 +4,11 @@
 #include "smartapi/model/Authorization.h"
 #include <QtDebug>
 
-Activity::Activity(QString uri) : Obj(uri)
+Activity::Activity(QString uri) : Evaluation(uri)
 {
        setType(RESOURCE__ACTIVITY);
        INIT_PROPERTY(mTemporalContext)
        INIT_PROPERTY(mAuthorization)
-       INIT_PROPERTY(mMethod)
        INIT_PROPERTY(mTraverseUntil);
        INIT_PROPERTYLIST(mInputs,PROPERTY__HASINPUT);
        INIT_PROPERTYLIST(mOutputs,PROPERTY__HASOUTPUT);
@@ -21,9 +20,8 @@ Activity::Activity(QString uri) : Obj(uri)
        INIT_PROPERTYLIST(mTraverseTo,PROPERTY__TRAVERSETO);
 }
 
-Activity::Activity(Activity* a) : Obj(a)
+Activity::Activity(Activity* a) : Evaluation(a)
 {
-       SET_PROPERTY_REFERENCE(PROPERTY__METHOD, mMethod, Variant)
        SET_PROPERTY_REFERENCE(PROPERTY__TEMPORALCONTEXT, mTemporalContext, TemporalContext)
        SET_PROPERTY_REFERENCE(PROPERTY__AUTHORIZATION, mAuthorization, Authorization)
        SET_PROPERTY_REFERENCE(PROPERTY__TRAVERSEUNTIL, mTraverseUntil, Variant)
@@ -59,7 +57,6 @@ Resource* Activity::serialize(Model* model)
 void Activity::parse(Statement* statement)
 {
        INIT_PARSE(statement)
-       PARSE_PROPERTY(PROPERTY__METHOD, setMethod, Variant)
        PARSE_PROPERTY(PROPERTY__TEMPORALCONTEXT, setTemporalContext, TemporalContext)
        PARSE_PROPERTY(PROPERTY__HASINPUT, addInput, Input)
        PARSE_PROPERTY(PROPERTY__HASOUTPUT, addOutput, Output)
index 4b48f41431afd4df0b6ae9f929abe226f77a360a..b99c19b122dc2676d4cab729544c13e03379071b 100644 (file)
@@ -2,7 +2,7 @@
 #define _ACTIVITY_H_
 
 #include "smartapi/common/RESOURCE.h"
-#include "smartapi/model/Obj.h"
+#include "smartapi/model/Evaluation.h"
 #include "smartapi/model/Input.h"
 #include "smartapi/model/Output.h"
 #include "smartapi/model/Availability.h"
@@ -21,7 +21,7 @@
 #include <QString>
 #include <QList>
 
-class Activity : public Obj
+class Activity : public Evaluation
 {
 public:
        Activity(QString uri = QString());
@@ -32,12 +32,6 @@ public:
        void parse(Statement* statement);
        virtual void clearReferences(QSet<GraphItem*>* trash);
        
-       bool hasMethod()                                                                                        { return mMethod != NULL; }
-       QString getMethod()                                                                                     { PROPERTYVAL(mMethod, asString, QString()); }
-       void setMethod(QString method)                                                          { setMethod(new Variant(QUrl(method))); }
-       void setMethod(QUrl method)                                                                     { setMethod(new Variant(method)); }
-       void setMethod(Variant* method)                                                         { add(PROPERTY__METHOD, method); mMethod = method; }
-
        bool hasInput()                                                                                         { return mInputs.length() > 0; }
        PropertyList<Input*> getInputs()                                                        { return mInputs; }
        void setInput(Input* input)                                                                     { addInput(input); }
@@ -103,7 +97,6 @@ public:
        void addTraverseTo(int depth)                                                           { addTraverseTo(new Variant(depth)); }
 
 private:
-       Variant* mMethod;
        TemporalContext* mTemporalContext;
        Authorization* mAuthorization;
        PropertyList<Input*> mInputs;
index ec114f5a70ba06251ac972698a42857efe95058d..f2668f1089f2d31bf52711aa80a39cfb86080a48 100755 (executable)
@@ -67,36 +67,6 @@ void Availability::parse(Statement* statement)
        Ability::parse(statement);
 }
 
-void Availability::setTemporalContext(TemporalContext* tc)
-{ 
-       Ability::setTemporalContext(tc);
-       addType(RESOURCE__TEMPORALAVAILABILITY);
-}
-
-void Availability::setTemporalContext(QDateTime start, QDateTime end)
-{
-       Ability::setTemporalContext(start, end);
-       addType(RESOURCE__TEMPORALAVAILABILITY);
-}
-
-void Availability::setTemporalContext(QDateTime start, QDateTime end, QString during)
-{
-       Ability::setTemporalContext(start, end, during);
-       addType(RESOURCE__TEMPORALAVAILABILITY);
-}
-
-void Availability::setTemporalContext(QTime start, QTime end)
-{
-       Ability::setTemporalContext(start, end);
-       addType(RESOURCE__TEMPORALAVAILABILITY);
-}
-
-void Availability::setTemporalContext(QTime start, QTime end, QString during)
-{
-       Ability::setTemporalContext(start, end, during);
-       addType(RESOURCE__TEMPORALAVAILABILITY);
-}
-
 void Availability::setProperty(Obj* property)
 { 
        Ability::setProperty(property);
index 5ea2d4844f2705851841efda48ad0d0cc458c6a3..840a4dabfc845a897d1072abb62f230df99bfcb4 100644 (file)
@@ -28,12 +28,6 @@ public:
 
        void parse(Statement* statement);
        
-       void setTemporalContext(TemporalContext* tc);
-       void setTemporalContext(QDateTime start, QDateTime end);
-       void setTemporalContext(QDateTime start, QDateTime end, QString during);
-       void setTemporalContext(QTime start, QTime end);
-       void setTemporalContext(QTime start, QTime end, QString during);
-
        void setProperty(Obj* property);
        void setProperty(QString property);
        
index 4a980b60d82faaff427dffb2a7c3fd21ba0c9d3b..049608fea03b95c341403b328779db2c5b16aeba 100644 (file)
@@ -8,11 +8,11 @@
 class Calculable : public Obj
 {
 public:
-    Calculable(QString identifierUri) : Obj(identifierUri) {}
-    Calculable(Calculable* o): Obj(o) {}
-    ~Calculable() {}
+       Calculable(QString identifierUri) : Obj(identifierUri) {}
+       Calculable(Calculable* o): Obj(o) {}
+       ~Calculable() {}
 
-    virtual double calculate(QList<double> args) = 0;
+       virtual double calculate(QList<double> args) = 0;
 };
 
 #endif // CALCULABLE_H
index c7cc6fdd5445dad5c2bbe52b38536f2819886df5..d5ca9b373ca68db50cc5fb12d1764d00f2ed5f74 100644 (file)
@@ -27,91 +27,91 @@ public:
        void parse(Statement* statement);
        virtual void clearReferences(QSet<GraphItem*>* trash);
        
-    bool hasAction()                            { return mActions.length() > 0; }
-    PropertyList<Variant*> getActions()         { return mActions; }
-    void addAction(Obj* o)                      { mActions.append(new Variant(o)); }
-    void addAction(Variant* variant)            { mActions.append(variant); }
-    void removeAction(Variant* variant)         { mActions.removeOne(variant); }
+       bool hasAction()                            { return mActions.length() > 0; }
+       PropertyList<Variant*> getActions()         { return mActions; }
+       void addAction(Obj* o)                      { mActions.append(new Variant(o)); }
+       void addAction(Variant* variant)            { mActions.append(variant); }
+       void removeAction(Variant* variant)         { mActions.removeOne(variant); }
 
-    bool hasOr()                                { return mOrs.length() > 0; }
-    PropertyList<Variant*> getOrs()             { return mOrs; }
-    void addOr(Obj* o)                          { mOrs.append(new Variant(o)); }
-    void addOr(Variant* variant)                { mOrs.append(variant); }
-    void removeOr(Variant* variant)             { mOrs.removeOne(variant); }
+       bool hasOr()                                { return mOrs.length() > 0; }
+       PropertyList<Variant*> getOrs()             { return mOrs; }
+       void addOr(Obj* o)                          { mOrs.append(new Variant(o)); }
+       void addOr(Variant* variant)                { mOrs.append(variant); }
+       void removeOr(Variant* variant)             { mOrs.removeOne(variant); }
        
-    bool hasXor()                               { return mXors.length() > 0; }
-    PropertyList<Variant*> getXors()            { return mXors; }
-    void addXor(Obj* o)                         { mXors.append(new Variant(o)); }
-    void addXor(Variant* variant)               { mXors.append(variant); }
-    void removeXor(Variant* variant)            { mXors.removeOne(variant); }
+       bool hasXor()                               { return mXors.length() > 0; }
+       PropertyList<Variant*> getXors()            { return mXors; }
+       void addXor(Obj* o)                         { mXors.append(new Variant(o)); }
+       void addXor(Variant* variant)               { mXors.append(variant); }
+       void removeXor(Variant* variant)            { mXors.removeOne(variant); }
        
-    bool hasAnd()                               { return mAnds.length() > 0; }
-    PropertyList<Variant*> getAnds()            { return mAnds; }
-    void addAnd(Obj* o)                         { mAnds.append(new Variant(o)); }
-    void addAnd(Variant* variant)               { mAnds.append(variant); }
-    void removeAnd(Variant* variant)            { mAnds.removeOne(variant); }
+       bool hasAnd()                               { return mAnds.length() > 0; }
+       PropertyList<Variant*> getAnds()            { return mAnds; }
+       void addAnd(Obj* o)                         { mAnds.append(new Variant(o)); }
+       void addAnd(Variant* variant)               { mAnds.append(variant); }
+       void removeAnd(Variant* variant)            { mAnds.removeOne(variant); }
 
-    bool hasRegex()                             { return mRegexes.length() > 0; }
-    PropertyList<Variant*> getRegexes()         { return mRegexes; }
-    void addRegex(Variant* regex)               { mRegexes.append(regex); }
-    void addRegex(QString regex)                { addRegex(new Variant(regex)); }
+       bool hasRegex()                             { return mRegexes.length() > 0; }
+       PropertyList<Variant*> getRegexes()         { return mRegexes; }
+       void addRegex(Variant* regex)               { mRegexes.append(regex); }
+       void addRegex(QString regex)                { addRegex(new Variant(regex)); }
 
-    bool hasEqual()                             { return mEquals.length() > 0; }
-    PropertyList<Variant*> getEquals()          { return mEquals; }
-    void addEqual(Obj* o)                       { mEquals.append(new Variant(o)); }
-    void addEqual(Variant* variant)             { mEquals.append(variant); }
-    void removeEqual(Variant* variant)          { mEquals.removeOne(variant); }
+       bool hasEqual()                             { return mEquals.length() > 0; }
+       PropertyList<Variant*> getEquals()          { return mEquals; }
+       void addEqual(Obj* o)                       { mEquals.append(new Variant(o)); }
+       void addEqual(Variant* variant)             { mEquals.append(variant); }
+       void removeEqual(Variant* variant)          { mEquals.removeOne(variant); }
 
-    bool hasNonEqual()                          { return mNonEquals.length() > 0; }
-    PropertyList<Variant*> getNonEquals()       { return mNonEquals; }
-    void addNonEqual(Obj* o)                    { mNonEquals.append(new Variant(o)); }
-    void addNonEqual(Variant* variant)          { mNonEquals.append(variant); }
-    void removeNonEqual(Variant* variant)       { mNonEquals.removeOne(variant); }
+       bool hasNonEqual()                          { return mNonEquals.length() > 0; }
+       PropertyList<Variant*> getNonEquals()       { return mNonEquals; }
+       void addNonEqual(Obj* o)                    { mNonEquals.append(new Variant(o)); }
+       void addNonEqual(Variant* variant)          { mNonEquals.append(variant); }
+       void removeNonEqual(Variant* variant)       { mNonEquals.removeOne(variant); }
 
-    bool hasLesser()                            { return mLessers.length() > 0; }
-    PropertyList<Variant*> getLessers()         { return mLessers; }
-    void addLesser(Obj* o)                      { mLessers.append(new Variant(o)); }
-    void addLesser(Variant* variant)            { mLessers.append(variant); }
-    void removeLesser(Variant* variant)         { mLessers.removeOne(variant); }
+       bool hasLesser()                            { return mLessers.length() > 0; }
+       PropertyList<Variant*> getLessers()         { return mLessers; }
+       void addLesser(Obj* o)                      { mLessers.append(new Variant(o)); }
+       void addLesser(Variant* variant)            { mLessers.append(variant); }
+       void removeLesser(Variant* variant)         { mLessers.removeOne(variant); }
 
-    bool hasLesserOrEqual()                     { return mLesserOrEquals.length() > 0; }
-    PropertyList<Variant*> getLesserOrEquals()  { return mLesserOrEquals; }
-    void addLesserOrEqual(Obj* o)               { mLesserOrEquals.append(new Variant(o)); }
-    void addLesserOrEqual(Variant* variant)     { mLesserOrEquals.append(variant); }
-    void removeLesserOrEqual(Variant* variant)  { mLesserOrEquals.removeOne(variant); }
+       bool hasLesserOrEqual()                     { return mLesserOrEquals.length() > 0; }
+       PropertyList<Variant*> getLesserOrEquals()  { return mLesserOrEquals; }
+       void addLesserOrEqual(Obj* o)               { mLesserOrEquals.append(new Variant(o)); }
+       void addLesserOrEqual(Variant* variant)     { mLesserOrEquals.append(variant); }
+       void removeLesserOrEqual(Variant* variant)  { mLesserOrEquals.removeOne(variant); }
 
-    bool hasGreater()                           { return mGreaters.length() > 0; }
-    PropertyList<Variant*> getGreaters()        { return mGreaters; }
-    void addGreater(Obj* o)                     { mGreaters.append(new Variant(o)); }
-    void addGreater(Variant* variant)           { mGreaters.append(variant); }
-    void removeGreater(Variant* variant)        { mGreaters.removeOne(variant); }
+       bool hasGreater()                           { return mGreaters.length() > 0; }
+       PropertyList<Variant*> getGreaters()        { return mGreaters; }
+       void addGreater(Obj* o)                     { mGreaters.append(new Variant(o)); }
+       void addGreater(Variant* variant)           { mGreaters.append(variant); }
+       void removeGreater(Variant* variant)        { mGreaters.removeOne(variant); }
 
-    bool hasGreaterOrEqual()                    { return mGreaterOrEquals.length() > 0; }
-    PropertyList<Variant*> getGreaterOrEquals() { return mGreaterOrEquals; }
-    void addGreaterOrEqual(Obj* o)              { mGreaterOrEquals.append(new Variant(o)); }
-    void addGreaterOrEqual(Variant* variant)    { mGreaterOrEquals.append(variant); }
-    void removeGreaterOrEqual(Variant* variant) { mGreaterOrEquals.removeOne(variant); }
+       bool hasGreaterOrEqual()                    { return mGreaterOrEquals.length() > 0; }
+       PropertyList<Variant*> getGreaterOrEquals() { return mGreaterOrEquals; }
+       void addGreaterOrEqual(Obj* o)              { mGreaterOrEquals.append(new Variant(o)); }
+       void addGreaterOrEqual(Variant* variant)    { mGreaterOrEquals.append(variant); }
+       void removeGreaterOrEqual(Variant* variant) { mGreaterOrEquals.removeOne(variant); }
 
-       bool hasTemporalContext()                                                                                   { return (mTemporalContext != NULL); }
-       TemporalContext* getTemporalContext()                                                       { return mTemporalContext; }
-       void setTemporalContext(TemporalContext* temporalContext)                   { add(PROPERTY__TEMPORALCONTEXT, temporalContext); mTemporalContext = temporalContext; }
-       void setTemporalContext(QDateTime start)                                                    { setTemporalContext(new TemporalContext(start)); }
-       void setTemporalContext(QDateTime start, QDateTime end)                     { setTemporalContext(new TemporalContext(start, end)); }
-       void setTemporalContext(QDateTime start, QDateTime end, QString during) { setTemporalContext(new TemporalContext(start, end, during)); }
+       bool hasTemporalContext()                                                                                               { return (mTemporalContext != NULL); }
+       TemporalContext* getTemporalContext()                                                                   { return mTemporalContext; }
+       void setTemporalContext(TemporalContext* temporalContext)                               { add(PROPERTY__TEMPORALCONTEXT, temporalContext); mTemporalContext = temporalContext; }
+       void setTemporalContext(QDateTime start)                                                                { setTemporalContext(new TemporalContext(start)); }
+       void setTemporalContext(QDateTime start, QDateTime end)                                 { setTemporalContext(new TemporalContext(start, end)); }
+       void setTemporalContext(QDateTime start, QDateTime end, QString during) { setTemporalContext(new TemporalContext(start, end, during)); }
 
 private:
        TemporalContext* mTemporalContext;
-    PropertyList<Variant*> mActions;
-    PropertyList<Variant*> mOrs;
-    PropertyList<Variant*> mXors;
-    PropertyList<Variant*> mAnds;
-    PropertyList<Variant*> mRegexes;
-    PropertyList<Variant*> mEquals;
-    PropertyList<Variant*> mNonEquals;
-    PropertyList<Variant*> mLessers;
-    PropertyList<Variant*> mLesserOrEquals;
-    PropertyList<Variant*> mGreaters;
-    PropertyList<Variant*> mGreaterOrEquals;
+       PropertyList<Variant*> mActions;
+       PropertyList<Variant*> mOrs;
+       PropertyList<Variant*> mXors;
+       PropertyList<Variant*> mAnds;
+       PropertyList<Variant*> mRegexes;
+       PropertyList<Variant*> mEquals;
+       PropertyList<Variant*> mNonEquals;
+       PropertyList<Variant*> mLessers;
+       PropertyList<Variant*> mLesserOrEquals;
+       PropertyList<Variant*> mGreaters;
+       PropertyList<Variant*> mGreaterOrEquals;
 };
 
 #endif // _CONDITION_H_
index 3ea981ec05b874d33aeff3fa4b24a6c4ac4996c3..e6e112921ddddec005787cd5d89e1a01c427db81 100755 (executable)
@@ -1,6 +1,5 @@
 #include "Evaluation.h"
 
-#include "smartapi/model/Activity.h"
 #include "smartapi/model/Device.h"
 #include "smartapi/model/Entity.h"
 #include "smartapi/model/Map.h"
@@ -8,7 +7,6 @@
 #include "smartapi/model/Parameter.h"
 #include "smartapi/model/Service.h"
 #include "smartapi/model/SystemOfInterest.h"
-#include "smartapi/model/TemporalContext.h"
 #include "smartapi/model/TimeSeries.h"
 #include "smartapi/model/ValueObject.h"
 #include "smartapi/rdf/Variant.h"
@@ -25,20 +23,17 @@ Evaluation::Evaluation(QString uri)
        setType(RESOURCE__EVALUATION);
 
        INIT_PROPERTY(mSystemOfInterest);
-       INIT_PROPERTY(mTemporalContext);
-
+       INIT_PROPERTY(mMethod);
        INIT_PROPERTYLIST(mTimeSeries,PROPERTY__TIMESERIES);
-       INIT_PROPERTYLIST(mActivities,PROPERTY__ACTIVITY);
 }
 
 Evaluation::Evaluation(Evaluation* o) : ValueObject(o)
 {
        QListIterator<QUrl> e(o->getCategories());
        while (e.hasNext()) addCategory(e.next());
+       SET_PROPERTY_REFERENCE(PROPERTY__METHOD, mMethod, Variant)
        SET_PROPERTY_REFERENCE(PROPERTY__SYSTEMOFINTEREST, mSystemOfInterest, SystemOfInterest)
        SET_PROPERTY_REFERENCE(PROPERTY__TEMPORALCONTEXT, mTemporalContext, TemporalContext)
-       SET_PROPERTYLIST_REFERENCE(PROPERTY__TIMESERIES, mTimeSeries, TimeSeries)
-       SET_PROPERTYLIST_REFERENCE(PROPERTY__ACTIVITY, mActivities, Activity)
        setType(RESOURCE__EVALUATION);
 }
 
@@ -98,10 +93,9 @@ void Evaluation::parse(Statement* statement)
                return;
        }
 
+       PARSE_PROPERTY(PROPERTY__METHOD, setMethod, Variant)
        PARSE_PROPERTY(PROPERTY__SYSTEMOFINTEREST, setSystemOfInterest, SystemOfInterest)
-       PARSE_PROPERTY(PROPERTY__TEMPORALCONTEXT, setTemporalContext, TemporalContext)
        PARSE_PROPERTY(PROPERTY__TIMESERIES, addTimeSerie, TimeSeries)
-       PARSE_PROPERTY(PROPERTY__ACTIVITY, addActivity, Activity)
 
        FINISH_PARSE(ValueObject)
 }
@@ -116,19 +110,6 @@ bool Evaluation::isOfCategory(QString category)
        return isOfCategory(QUrl(category));
 }
 
-Activity* Evaluation::firstActivity()
-{
-       if (mActivities.length() > 0) return mActivities.at(0);
-       return NULL;
-}
-
-Activity* Evaluation::newActivity(QString identifier)
-{
-       Activity* activity = new Activity(identifier);
-       addActivity(activity);
-       return activity;
-}
-
 void Evaluation::setSystemOfInterestWithSameAs(QString sameAs)
 {
        SystemOfInterest* soi = new SystemOfInterest();
index c9ef47711af6a0aedb4d37cf335617ba3463182e..1155a4137df9b0fa826c66ad4cfae1a5dc64d99c 100644 (file)
@@ -63,28 +63,18 @@ public:
        void setSystemOfInterest(SystemOfInterest* system)                      { add(PROPERTY__SYSTEMOFINTEREST, (GraphItem*)system); mSystemOfInterest = system; }
        void setSystemOfInterestWithSameAs(QString system);
        
-       bool hasTemporalContext()                                                                       { return (mTemporalContext != NULL); }
-       TemporalContext* getTemporalContext()                                           { return mTemporalContext; }
-       void setTemporalContext(TemporalContext* temporalContext)       { add(PROPERTY__TEMPORALCONTEXT, (GraphItem*)temporalContext); mTemporalContext = temporalContext; }
-       void setTemporalContext(QDateTime start, QDateTime end)         { setTemporalContext(new TemporalContext(start, end)); }
-       void setTemporalContext(QDateTime start, QDateTime end, QString during) { setTemporalContext(new TemporalContext(start, end, during)); }
-       void setTemporalContext(QTime start, QTime end)                         { setTemporalContext(new TemporalContext(start, end)); }
-       void setTemporalContext(QTime start, QTime end, QString during) { setTemporalContext(new TemporalContext(start, end, during)); }
-
-       bool hasActivity()                                                                                      { return mActivities.length() > 0; }
-       PropertyList<Activity*> getActivities()                                         { return mActivities; }
-       void setActivity(Activity* activity)                                            { mActivities.clear(); addActivity(activity); }
-       void addActivity(Activity* activity)                                            { mActivities.append(activity); }
-       Activity* firstActivity();
-       Activity* newActivity(QString identifier = QString());
+       bool hasMethod()                                                                                        { return mMethod != NULL; }
+       QString getMethod()                                                                                     { PROPERTYVAL(mMethod, asString, QString()); }
+       void setMethod(QString method)                                                          { setMethod(new Variant(QUrl(method))); }
+       void setMethod(QUrl method)                                                                     { setMethod(new Variant(method)); }
+       void setMethod(Variant* method)                                                         { add(PROPERTY__METHOD, method); mMethod = method; }
 
 private:
        QList<QUrl> mCategories;
 
+       Variant* mMethod;
        SystemOfInterest* mSystemOfInterest;
-       TemporalContext* mTemporalContext;
        PropertyList<TimeSeries*> mTimeSeries;
-       PropertyList<Activity*> mActivities;
 };
 
 #endif // _EVALUATION_H_
index 79b15f415ade423092e3c40bb995d90921acdba4..9fbd8fdc4d8b83ff44e5deb9d3cacf3c89da0f0d 100644 (file)
@@ -35,11 +35,11 @@ public:
 
        bool hasOutputValue()                                                   { return mOutputValues.length() > 0; }
        PropertyList<ValueObject*> getOutputValues()    { return mOutputValues; }
-    void setOutputValue(ValueObject* v)             { mOutputValues.clear(); addOutputValue(v); }
-    void addOutputValue(ValueObject* v)             { mOutputValues.append(v); }
+       void setOutputValue(ValueObject* v)                             { mOutputValues.clear(); addOutputValue(v); }
+       void addOutputValue(ValueObject* v)                             { mOutputValues.append(v); }
                
 private:
-    InputType mInputType;
+       InputType mInputType;
        PropertyList<ValueObject*> mOutputValues;
 };
 
index f1a4636b2994eea78f098e08efed5dbec73e70dc..b88c91753830a8a5c9e7d8bacafd6c79fbc92b9c 100644 (file)
@@ -1,19 +1,19 @@
 #include "License.h"
 
-License::License(QString uri) : Obj(uri)
+License::License(QString uri) : Contract(uri)
 {
-    setType(RESOURCE__LICENSE);
-    INIT_PROPERTY(mLicenseKey)
-    INIT_PROPERTY(mAccount)
-    INIT_PROPERTYLIST(mPriceSpecifications,PROPERTY__HASPRICESPECIFICATION);
+       setType(RESOURCE__LICENSE);
+       INIT_PROPERTY(mLicenseKey)
+       INIT_PROPERTY(mAccount)
+       INIT_PROPERTYLIST(mPriceSpecifications,PROPERTY__HASPRICESPECIFICATION);
 }
 
-License::License(License* a) : Obj(a)
+License::License(License* a) : Contract(a)
 {
-    SET_PROPERTY_REFERENCE(PROPERTY__LICENSEKEY, mLicenseKey, Variant)
-    SET_PROPERTY_REFERENCE(PROPERTY__ACCOUNT, mAccount, Account)
-    SET_PROPERTYLIST_REFERENCE(PROPERTY__HASPRICESPECIFICATION, mPriceSpecifications, PriceSpecification)
-    setType(RESOURCE__LICENSE);
+       SET_PROPERTY_REFERENCE(PROPERTY__LICENSEKEY, mLicenseKey, Variant)
+       SET_PROPERTY_REFERENCE(PROPERTY__ACCOUNT, mAccount, Account)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__HASPRICESPECIFICATION, mPriceSpecifications, PriceSpecification)
+       setType(RESOURCE__LICENSE);
 }
 
 License::~License()
@@ -22,21 +22,21 @@ License::~License()
 
 void License::clearReferences(QSet<GraphItem*>* trash)
 {
-    INIT_CLEAR(Obj,trash);
-    FINISH_CLEAR(Obj,trash);
+       INIT_CLEAR(Obj,trash);
+       FINISH_CLEAR(Obj,trash);
 }
 
 Resource* License::serialize(Model* model)
 {
-    INIT_SERIALIZE(Obj,model)
-    FINISH_SERIALIZE(Obj)
+       INIT_SERIALIZE(Obj,model)
+       FINISH_SERIALIZE(Obj)
 }
 
 void License::parse(Statement* statement)
 {
-    INIT_PARSE(statement)
-    PARSE_PROPERTY(PROPERTY__LICENSEKEY, setLicenseKey, Variant)
-    PARSE_PROPERTY(PROPERTY__ACCOUNT, setAccount, Account)
-    PARSE_PROPERTY(PROPERTY__HASPRICESPECIFICATION, addPriceSpecification, PriceSpecification)
-    FINISH_PARSE(Obj)
+       INIT_PARSE(statement)
+       PARSE_PROPERTY(PROPERTY__LICENSEKEY, setLicenseKey, Variant)
+       PARSE_PROPERTY(PROPERTY__ACCOUNT, setAccount, Account)
+       PARSE_PROPERTY(PROPERTY__HASPRICESPECIFICATION, addPriceSpecification, PriceSpecification)
+       FINISH_PARSE(Obj)
 }
index a97be8176de03457a5dde763a248a8d92423cc34..cc4b34cb8bb3e846531d1fbd9b1025720b4c6319 100644 (file)
@@ -2,41 +2,41 @@
 #define LICENSE_H
 
 #include "smartapi/model/Account.h"
-#include "smartapi/model/Obj.h"
+#include "smartapi/model/Contract.h"
 #include "smartapi/model/PriceSpecification.h"
 #include "smartapi/common/PROPERTY.h"
 
 #include <QString>
 #include <QList>
 
-class License : public Obj
+class License : public Contract
 {
 public:
-    License(QString uri = QString());
-    License(License* i);
-    ~License();
+       License(QString uri = QString());
+       License(License* i);
+       ~License();
 
-    Resource* serialize(Model* model);
-    void parse(Statement* statement);
-    virtual void clearReferences(QSet<GraphItem*>* trash);
+       Resource* serialize(Model* model);
+       void parse(Statement* statement);
+       virtual void clearReferences(QSet<GraphItem*>* trash);
 
-    bool hasLicenseKey()                                                { return mLicenseKey != NULL; }
-    void setLicenseKey(Variant* h)                                      { add(PROPERTY__LICENSEKEY, h); mLicenseKey = h; }
-    void setLicenseKey(QString licenseKey)                              { setLicenseKey(new Variant(licenseKey)); }
-    QString getLicenseKey()                                             { PROPERTYVAL(mLicenseKey, asString, QString()); }
+       bool hasLicenseKey()                                                                                            { return mLicenseKey != NULL; }
+       void setLicenseKey(Variant* h)                                                                          { add(PROPERTY__LICENSEKEY, h); mLicenseKey = h; }
+       void setLicenseKey(QString licenseKey)                                                          { setLicenseKey(new Variant(licenseKey)); }
+       QString getLicenseKey()                                                                                         { PROPERTYVAL(mLicenseKey, asString, QString()); }
 
-    bool hasAccount()                                                   { return (mAccount != NULL); }
-    Account* getAccount()                                               { return mAccount; }
-    void setAccount(Account* account)                                   { add(PROPERTY__ACCOUNT, account); mAccount = account; }
+       bool hasAccount()                                                                                                       { return (mAccount != NULL); }
+       Account* getAccount()                                                                                           { return mAccount; }
+       void setAccount(Account* account)                                                                       { add(PROPERTY__ACCOUNT, account); mAccount = account; }
 
-    bool hasPriceSpecification()                                                                               { return !mPriceSpecifications.isEmpty(); }
-    void addPriceSpecification(PriceSpecification* priceSpecification) { mPriceSpecifications.append(priceSpecification); }
-    PropertyList<PriceSpecification*> getPriceSpecifications()                 { return mPriceSpecifications; }
+       bool hasPriceSpecification()                                                                            { return !mPriceSpecifications.isEmpty(); }
+       void addPriceSpecification(PriceSpecification* priceSpecification)      { mPriceSpecifications.append(priceSpecification); }
+       PropertyList<PriceSpecification*> getPriceSpecifications()                      { return mPriceSpecifications; }
 
 private:
-    Variant* mLicenseKey;
-    Account* mAccount;
-    PropertyList<PriceSpecification*> mPriceSpecifications;
+       Variant* mLicenseKey;
+       Account* mAccount;
+       PropertyList<PriceSpecification*> mPriceSpecifications;
 };
 
 #endif // LICENSE_H
index 41006beb1642e50ef31eea7e118782b328502082..061c1cbbe2b394e66a03c9553a9bf4b6c08ad4fb 100644 (file)
@@ -5,19 +5,19 @@
 #include <QList>
 
 LinearCalculation::LinearCalculation(QString identifierUri) :
-    CalculationMethod(identifierUri)
+       CalculationMethod(identifierUri)
 {
-    setType(RESOURCE__LINEARCALCULATION);
-    INIT_PROPERTY(mOffset)
-    INIT_PROPERTYLIST(mMultipliers,PROPERTY__MULTIPLIER);
+       setType(RESOURCE__LINEARCALCULATION);
+       INIT_PROPERTY(mOffset)
+       INIT_PROPERTYLIST(mMultipliers,PROPERTY__MULTIPLIER);
 }
 
 LinearCalculation::LinearCalculation(LinearCalculation* o) :
-    CalculationMethod(o)
+       CalculationMethod(o)
 {
-    SET_PROPERTY_REFERENCE(PROPERTY__OFFSET, mOffset, Variant)
-    SET_PROPERTYLIST_REFERENCE(PROPERTY__MULTIPLIER, mMultipliers, Variant)
-    setType(RESOURCE__LINEARCALCULATION);
+       SET_PROPERTY_REFERENCE(PROPERTY__OFFSET, mOffset, Variant)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__MULTIPLIER, mMultipliers, Variant)
+       setType(RESOURCE__LINEARCALCULATION);
 }
 
 LinearCalculation::~LinearCalculation()
@@ -26,38 +26,38 @@ LinearCalculation::~LinearCalculation()
 
 Resource* LinearCalculation::serialize(Model* model)
 {
-    INIT_SERIALIZE(CalculationMethod,model)
-    FINISH_SERIALIZE(CalculationMethod)
+       INIT_SERIALIZE(CalculationMethod,model)
+       FINISH_SERIALIZE(CalculationMethod)
 }
 
 void LinearCalculation::parse(Statement* statement)
 {
-    INIT_PARSE(statement)
-    PARSE_PROPERTY(PROPERTY__OFFSET, setOffset, Variant)
-    PARSE_PROPERTY(PROPERTY__MULTIPLIER, addMultiplier, Variant)
-    FINISH_PARSE(CalculationMethod)
+       INIT_PARSE(statement)
+       PARSE_PROPERTY(PROPERTY__OFFSET, setOffset, Variant)
+       PARSE_PROPERTY(PROPERTY__MULTIPLIER, addMultiplier, Variant)
+       FINISH_PARSE(CalculationMethod)
 }
 
 double LinearCalculation::getMultiplier(int index)
 {
-    if (hasMultiplier()) {
-        if (index < mMultipliers.length()) {
-            return mMultipliers.at(index)->asDouble();
-        }
-    }
-    // if there is no multiplier for the requested variable index, return default multiplier 1
-    return 1;
+       if (hasMultiplier()) {
+               if (index < mMultipliers.length()) {
+                       return mMultipliers.at(index)->asDouble();
+               }
+       }
+       // if there is no multiplier for the requested variable index, return default multiplier 1
+       return 1;
 }
 
 // calculates y as the result
 double LinearCalculation::calculate(QList<double> args)
 {
-    double res = 0.0;
-    for (int i = 0; i < args.length(); i++) {
-        res += (args.at(i) == NULL ? 0 : args.at(i) * getMultiplier(i));
-    }
-    if (hasOffset()) {
-        res += getOffset();
-    }
-    return res;
+       double res = 0.0;
+       for (int i = 0; i < args.length(); i++) {
+               res += args.at(i) * getMultiplier(i);
+       }
+       if (hasOffset()) {
+               res += getOffset();
+       }
+       return res;
 }
index 569179108bb1be751c11858a7a3d771bbc81d37c..09f52d774bea178c2581a33e91fb58ea80c4c23d 100755 (executable)
@@ -1,6 +1,7 @@
 #include "Message.h"
 #include "smartapi/common/PROPERTY.h"
 #include "smartapi/common/Tools.h"
+#include "smartapi/model/Activity.h"
 #include <QtDebug>
 
 Message::Message() :
@@ -9,8 +10,7 @@ Message::Message() :
        setType(RESOURCE__MESSAGE);
        INIT_PROPERTY(mMessageId)
        INIT_PROPERTY(mProcessId)
-       INIT_PROPERTY(mMethod)
-
+       INIT_PROPERTYLIST(mActivities,PROPERTY__ACTIVITY);
 }
 
 Message::Message(QString uri) :
@@ -19,14 +19,14 @@ Message::Message(QString uri) :
        setType(RESOURCE__MESSAGE);
        INIT_PROPERTY(mMessageId)
        INIT_PROPERTY(mProcessId)
-       INIT_PROPERTY(mMethod)
+       INIT_PROPERTYLIST(mActivities,PROPERTY__ACTIVITY);
 }
 
 Message::Message(Message* m) : Evaluation(m)
 {
        SET_PROPERTY_REFERENCE(PROPERTY__ID, mMessageId, Variant)
        SET_PROPERTY_REFERENCE(PROPERTY__PROCESSID, mProcessId, Variant)
-       SET_PROPERTY_REFERENCE(PROPERTY__METHOD, mMethod, Variant)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__ACTIVITY, mActivities, Activity)
        setType(RESOURCE__MESSAGE);
 }
 
@@ -50,6 +50,19 @@ void Message::parse(Statement* statement)
        INIT_PARSE(statement)
        PARSE_PROPERTY(PROPERTY__ID, setMessageId, Variant)
        PARSE_PROPERTY(PROPERTY__PROCESSID, setProcessId, Variant)
-       PARSE_PROPERTY(PROPERTY__METHOD, setMethod, Variant)
+       PARSE_PROPERTY(PROPERTY__ACTIVITY, addActivity, Activity)
        FINISH_PARSE(Evaluation)
 }
+
+Activity* Message::firstActivity()
+{
+       if (mActivities.length() > 0) return mActivities.at(0);
+       return NULL;
+}
+
+Activity* Message::newActivity(QString identifier)
+{
+       Activity* activity = new Activity(identifier);
+       addActivity(activity);
+       return activity;
+}
index ee1d662dff8798a0d502a7a26c550dfba2ce4c8b..d91fcbffd7dac6cf8867d3dd4880d26a48fe9c9e 100644 (file)
@@ -35,16 +35,17 @@ public:
        void setProcessId(Variant* id)  { add(PROPERTY__PROCESSID, id); mProcessId = id; }
        void setProcessId(int id)       { setProcessId(new Variant(id)); }
 
-       bool hasMethod()                { return (mMethod != NULL); }
-       QUrl getMethod()                { PROPERTYVAL(mMethod, asUrl, QUrl()); }
-       void setMethod(Variant* m)      { add(PROPERTY__METHOD, m); mMethod = m; }
-       void setMethod(QUrl m)          { setMethod(new Variant(m)); }
-       void setMethod(QString m)       { setMethod(QUrl(m)); }
+       bool hasActivity()                                                                                      { return mActivities.length() > 0; }
+       PropertyList<Activity*> getActivities()                                         { return mActivities; }
+       void setActivity(Activity* activity)                                            { mActivities.clear(); addActivity(activity); }
+       void addActivity(Activity* activity)                                            { mActivities.append(activity); }
+       Activity* firstActivity();
+       Activity* newActivity(QString identifier = QString());
 
 private:
        Variant* mMessageId;
        Variant* mProcessId;
-       Variant* mMethod;
+       PropertyList<Activity*> mActivities;
 };
 
 #endif // _MESSAGE_H_
index 80005ec14e64b6e7dcc478c3cd27bb37d76441f7..d45a1854a1bd0c2d344185a85fde286ec42b4ca5 100755 (executable)
@@ -111,10 +111,10 @@ Obj::Obj(Obj* o)
                QListIterator<QString> t(o->getTypes());
                while (t.hasNext()) mTypes.append(t.next());
 
-               mErrors = o->getErrors();
-               mProvenances = o->getProvenances();
-               mRestrictions = o->getRestrictions();
-               mOfferings = o->getOfferings();
+               mErrors                 = o->getErrors();
+               mProvenances    = o->getProvenances();
+               mRestrictions   = o->getRestrictions();
+               mOfferings              = o->getOfferings();
 
                // Copy all items in the property list. Note that because of this operation,
                // any child of Obj does not need to copy any properties or property lists
index b9ca92066d039590613c2b5cd8c54beffa16f3a4..e4f3e831c985a4eac78b2b6bb69c03e66abd8755 100755 (executable)
@@ -3,20 +3,20 @@
 #include "smartapi/common/Tools.h"
 
 Provenance::Provenance(QString identifierUri) :
-    Obj(identifierUri)
+       Evaluation(identifierUri)
 { 
        setType(RESOURCE__PROVENANCE); 
-    INIT_PROPERTY(mGenerationMethods)
-    INIT_PROPERTY(mDataSources)
-    INIT_PROPERTY(mProperties)
+       INIT_PROPERTY(mGenerationMethods)
+       INIT_PROPERTY(mDataSources)
+       INIT_PROPERTY(mProperties)
 }
        
 Provenance::Provenance(Provenance* p)
-       : Obj(p)
+       : Evaluation(p)
 {
-    SET_PROPERTYLIST_REFERENCE(PROPERTY__GENERATIONMETHOD, mGenerationMethods, Variant)
-    SET_PROPERTYLIST_REFERENCE(PROPERTY__DATASOURCE, mDataSources, Variant)
-    SET_PROPERTYLIST_REFERENCE(PROPERTY__SMARTAPI_PROPERTY, mProperties, Variant)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__GENERATIONMETHOD, mGenerationMethods, Variant)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__DATASOURCE, mDataSources, Variant)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__SMARTAPI_PROPERTY, mProperties, Variant)
        setType(RESOURCE__PROVENANCE);
 }
 
@@ -26,21 +26,21 @@ Provenance::~Provenance()
        
 void Provenance::clearReferences(QSet<GraphItem*>* trash)
 {      
-    INIT_CLEAR(Obj,trash);
-    FINISH_CLEAR(Obj,trash);
+       INIT_CLEAR(Obj,trash);
+       FINISH_CLEAR(Obj,trash);
 }
 
 Resource* Provenance::serialize(Model* model)
 {
        INIT_SERIALIZE(Obj,model)
-    FINISH_SERIALIZE(Obj)
+       FINISH_SERIALIZE(Obj)
 }
 
 void Provenance::parse(Statement* statement)
 {
-    INIT_PARSE(statement)
-    PARSE_PROPERTY(PROPERTY__GENERATIONMETHOD, addGenerationMethod, Variant)
-    PARSE_PROPERTY(PROPERTY__DATASOURCE, addDataSource, Variant)
-    PARSE_PROPERTY(PROPERTY__SMARTAPI_PROPERTY, addProperty, Variant)
-    FINISH_PARSE(Obj)
+       INIT_PARSE(statement)
+       PARSE_PROPERTY(PROPERTY__GENERATIONMETHOD, addGenerationMethod, Variant)
+       PARSE_PROPERTY(PROPERTY__DATASOURCE, addDataSource, Variant)
+       PARSE_PROPERTY(PROPERTY__SMARTAPI_PROPERTY, addProperty, Variant)
+       FINISH_PARSE(Obj)
 }
index 450d926bfca0cc483b7e88440d3a5aa764107d3e..7195a588802abb2adeba9df5cdd0ca904e696bd1 100644 (file)
@@ -1,14 +1,14 @@
 #ifndef _PROVENANCE_H_
 #define _PROVENANCE_H_
 
-#include "smartapi/model/Obj.h"
+#include "smartapi/model/Evaluation.h"
 #include "smartapi/model/Activity.h"
 #include "smartapi/model/ValueObject.h"
 #include "smartapi/rdf/Resource.h"
 #include "smartapi/rdf/PropertyList.h"
 #include <QString>
 
-class Provenance : public Obj
+class Provenance : public Evaluation
 {
 public:
        Provenance(QString identifierUri = QString());
@@ -19,26 +19,26 @@ public:
        void parse(Statement* statement);
        virtual void clearReferences(QSet<GraphItem*>* trash);
        
-       bool hasGenerationMethod()                                          { return mGenerationMethods.length() > 0; }
-       PropertyList<Variant*> getGenerationMethods()                       { return mGenerationMethods; }
-       void addGenerationMethod(Variant* generationMethod)                 { mGenerationMethods.append(generationMethod); }
-       void addGenerationMethod(QUrl generationMethod)                     { addGenerationMethod(new Variant(generationMethod)); }
-       void addGenerationMethod(QString generationMethod)                  { addGenerationMethod(QUrl(generationMethod)); }
-       void setGenerationMethods(PropertyList<Variant*> generationMethods) { mGenerationMethods = generationMethods; add(PROPERTY__GENERATIONMETHOD, &mGenerationMethods); }
+       bool hasGenerationMethod()                                                                                      { return mGenerationMethods.length() > 0; }
+       PropertyList<Variant*> getGenerationMethods()                                           { return mGenerationMethods; }
+       void addGenerationMethod(Variant* generationMethod)                                     { mGenerationMethods.append(generationMethod); }
+       void addGenerationMethod(QUrl generationMethod)                                         { addGenerationMethod(new Variant(generationMethod)); }
+       void addGenerationMethod(QString generationMethod)                                      { addGenerationMethod(QUrl(generationMethod)); }
+       void setGenerationMethods(PropertyList<Variant*> generationMethods)     { mGenerationMethods = generationMethods; add(PROPERTY__GENERATIONMETHOD, &mGenerationMethods); }
 
-       bool hasDataSource()                                                { return mDataSources.length() > 0; }
-       PropertyList<Variant*> getDataSources()                             { return mDataSources; }
-       void addDataSource(Variant* dataSource)                             { mDataSources.append(dataSource); }
-       void addDataSource(QUrl dataSource)                                 { addDataSource(new Variant(dataSource)); }
-       void addDataSource(QString dataSource)                              { addDataSource(QUrl(dataSource)); }
-       void setDataSources(PropertyList<Variant*> dataSources)             { mDataSources = dataSources; add(PROPERTY__DATASOURCE, &mDataSources); }
+       bool hasDataSource()                                                                                            { return mDataSources.length() > 0; }
+       PropertyList<Variant*> getDataSources()                                                         { return mDataSources; }
+       void addDataSource(Variant* dataSource)                                                         { mDataSources.append(dataSource); }
+       void addDataSource(QUrl dataSource)                                                                     { addDataSource(new Variant(dataSource)); }
+       void addDataSource(QString dataSource)                                                          { addDataSource(QUrl(dataSource)); }
+       void setDataSources(PropertyList<Variant*> dataSources)                         { mDataSources = dataSources; add(PROPERTY__DATASOURCE, &mDataSources); }
 
-       bool hasProperty()                                                  { return mProperties.length() > 0; }
-       PropertyList<Variant*> getProperties()                              { return mProperties; }
-       void addProperty(Variant* property)                                 { mProperties.append(property); }
-       void addProperty(QUrl property)                                     { addProperty(new Variant(property)); }
-       void addProperty(QString property)                                  { addProperty(Tools::stripUri(property)); }
-       void setProperties(PropertyList<Variant*> properties)               { mProperties = properties; add(PROPERTY__SMARTAPI_PROPERTY, &mProperties); }
+       bool hasProperty()                                                                                                      { return mProperties.length() > 0; }
+       PropertyList<Variant*> getProperties()                                                          { return mProperties; }
+       void addProperty(Variant* property)                                                                     { mProperties.append(property); }
+       void addProperty(QUrl property)                                                                         { addProperty(new Variant(property)); }
+       void addProperty(QString property)                                                                      { addProperty(Tools::stripUri(property)); }
+       void setProperties(PropertyList<Variant*> properties)                           { mProperties = properties; add(PROPERTY__SMARTAPI_PROPERTY, &mProperties); }
        
 private:
        PropertyList<Variant*> mGenerationMethods;
index 220d9f17ef43be32282328aed75d6f9fbdbc9d6d..3b3ac50b7e70b7fbae4d3de040dd909844ff7f87 100755 (executable)
@@ -4,15 +4,15 @@
 #include "smartapi/common/Tools.h"
 
 Restriction::Restriction(QString identifierUri)
-    : Obj(identifierUri)
+       : Evaluation(identifierUri)
 {
        setType(RESOURCE__RESTRICTION);
-    INIT_PROPERTY(mCardinality);
-    INIT_PROPERTY(mMinCardinality);
-    INIT_PROPERTY(mMaxCardinality);
-    INIT_PROPERTY(mOptional);
-    INIT_PROPERTY(mDataRange);
-    INIT_PROPERTYLIST(mOnProperties,PROPERTY__ONPROPERTY);
+       INIT_PROPERTY(mCardinality);
+       INIT_PROPERTY(mMinCardinality);
+       INIT_PROPERTY(mMaxCardinality);
+       INIT_PROPERTY(mOptional);
+       INIT_PROPERTY(mDataRange);
+       INIT_PROPERTYLIST(mOnProperties,PROPERTY__ONPROPERTY);
 }
 
 Restriction::Restriction(Variant* cardinality, Variant* minCardinality, Variant* maxCardinality, bool optional, QString dataRange, QStringList properties)
@@ -21,22 +21,22 @@ Restriction::Restriction(Variant* cardinality, Variant* minCardinality, Variant*
        mCardinality = cardinality;
        mMinCardinality = minCardinality;
        mMaxCardinality = maxCardinality;
-    mOptional = new Variant(optional);
+       mOptional = new Variant(optional);
 
        if (!dataRange.isNull()) {
-        setDataRange(dataRange);
+               setDataRange(dataRange);
        }
 
        QListIterator<QString> i(properties);
        while (i.hasNext()) {
-        addOnProperty(i.next());
+               addOnProperty(i.next());
        }
 }
 
 Restriction::Restriction(Variant* cardinality, Variant* minCardinality, Variant* maxCardinality, bool optional, QString dataRange, QString property)
        : Restriction(cardinality, minCardinality, maxCardinality, optional, dataRange, QStringList())
 {
-    addOnProperty(property);
+       addOnProperty(property);
 }
 
 Restriction::Restriction(Variant* cardinality, Variant* minCardinality, Variant* maxCardinality, bool optional, QStringList dataRanges, QStringList properties)
@@ -47,25 +47,25 @@ Restriction::Restriction(Variant* cardinality, Variant* minCardinality, Variant*
        while (dri.hasNext()) {
                list.append(new Obj(dri.next()));
        }
-    setDataRange(new Obj());
+       setDataRange(new Obj());
        mDataRange->add(PROPERTY__ONEOF, list);
 }
 
 Restriction::Restriction(Variant* cardinality, Variant* minCardinality, Variant* maxCardinality, bool optional, QStringList dataRanges, QString property)
        : Restriction(cardinality, minCardinality, maxCardinality, optional, dataRanges, QStringList())
 {
-    addOnProperty(property);
+       addOnProperty(property);
 }
 
 Restriction::Restriction(Restriction *restriction)
-       : Obj(restriction)
+       : Evaluation(restriction)
 {
-    SET_PROPERTY_REFERENCE(PROPERTY__CARDINALITY, mCardinality, Variant)
-    SET_PROPERTY_REFERENCE(PROPERTY__MINCARDINALITY, mMinCardinality, Variant)
-    SET_PROPERTY_REFERENCE(PROPERTY__MAXCARDINALITY, mMaxCardinality, Variant)
-    SET_PROPERTY_REFERENCE(PROPERTY__OPTIONAL, mOptional, Variant)
-    SET_PROPERTY_REFERENCE(PROPERTY__ONDATARANGE, mDataRange, Obj)
-    SET_PROPERTYLIST_REFERENCE(PROPERTY__ONPROPERTY, mOnProperties, Obj)
+       SET_PROPERTY_REFERENCE(PROPERTY__CARDINALITY, mCardinality, Variant)
+       SET_PROPERTY_REFERENCE(PROPERTY__MINCARDINALITY, mMinCardinality, Variant)
+       SET_PROPERTY_REFERENCE(PROPERTY__MAXCARDINALITY, mMaxCardinality, Variant)
+       SET_PROPERTY_REFERENCE(PROPERTY__OPTIONAL, mOptional, Variant)
+       SET_PROPERTY_REFERENCE(PROPERTY__ONDATARANGE, mDataRange, Obj)
+       SET_PROPERTYLIST_REFERENCE(PROPERTY__ONPROPERTY, mOnProperties, Obj)
        setType(RESOURCE__RESTRICTION);
 }
 
@@ -75,24 +75,24 @@ Restriction::~Restriction()
 
 void Restriction::clearReferences(QSet<GraphItem*>* trash)
 {
-    INIT_CLEAR(Obj,trash);
-    FINISH_CLEAR(Obj,trash);
+       INIT_CLEAR(Obj,trash);
+       FINISH_CLEAR(Obj,trash);
 }
 
 Resource* Restriction::serialize(Model* model)
 {
        INIT_SERIALIZE(Obj,model)
-    FINISH_SERIALIZE(Obj)
+       FINISH_SERIALIZE(Obj)
 }
 
 void Restriction::parse(Statement* statement)
 {
-    INIT_PARSE(statement)
-    PARSE_PROPERTY(PROPERTY__CARDINALITY, setCardinality, Variant)
-    PARSE_PROPERTY(PROPERTY__MINCARDINALITY, setMinCardinality, Variant)
-    PARSE_PROPERTY(PROPERTY__MAXCARDINALITY, setMaxCardinality, Variant)
-    PARSE_PROPERTY(PROPERTY__ONPROPERTY, addOnProperty, Obj)
-    PARSE_PROPERTY(PROPERTY__OPTIONAL, setOptional, Variant)
-    PARSE_PROPERTY(PROPERTY__ONDATARANGE, setDataRange, Obj)
-    FINISH_PARSE(Obj)
+       INIT_PARSE(statement)
+       PARSE_PROPERTY(PROPERTY__CARDINALITY, setCardinality, Variant)
+       PARSE_PROPERTY(PROPERTY__MINCARDINALITY, setMinCardinality, Variant)
+       PARSE_PROPERTY(PROPERTY__MAXCARDINALITY, setMaxCardinality, Variant)
+       PARSE_PROPERTY(PROPERTY__ONPROPERTY, addOnProperty, Obj)
+       PARSE_PROPERTY(PROPERTY__OPTIONAL, setOptional, Variant)
+       PARSE_PROPERTY(PROPERTY__ONDATARANGE, setDataRange, Obj)
+       FINISH_PARSE(Obj)
 }
index c5b256008614f0807030c3c4d50bbcad988173dd..6d5a8904f70f73237acfaf7cd1886dd2acf7b2ac 100644 (file)
@@ -1,13 +1,13 @@
 #ifndef _RESTRICTION_H_
 #define _RESTRICTION_H_
 
-#include "smartapi/model/Obj.h"
+#include "smartapi/model/Evaluation.h"
 #include "smartapi/rdf/PropertyList.h"
 #include "smartapi/rdf/Variant.h"
 #include "smartapi/common/RESOURCE.h"
 #include "smartapi/common/PROPERTY.h"
 
-class Restriction : public Obj
+class Restriction : public Evaluation
 {
 public:
        Restriction(QString identifierUri = QString());
index 25224840aafd37845cadca9d36b3e0d46a1b03d5..89c036472f52323f8a00b444884b2ac52417e032 100755 (executable)
@@ -20,7 +20,6 @@ ValueObject::ValueObject(QString uri) : Obj(uri)
        INIT_PROPERTY(mDataType)
        INIT_PROPERTY(mOperation)
        INIT_PROPERTY(mTemporalContext)
-       INIT_PROPERTYLIST(mCapabilities,PROPERTY__HASCAPABILITY)
 }
 
 ValueObject::ValueObject(QUrl uri, QString quantity, QString unit, Variant* value) :
@@ -96,7 +95,6 @@ ValueObject::ValueObject(ValueObject* v) : Obj(v)
        SET_PROPERTY_REFERENCE(PROPERTY__KEY, mKey, Variant)
        SET_PROPERTY_REFERENCE(PROPERTY__OPERATION, mOperation, Variant)
        SET_PROPERTY_REFERENCE(PROPERTY__TEMPORALCONTEXT, mTemporalContext, TemporalContext)
-       SET_PROPERTYLIST_REFERENCE(PROPERTY__HASCAPABILITY, mCapabilities, Activity)
        setType(RESOURCE__VALUEOBJECT);
 }
 
@@ -129,21 +127,6 @@ void ValueObject::parse(Statement* statement)
        PARSE_PROPERTY(PROPERTY__KEY, setKey, Variant)
        PARSE_PROPERTY(PROPERTY__OPERATION, setOperation, Variant)
        PARSE_PROPERTY(PROPERTY__TEMPORALCONTEXT, setTemporalContext, TemporalContext)
-       PARSE_PROPERTY(PROPERTY__HASCAPABILITY, addCapability, Activity)
        FINISH_PARSE(Obj)
 }
 
-void ValueObject::addCapability(QString uri)
-{
-       Activity* activity = new Activity(uri);
-       activity->clearTypes();
-       addCapability(activity);
-}
-
-void ValueObject::addCapability(QStringList uris)
-{
-       QStringListIterator ui(uris);
-       while (ui.hasNext()) {
-               addCapability(ui.next());
-       }
-}
index 9d98dd757215b6525787517d2c35de8861e101bb..5794f5574d323cc2172a1c5acbc79ed3a2c34633 100644 (file)
@@ -127,7 +127,10 @@ public:
        TemporalContext* getTemporalContext()                                           { return mTemporalContext; }
        void setTemporalContext(TemporalContext* temporalContext)       { set(PROPERTY__TEMPORALCONTEXT, temporalContext); mTemporalContext = temporalContext; }
        void setTemporalContext(QDateTime start, QDateTime end)         { setTemporalContext(new TemporalContext(start, end)); }
+       void setTemporalContext(QDateTime start, QDateTime end, QString during) { setTemporalContext(new TemporalContext(start, end, during)); }
        void setTemporalContext(QDateTime start)                                        { setTemporalContext(new TemporalContext(start)); }
+       void setTemporalContext(QTime start, QTime end)                         { setTemporalContext(new TemporalContext(start, end)); }
+       void setTemporalContext(QTime start, QTime end, QString during) { setTemporalContext(new TemporalContext(start, end, during)); }
 
        bool hasInstant()                                                                                       { return mInstant != NULL; }
        QDateTime getInstant()                                                                          { PROPERTYVAL(mInstant, asDateTime, QDateTime()) }
@@ -139,14 +142,6 @@ public:
        void setKey(Variant* l)                                                                         { set(PROPERTY__KEY, l); mKey = l; }
        void setKey(QString l)                                                                          { setKey(new Variant(l)); }
 
-       bool hasCapability()                                                                            { return (mCapabilities.length() > 0); }
-       PropertyList<Activity*> getCapabilities()                                       { return mCapabilities; }
-       void setCapabilities(PropertyList<Activity*> capabilities)      { mCapabilities = capabilities; add(PROPERTY__HASCAPABILITY, &mCapabilities); }
-       void addCapability(Activity* capability)                                        { mCapabilities.append(capability); }
-       void addCapability(QList<Activity*> capabilities)                       { mCapabilities.append(capabilities); }
-       void addCapability(QString uri);
-       void addCapability(QStringList uris);
-
 protected:
        Variant* mQuantity;
        Variant* mUnit;
@@ -161,7 +156,6 @@ protected:
        Variant* mKey;
        Variant* mStep;
        TemporalContext* mTemporalContext;
-       PropertyList<Activity*> mCapabilities;
 };
 
 #endif // _VALUEOBJECT_H_
index 3f1ee5f8e61806f834956574e1bdf449f95b32c0..3b1d8f773e4da75d4cf25d75a4538ba367b61d4c 100644 (file)
@@ -127,7 +127,7 @@ public class ClassMapper {
                Class<? extends Obj> klazz = ClassMapper.klazzMap.get(type);
                if ( klazz  != null ) {
                        try {
-                               return klazz.cast(klazz.newInstance());
+                               return klazz.cast(klazz.getDeclaredConstructor().newInstance());
                        } catch ( Exception e ) {
                                e.printStackTrace();
                                return null;
index 9089dc1cbfbee78c037585fc0baacdd88afee334..896577cecd87eca5e0f26f80421afada85405187 100644 (file)
@@ -14,6 +14,7 @@ import java.io.UnsupportedEncodingException;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.security.PrivateKey;
@@ -218,18 +219,20 @@ public class Tools {
                        Obj obj = null;
                        try {
                                if ( contentType != null ) {
-                                       obj = Tools.toObj(body, SERIALIZATION.fromContentType(contentType));                                    
-                               } else {                                        
-                                       obj = Tools.toObj(body);                                        
+                                       obj = Tools.toObj(body, SERIALIZATION.fromContentType(contentType));
+                               } else {
+                                       obj = Tools.toObj(body);
                                }
                        } catch ( Exception e ) {
                                System.err.println("Exception while parsing body of a HttpMessage into " + clazz.getName() + ".");
                                System.err.println(content);
                                e.printStackTrace();
                        }
-                       try { message = clazz.newInstance(); }
+                       try { message = clazz.getDeclaredConstructor().newInstance(); }
                        catch (InstantiationException e) {}
                        catch (IllegalAccessException e) {}
+                       catch (NoSuchMethodException e) {}
+                       catch (InvocationTargetException e) {}
                        try {
                                message = clazz.cast(obj);
                        } catch ( Exception e ) {
@@ -255,9 +258,11 @@ public class Tools {
                                }
                                Tools.clearMessageParts();
                        }
-                       try { message = clazz.newInstance(); }
+                       try { message = clazz.getDeclaredConstructor().newInstance(); }
                        catch (InstantiationException e) {}
                        catch (IllegalAccessException e) {}
+                       catch (NoSuchMethodException e) {}
+                       catch (InvocationTargetException e) {}
                        try {
                                message = clazz.cast(obj);
                        } catch ( Exception e ) {
@@ -914,7 +919,7 @@ public class Tools {
 
        public static void printErrors(Obj obj) {
                for ( smartapi.model.Error error : obj.getErrors() ) {
-                       Tools.printError(error);                
+                       Tools.printError(error);
                }
        }
 
@@ -1045,7 +1050,7 @@ public class Tools {
 //             return Tools.deepCopy(obj);
                O clone = null;
                try {
-                       clone = (O)obj.getClass().newInstance();
+                       clone = (O)obj.getClass().getDeclaredConstructor().newInstance();
                } catch ( Exception e ) {
                        e.printStackTrace();
                }
@@ -1111,14 +1116,14 @@ public class Tools {
                // create empty version of the object
                Obj emptyObj = new Obj();
                try {
-                       emptyObj = (Obj)obj.getClass().newInstance();
+                       emptyObj = (Obj)obj.getClass().getDeclaredConstructor().newInstance();
                } catch ( Exception e ) {
                        e.printStackTrace();
                }
                obj.clearProperties();
                List types = emptyObj.get(PROPERTY.RDF_TYPE);
                if ( types != null && types.size() > 0 ) {
-                       obj.set(PROPERTY.RDF_TYPE, types);                      
+                       obj.set(PROPERTY.RDF_TYPE, types);      
                }
        }
 
@@ -1143,7 +1148,7 @@ public class Tools {
 //                     // create empty version of the inherited class
 //                     Object o = new Obj();
 //                     try {
-//                             o = tmpClass.newInstance();
+//                             o = tmpClass.getDeclaredConstructor().newInstance();
 //                     } catch ( Exception e ) {
 //                             e.printStackTrace();
 //                     }
index 569e2f350d3c0770c7058d7f433597498fcc2e80..c4ad8947e2d46ea860631204ad295d66fcab6664 100644 (file)
@@ -9,7 +9,7 @@ import smartapi.common.Tools;
 import smartapi.rdf.Variant;
 
 
-public class Availability extends Ability{
+public class Availability extends Ability {
 
        public Availability()
        {
@@ -65,42 +65,6 @@ public class Availability extends Ability{
                this.setRing(ring);
        }
 
-       public void setTemporalContext(TemporalContext temporalContext)
-       {
-               super.setTemporalContext(temporalContext);
-               this.addType(RESOURCE.TEMPORALAVAILABILITY);
-       }
-
-       public void setTemporalContext(Date start, Date end)
-       {
-               super.setTemporalContext(start, end);
-               this.addType(RESOURCE.TEMPORALAVAILABILITY);
-       }
-
-       public void setTemporalContext(Date start, Date end, String during)
-       {
-               super.setTemporalContext(start, end, during);
-               this.addType(RESOURCE.TEMPORALAVAILABILITY);
-       }
-
-       public void setTemporalContext(Date start)
-       {
-               super.setTemporalContext(start);
-               this.addType(RESOURCE.TEMPORALAVAILABILITY);
-       }
-
-       public void setTemporalContext(Time start, Time end)
-       {
-               super.setTemporalContext(start, end);
-               this.addType(RESOURCE.TEMPORALAVAILABILITY);
-       }
-
-       public void setTemporalContext(Time start, Time end, String during)
-       {
-               super.setTemporalContext(start, end, during);
-               this.addType(RESOURCE.TEMPORALAVAILABILITY);
-       }
-
        public void setProperty(Obj property)
        {
                super.setProperty(property);
@@ -236,16 +200,16 @@ public class Availability extends Ability{
                                                } else {
                                                        // first level 'or' values are not availabilities, there is some abnormal condition structure, just add as new 'or' value
                                                        this.getCondition().addOr(availability);
-                                                       return;                                                 
+                                                       return;
                                                }
                                        }
                                        // first level condition does not have 'ands' nor 'ors', add as 'or' value
                                        this.getCondition().addOr(availability);
-                                       return;                                                 
+                                       return;
                                }
                        } else {
                                // if 'this' is an empty availability, then replace 'this' with availability
-                               if ( !this.hasType(RESOURCE.TEMPORALAVAILABILITY) && !this.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY) && !this.hasProperty() ) {
+                               if ( !this.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY) && !this.hasProperty() ) {
                                        this.clearProperties();
                                        Tools.copy(availability, this);
                                        return;
@@ -284,18 +248,6 @@ public class Availability extends Ability{
         */
        public boolean sameTypeAndProperty(Availability firstAvailability, Availability secondAvailability)
        {
-               if ( firstAvailability.hasType(RESOURCE.TEMPORALAVAILABILITY) && secondAvailability.hasType(RESOURCE.TEMPORALAVAILABILITY) ) {
-                       if ( firstAvailability.hasTemporalContext() && secondAvailability.hasTemporalContext() ) {
-                               if ( (firstAvailability.getTemporalContext().containsTimeValues() && secondAvailability.getTemporalContext().containsTimeValues()) ) {
-                                       return true;
-                               }
-                               if ( (firstAvailability.getTemporalContext().containsDateValues() && secondAvailability.getTemporalContext().containsDateValues()) ) {
-                                       return true;
-                               }
-                               return false;
-                       }
-                       return false;
-               }
                if ( firstAvailability.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY) && secondAvailability.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY) ) {
                        if ( firstAvailability.hasProperty() && secondAvailability.hasProperty() ) {
                                // if they have same property
index ce83021a3e005d3388fc5680b36b816e561aa905..7473ff79f61128159314c6c4b75a547e0e72278e 100644 (file)
@@ -214,7 +214,8 @@ public class Capacity extends ValueObject {
                                double perc = value/max*100;
                                // if percentage does not have decimals
                                if ( perc % 1 == 0 ) {
-                                       setPercentage(new Variant((new Double(perc)).intValue()));
+                                       Double p = Double.valueOf(perc);
+                                       setPercentage(new Variant(p.intValue()));
                                        return true;
                                } else {
                                        // round to two decimals
index abfec85b4a70fab8674363a95dcc62b5a84296c4..6c500a909745c560661503f19fda86a71e4b8ed7 100644 (file)
@@ -5,7 +5,7 @@ import java.util.List;
 import smartapi.common.PROPERTY;
 import smartapi.common.RESOURCE;
 
-public class License extends Obj {
+public class License extends Contract {
 
        public License()
        {
index 13dece2085913d96006f983ee6bdb3ec5e1ab93c..cbc16840ef01a2ae28611d988ea1f78037779cd2 100644 (file)
@@ -10,6 +10,8 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import java.lang.reflect.InvocationTargetException;
+
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.Duration;
 
@@ -631,7 +633,7 @@ public class Obj implements ObjectInterface {
         * @param resource
         * @return
         */
-       public static <O extends Obj> O parse(Class<O> clazz, Resource resource) throws NullPointerException
+       public static <O extends Obj> O parse(Class<O> clazz, Resource resource) throws NullPointerException, InvocationTargetException, NoSuchMethodException
        {                       
                //System.out.println("parsing resource with uri: " + resource.getURI() + " and class: " + clazz.getSimpleName() + " bnid: " + resource.getId().getBlankNodeId().toString());
                String key = resource.isAnon() ? resource.getId().getBlankNodeId().toString() : resource.getURI();
@@ -641,7 +643,7 @@ public class Obj implements ObjectInterface {
 
                if ( resource == null ) throw new NullPointerException("Unable to parse a null resource.");
                O obj = null;
-               try { obj = clazz.newInstance(); }
+               try { obj = clazz.getDeclaredConstructor().newInstance(); }
                catch (InstantiationException e) {}
                catch (IllegalAccessException e) {}
                Tools.parsedObjs.put(key, obj);
@@ -806,7 +808,15 @@ public class Obj implements ObjectInterface {
                                        e.printStackTrace();
                                }
                                // type does not match with any built-in type, use Obj
-                               this.add(predicate, Obj.parse(Obj.class, resource));
+                               try {
+                                       this.add(predicate, Obj.parse(Obj.class, resource));
+                               } catch ( InvocationTargetException ite ) {
+                                       System.err.println("Failed to add a value to " + predicate + ". Target class is not defined.");
+                                       ite.printStackTrace();
+                               } catch ( NoSuchMethodException nsm ) {
+                                       System.err.println("Failed to add a value to " + predicate + ". Target class cannot be invoked.");
+                                       nsm.printStackTrace();
+                               }
                                return;
 
                        }
index e1cdff3e589e70315f38bb7a94ce6a644a7ac688..9d993a41f69fbc75529ca3d8a62b1469d4191d53 100644 (file)
@@ -12,7 +12,7 @@ import smartapi.common.PROPERTY;
 import smartapi.common.RESOURCE;
 import smartapi.rdf.Variant;
 
-public class Provenance extends Obj {
+public class Provenance extends Evaluation {
 
        public Provenance()
        {
index b48e5b58d08ec998fdedb8cf6c9768ca88001909..e34d228703a668112ec494ea5066531fe0a5d8a5 100644 (file)
@@ -95,7 +95,7 @@ public class NudeList extends List {
                                                if ( dataType == XSDDatatype.XSDstring ) {
                                                        String nude = lit.getString();
                                                        if ( isPrimitiveJsonList(nude) ) {
-                                                               this.setList(NudeList.fromNude(nude, null));                                                            
+                                                               this.setList(NudeList.fromNude(nude, null));
                                                        } else {
                                                                // if base object is already set -> parse nude list values
                                                                if ( this.hasBaseObject() ) {
@@ -106,7 +106,7 @@ public class NudeList extends List {
                                                                        }
                                                                } else {
                                                                        this.nude = nude;
-                                                               }                                                               
+                                                               }
                                                        }
                                                        return;
                                                } else {
@@ -135,21 +135,21 @@ public class NudeList extends List {
                if ( this.getItems().size() > 0 ) {
                        if ( this.getItems().get(0) instanceof Nudeable ) {
                                for ( Object object : this.getItems() ) {
-                                       str.append("," + ((Nudeable)object).toNude().toString());                                       
-                               }                               
+                                       str.append("," + ((Nudeable)object).toNude().toString());
+                               }
                        }
                        if ( this.getItems().get(0) instanceof Variant ) {
                                if ( ((Variant)this.getItems().get(0)).getType() == VARIANT.INTEGER ||
                                                ((Variant)this.getItems().get(0)).getType() == VARIANT.DOUBLE ||
                                                ((Variant)this.getItems().get(0)).getType() == VARIANT.FLOAT ) {
                                        for ( Object object : this.getItems() ) {
-                                               str.append("," + ((Variant)object).toString());                 
-                                       }                                                                       
+                                               str.append("," + ((Variant)object).toString());
+                                       }
                                }
                                if ( ((Variant)this.getItems().get(0)).getType() == VARIANT.STRING ) {
                                        for ( Object object : this.getItems() ) {
                                                str.append(",\"" + ((Variant)object).toString() + "\"");
-                                       }                                                                       
+                                       }
                                }
                        }
                }
@@ -215,7 +215,7 @@ public class NudeList extends List {
                                if ( array.get(0) instanceof JSONObject ) {
                                        for ( int i = 0; i < array.length(); i++ ) {
                                                try {
-                                                       Nudeable nudeable = baseObject.getClass().newInstance();
+                                                       Nudeable nudeable = baseObject.getClass().getDeclaredConstructor().newInstance();
                                                        nudeable.fromNude(array.getJSONObject(i));
                                                        ret.add(nudeable);
                                                } catch ( Exception e ) {
@@ -223,7 +223,7 @@ public class NudeList extends List {
                                                        e.printStackTrace();
                                                }
                                        }
-                                       return ret;                                     
+                                       return ret;
                                }
                                if ( array.get(0) instanceof String ) {
                                        for ( int i = 0; i < array.length(); i++ ) {
@@ -234,7 +234,7 @@ public class NudeList extends List {
                                                        e.printStackTrace();
                                                }
                                        }
-                                       return ret;                                                                             
+                                       return ret;
                                }
                                if ( array.get(0) instanceof Integer ) {
                                        for ( int i = 0; i < array.length(); i++ ) {
@@ -245,7 +245,7 @@ public class NudeList extends List {
                                                        e.printStackTrace();
                                                }
                                        }
-                                       return ret;                                                                             
+                                       return ret;
                                }
                                if ( array.get(0) instanceof Boolean ) {
                                        for ( int i = 0; i < array.length(); i++ ) {
@@ -256,7 +256,7 @@ public class NudeList extends List {
                                                        e.printStackTrace();
                                                }
                                        }
-                                       return ret;                                                                             
+                                       return ret;
                                }
                                if ( array.get(0) instanceof Double ) {
                                        for ( int i = 0; i < array.length(); i++ ) {
@@ -267,7 +267,7 @@ public class NudeList extends List {
                                                        e.printStackTrace();
                                                }
                                        }
-                                       return ret;                                                                             
+                                       return ret;
                                }
                                if ( array.get(0) instanceof Long ) {
                                        for ( int i = 0; i < array.length(); i++ ) {
@@ -278,7 +278,7 @@ public class NudeList extends List {
                                                        e.printStackTrace();
                                                }
                                        }
-                                       return ret;                                                                             
+                                       return ret;
                                }
                        }
                } catch ( Exception e ) {
index 5251f7d58e3406dd9e017da9a6de2c2dc67504e2..752d65835c7e0b2b738518ef040e880e7e9087b4 100644 (file)
@@ -4,6 +4,7 @@ import java.sql.Time;
 import java.util.Date;
 
 import java.net.URL;
+import java.lang.reflect.InvocationTargetException;
 
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.Duration;
@@ -232,7 +233,17 @@ public class Variant {
                        }
                        
                        // should not get here
-                       return new Variant(Obj.parse(Obj.class, resource));
+                       try {
+                               return new Variant(Obj.parse(Obj.class, resource));
+                       } catch ( InvocationTargetException ite ) {
+                               System.err.println("Failed to create a Variant. Target class is not defined.");
+                               ite.printStackTrace();
+                               return null;
+                       } catch ( NoSuchMethodException nsm ) {
+                               System.err.println("Failed to create a Variant. Target class cannot be invoked.");
+                               nsm.printStackTrace();
+                               return null;
+                       }
                }
                // could not identify datatype
                System.err.println("Parsing variant failed. Unable to detect RDFDatatype (" + dataType + ") for literal.");
index 4a46b8db0b727afe2213e3607f041cef47ac254b..708e68ac6473b67ae102ebddd64cada8633fbb4f 100644 (file)
@@ -12,6 +12,7 @@ import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.nio.charset.StandardCharsets;
+import java.lang.reflect.InvocationTargetException;
 
 import java.security.PrivateKey;
 import java.security.PublicKey;
@@ -204,24 +205,28 @@ public class TestSequence {
                        printTestTime(testStartTime, "Test interrupted in");
                        e.printStackTrace();
                }
-               TimeSeries tsParsed = Obj.parse(TimeSeries.class, res);
                
-               // test if list items are still there
-               if ( tsParsed.hasList() ) {
-                       ArrayList<Evaluation> tsl = (ArrayList<Evaluation>)(ArrayList<?>)tsParsed.getList().getItems();
-                       if ( tsl.size() == listSize ) {
-                               System.out.println("ListSerializeParseTest (list size: " + listSize + ") passed.");
-                               printTestTime(testStartTime, "Test executed in");
+               try {
+                       TimeSeries tsParsed = Obj.parse(TimeSeries.class, res);
+                       // test if list items are still there
+                       if ( tsParsed.hasList() ) {
+                               ArrayList<Evaluation> tsl = (ArrayList<Evaluation>)(ArrayList<?>)tsParsed.getList().getItems();
+                               if ( tsl.size() == listSize ) {
+                                       System.out.println("ListSerializeParseTest (list size: " + listSize + ") passed.");
+                                       printTestTime(testStartTime, "Test executed in");
+                               } else {
+                                       System.err.println("ListSerializeParseTest (list size: " + listSize + ") failed!");
+                                       System.err.println("Size of serialized and parsed list is " + tsl.size() + ".");
+                                       printTestTime(testStartTime, "Test executed in");
+                               }
                        } else {
                                System.err.println("ListSerializeParseTest (list size: " + listSize + ") failed!");
-                               System.err.println("Size of serialized and parsed list is " + tsl.size() + ".");
+                               System.err.println("Size of serialized and parsed list is 0.");
                                printTestTime(testStartTime, "Test executed in");
                        }
-               } else {
-                       System.err.println("ListSerializeParseTest (list size: " + listSize + ") failed!");
-                       System.err.println("Size of serialized and parsed list is 0.");
-                       printTestTime(testStartTime, "Test executed in");
-               }               
+               }
+               catch (NoSuchMethodException e) {}
+               catch (InvocationTargetException e) {}
        }
        
        public void arraySerializeParseTest(int listSize)
@@ -264,24 +269,29 @@ public class TestSequence {
                        printTestTime(testStartTime, "Test interrupted in");
                        e.printStackTrace();
                }
-               TimeSeries tsParsed = Obj.parse(TimeSeries.class, res);
-                                       
-               // test if list items are still there
-               if ( tsParsed.hasList() ) {
-                       ArrayList<Evaluation> tsl = (ArrayList<Evaluation>)(ArrayList<?>)tsParsed.getList().getItems();
-                       if ( tsl.size() == listSize ) {
-                               System.out.println("ArraySerializeParseTest (array size: " + listSize + ") passed.");
-                               printTestTime(testStartTime, "Test executed in");
+               
+               try {
+                       TimeSeries tsParsed = Obj.parse(TimeSeries.class, res);
+                                               
+                       // test if list items are still there
+                       if ( tsParsed.hasList() ) {
+                               ArrayList<Evaluation> tsl = (ArrayList<Evaluation>)(ArrayList<?>)tsParsed.getList().getItems();
+                               if ( tsl.size() == listSize ) {
+                                       System.out.println("ArraySerializeParseTest (array size: " + listSize + ") passed.");
+                                       printTestTime(testStartTime, "Test executed in");
+                               } else {
+                                       System.err.println("ArraySerializeParseTest (array size: " + listSize + ") failed!");
+                                       System.err.println("Size of serialized and parsed array is " + tsl.size() + ".");
+                                       printTestTime(testStartTime, "Test executed in");
+                               }
                        } else {
                                System.err.println("ArraySerializeParseTest (array size: " + listSize + ") failed!");
-                               System.err.println("Size of serialized and parsed array is " + tsl.size() + ".");
+                               System.err.println("Size of serialized and parsed array is 0.");
                                printTestTime(testStartTime, "Test executed in");
                        }
-               } else {
-                       System.err.println("ArraySerializeParseTest (array size: " + listSize + ") failed!");
-                       System.err.println("Size of serialized and parsed array is 0.");
-                       printTestTime(testStartTime, "Test executed in");
                }
+               catch (NoSuchMethodException e) {}
+               catch (InvocationTargetException e) {}
        }
        public void listOfMapsTest()
        {
@@ -1347,24 +1357,29 @@ public class TestSequence {
                        printTestTime(testStartTime, "Test interrupted in");
                        e.printStackTrace();
                }
-               Response resParsed = Obj.parse(Response.class, resource);
                
-               // test if list items are still there
-               java.util.List<Variant> items = resParsed.get("http://evaluation.com");
-               if ( items.size() != 0 ) {
-                       if ( items.size() == itemSize ) {
-                               System.out.println("HugeDataTest (data size: " + itemSize + ") passed.");
-                               printTestTime(testStartTime, "Test executed in");
+               try {
+                       Response resParsed = Obj.parse(Response.class, resource);
+                       
+                       // test if list items are still there
+                       java.util.List<Variant> items = resParsed.get("http://evaluation.com");
+                       if ( items.size() != 0 ) {
+                               if ( items.size() == itemSize ) {
+                                       System.out.println("HugeDataTest (data size: " + itemSize + ") passed.");
+                                       printTestTime(testStartTime, "Test executed in");
+                               } else {
+                                       System.err.println("HugeDataTest (data size: " + itemSize + ") failed!");
+                                       System.err.println("Size of serialized and parsed data is " + items.size() + ".");
+                                       printTestTime(testStartTime, "Test executed in");
+                               }
                        } else {
                                System.err.println("HugeDataTest (data size: " + itemSize + ") failed!");
-                               System.err.println("Size of serialized and parsed data is " + items.size() + ".");
+                               System.err.println("Size of serialized and parsed data is 0.");
                                printTestTime(testStartTime, "Test executed in");
                        }
-               } else {
-                       System.err.println("HugeDataTest (data size: " + itemSize + ") failed!");
-                       System.err.println("Size of serialized and parsed data is 0.");
-                       printTestTime(testStartTime, "Test executed in");
                }
+               catch (NoSuchMethodException e) {}
+               catch (InvocationTargetException e) {}
        }
        
        public void fileInputTest(String fileName, String serialization)
index 732dd4adaec0fe95093a692a659f789d0631bf0c..cdc2a4f81882cb5d19f4063e01594d11648414dc 100644 (file)
@@ -4,6 +4,7 @@ from SmartAPI.common.Tools import Tools
 from SmartAPI.rdf.Resource import Resource
 
 from SmartAPI.model.Entity import Entity
+from SmartAPI.model.Evaluation import Evaluation
 from SmartAPI.model.Obj import Obj
 from SmartAPI.model.Input import Input
 from SmartAPI.rdf.Variant import Variant
@@ -13,10 +14,10 @@ from SmartAPI.model.TemporalContext import TemporalContext
 from rdflib.term import URIRef
 
 
-class Activity(Obj):
+class Activity(Evaluation):
 
        def __init__(self, uri = None):
-               Obj.__init__(self, uri)
+               Evaluation.__init__(self, uri)
                self.setType(RESOURCE.ACTIVITY)
                
                self.init_property(PROPERTY.HASINPUT, 'inputs', self.hasInput, self.getInputs, True)
@@ -29,7 +30,6 @@ class Activity(Obj):
                self.init_property(PROPERTY.ENTITY, 'entities', self.hasEntity, self.getEntities, True)
                self.init_property(PROPERTY.TEMPORALCONTEXT, 'temporalContext', self.hasTemporalContext, self.getTemporalContext)
                self.init_property(PROPERTY.TIMESERIES, 'timeSeries', self.hasTimeSeries, self.getTimeSeries, True)
-               self.init_property(PROPERTY.METHOD, 'method', self.hasMethod, self.getMethod)
 
        def _parseStatement(self, statement):
                from SmartAPI.model.Availability import Availability
@@ -50,7 +50,6 @@ class Activity(Obj):
                self.parse_property(statement, PROPERTY.ENTITY, self.addEntity, Entity)
                self.parse_property(statement, PROPERTY.TEMPORALCONTEXT, self.setTemporalContext, TemporalContext)
                self.parse_property(statement, PROPERTY.TIMESERIES, self.addTimeSerie, TimeSeries)
-               self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant)
 
                super(Activity, self)._parseStatement(statement)
 
@@ -189,23 +188,6 @@ class Activity(Obj):
                except:
                        return None
        
-       def hasMethod(self):
-               return self.method is not None
-       
-       def getMethod(self):
-               return self.method
-       
-       def setMethod(self, methodUri):
-               '''
-               @param methodUri: method Uri string
-               '''     
-               if isinstance(methodUri, str):
-                       methodUri = Variant(URIRef(methodUri))
-               elif isinstance(methodUri, URIRef):
-                       methodUri = Variant(methodUri)
-               
-               self.method = methodUri
-       
        def hasTemporalContext(self):
                return self.temporalContext is not None
 
index 156d5e4d7b09ea4b73fc71e7b084d5498b1307a5..cfb6747e51136d9517290e8d40f8e72695fcccb7 100644 (file)
@@ -10,34 +10,17 @@ from SmartAPI.rdf.Variant import Variant
 
 class Availability(Ability):
 
-       def __init__(self, uri = None, temporalContext = None, address = None, ring = None):
+       def __init__(self, uri = None, address = None, ring = None):
                Ability.__init__(self, uri)
-               self.init_property(PROPERTY.TEMPORALCONTEXT, 'temporalContext', self.hasTemporalContext, self.getTemporalContext)
                self.init_property(PROPERTY.LOCATION, 'ring', self.hasRing, self.getRing)
                self.init_property(PROPERTY.HASADDRESS, 'address', self.hasAddress, self.getAddress)
                self.init_property(PROPERTY.PRIORITY, 'priority', self.hasPriority, self.getPriority)
                self.setType(RESOURCE.AVAILABILITY)
-               if temporalContext is not None:
-                       self.setTemporalContext(temporalContext)
                if address is not None:
                        self.setAddress(address)
                if ring is not None:
                        self.setRing(ring)
        
-       def hasTemporalContext(self):
-               return self.temporalContext is not None
-       
-       def getTemporalContext(self):
-               return self.temporalContext
-       
-       def setTemporalContext(self, temporalContext = None, start = None, end = None, during = None):
-               if temporalContext is not None:
-                       temporalCtx = temporalContext
-               elif start is not None:
-                       temporalCtx = TemporalContext(start = start, end = end, during = during)
-               super(Availability, self).setTemporalContext(temporalCtx)
-               self.addType(RESOURCE.TEMPORALAVAILABILITY)
-               
        def hasRing(self):
                return self.ring is not None
        
@@ -143,17 +126,11 @@ class Availability(Ability):
                                                else:
                                                        # first level 'or' values are not availabilities, there is some abnormal condition structure, just add as new 'or' value
                                                        self.getCondition().addOr(availability)
-                                                       return                          
+                                                       return
                                        # first level condition does not have 'ands' nor 'ors', add as 'or' value
                                        self.getCondition().addOr(availability)
-                                       return          
-                       else:
-                               # if 'this' is an empty availability, then replace 'this' with availability
-                               if not self.hasType(RESOURCE.TEMPORALAVAILABILITY) and not self.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY) and not self.hasProperty():
-                                       #self.clearProperties()
-                                       Tools().clear(self)
-                                       Tools().copy(availability, self)
                                        return
+                       else:
                                # there was only one availability until now ->  if same type, create or, otherwise create and
                                if Availability().sameTypeAndProperty(self, availability):
                                        orCondition = Condition()
@@ -178,15 +155,7 @@ class Availability(Ability):
                        
        @classmethod
        def sameTypeAndProperty(cls, firstAvailability, secondAvailability):
-               if firstAvailability.hasType(RESOURCE.TEMPORALAVAILABILITY) and secondAvailability.hasType(RESOURCE.TEMPORALAVAILABILITY):
-                       if firstAvailability.hasTemporalContext() and secondAvailability.hasTemporalContext():
-                               if firstAvailability.getTemporalContext().containsTimeValues() and secondAvailability.getTemporalContext().containsTimeValues():
-                                       return True
-                               if firstAvailability.getTemporalContext().containsDateValues() and secondAvailability.getTemporalContext().containsDateValues():
-                                       return True
-                               return False
-                       return False
-               elif firstAvailability.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY) and secondAvailability.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY):
+               if firstAvailability.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY) and secondAvailability.hasType(RESOURCE.PROPERTYBASEDAVAILABILITY):
                        if firstAvailability.hasProperty() and secondAvailability.hasProperty():
                                # if they have same property
                                if firstAvailability.getPropertyAsString() == secondAvailability.getPropertyAsString():
@@ -199,13 +168,8 @@ class Availability(Ability):
 if __name__ == '__main__':
        import datetime
        from SmartAPI.common.Tools import Tools
-       t = TemporalContext()
-       
-       t.setStart(datetime.datetime.now())
-       t.setEnd(datetime.datetime.now())
-       t.setDuration('P10D')
        
-       a = Availability(address = 'Espoo', temporalContext = t)
+       a = Availability(address = 'Espoo')
        a.addPersonByUsername('someperson')
        a.turtlePrint()
        
index d0a5bc8c13762cdde5c984c7888ed2dbd3ae609a..f92b565a7d90881ceb5cbb5d63b633c42d43ed78 100644 (file)
@@ -27,6 +27,7 @@ class Evaluation(ValueObject):
                self.init_property(PROPERTY.TIMESERIES, 'timeSeries', self.hasTimeSeries, self.getTimeSeries, islist = True)
                self.init_property(PROPERTY.VALUEOBJECT, 'valueObjects', self.hasValueObject, self.getValueObjects, islist = True)
                self.init_property(PROPERTY.ACTIVITY, 'activities', self.hasActivity, self.getActivities, islist = True)
+               self.init_property(PROPERTY.METHOD, 'method', self.hasMethod, self.getMethod)
                
        @classmethod
        def fromString(cls, data, serialization):
@@ -52,6 +53,7 @@ class Evaluation(ValueObject):
                self.parse_property(statement, PROPERTY.TIMESERIES, self.addTimeSerie, TimeSeries)
                self.parse_property(statement, PROPERTY.VALUEOBJECT, self.addValueObject, ValueObject)
                self.parse_property(statement, PROPERTY.ACTIVITY, self.addActivity, Activity)
+               self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant)
                super(Evaluation, self)._parseStatement(statement)
 
        def hasCategory(self):
@@ -64,7 +66,7 @@ class Evaluation(ValueObject):
        def addCategory(self, category):
                from SmartAPI.rdf.Variant import Variant
                from SmartAPI.model.Obj import Obj
-                                                               
+               
                if isinstance(category, Obj):
                        category = category.getIdentifierUri()
                if isinstance(category, str):
@@ -119,6 +121,23 @@ class Evaluation(ValueObject):
                soi.setSameAs(sameAs)
                self.systemOfInterest = soi
        
+       def hasMethod(self):
+               return self.method is not None
+       
+       def getMethod(self):
+               return self.method
+       
+       def setMethod(self, methodUri):
+               '''
+               @param methodUri: method Uri string
+               '''     
+               if isinstance(methodUri, str):
+                       methodUri = Variant(URIRef(methodUri))
+               elif isinstance(methodUri, URIRef):
+                       methodUri = Variant(methodUri)
+               
+               self.method = methodUri
+               
        def hasActivity(self):
                return len(self.activities) > 0
        
index e0f0fae060a46763cf8ae1f0fd561a3d17057381..2dc3d65ac6f8c5b0489d5ae915dda29c55ff6d07 100644 (file)
@@ -2,6 +2,7 @@ from SmartAPI.common.PROPERTY import PROPERTY
 from SmartAPI.common.RESOURCE import RESOURCE
 from SmartAPI.common.Tools import Tools
 from SmartAPI.model.Activity import Activity
+from SmartAPI.model.Evaluation import Evaluation
 from SmartAPI.model.Obj import Obj
 
 from SmartAPI.rdf.Resource import Resource
@@ -11,10 +12,10 @@ from rdflib import URIRef
 import traceback
 from mercurial.bundlerepo import instance
 
-class Provenance(Obj):
+class Provenance(Evaluation):
 
        def __init__(self, uri = None):
-               Obj.__init__(self, uri)
+               Evaluation.__init__(self, uri)
                self.init_property(PROPERTY.GENERATIONMETHOD, 'generationMethods', self.hasGenerationMethod, self.getGenerationMethods, True)
                self.init_property(PROPERTY.DATASOURCE, 'dataSources', self.hasDataSource, self.getDataSources, True)
                self.init_property(PROPERTY.SMARTAPI_PROPERTY, 'props', self.hasProperty, self.getProperties, True)