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,301 @@
|
|
|
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, campaign, datastream, multi_datastream, observation_group
|
|
18
|
+
from staplus_client.model.ext import entity_list, entity_type
|
|
19
|
+
from staplus_client.dao.license import LicenseDao
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class License(entity.Entity):
|
|
23
|
+
|
|
24
|
+
def __init__(self,
|
|
25
|
+
name='',
|
|
26
|
+
definition='',
|
|
27
|
+
description=None,
|
|
28
|
+
attribution_text=None,
|
|
29
|
+
logo=None,
|
|
30
|
+
datastreams=None,
|
|
31
|
+
multi_datastreams=None,
|
|
32
|
+
campaigns=None,
|
|
33
|
+
observation_groups=None,
|
|
34
|
+
**kwargs):
|
|
35
|
+
super().__init__(**kwargs)
|
|
36
|
+
self.name = name
|
|
37
|
+
self.description = description
|
|
38
|
+
self.definition = definition
|
|
39
|
+
self.attribution_text = attribution_text
|
|
40
|
+
self.logo = logo
|
|
41
|
+
self.datastreams = datastreams
|
|
42
|
+
self.multi_datastreams = multi_datastreams
|
|
43
|
+
self.campaigns = campaigns
|
|
44
|
+
self.observation_groups = observation_groups
|
|
45
|
+
|
|
46
|
+
def __new__(cls, *args, **kwargs):
|
|
47
|
+
new_license = super().__new__(cls)
|
|
48
|
+
attributes = {'_id': None, '_name': '', '_description': '', '_definition': '',
|
|
49
|
+
'_logo': '', '_attribution_text': '',
|
|
50
|
+
'_datastreams': None, '_multi_datastreams': None,
|
|
51
|
+
'_campaigns': None, '_observation_groups': None,
|
|
52
|
+
'_self_link': '', '_service': None}
|
|
53
|
+
for key, value in attributes.items():
|
|
54
|
+
new_license.__dict__[key] = value
|
|
55
|
+
return new_license
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def name(self):
|
|
59
|
+
return self._name
|
|
60
|
+
|
|
61
|
+
@name.setter
|
|
62
|
+
def name(self, value):
|
|
63
|
+
if value is None:
|
|
64
|
+
self._name = None
|
|
65
|
+
return
|
|
66
|
+
if not isinstance(value, str):
|
|
67
|
+
raise ValueError('name should be of type str!')
|
|
68
|
+
self._name = value
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def description(self):
|
|
72
|
+
return self._description
|
|
73
|
+
|
|
74
|
+
@description.setter
|
|
75
|
+
def description(self, value):
|
|
76
|
+
if value is None:
|
|
77
|
+
self._description = None
|
|
78
|
+
return
|
|
79
|
+
if not isinstance(value, str):
|
|
80
|
+
raise ValueError('description should be of type str!')
|
|
81
|
+
self._description = value
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def definition(self):
|
|
85
|
+
return self._definition
|
|
86
|
+
|
|
87
|
+
@definition.setter
|
|
88
|
+
def definition(self, value):
|
|
89
|
+
if value is None:
|
|
90
|
+
self._definition = None
|
|
91
|
+
return
|
|
92
|
+
if not isinstance(value, str):
|
|
93
|
+
raise ValueError('definition should be of type str!')
|
|
94
|
+
self._definition = value
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def logo(self):
|
|
98
|
+
return self._logo
|
|
99
|
+
|
|
100
|
+
@logo.setter
|
|
101
|
+
def logo(self, value):
|
|
102
|
+
if value is None:
|
|
103
|
+
self._value = None
|
|
104
|
+
return
|
|
105
|
+
if not isinstance(value, str):
|
|
106
|
+
raise ValueError('logo should be of type str!')
|
|
107
|
+
self._logo = value
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def attribution_text(self):
|
|
111
|
+
return self._attribution_text
|
|
112
|
+
|
|
113
|
+
@attribution_text.setter
|
|
114
|
+
def attribution_text(self, value):
|
|
115
|
+
if value is None:
|
|
116
|
+
self._attribution_text = None
|
|
117
|
+
return
|
|
118
|
+
if not isinstance(value, str):
|
|
119
|
+
raise ValueError('attributionText should be of type str!')
|
|
120
|
+
self._attribution_text = value
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def observation_groups(self):
|
|
124
|
+
return self._observation_groups
|
|
125
|
+
|
|
126
|
+
@observation_groups.setter
|
|
127
|
+
def observation_groups(self, values):
|
|
128
|
+
if values is None:
|
|
129
|
+
self._observation_groups = None
|
|
130
|
+
return
|
|
131
|
+
if isinstance(values, list) and all(isinstance(cs, observation_group.ObservationGroup) for cs in values):
|
|
132
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
133
|
+
self._observation_groups = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
134
|
+
return
|
|
135
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
136
|
+
any((not isinstance(ds, observation_group.ObservationGroup)) for ds in values.entities):
|
|
137
|
+
raise ValueError('observation_groups should be a list of ObservationGroup')
|
|
138
|
+
self._observation_groups = values
|
|
139
|
+
|
|
140
|
+
def get_observation_groups(self):
|
|
141
|
+
result = self.service.observation_groups()
|
|
142
|
+
result.parent = self
|
|
143
|
+
return result
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def campaigns(self):
|
|
147
|
+
return self._campaigns
|
|
148
|
+
|
|
149
|
+
@campaigns.setter
|
|
150
|
+
def campaigns(self, values):
|
|
151
|
+
if values is None:
|
|
152
|
+
self._campaigns = None
|
|
153
|
+
return
|
|
154
|
+
if isinstance(values, list) and all(isinstance(cs, campaign.Campaign) for cs in values):
|
|
155
|
+
entity_class = entity_type.EntityTypes['Campaign']['class']
|
|
156
|
+
self._campaigns = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
157
|
+
return
|
|
158
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
159
|
+
any((not isinstance(ds, campaign.Campaign)) for ds in values.entities):
|
|
160
|
+
raise ValueError('campaigns should be a list of Campaign')
|
|
161
|
+
self._campaigns = values
|
|
162
|
+
|
|
163
|
+
def get_campaigns(self):
|
|
164
|
+
result = self.service.campaigns()
|
|
165
|
+
result.parent = self
|
|
166
|
+
return result
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def datastreams(self):
|
|
170
|
+
return self._datastreams
|
|
171
|
+
|
|
172
|
+
@datastreams.setter
|
|
173
|
+
def datastreams(self, values):
|
|
174
|
+
if values is None:
|
|
175
|
+
self._datastreams = None
|
|
176
|
+
return
|
|
177
|
+
if isinstance(values, list) and all(isinstance(ds, datastream.Datastream) for ds in values):
|
|
178
|
+
entity_class = entity_type.EntityTypes['Datastream']['class']
|
|
179
|
+
self._datastreams = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
180
|
+
return
|
|
181
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
182
|
+
any((not isinstance(ds, datastream.Datastream)) for ds in values.entities):
|
|
183
|
+
raise ValueError('datastreams should be a list of Datastream')
|
|
184
|
+
self._datastreams = values
|
|
185
|
+
|
|
186
|
+
def get_datastreams(self):
|
|
187
|
+
result = self.service.datastreams()
|
|
188
|
+
result.parent = self
|
|
189
|
+
return result
|
|
190
|
+
|
|
191
|
+
@property
|
|
192
|
+
def multi_datastreams(self):
|
|
193
|
+
return self._multi_datastreams
|
|
194
|
+
|
|
195
|
+
@multi_datastreams.setter
|
|
196
|
+
def multi_datastreams(self, values):
|
|
197
|
+
if values is None:
|
|
198
|
+
self._multi_datastreams = None
|
|
199
|
+
return
|
|
200
|
+
if isinstance(values, list) and all(isinstance(ds, multi_datastream.MultiDatastream) for ds in values):
|
|
201
|
+
entity_class = entity_type.EntityTypes['MultiDatastream']['class']
|
|
202
|
+
self._multi_datastreams = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
203
|
+
return
|
|
204
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
205
|
+
any((not isinstance(ds, multi_datastream.MultiDatastream)) for ds in values.entities):
|
|
206
|
+
raise ValueError('multi_datastreams should be a list of MultiDatastream')
|
|
207
|
+
self._multi_datastreams = values
|
|
208
|
+
|
|
209
|
+
def get_multi_datastreams(self):
|
|
210
|
+
result = self.service.multi_datastreams()
|
|
211
|
+
result.parent = self
|
|
212
|
+
return result
|
|
213
|
+
|
|
214
|
+
def ensure_service_on_children(self, service):
|
|
215
|
+
if self.campaigns is not None:
|
|
216
|
+
self.campaigns.set_service(service)
|
|
217
|
+
if self.observation_groups is not None:
|
|
218
|
+
self.observation_groups.set_service(service)
|
|
219
|
+
if self.datastreams is not None:
|
|
220
|
+
self.datastreams.set_service(service)
|
|
221
|
+
if self.multi_datastreams is not None:
|
|
222
|
+
self.multi_datastreams.set_service(service)
|
|
223
|
+
|
|
224
|
+
def __eq__(self, other):
|
|
225
|
+
if other is None:
|
|
226
|
+
return False
|
|
227
|
+
if not isinstance(other, type(self)):
|
|
228
|
+
return False
|
|
229
|
+
if id(self) == id(other):
|
|
230
|
+
return True
|
|
231
|
+
if self.name != other.name:
|
|
232
|
+
return False
|
|
233
|
+
if self.attribution_text != other.attribution_text:
|
|
234
|
+
return False
|
|
235
|
+
if self.definition != other.definition:
|
|
236
|
+
return False
|
|
237
|
+
if self.description != other.description:
|
|
238
|
+
return False
|
|
239
|
+
if self.logo != other.logo:
|
|
240
|
+
return False
|
|
241
|
+
return True
|
|
242
|
+
|
|
243
|
+
def __ne__(self, other):
|
|
244
|
+
return not self == other
|
|
245
|
+
|
|
246
|
+
def __getstate__(self):
|
|
247
|
+
data = super().__getstate__()
|
|
248
|
+
if self.description is not None and self.description != '':
|
|
249
|
+
data['description'] = self.description
|
|
250
|
+
if self.definition is not None and self.definition != '':
|
|
251
|
+
data['definition'] = self.definition
|
|
252
|
+
if self.logo is not None and self.logo != '':
|
|
253
|
+
data['logo'] = self.logo
|
|
254
|
+
if self.attribution_text is not None and self.attribution_text != '':
|
|
255
|
+
data['attributionText'] = self.attribution_text
|
|
256
|
+
if self._datastreams is not None and len(self.datastreams.entities) > 0:
|
|
257
|
+
data['Datastreams'] = self.datastreams.__getstate__()
|
|
258
|
+
if self._multi_datastreams is not None and len(self.multi_datastreams.entities) > 0:
|
|
259
|
+
data['MultiDatastreams'] = self.multi_datastreams.__getstate__()
|
|
260
|
+
if self._campaigns is not None and len(self.campaigns.entities) > 0:
|
|
261
|
+
data['Campaigns'] = self.campaigns.__getstate__()
|
|
262
|
+
if self._observation_groups is not None and len(self.observation_groups.entities) > 0:
|
|
263
|
+
data['ObservationGroups'] = self.observation_groups.__getstate__()
|
|
264
|
+
return data
|
|
265
|
+
|
|
266
|
+
def __setstate__(self, state):
|
|
267
|
+
super().__setstate__(state)
|
|
268
|
+
self.name = state.get("name", None)
|
|
269
|
+
self.description = state.get("description", None)
|
|
270
|
+
self.definition = state.get("definition", None)
|
|
271
|
+
self.logo = state.get("logo", None)
|
|
272
|
+
self.attribution_text = state.get("attributionText", None)
|
|
273
|
+
|
|
274
|
+
if state.get("Datastreams", None) is not None and isinstance(state["Datastreams"], list):
|
|
275
|
+
entity_class = entity_type.EntityTypes['Datastream']['class']
|
|
276
|
+
self.datastreams = utils.transform_json_to_entity_list(state['Datastreams'], entity_class)
|
|
277
|
+
self.datastreams.next_link = state.get("Datastreams@iot.nextLink", None)
|
|
278
|
+
self.datastreams.count = state.get("Datastreams@iot.count", None)
|
|
279
|
+
if state.get("MultiDatastreams", None) is not None and isinstance(state["MultiDatastreams"], list):
|
|
280
|
+
entity_class = entity_type.EntityTypes['MultiDatastream']['class']
|
|
281
|
+
self.multi_datastreams = utils.transform_json_to_entity_list(state['MultiDatastreams'], entity_class)
|
|
282
|
+
self.multi_datastreams.next_link = state.get("MultiDatastreams@iot.nextLink", None)
|
|
283
|
+
self.multi_datastreams.count = state.get("MultiDatastreams@iot.count", None)
|
|
284
|
+
if state.get("Campaigns", None) is not None and isinstance(state["Campaigns"], list):
|
|
285
|
+
entity_class = entity_type.EntityTypes['Campaign']['class']
|
|
286
|
+
self.campaigns = utils.transform_json_to_entity_list(state['Campaigns'], entity_class)
|
|
287
|
+
self.campaigns.next_link = state.get("Campaigns@iot.nextLink", None)
|
|
288
|
+
self.campaigns.count = state.get("Campaigns@iot.count", None)
|
|
289
|
+
if state.get("ObservationGroups", None) is not None and isinstance(state["ObservationGroups"], list):
|
|
290
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
291
|
+
self.observation_groups = utils.transform_json_to_entity_list(state['ObservationGroups'], entity_class)
|
|
292
|
+
self.observation_groups.next_link = state.get("ObservationGroups@iot.nextLink", None)
|
|
293
|
+
self.observation_groups.count = state.get("ObservationGroups@iot.count", None)
|
|
294
|
+
|
|
295
|
+
def get_dao(self, service):
|
|
296
|
+
return LicenseDao(service)
|
|
297
|
+
|
|
298
|
+
def clone(self):
|
|
299
|
+
entity = self.__class__()
|
|
300
|
+
entity.id = self.id
|
|
301
|
+
return entity
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from frost_sta_client.model import location
|
|
2
|
+
from staplus_client.dao.location import LocationDao
|
|
3
|
+
|
|
4
|
+
class Location(location.Location):
|
|
5
|
+
|
|
6
|
+
def clone(self):
|
|
7
|
+
entity = self.__class__()
|
|
8
|
+
entity.id = self.id
|
|
9
|
+
return entity
|
|
10
|
+
|
|
11
|
+
def get_things(self):
|
|
12
|
+
result = self.service.things()
|
|
13
|
+
result.parent = self
|
|
14
|
+
return result
|
|
15
|
+
|
|
16
|
+
def get_historical_locations(self):
|
|
17
|
+
result = self.service.historical_locations()
|
|
18
|
+
result.parent = self
|
|
19
|
+
return result
|
|
20
|
+
|
|
21
|
+
def get_dao(self, service):
|
|
22
|
+
return LocationDao(service)
|
|
@@ -0,0 +1,160 @@
|
|
|
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 frost_sta_client.model import multi_datastream
|
|
17
|
+
from staplus_client import utils
|
|
18
|
+
from staplus_client.model.ext import entity_list, entity_type
|
|
19
|
+
from staplus_client.dao.multi_datastream import MultiDatastreamDao
|
|
20
|
+
from staplus_client.model import license, campaign, party
|
|
21
|
+
|
|
22
|
+
class MultiDatastream(multi_datastream.MultiDatastream):
|
|
23
|
+
def __init__(self,
|
|
24
|
+
name='',
|
|
25
|
+
description='',
|
|
26
|
+
properties=None,
|
|
27
|
+
unit_of_measurements=None,
|
|
28
|
+
observation_type='',
|
|
29
|
+
multi_observation_data_types=None,
|
|
30
|
+
observed_area=None,
|
|
31
|
+
phenomenon_time=None,
|
|
32
|
+
result_time=None,
|
|
33
|
+
thing=None,
|
|
34
|
+
sensor=None,
|
|
35
|
+
observed_properties=None,
|
|
36
|
+
observations=None,
|
|
37
|
+
campaigns=None,
|
|
38
|
+
party=None,
|
|
39
|
+
license=None,
|
|
40
|
+
**kwargs):
|
|
41
|
+
super().__init__(name, description, properties, unit_of_measurements, observation_type,
|
|
42
|
+
multi_observation_data_types, observed_area, phenomenon_time, result_time,
|
|
43
|
+
thing, sensor, observed_properties, observations, **kwargs)
|
|
44
|
+
self.party = party
|
|
45
|
+
self.license = license
|
|
46
|
+
self.campaigns = campaigns
|
|
47
|
+
|
|
48
|
+
def __new__(cls, *args, **kwargs):
|
|
49
|
+
new_mds = super().__new__(cls, args, kwargs)
|
|
50
|
+
attributes = dict( _campaigns=None, _party=None, _license=None, _self_link='', _service=None)
|
|
51
|
+
for key, value in attributes.items():
|
|
52
|
+
new_mds.__dict__[key] = value
|
|
53
|
+
return new_mds
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def party(self):
|
|
57
|
+
return self._party
|
|
58
|
+
|
|
59
|
+
@party.setter
|
|
60
|
+
def party(self, value):
|
|
61
|
+
if value is None or isinstance(value, party.Party):
|
|
62
|
+
self._party = value
|
|
63
|
+
return
|
|
64
|
+
raise ValueError('party should be of type Party!')
|
|
65
|
+
|
|
66
|
+
def get_party(self):
|
|
67
|
+
result = self.service.party()
|
|
68
|
+
result.parent = self
|
|
69
|
+
return result
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def license(self):
|
|
73
|
+
return self._license
|
|
74
|
+
|
|
75
|
+
@license.setter
|
|
76
|
+
def license(self, value):
|
|
77
|
+
if value is None or isinstance(value, license.License):
|
|
78
|
+
self._license = value
|
|
79
|
+
return
|
|
80
|
+
raise ValueError('license should be of type License!')
|
|
81
|
+
|
|
82
|
+
def get_license(self):
|
|
83
|
+
result = self.service.license()
|
|
84
|
+
result.parent = self
|
|
85
|
+
return result
|
|
86
|
+
|
|
87
|
+
def get_thing(self):
|
|
88
|
+
result = self.service.thing()
|
|
89
|
+
result.parent = self
|
|
90
|
+
return result
|
|
91
|
+
|
|
92
|
+
def get_sensor(self):
|
|
93
|
+
result = self.service.sensor()
|
|
94
|
+
result.parent = self
|
|
95
|
+
return result
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def campaigns(self):
|
|
99
|
+
return self._campaigns
|
|
100
|
+
|
|
101
|
+
@campaigns.setter
|
|
102
|
+
def campaigns(self, values):
|
|
103
|
+
if values is None:
|
|
104
|
+
self._campaigns = None
|
|
105
|
+
return
|
|
106
|
+
if isinstance(values, list) and all(isinstance(ps, campaign.Campaign) for ps in values):
|
|
107
|
+
entity_class = entity_type.EntityTypes['Campaign']['class']
|
|
108
|
+
self._campaigns = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
109
|
+
return
|
|
110
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
111
|
+
any((not isinstance(ps, campaign.Campaign)) for ps in values.entities):
|
|
112
|
+
raise ValueError('campaigns should be a list of Campaign')
|
|
113
|
+
self._campaigns = values
|
|
114
|
+
|
|
115
|
+
def get_campaigns(self):
|
|
116
|
+
result = self.service.campaigns()
|
|
117
|
+
result.parent = self
|
|
118
|
+
return result
|
|
119
|
+
|
|
120
|
+
def ensure_service_on_children(self, service):
|
|
121
|
+
super().ensure_service_on_children(service)
|
|
122
|
+
if self.party is not None:
|
|
123
|
+
self.party.set_service(service)
|
|
124
|
+
if self.license is not None:
|
|
125
|
+
self.license.set_service(service)
|
|
126
|
+
if self.campaigns is not None:
|
|
127
|
+
self.campaigns.set_service(service)
|
|
128
|
+
|
|
129
|
+
def __getstate__(self):
|
|
130
|
+
data = super().__getstate__()
|
|
131
|
+
if self.party is not None:
|
|
132
|
+
data['Party'] = self.party
|
|
133
|
+
if self.license is not None:
|
|
134
|
+
data['License'] = self.license
|
|
135
|
+
if self._campaigns is not None and len(self.campaigns.entities) > 0:
|
|
136
|
+
data['Campaigns'] = self.campaigns.__getstate__()
|
|
137
|
+
|
|
138
|
+
return data
|
|
139
|
+
|
|
140
|
+
def __setstate__(self, state):
|
|
141
|
+
super().__setstate__(state)
|
|
142
|
+
if state.get("Party", None) is not None:
|
|
143
|
+
self.party = party.Party()
|
|
144
|
+
self.party.__setstate__(state["Party"])
|
|
145
|
+
if state.get("License", None) is not None:
|
|
146
|
+
self.license = license.License()
|
|
147
|
+
self.license.__setstate__(state["License"])
|
|
148
|
+
if state.get("Campaigns", None) is not None and isinstance(state["Campaigns"], list):
|
|
149
|
+
entity_class = entity_type.EntityTypes['Campaign']['class']
|
|
150
|
+
self.campaigns = utils.transform_json_to_entity_list(state['Campaigns'], entity_class)
|
|
151
|
+
self.campaigns.next_link = state.get("Campaigns@iot.nextLink", None)
|
|
152
|
+
self.campaigns.count = state.get("Campaigns@iot.count", None)
|
|
153
|
+
|
|
154
|
+
def get_dao(self, service):
|
|
155
|
+
return MultiDatastreamDao(service)
|
|
156
|
+
|
|
157
|
+
def clone(self):
|
|
158
|
+
entity = self.__class__()
|
|
159
|
+
entity.id = self.id
|
|
160
|
+
return entity
|