staplus-client 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- staplus_client/__init__.py +47 -0
- staplus_client/__version__.py +8 -0
- staplus_client/dao/__init__.py +18 -0
- staplus_client/dao/actuator.py +30 -0
- staplus_client/dao/base.py +70 -0
- staplus_client/dao/campaign.py +25 -0
- staplus_client/dao/datastream.py +35 -0
- staplus_client/dao/features_of_interest.py +36 -0
- staplus_client/dao/historical_location.py +35 -0
- staplus_client/dao/license.py +25 -0
- staplus_client/dao/location.py +35 -0
- staplus_client/dao/multi_datastream.py +36 -0
- staplus_client/dao/observation.py +55 -0
- staplus_client/dao/observation_group.py +25 -0
- staplus_client/dao/observedproperty.py +35 -0
- staplus_client/dao/party.py +25 -0
- staplus_client/dao/relation.py +57 -0
- staplus_client/dao/sensor.py +35 -0
- staplus_client/dao/task.py +30 -0
- staplus_client/dao/tasking_capability.py +30 -0
- staplus_client/dao/thing.py +36 -0
- staplus_client/model/__init__.py +29 -0
- staplus_client/model/campaign.py +417 -0
- staplus_client/model/datastream.py +166 -0
- staplus_client/model/entity.py +29 -0
- staplus_client/model/ext/__init__.py +0 -0
- staplus_client/model/ext/entity_list.py +75 -0
- staplus_client/model/ext/entity_type.py +142 -0
- staplus_client/model/ext/unitofmeasurement.py +5 -0
- staplus_client/model/feature_of_interest.py +17 -0
- staplus_client/model/historical_location.py +21 -0
- staplus_client/model/license.py +301 -0
- staplus_client/model/location.py +22 -0
- staplus_client/model/multi_datastream.py +160 -0
- staplus_client/model/observation.py +218 -0
- staplus_client/model/observation_group.py +399 -0
- staplus_client/model/observedproperty.py +20 -0
- staplus_client/model/party.py +315 -0
- staplus_client/model/relation.py +246 -0
- staplus_client/model/sensor.py +16 -0
- staplus_client/model/thing.py +110 -0
- staplus_client/query/__init__.py +0 -0
- staplus_client/query/query.py +109 -0
- staplus_client/service/BearerAuth.py +23 -0
- staplus_client/service/__init__.py +17 -0
- staplus_client/service/auth_handler.py +23 -0
- staplus_client/service/staplusservice.py +162 -0
- staplus_client/utils.py +64 -0
- staplus_client-0.3.3.dist-info/LICENSE +165 -0
- staplus_client-0.3.3.dist-info/METADATA +470 -0
- staplus_client-0.3.3.dist-info/RECORD +53 -0
- staplus_client-0.3.3.dist-info/WHEEL +5 -0
- staplus_client-0.3.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# Copyright (C) 2023-2024 Secure Dimensions GmbH, Munich, Germany.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU Lesser General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
+
|
|
16
|
+
from staplus_client import utils
|
|
17
|
+
from staplus_client.model import entity
|
|
18
|
+
from staplus_client.model import datastream, multi_datastream, thing, observation_group, campaign
|
|
19
|
+
from staplus_client.model.ext import entity_list, entity_type
|
|
20
|
+
from staplus_client.dao.party import PartyDao
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Party(entity.Entity):
|
|
24
|
+
|
|
25
|
+
def __init__(self,
|
|
26
|
+
description=None,
|
|
27
|
+
auth_id=None,
|
|
28
|
+
role='',
|
|
29
|
+
display_name=None,
|
|
30
|
+
datastreams=None,
|
|
31
|
+
multi_datastreams=None,
|
|
32
|
+
things=None,
|
|
33
|
+
campaigns=None,
|
|
34
|
+
observation_groups=None,
|
|
35
|
+
**kwargs):
|
|
36
|
+
super().__init__(**kwargs)
|
|
37
|
+
self.description = description
|
|
38
|
+
self.auth_id = auth_id
|
|
39
|
+
self.role = role
|
|
40
|
+
self.display_name = display_name
|
|
41
|
+
self.datastreams = datastreams
|
|
42
|
+
self.multi_datastreams = multi_datastreams
|
|
43
|
+
self.things = things
|
|
44
|
+
self.campaigns = campaigns
|
|
45
|
+
self.observation_groups = observation_groups
|
|
46
|
+
|
|
47
|
+
def __new__(cls, *args, **kwargs):
|
|
48
|
+
new_party = super().__new__(cls)
|
|
49
|
+
attributes = {'_id': None, '_description': '', '_auth_id': '', '_role': '', '_display_name': '',
|
|
50
|
+
'_datastreams': None, '_multi_datastreams': None, '_things': None,
|
|
51
|
+
'_campaigns': None, '_observation_groups': None,
|
|
52
|
+
'_self_link': '', '_service': None}
|
|
53
|
+
for key, value in attributes.items():
|
|
54
|
+
new_party.__dict__[key] = value
|
|
55
|
+
return new_party
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def description(self):
|
|
59
|
+
return self._description
|
|
60
|
+
|
|
61
|
+
@description.setter
|
|
62
|
+
def description(self, value):
|
|
63
|
+
if value is None:
|
|
64
|
+
self._description = None
|
|
65
|
+
return
|
|
66
|
+
if not isinstance(value, str):
|
|
67
|
+
raise ValueError('description should be of type str!')
|
|
68
|
+
self._description = value
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def auth_id(self):
|
|
72
|
+
return self._auth_id
|
|
73
|
+
|
|
74
|
+
@auth_id.setter
|
|
75
|
+
def auth_id(self, value):
|
|
76
|
+
if value is None:
|
|
77
|
+
self._auth_id = None
|
|
78
|
+
return
|
|
79
|
+
if not isinstance(value, str):
|
|
80
|
+
raise ValueError('authId should be of type str!')
|
|
81
|
+
self._auth_id = value
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def role(self):
|
|
85
|
+
return self._role
|
|
86
|
+
|
|
87
|
+
@role.setter
|
|
88
|
+
def role(self, value):
|
|
89
|
+
if value is None:
|
|
90
|
+
self._role = None
|
|
91
|
+
return
|
|
92
|
+
if not isinstance(value, str):
|
|
93
|
+
raise ValueError('role should be of type str!')
|
|
94
|
+
self._role = value
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def display_name(self):
|
|
98
|
+
return self._display_name
|
|
99
|
+
|
|
100
|
+
@display_name.setter
|
|
101
|
+
def display_name(self, value):
|
|
102
|
+
if value is None:
|
|
103
|
+
self._display_name = None
|
|
104
|
+
return
|
|
105
|
+
if not isinstance(value, str):
|
|
106
|
+
raise ValueError('displayName should be of type str!')
|
|
107
|
+
self._display_name = value
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def datastreams(self):
|
|
111
|
+
return self._datastreams
|
|
112
|
+
|
|
113
|
+
@datastreams.setter
|
|
114
|
+
def datastreams(self, values):
|
|
115
|
+
if values is None:
|
|
116
|
+
self._datastreams = None
|
|
117
|
+
return
|
|
118
|
+
if isinstance(values, list) and all(isinstance(ds, datastream.Datastream) for ds in values):
|
|
119
|
+
entity_class = entity_type.EntityTypes['Datastream']['class']
|
|
120
|
+
self._datastreams = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
121
|
+
return
|
|
122
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
123
|
+
any((not isinstance(ds, datastream.Datastream)) for ds in values.entities):
|
|
124
|
+
raise ValueError('datastreams should be a list of datastreams')
|
|
125
|
+
self._datastreams = values
|
|
126
|
+
|
|
127
|
+
def get_datastreams(self):
|
|
128
|
+
result = self.service.datastreams()
|
|
129
|
+
result.parent = self
|
|
130
|
+
return result
|
|
131
|
+
|
|
132
|
+
@property
|
|
133
|
+
def campaigns(self):
|
|
134
|
+
return self._campaigns
|
|
135
|
+
|
|
136
|
+
@campaigns.setter
|
|
137
|
+
def campaigns(self, values):
|
|
138
|
+
if values is None:
|
|
139
|
+
self._campaigns = None
|
|
140
|
+
return
|
|
141
|
+
if isinstance(values, list) and all(isinstance(t, campaign.Campaign) for t in values):
|
|
142
|
+
entity_class = entity_type.EntityTypes['CampaignThing']['class']
|
|
143
|
+
self._campaigns = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
144
|
+
return
|
|
145
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
146
|
+
any((not isinstance(t, campaign.Campaign)) for t in values.entities):
|
|
147
|
+
raise ValueError('campaigns should be a list of Campaign')
|
|
148
|
+
self._things = values
|
|
149
|
+
|
|
150
|
+
def get_campaigns(self):
|
|
151
|
+
result = self.service.campaigns()
|
|
152
|
+
result.parent = self
|
|
153
|
+
return result
|
|
154
|
+
|
|
155
|
+
@property
|
|
156
|
+
def things(self):
|
|
157
|
+
return self._things
|
|
158
|
+
|
|
159
|
+
@things.setter
|
|
160
|
+
def things(self, values):
|
|
161
|
+
if values is None:
|
|
162
|
+
self._things = None
|
|
163
|
+
return
|
|
164
|
+
if isinstance(values, list) and all(isinstance(t, thing.Thing) for t in values):
|
|
165
|
+
entity_class = entity_type.EntityTypes['Thing']['class']
|
|
166
|
+
self._things = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
167
|
+
return
|
|
168
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
169
|
+
any((not isinstance(t, thing.Thing)) for t in values.entities):
|
|
170
|
+
raise ValueError('things should be a list of Thing')
|
|
171
|
+
self._things = values
|
|
172
|
+
|
|
173
|
+
def get_things(self):
|
|
174
|
+
result = self.service.things()
|
|
175
|
+
result.parent = self
|
|
176
|
+
return result
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def observation_groups(self):
|
|
180
|
+
return self._observation_groups
|
|
181
|
+
|
|
182
|
+
@observation_groups.setter
|
|
183
|
+
def observation_groups(self, values):
|
|
184
|
+
if values is None:
|
|
185
|
+
self._observation_groups = None
|
|
186
|
+
return
|
|
187
|
+
if isinstance(values, list) and all(isinstance(t, observation_group.ObservationGroup) for t in values):
|
|
188
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
189
|
+
self._observation_groups = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
190
|
+
return
|
|
191
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
192
|
+
any((not isinstance(t, observation_group.ObservationGroup)) for t in values.entities):
|
|
193
|
+
raise ValueError('observation_groups should be a list of ObservationGroup')
|
|
194
|
+
self._observation_groups = values
|
|
195
|
+
|
|
196
|
+
def get_observation_groups(self):
|
|
197
|
+
result = self.service.observation_groups()
|
|
198
|
+
result.parent = self
|
|
199
|
+
return result
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def multi_datastreams(self):
|
|
203
|
+
return self._multi_datastreams
|
|
204
|
+
|
|
205
|
+
@multi_datastreams.setter
|
|
206
|
+
def multi_datastreams(self, values):
|
|
207
|
+
if values is None:
|
|
208
|
+
self._multi_datastreams = None
|
|
209
|
+
return
|
|
210
|
+
if isinstance(values, list) and all(isinstance(ds, multi_datastream.MultiDatastream) for ds in values):
|
|
211
|
+
entity_class = entity_type.EntityTypes['MultiDatastream']['class']
|
|
212
|
+
self._multi_datastreams = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
213
|
+
return
|
|
214
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
215
|
+
any((not isinstance(ds, multi_datastream.MultiDatastream)) for ds in values.entities):
|
|
216
|
+
raise ValueError('multi_datastreams should be a list of MultiDatastream')
|
|
217
|
+
self._multi_datastreams = values
|
|
218
|
+
|
|
219
|
+
def get_multi_datastreams(self):
|
|
220
|
+
result = self.service.multi_datastreams()
|
|
221
|
+
result.parent = self
|
|
222
|
+
return result
|
|
223
|
+
|
|
224
|
+
def ensure_service_on_children(self, service):
|
|
225
|
+
if self.datastreams is not None:
|
|
226
|
+
self.datastreams.set_service(service)
|
|
227
|
+
if self.multi_datastreams is not None:
|
|
228
|
+
self.multi_datastreams.set_service(service)
|
|
229
|
+
if self.campaigns is not None:
|
|
230
|
+
self.campaigns.set_service(service)
|
|
231
|
+
if self.observation_groups is not None:
|
|
232
|
+
self.observation_groups.set_service(service)
|
|
233
|
+
|
|
234
|
+
def __eq__(self, other):
|
|
235
|
+
if other is None:
|
|
236
|
+
return False
|
|
237
|
+
if not isinstance(other, type(self)):
|
|
238
|
+
return False
|
|
239
|
+
if id(self) == id(other):
|
|
240
|
+
return True
|
|
241
|
+
if self.auth_id != other.auth_id:
|
|
242
|
+
return False
|
|
243
|
+
if self.description != other.description:
|
|
244
|
+
return False
|
|
245
|
+
if self.role != other.role:
|
|
246
|
+
return False
|
|
247
|
+
if self.display_name != other.display_name:
|
|
248
|
+
return False
|
|
249
|
+
return True
|
|
250
|
+
|
|
251
|
+
def __ne__(self, other):
|
|
252
|
+
return not self == other
|
|
253
|
+
|
|
254
|
+
def __getstate__(self):
|
|
255
|
+
data = super().__getstate__()
|
|
256
|
+
if self.auth_id is not None and self.auth_id != '':
|
|
257
|
+
data['authId'] = self.auth_id
|
|
258
|
+
if self.description is not None and self.description != '':
|
|
259
|
+
data['description'] = self.description
|
|
260
|
+
if self.role is not None and self.role != '':
|
|
261
|
+
data['role'] = self.role
|
|
262
|
+
if self.display_name is not None and self.display_name != '':
|
|
263
|
+
data['displayName'] = self.display_name
|
|
264
|
+
if self._datastreams is not None and len(self.datastreams.entities) > 0:
|
|
265
|
+
data['Datastreams'] = self.datastreams.__getstate__()
|
|
266
|
+
if self._multi_datastreams is not None and len(self.multi_datastreams.entities) > 0:
|
|
267
|
+
data['MultiDatastreams'] = self.multi_datastreams.__getstate__()
|
|
268
|
+
if self._things is not None and len(self.things.entities) > 0:
|
|
269
|
+
data['Things'] = self.things.__getstate__()
|
|
270
|
+
if self._campaigns is not None and len(self.campaigns.entities) > 0:
|
|
271
|
+
data['Campaigns'] = self.campaigns.__getstate__()
|
|
272
|
+
if self._observation_groups is not None and len(self.observation_groups.entities) > 0:
|
|
273
|
+
data['ObservationGroups'] = self.observation_groups.__getstate__()
|
|
274
|
+
return data
|
|
275
|
+
|
|
276
|
+
def __setstate__(self, state):
|
|
277
|
+
super().__setstate__(state)
|
|
278
|
+
self.auth_id = state.get("authId", None)
|
|
279
|
+
self.description = state.get("description", None)
|
|
280
|
+
self.role = state.get("role", None)
|
|
281
|
+
self.display_name = state.get("displayName", None)
|
|
282
|
+
|
|
283
|
+
if state.get("Datastreams", None) is not None and isinstance(state["Datastreams"], list):
|
|
284
|
+
entity_class = entity_type.EntityTypes['Datastream']['class']
|
|
285
|
+
self.datastreams = utils.transform_json_to_entity_list(state['Datastreams'], entity_class)
|
|
286
|
+
self.datastreams.next_link = state.get("Datastreams@iot.nextLink", None)
|
|
287
|
+
self.datastreams.count = state.get("Datastreams@iot.count", None)
|
|
288
|
+
if state.get("MultiDatastreams", None) is not None and isinstance(state["MultiDatastreams"], list):
|
|
289
|
+
entity_class = entity_type.EntityTypes['MultiDatastream']['class']
|
|
290
|
+
self.multi_datastreams = utils.transform_json_to_entity_list(state['MultiDatastreams'], entity_class)
|
|
291
|
+
self.multi_datastreams.next_link = state.get("MultiDatastreams@iot.nextLink", None)
|
|
292
|
+
self.multi_datastreams.count = state.get("MultiDatastreams@iot.count", None)
|
|
293
|
+
if state.get("Things", None) is not None and isinstance(state["Things"], list):
|
|
294
|
+
entity_class = entity_type.EntityTypes['Thing']['class']
|
|
295
|
+
self.things = utils.transform_json_to_entity_list(state['Things'], entity_class)
|
|
296
|
+
self.things.next_link = state.get("Things@iot.nextLink", None)
|
|
297
|
+
self.things.count = state.get("Things@iot.count", None)
|
|
298
|
+
if state.get("Campaigns", None) is not None and isinstance(state["Campaigns"], list):
|
|
299
|
+
entity_class = entity_type.EntityTypes['Campaign']['class']
|
|
300
|
+
self.campaigns = utils.transform_json_to_entity_list(state['Campaigns'], entity_class)
|
|
301
|
+
self.campaigns.next_link = state.get("Campaigns@iot.nextLink", None)
|
|
302
|
+
self.campaigns.count = state.get("Campaigns@iot.count", None)
|
|
303
|
+
if state.get("ObservationGroups", None) is not None and isinstance(state["ObservationGroups"], list):
|
|
304
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
305
|
+
self.observation_groups = utils.transform_json_to_entity_list(state['ObservationGroups'], entity_class)
|
|
306
|
+
self.observation_groups.next_link = state.get("ObservationGroups@iot.nextLink", None)
|
|
307
|
+
self.observation_groups.count = state.get("ObservationGroups@iot.count", None)
|
|
308
|
+
|
|
309
|
+
def get_dao(self, service):
|
|
310
|
+
return PartyDao(service)
|
|
311
|
+
|
|
312
|
+
def clone(self):
|
|
313
|
+
entity = self.__class__()
|
|
314
|
+
entity.id = self.id
|
|
315
|
+
return entity
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Copyright (C) 2023-2024 Secure Dimensions GmbH, Munich, Germany.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU Lesser General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
+
|
|
16
|
+
from staplus_client import utils
|
|
17
|
+
from staplus_client.model import entity, observation_group, observation
|
|
18
|
+
from staplus_client.model.ext import entity_list, entity_type
|
|
19
|
+
from staplus_client.dao.relation import RelationDao, SubjectsDao, ObjectsDao
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Relation(entity.Entity):
|
|
23
|
+
|
|
24
|
+
def __init__(self,
|
|
25
|
+
description=None,
|
|
26
|
+
role='',
|
|
27
|
+
external_resource=None,
|
|
28
|
+
properties=None,
|
|
29
|
+
subject=None,
|
|
30
|
+
object=None,
|
|
31
|
+
observation_groups=None,
|
|
32
|
+
**kwargs):
|
|
33
|
+
super().__init__(**kwargs)
|
|
34
|
+
if properties is None:
|
|
35
|
+
properties = {}
|
|
36
|
+
self.description = description
|
|
37
|
+
self.role = role
|
|
38
|
+
self.external_resource = external_resource
|
|
39
|
+
self.properties = properties
|
|
40
|
+
self.subject = subject
|
|
41
|
+
self.object = object
|
|
42
|
+
self.observation_groups = observation_groups
|
|
43
|
+
|
|
44
|
+
def __new__(cls, *args, **kwargs):
|
|
45
|
+
new_relation = super().__new__(cls)
|
|
46
|
+
attributes = {'_id': None, '_description': '', '_role': '',
|
|
47
|
+
'_external_resource': None, '_properties': None,
|
|
48
|
+
'_subject': None, '_object': None, '_observation_groups': None,
|
|
49
|
+
'_self_link': '', '_service': None}
|
|
50
|
+
for key, value in attributes.items():
|
|
51
|
+
new_relation.__dict__[key] = value
|
|
52
|
+
return new_relation
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def description(self):
|
|
56
|
+
return self._description
|
|
57
|
+
|
|
58
|
+
@description.setter
|
|
59
|
+
def description(self, value):
|
|
60
|
+
if value is None:
|
|
61
|
+
self._description = None
|
|
62
|
+
return
|
|
63
|
+
if not isinstance(value, str):
|
|
64
|
+
raise ValueError('description should be of type str!')
|
|
65
|
+
self._description = value
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def role(self):
|
|
69
|
+
return self._role
|
|
70
|
+
|
|
71
|
+
@role.setter
|
|
72
|
+
def role(self, value):
|
|
73
|
+
if value is None:
|
|
74
|
+
self._role = None
|
|
75
|
+
return
|
|
76
|
+
if not isinstance(value, str):
|
|
77
|
+
raise ValueError('role should be of type str!')
|
|
78
|
+
self._role = value
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def external_resource(self):
|
|
82
|
+
return self._external_resource
|
|
83
|
+
|
|
84
|
+
@external_resource.setter
|
|
85
|
+
def external_resource(self, value):
|
|
86
|
+
if value is None:
|
|
87
|
+
self._external_resource = None
|
|
88
|
+
return
|
|
89
|
+
if not isinstance(value, str):
|
|
90
|
+
raise ValueError('externalObject should be of type str!')
|
|
91
|
+
self._external_resource = value
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def properties(self):
|
|
95
|
+
return self._properties
|
|
96
|
+
|
|
97
|
+
@properties.setter
|
|
98
|
+
def properties(self, value):
|
|
99
|
+
if value is None:
|
|
100
|
+
self._properties = {}
|
|
101
|
+
return
|
|
102
|
+
if not isinstance(value, dict):
|
|
103
|
+
raise ValueError('properties should be of type dict')
|
|
104
|
+
self._properties = value
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def subject(self):
|
|
108
|
+
return self._subject
|
|
109
|
+
|
|
110
|
+
@subject.setter
|
|
111
|
+
def subject(self, value):
|
|
112
|
+
if value is None:
|
|
113
|
+
self._subject = None
|
|
114
|
+
return
|
|
115
|
+
if not isinstance(value, observation.Observation):
|
|
116
|
+
raise ValueError('subject should be of type Observation!')
|
|
117
|
+
self._subject = value
|
|
118
|
+
|
|
119
|
+
def get_subject(self):
|
|
120
|
+
result = self.service.subject()
|
|
121
|
+
result.parent = self
|
|
122
|
+
return result
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def object(self):
|
|
126
|
+
return self._object
|
|
127
|
+
|
|
128
|
+
@object.setter
|
|
129
|
+
def object(self, value):
|
|
130
|
+
if value is None:
|
|
131
|
+
self._object = None
|
|
132
|
+
return
|
|
133
|
+
if not isinstance(value, observation.Observation):
|
|
134
|
+
raise ValueError('object should be of type Observation!')
|
|
135
|
+
self._object = value
|
|
136
|
+
|
|
137
|
+
def get_object(self):
|
|
138
|
+
result = self.service.object()
|
|
139
|
+
result.parent = self
|
|
140
|
+
return result
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def observation_groups(self):
|
|
144
|
+
return self._observation_groups
|
|
145
|
+
|
|
146
|
+
@observation_groups.setter
|
|
147
|
+
def observation_groups(self, values):
|
|
148
|
+
if values is None:
|
|
149
|
+
self._observation_groups = None
|
|
150
|
+
return
|
|
151
|
+
if isinstance(values, list) and all(isinstance(gs, observation_group.ObservationGroup) for gs in values):
|
|
152
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
153
|
+
self._observation_groups = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
154
|
+
return
|
|
155
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
156
|
+
any((not isinstance(gs, observation_group.ObservationGroup)) for gs in values.entities):
|
|
157
|
+
raise ValueError('observation_groups should be a list of ObservationGroup')
|
|
158
|
+
self._observation_groups = values
|
|
159
|
+
|
|
160
|
+
def get_observation_groups(self):
|
|
161
|
+
result = self.service.observation_groups()
|
|
162
|
+
result.parent = self
|
|
163
|
+
return result
|
|
164
|
+
|
|
165
|
+
def ensure_service_on_children(self, service):
|
|
166
|
+
if self.subject is not None:
|
|
167
|
+
self.subject.set_service(service)
|
|
168
|
+
if self.object is not None:
|
|
169
|
+
self.object.set_service(service)
|
|
170
|
+
if self.observation_groups is not None:
|
|
171
|
+
self.observation_groups.set_service(service)
|
|
172
|
+
|
|
173
|
+
def __eq__(self, other):
|
|
174
|
+
if other is None:
|
|
175
|
+
return False
|
|
176
|
+
if id(self) == id(other):
|
|
177
|
+
return True
|
|
178
|
+
if self.role != other.role:
|
|
179
|
+
return False
|
|
180
|
+
if self.description != other.description:
|
|
181
|
+
return False
|
|
182
|
+
if self.external_resource != other.external_resource:
|
|
183
|
+
return False
|
|
184
|
+
|
|
185
|
+
return True
|
|
186
|
+
|
|
187
|
+
def __ne__(self, other):
|
|
188
|
+
return not self == other
|
|
189
|
+
|
|
190
|
+
def __getstate__(self):
|
|
191
|
+
data = super().__getstate__()
|
|
192
|
+
if self.role is not None and self.role != '':
|
|
193
|
+
data['role'] = self.role
|
|
194
|
+
if self.description is not None and self.description != '':
|
|
195
|
+
data['description'] = self.description
|
|
196
|
+
if self.external_resource is not None and self.external_resource != {}:
|
|
197
|
+
data['externalResource'] = self.external_resource
|
|
198
|
+
if self.properties is not None and self.properties != {}:
|
|
199
|
+
data['properties'] = self.properties
|
|
200
|
+
if self.subject is not None and self.subject != {}:
|
|
201
|
+
data['Subject'] = self.subject
|
|
202
|
+
if self.object is not None and self.object != {}:
|
|
203
|
+
data['Object'] = self.object
|
|
204
|
+
if self._observation_groups is not None and len(self.observation_groups.entities) > 0:
|
|
205
|
+
data['ObservationGroups'] = self.observation_groups.__getstate__()
|
|
206
|
+
|
|
207
|
+
return data
|
|
208
|
+
|
|
209
|
+
def __setstate__(self, state):
|
|
210
|
+
super().__setstate__(state)
|
|
211
|
+
self.description = state.get("description", None)
|
|
212
|
+
self.role = state.get("role", None)
|
|
213
|
+
self.external_resource = state.get("externalResource", None)
|
|
214
|
+
self.subject = state.get("Subject", None)
|
|
215
|
+
self.object = state.get("Object", None)
|
|
216
|
+
|
|
217
|
+
if state.get("ObservationGroups", None) is not None and isinstance(state["ObservationGroups"], list):
|
|
218
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
219
|
+
self.observation_groups = utils.transform_json_to_entity_list(state['ObservationGroups'], entity_class)
|
|
220
|
+
self.observation_groups.next_link = state.get("ObservationGroups@iot.nextLink", None)
|
|
221
|
+
self.observation_groups.count = state.get("ObservationGroups@iot.count", None)
|
|
222
|
+
|
|
223
|
+
def get_dao(self, service):
|
|
224
|
+
return RelationDao(service)
|
|
225
|
+
|
|
226
|
+
def clone(self):
|
|
227
|
+
entity = self.__class__()
|
|
228
|
+
entity.id = self.id
|
|
229
|
+
return entity
|
|
230
|
+
|
|
231
|
+
class Objects(Relation):
|
|
232
|
+
def get_dao(self, service):
|
|
233
|
+
return ObjectsDao(service)
|
|
234
|
+
|
|
235
|
+
def clone(self):
|
|
236
|
+
entity = self.__class__()
|
|
237
|
+
entity.id = self.id
|
|
238
|
+
return entity
|
|
239
|
+
class Subjects(Relation):
|
|
240
|
+
def get_dao(self, service):
|
|
241
|
+
return SubjectsDao(service)
|
|
242
|
+
|
|
243
|
+
def clone(self):
|
|
244
|
+
entity = self.__class__()
|
|
245
|
+
entity.id = self.id
|
|
246
|
+
return entity
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from frost_sta_client.model import sensor
|
|
2
|
+
class Sensor(sensor.Sensor):
|
|
3
|
+
def clone(self):
|
|
4
|
+
entity = self.__class__()
|
|
5
|
+
entity.id = self.id
|
|
6
|
+
return entity
|
|
7
|
+
|
|
8
|
+
def get_datastreams(self):
|
|
9
|
+
result = self.service.datastreams()
|
|
10
|
+
result.parent = self
|
|
11
|
+
return result
|
|
12
|
+
|
|
13
|
+
def get_multi_datastreams(self):
|
|
14
|
+
result = self.service.multi_datastreams()
|
|
15
|
+
result.parent = self
|
|
16
|
+
return result
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Copyright (C) 2023-2024 Secure Dimensions GmbH, Munich, Germany.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU Lesser General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
+
import staplus_client
|
|
16
|
+
from frost_sta_client.model import thing
|
|
17
|
+
|
|
18
|
+
from staplus_client.dao.thing import ThingDao
|
|
19
|
+
from staplus_client.model import party
|
|
20
|
+
from staplus_client.model import location
|
|
21
|
+
from staplus_client.model.ext import entity_list, entity_type
|
|
22
|
+
|
|
23
|
+
class Thing(thing.Thing):
|
|
24
|
+
|
|
25
|
+
def __init__(self,
|
|
26
|
+
name='',
|
|
27
|
+
description='',
|
|
28
|
+
properties=None,
|
|
29
|
+
locations=None,
|
|
30
|
+
historical_locations=None,
|
|
31
|
+
datastreams=None,
|
|
32
|
+
multi_datastreams=None,
|
|
33
|
+
tasking_capabilities=None,
|
|
34
|
+
party=None,
|
|
35
|
+
**kwargs):
|
|
36
|
+
super().__init__(name, description, properties, locations, historical_locations,
|
|
37
|
+
datastreams, multi_datastreams, tasking_capabilities, **kwargs)
|
|
38
|
+
self.party = party
|
|
39
|
+
|
|
40
|
+
def __new__(cls, *args, **kwargs):
|
|
41
|
+
new_thing = super().__new__(cls, args, kwargs)
|
|
42
|
+
attributes = {'_party': None}
|
|
43
|
+
for key, value in attributes.items():
|
|
44
|
+
new_thing.__dict__[key] = value
|
|
45
|
+
return new_thing
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def party(self):
|
|
49
|
+
return self._party
|
|
50
|
+
|
|
51
|
+
@party.setter
|
|
52
|
+
def party(self, value):
|
|
53
|
+
if value is None or isinstance(value, party.Party):
|
|
54
|
+
self._party = value
|
|
55
|
+
return
|
|
56
|
+
raise ValueError('party should be of type Party!')
|
|
57
|
+
|
|
58
|
+
def get_party(self):
|
|
59
|
+
result = self.service.party()
|
|
60
|
+
result.parent = self
|
|
61
|
+
return result
|
|
62
|
+
|
|
63
|
+
def get_locations(self):
|
|
64
|
+
result = self.service.locations()
|
|
65
|
+
result.parent = self
|
|
66
|
+
return result
|
|
67
|
+
|
|
68
|
+
def get_historical_locations(self):
|
|
69
|
+
result = self.service.historical_locations()
|
|
70
|
+
result.parent = self
|
|
71
|
+
return result
|
|
72
|
+
|
|
73
|
+
def ensure_service_on_children(self, service):
|
|
74
|
+
super().ensure_service_on_children(service)
|
|
75
|
+
if self.party is not None:
|
|
76
|
+
self.party.set_service(service)
|
|
77
|
+
|
|
78
|
+
def __getstate__(self):
|
|
79
|
+
data = super().__getstate__()
|
|
80
|
+
if self.party is not None:
|
|
81
|
+
data['Party'] = self.party
|
|
82
|
+
|
|
83
|
+
return data
|
|
84
|
+
|
|
85
|
+
def __setstate__(self, state):
|
|
86
|
+
super().__setstate__(state)
|
|
87
|
+
if state.get("Party", None) is not None:
|
|
88
|
+
self.party = party.Party()
|
|
89
|
+
self.party.__setstate__(state["Party"])
|
|
90
|
+
|
|
91
|
+
def locations(self, values):
|
|
92
|
+
if values is None:
|
|
93
|
+
self._locations = None
|
|
94
|
+
return
|
|
95
|
+
if isinstance(values, list) and all(isinstance(loc, location.Location) for loc in values):
|
|
96
|
+
entity_class = entity_type.EntityTypes['Location']['class']
|
|
97
|
+
self._locations = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
98
|
+
return
|
|
99
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
100
|
+
any((not isinstance(loc, location.Location)) for loc in values.entities):
|
|
101
|
+
raise ValueError('locations should be a list of locations')
|
|
102
|
+
self._locations = values
|
|
103
|
+
|
|
104
|
+
def get_dao(self, service):
|
|
105
|
+
return ThingDao(service)
|
|
106
|
+
|
|
107
|
+
def clone(self):
|
|
108
|
+
entity = self.__class__()
|
|
109
|
+
entity.id = self.id
|
|
110
|
+
return entity
|
|
File without changes
|