New headers; Java: bump version to 1.0.2
[smartapi.git] / Common / C++ / SmartAPI / smartapi / model / Entity.h
1 #ifndef _ENTITY_H_
2 #define _ENTITY_H_
3
4 #include "smartapi/common/RESOURCE.h"
5 #include "smartapi/common/PROPERTY.h"
6 #include "smartapi/model/Activity.h"
7 #include "smartapi/model/Address.h"
8 #include "smartapi/model/Classification.h"
9 #include "smartapi/model/Controllability.h"
10 #include "smartapi/model/Coordinates.h"
11 #include "smartapi/model/HeartBeat.h"
12 #include "smartapi/model/Obj.h"
13 #include "smartapi/model/Route.h"
14 #include "smartapi/rdf/Variant.h"
15 #include "smartapi/model/TimeSeries.h"
16 #include "smartapi/model/Zone.h"
17
18 #include "smartapi/rdf/GraphItem.h"
19 #include "smartapi/rdf/Resource.h"
20 #include "smartapi/rdf/Statement.h"
21 #include "smartapi/rdf/Model.h"
22
23 #include <QString>
24 #include <QList>
25 #include <QVariantMap>
26 #include <QDateTime>
27
28 #include "smartapi/rdf/PropertyList.h"
29
30
31 class Availability;
32 class Capacity;
33
34 class Entity : public Obj
35 {
36 public:
37         Entity(QString uri = QString());
38         Entity(Entity* e);
39         ~Entity();
40
41         virtual void clearReferences(QSet<GraphItem*>* trash);
42
43         Resource* serialize(Model* model);
44         void parse(Statement* statement);
45
46         bool hasZone()                                                                                  { return mZone != NULL; }
47         Zone* getZone()                                                                                 { return mZone; }
48         void setZone(Zone* zone)                                                                { add(PROPERTY__ZONE, zone); mZone = zone; }
49         
50         bool hasCoordinates()                                                                   { return mCoordinates != NULL; }
51         Coordinates* getCoordinates()                                                   { return mCoordinates; }
52         void setCoordinates(Coordinates* c)                                             { add(PROPERTY__LOCATION, c); mCoordinates = c; }
53         void setCoordinates(double lat, double lon)                             { setCoordinates(new Coordinates(lat, lon)); }
54
55         bool hasAddress()                                                                               { return mAddress != NULL; }
56         Address* getAddress()                                                                   { return mAddress; }
57         void setAddress(Address* a)                                                             { add(PROPERTY__HASADDRESS, a); mAddress = a; }
58         
59         bool hasAvailability()                                                                  { return (mAvailabilities.length() > 0); }
60         PropertyList<Availability*> getAvailabilities()                 { return mAvailabilities; }
61         void setAvailability(Availability* availability)                { mAvailabilities.append(availability); }
62
63         bool hasManagedBy()                                                                     { return (mManagedBy != NULL); }
64         void setManagedBy(GraphItem* v)                                                 { add(PROPERTY__ISMANAGEDBY, v); mManagedBy = v; }
65         void setManagedBy(QUrl uri)                                                             { setManagedBy(new Variant(uri)); }
66         void setManagedBy(QString uri)                                                  { setManagedBy(QUrl(uri)); }
67         void setManagedBy(Entity* e);
68         GraphItem* getManagedBy()                                                               { return mManagedBy; }
69
70         bool hasServedBy()                                                                              { return (mServedBy != NULL); }
71         void setServedBy(GraphItem* v)                                                  { add(PROPERTY__ISSERVEDBY, v); mServedBy = v; }
72         void setServedBy(QUrl uri)                                                              { setServedBy(new Variant(uri)); }
73         void setServedBy(QString uri)                                                   { setServedBy(QUrl(uri)); }
74         void setServedBy(Entity* e);
75         GraphItem* getServedBy()                                                                { return mServedBy; }
76
77         bool hasHeartBeat()                                                                             { return mHeartBeat != NULL; }
78         HeartBeat* getHeartBeat()                                                               { return mHeartBeat; }
79         void setHeartBeat(HeartBeat* h)                                                 { add(PROPERTY__HEARTBEAT, h); mHeartBeat = h; }
80
81         bool hasWebsite()                                                                               { return (mWebsites.length() > 0); }
82         PropertyList<Variant*> getWebsites()                                    { return mWebsites; }
83         void addWebsite(Variant* url)                                                   { mWebsites.append(url); }
84         void addWebsite(QString url)                                                    { mWebsites.append(new Variant(url)); }
85         void setWebsites(PropertyList<Variant*> urls)                   { mWebsites = urls; add(PROPERTY__HASURL, &mWebsites); }
86         void setWebsite(QString url)                                                    { mWebsites.clear(); addWebsite(url); }
87
88         bool hasLogo()                                                                                  { return (mLogos.length() > 0); }
89         PropertyList<Variant*> getLogos()                                               { return mLogos; }
90         void addLogo(Variant* url)                                                              { mLogos.append(url); }
91         void addLogo(QString url)                                                               { mLogos.append(new Variant(url)); }
92         void setLogos(PropertyList<Variant*> urls)                              { mLogos = urls; add(PROPERTY__HASLOGO, &mLogos); }
93         void setLogo(QString url)                                                               { mLogos.clear(); addLogo(url); }
94
95         bool hasPhoto()                                                                                 { return (mPhotos.length() > 0); }
96         PropertyList<Variant*> getPhotos()                                              { return mPhotos; }
97         void addPhoto(Variant* url)                                                             { mPhotos.append(url); }
98         void addPhoto(QString url)                                                              { mPhotos.append(new Variant(url)); }
99         void setPhotos(PropertyList<Variant*> urls)                             { mPhotos = urls; add(PROPERTY__HASPHOTO, &mPhotos); }
100         void setPhoto(QString url)                                                              { mPhotos.clear(); addPhoto(url); }
101
102         bool hasSound()                                                                                 { return (mSounds.length() > 0); }
103         PropertyList<Variant*> getSounds()                                              { return mSounds; }
104         void addSound(Variant* url)                                                     { mSounds.append(url); }
105         void addSound(QString url)                                                              { mSounds.append(new Variant(url)); }
106         void setSounds(PropertyList<Variant*> urls)                             { mSounds = urls; add(PROPERTY__HASSOUND, &mSounds); }
107         void setSound(QString url)                                                              { mSounds.clear(); addSound(url); }
108
109         void addAvailability(Availability* availability);
110         void addAvailability(TemporalContext* temporalContext);
111         void addAvailability(QDateTime start, QDateTime end);
112         // TODO should there be specific methods for QDate and QTime types?
113         void addAvailability(Address* address);
114         void addAvailability(Ring* ring);
115
116         bool hasControllability()                                                                       { return (mControllabilities.length() > 0); }
117         PropertyList<Controllability*> getControllabilities()           { return mControllabilities; }
118         void addControllability(Controllability* controllability)       { mControllabilities.append(controllability); }
119
120         bool hasDataAvailability()                                                                      { return (mDataAvailabilities.length() > 0); }
121         PropertyList<Availability*> getDataAvailabilities()                     { return mDataAvailabilities; }
122         void addDataAvailability(Availability* availability)            { mDataAvailabilities.append(availability); }
123
124         bool hasClassification()                                                                        { return (mClassifications.length() > 0); }
125         PropertyList<Classification*> getClassifications()                      { return mClassifications; }
126         void addClassification(Classification* classification)          { mClassifications.append(classification); }
127
128         bool hasCapability()                                                                            { return (mCapabilities.length() > 0); }
129         PropertyList<Activity*> getCapabilities()                                       { return mCapabilities; }
130         void setCapabilities(PropertyList<Activity*> capabilities)      { mCapabilities = capabilities; add(PROPERTY__HASCAPABILITY, &mCapabilities); }
131         void addCapability(Activity* capability)                                        { mCapabilities.append(capability); }
132
133         bool hasCapacity()                                                                                      { return (mCapacities.length() > 0); }
134         PropertyList<Capacity*> getCapacities()                                         { return mCapacities; }
135         void setCapacity(PropertyList<Capacity*> caps)                          { mCapacities = caps; add(PROPERTY__CAPACITY, &mCapacities);  }
136         void addCapacity(Capacity* cap)                                                         { mCapacities.append(cap); }
137
138         bool hasInterface()                                                                                     { return (mInterfaces.length() > 0); }
139         PropertyList<InterfaceAddress*> getInterfaces()                         { return mInterfaces; }
140         void setInterface(InterfaceAddress* interfaceAddress)           { mInterfaces.clear(); mInterfaces.append(interfaceAddress); }
141         void addInterface(InterfaceAddress* interfaceAddress)           { mInterfaces.append(interfaceAddress); }
142
143         bool hasOwner()                                                                                         { return (mOwners.length() > 0); }
144         PropertyList<Entity*> getOwners()                                                       { return mOwners; }
145         void setOwner(Entity* e)                                                                        { mOwners.clear(); mOwners.append(e); }
146         void addOwner(Entity* e)                                                                        { mOwners.append(e); }
147         
148         bool hasCreator()                                                                                       { return (mCreators.length() > 0); }
149         PropertyList<Entity*> getCreators()                                                     { return mCreators; }
150         void setCreator(Entity* e)                                                                      { mCreators.clear(); mCreators.append(e); }
151         void addCreator(Entity* e)                                                                      { mCreators.append(e); }
152         
153         bool hasManagedEntity()                                                                         { return (mManagedEntities.length() > 0); }
154         PropertyList<Entity*> getManagedEntities()                                      { return mManagedEntities; }
155         void setManagedEntity(Entity* e)                                                        { mManagedEntities.clear(); mManagedEntities.append(e); }
156         void addManagedEntity(Entity* e)                                                        { mManagedEntities.append(e); }
157         
158         Route* getRoute()                                                                                       { return mRoute; }
159         bool hasRoute()                                                                                         { return (mRoute != NULL); }
160         void setRoute(Route* l)                                                                         { add(PROPERTY__ROUTE, l); mRoute = l; }
161
162         bool hasValueObject()                                                                           { return (mValueObjects.length() > 0); }
163         PropertyList<ValueObject*> getValueObjects()                            { return mValueObjects; }
164         void setValueObjects(PropertyList<ValueObject*> objects)        { mValueObjects = objects; add(PROPERTY__VALUEOBJECT, &mValueObjects); }
165         void addValueObject(ValueObject* valueObject)                           { mValueObjects.append(valueObject); }
166
167         ValueObject* getValueObject(QString quantity);
168         ValueObject* newValueObject(QString identifier = QString());
169         ValueObject* newValueObject(QString quantity, QString unit, QString dataType, QString description, QStringList types);
170
171 private:
172         GraphItem* mManagedBy;
173         GraphItem* mServedBy;
174         Coordinates* mCoordinates;
175         Address* mAddress;
176         Zone* mZone;
177         HeartBeat* mHeartBeat;
178         Route* mRoute;
179
180         PropertyList<Variant*> mWebsites;
181         PropertyList<Variant*> mLogos;
182         PropertyList<Variant*> mPhotos;
183         PropertyList<Variant*> mSounds;
184         PropertyList<Controllability*> mControllabilities;
185         PropertyList<Availability*> mAvailabilities;
186         PropertyList<Availability*> mDataAvailabilities;
187         PropertyList<Activity*> mCapabilities;
188         PropertyList<Capacity*> mCapacities;
189         PropertyList<Classification*> mClassifications;
190         PropertyList<Entity*> mCreators;
191         PropertyList<Entity*> mOwners;  
192         PropertyList<InterfaceAddress*> mInterfaces;
193         PropertyList<Entity*> mManagedEntities;
194         PropertyList<ValueObject*> mValueObjects;
195
196 };
197
198 #endif // _ENTITY_H_