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,218 @@
|
|
|
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 datetime import datetime
|
|
17
|
+
|
|
18
|
+
from frost_sta_client.model import observation
|
|
19
|
+
from staplus_client import utils
|
|
20
|
+
from staplus_client.model.ext import entity_list, entity_type
|
|
21
|
+
from staplus_client.dao.observation import ObservationDao, SubjectDao, ObjectDao
|
|
22
|
+
from staplus_client.model import observation_group, relation
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Observation(observation.Observation):
|
|
26
|
+
|
|
27
|
+
def __init__(self,
|
|
28
|
+
phenomenon_time=None,
|
|
29
|
+
result=None,
|
|
30
|
+
result_time=None,
|
|
31
|
+
result_quality=None,
|
|
32
|
+
valid_time=None,
|
|
33
|
+
parameters=None,
|
|
34
|
+
datastream=None,
|
|
35
|
+
multi_datastream=None,
|
|
36
|
+
feature_of_interest=None,
|
|
37
|
+
observation_groups=None,
|
|
38
|
+
subjects=None,
|
|
39
|
+
objects=None,
|
|
40
|
+
**kwargs):
|
|
41
|
+
super().__init__(phenomenon_time, result, result_time, result_quality, valid_time,
|
|
42
|
+
parameters, datastream, multi_datastream, feature_of_interest, **kwargs)
|
|
43
|
+
self.observation_groups = observation_groups
|
|
44
|
+
self.subjects = subjects
|
|
45
|
+
self.objects = objects
|
|
46
|
+
|
|
47
|
+
def __new__(cls, *args, **kwargs):
|
|
48
|
+
new_observation = super().__new__(cls, args, kwargs)
|
|
49
|
+
attributes = {'_observation_groups': None, '_subjects': None, '_objects': None}
|
|
50
|
+
for key, value in attributes.items():
|
|
51
|
+
new_observation.__dict__[key] = value
|
|
52
|
+
return new_observation
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def observation_groups(self):
|
|
56
|
+
return self._observation_groups
|
|
57
|
+
|
|
58
|
+
@observation_groups.setter
|
|
59
|
+
def observation_groups(self, values):
|
|
60
|
+
if values is None:
|
|
61
|
+
self._observation_groups = None
|
|
62
|
+
return
|
|
63
|
+
if isinstance(values, list) and all(isinstance(gs, observation_group.ObservationGroup) for gs in values):
|
|
64
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
65
|
+
self._observation_groups = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
66
|
+
return
|
|
67
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
68
|
+
any((not isinstance(gs, observation_group.ObservationGroup)) for gs in values.entities):
|
|
69
|
+
raise ValueError('groups should be a list of ObservationGroup')
|
|
70
|
+
self._observation_groups = values
|
|
71
|
+
|
|
72
|
+
def get_observation_groups(self):
|
|
73
|
+
result = self.service.observation_groups()
|
|
74
|
+
result.parent = self
|
|
75
|
+
return result
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def subjects(self):
|
|
79
|
+
return self._subjects
|
|
80
|
+
|
|
81
|
+
@subjects.setter
|
|
82
|
+
def subjects(self, values):
|
|
83
|
+
if values is None:
|
|
84
|
+
self._subjects = None
|
|
85
|
+
return
|
|
86
|
+
if isinstance(values, list) and all(isinstance(rs, relation.Relation) for rs in values):
|
|
87
|
+
entity_class = entity_type.EntityTypes['Relation']['class']
|
|
88
|
+
self._subjects = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
89
|
+
return
|
|
90
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
91
|
+
any((not isinstance(rs, relation.Relation)) for rs in values.entities):
|
|
92
|
+
raise ValueError('subjects should be a list of Relation')
|
|
93
|
+
self._subjects = values
|
|
94
|
+
|
|
95
|
+
def get_subjects(self):
|
|
96
|
+
result = self.service.subjects()
|
|
97
|
+
result.parent = self
|
|
98
|
+
return result
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def objects(self):
|
|
102
|
+
return self._objects
|
|
103
|
+
|
|
104
|
+
@objects.setter
|
|
105
|
+
def objects(self, values):
|
|
106
|
+
if values is None:
|
|
107
|
+
self._objects = None
|
|
108
|
+
return
|
|
109
|
+
if isinstance(values, list) and all(isinstance(rs, relation.Relation) for rs in values):
|
|
110
|
+
entity_class = entity_type.EntityTypes['Relation']['class']
|
|
111
|
+
self._objects = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
112
|
+
return
|
|
113
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
114
|
+
any((not isinstance(rs, relation.Relation)) for rs in values.entities):
|
|
115
|
+
raise ValueError('objects should be a list of Relation')
|
|
116
|
+
self._objects = values
|
|
117
|
+
|
|
118
|
+
def get_objects(self):
|
|
119
|
+
result = self.service.objects()
|
|
120
|
+
result.parent = self
|
|
121
|
+
return result
|
|
122
|
+
|
|
123
|
+
def get_datastream(self):
|
|
124
|
+
result = self.service.datastream()
|
|
125
|
+
result.parent = self
|
|
126
|
+
return result
|
|
127
|
+
|
|
128
|
+
def get_multi_datastream(self):
|
|
129
|
+
result = self.service.multi_datastream()
|
|
130
|
+
result.parent = self
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
def get_feature_of_interest(self):
|
|
134
|
+
result = self.service.features_of_interest()
|
|
135
|
+
result.parent = self
|
|
136
|
+
return result
|
|
137
|
+
|
|
138
|
+
def ensure_service_on_children(self, service):
|
|
139
|
+
super().ensure_service_on_children(service)
|
|
140
|
+
if self.observation_groups is not None:
|
|
141
|
+
self.observation_groups.set_service(service)
|
|
142
|
+
if self.subjects is not None:
|
|
143
|
+
self.subjects.set_service(service)
|
|
144
|
+
if self.objects is not None:
|
|
145
|
+
self.objects.set_service(service)
|
|
146
|
+
|
|
147
|
+
def __getstate__(self):
|
|
148
|
+
data = super().__getstate__()
|
|
149
|
+
if self._observation_groups is not None and len(self.observation_groups.entities) > 0:
|
|
150
|
+
data['ObservationGroups'] = self.observation_groups.__getstate__()
|
|
151
|
+
if self._subjects is not None and len(self.subjects.entities) > 0:
|
|
152
|
+
data['Subjects'] = self.subjects.__getstate__()
|
|
153
|
+
if self._objects is not None and len(self.objects.entities) > 0:
|
|
154
|
+
data['Objects'] = self.objects.__getstate__()
|
|
155
|
+
return data
|
|
156
|
+
|
|
157
|
+
def __setstate__(self, state):
|
|
158
|
+
super().__setstate__(state)
|
|
159
|
+
if state.get("ObservationGroups", None) is not None and isinstance(state["ObservationGroups"], list):
|
|
160
|
+
entity_class = entity_type.EntityTypes['ObservationGroup']['class']
|
|
161
|
+
self.observation_groups = utils.transform_json_to_entity_list(state['ObservationGroups'], entity_class)
|
|
162
|
+
self.observation_groups.next_link = state.get("ObservationGroups@iot.nextLink", None)
|
|
163
|
+
self.observation_groups.count = state.get("ObservationGroups@iot.count", None)
|
|
164
|
+
if state.get("Subjects", None) is not None and isinstance(state["Subjects"], list):
|
|
165
|
+
entity_class = entity_type.EntityTypes['Relation']['class']
|
|
166
|
+
self.subjects = utils.transform_json_to_entity_list(state['Subjects'], entity_class)
|
|
167
|
+
self.subjects.next_link = state.get("Subjects@iot.nextLink", None)
|
|
168
|
+
self.subjects.count = state.get("Subjects@iot.count", None)
|
|
169
|
+
if state.get("Objects", None) is not None and isinstance(state["Objects"], list):
|
|
170
|
+
entity_class = entity_type.EntityTypes['Relation']['class']
|
|
171
|
+
self.objects = utils.transform_json_to_entity_list(state['Objects'], entity_class)
|
|
172
|
+
self.objects.next_link = state.get("Objects@iot.nextLink", None)
|
|
173
|
+
self.objects.count = state.get("Objects@iot.count", None)
|
|
174
|
+
|
|
175
|
+
def __eq__(self, other):
|
|
176
|
+
if other is None or other == {}:
|
|
177
|
+
return False
|
|
178
|
+
if not isinstance(other, type(self)):
|
|
179
|
+
return False
|
|
180
|
+
if id(self) == id(other):
|
|
181
|
+
return True
|
|
182
|
+
if self.result != other.result:
|
|
183
|
+
return False
|
|
184
|
+
if datetime.fromisoformat(self.phenomenon_time) != datetime.fromisoformat(other.phenomenon_time):
|
|
185
|
+
return False
|
|
186
|
+
if self.result_time is not None and other.result_time is not None and datetime.fromisoformat(self.result_time) != datetime.fromisoformat(other.result_time):
|
|
187
|
+
return False
|
|
188
|
+
if self.valid_time is not None and other.valid_time is not None and datetime.fromisoformat(self.valid_time) != datetime.fromisoformat(other.valid_time):
|
|
189
|
+
return False
|
|
190
|
+
if self.parameters != other.parameters:
|
|
191
|
+
return False
|
|
192
|
+
if self.result_quality != other.result_quality:
|
|
193
|
+
return False
|
|
194
|
+
return True
|
|
195
|
+
|
|
196
|
+
def get_dao(self, service):
|
|
197
|
+
return ObservationDao(service)
|
|
198
|
+
|
|
199
|
+
def clone(self):
|
|
200
|
+
entity = self.__class__()
|
|
201
|
+
entity.id = self.id
|
|
202
|
+
return entity
|
|
203
|
+
class Object(Observation):
|
|
204
|
+
def get_dao(self, service):
|
|
205
|
+
return ObjectDao(service)
|
|
206
|
+
|
|
207
|
+
def clone(self):
|
|
208
|
+
entity = self.__class__()
|
|
209
|
+
entity.id = self.id
|
|
210
|
+
return entity
|
|
211
|
+
class Subject(Observation):
|
|
212
|
+
def get_dao(self, service):
|
|
213
|
+
return SubjectDao(service)
|
|
214
|
+
|
|
215
|
+
def clone(self):
|
|
216
|
+
entity = self.__class__()
|
|
217
|
+
entity.id = self.id
|
|
218
|
+
return entity
|
|
@@ -0,0 +1,399 @@
|
|
|
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 datetime import datetime
|
|
17
|
+
from staplus_client import utils
|
|
18
|
+
from frost_sta_client.utils import check_datetime
|
|
19
|
+
from staplus_client.model import entity
|
|
20
|
+
from staplus_client.model.ext import entity_list, entity_type
|
|
21
|
+
from staplus_client.dao.observation_group import ObservationGroupDao
|
|
22
|
+
from staplus_client.model import license, party, campaign, relation, observation
|
|
23
|
+
|
|
24
|
+
class ObservationGroup(entity.Entity):
|
|
25
|
+
|
|
26
|
+
def __init__(self,
|
|
27
|
+
name='',
|
|
28
|
+
description='',
|
|
29
|
+
purpose=None,
|
|
30
|
+
terms_of_use='',
|
|
31
|
+
privacy_policy=None,
|
|
32
|
+
creation_time=None,
|
|
33
|
+
end_time=None,
|
|
34
|
+
properties=None,
|
|
35
|
+
data_quality=None,
|
|
36
|
+
observations=None,
|
|
37
|
+
campaigns=None,
|
|
38
|
+
relations=None,
|
|
39
|
+
party=None,
|
|
40
|
+
license=None,
|
|
41
|
+
**kwargs):
|
|
42
|
+
super().__init__(**kwargs)
|
|
43
|
+
if properties is None:
|
|
44
|
+
properties = {}
|
|
45
|
+
self.name = name
|
|
46
|
+
self.description = description
|
|
47
|
+
self.purpose = purpose
|
|
48
|
+
self.terms_of_use = terms_of_use
|
|
49
|
+
self.privacy_policy = privacy_policy
|
|
50
|
+
self.creation_time = creation_time
|
|
51
|
+
self.end_time = end_time
|
|
52
|
+
self.properties = properties
|
|
53
|
+
self.data_quality = data_quality
|
|
54
|
+
self.observations = observations
|
|
55
|
+
self.campaigns = campaigns
|
|
56
|
+
self.relations = relations
|
|
57
|
+
self.party = party
|
|
58
|
+
self.license = license
|
|
59
|
+
|
|
60
|
+
def __new__(cls, *args, **kwargs):
|
|
61
|
+
new_group = super().__new__(cls)
|
|
62
|
+
attributes = {'_id': None, '_name': '', '_description': '', '_purpose': None, '_terms_of_use': '',
|
|
63
|
+
'_privacy_policy': None, '_creation_time': '', '_end_start': None,
|
|
64
|
+
'_properties': None, '_data_quality': None,
|
|
65
|
+
'_observations': None, '_relations': None, '_campaigns': None,
|
|
66
|
+
'_party': None, '_license': None,
|
|
67
|
+
'_self_link': '', '_service': None}
|
|
68
|
+
for key, value in attributes.items():
|
|
69
|
+
new_group.__dict__[key] = value
|
|
70
|
+
return new_group
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def name(self):
|
|
74
|
+
return self._name
|
|
75
|
+
|
|
76
|
+
@name.setter
|
|
77
|
+
def name(self, value):
|
|
78
|
+
if value is None:
|
|
79
|
+
self._name = None
|
|
80
|
+
return
|
|
81
|
+
if not isinstance(value, str):
|
|
82
|
+
raise ValueError('name should be of type str!')
|
|
83
|
+
self._name = value
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def description(self):
|
|
87
|
+
return self._description
|
|
88
|
+
|
|
89
|
+
@description.setter
|
|
90
|
+
def description(self, value):
|
|
91
|
+
if value is None:
|
|
92
|
+
self._description = None
|
|
93
|
+
return
|
|
94
|
+
if not isinstance(value, str):
|
|
95
|
+
raise ValueError('description should be of type str!')
|
|
96
|
+
self._description = value
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def purpose(self):
|
|
100
|
+
return self._purpose
|
|
101
|
+
|
|
102
|
+
@purpose.setter
|
|
103
|
+
def purpose(self, value):
|
|
104
|
+
if value is None:
|
|
105
|
+
self._purpose = None
|
|
106
|
+
return
|
|
107
|
+
if not isinstance(value, str):
|
|
108
|
+
raise ValueError('purpose should be of type str!')
|
|
109
|
+
self._purpose = value
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def terms_of_use(self):
|
|
113
|
+
return self._terms_of_use
|
|
114
|
+
|
|
115
|
+
@terms_of_use.setter
|
|
116
|
+
def terms_of_use(self, value):
|
|
117
|
+
if value is None:
|
|
118
|
+
self._terms_of_use = None
|
|
119
|
+
return
|
|
120
|
+
if not isinstance(value, str):
|
|
121
|
+
raise ValueError('termsOfUse should be of type str!')
|
|
122
|
+
self._terms_of_use = value
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def privacy_policy(self):
|
|
126
|
+
return self._privacy_policy
|
|
127
|
+
|
|
128
|
+
@privacy_policy.setter
|
|
129
|
+
def privacy_policy(self, value):
|
|
130
|
+
if value is None:
|
|
131
|
+
self._privacy_policy = None
|
|
132
|
+
return
|
|
133
|
+
if not isinstance(value, str):
|
|
134
|
+
raise ValueError('privacyPolicy should be of type str!')
|
|
135
|
+
self._privacy_policy = value
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def creation_time(self):
|
|
139
|
+
return self._creation_time
|
|
140
|
+
|
|
141
|
+
@creation_time.setter
|
|
142
|
+
def creation_time(self, value):
|
|
143
|
+
self._creation_time = check_datetime(value, 'creation_time')
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def end_time(self):
|
|
147
|
+
return self._end_time
|
|
148
|
+
|
|
149
|
+
@end_time.setter
|
|
150
|
+
def end_time(self, value):
|
|
151
|
+
if value is None:
|
|
152
|
+
self._end_time = None
|
|
153
|
+
return
|
|
154
|
+
self._end_time = check_datetime(value, 'end_time')
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def properties(self):
|
|
158
|
+
return self._properties
|
|
159
|
+
|
|
160
|
+
@properties.setter
|
|
161
|
+
def properties(self, value):
|
|
162
|
+
if value is None:
|
|
163
|
+
self._properties = {}
|
|
164
|
+
return
|
|
165
|
+
if not isinstance(value, dict):
|
|
166
|
+
raise ValueError('properties should be of type dict!')
|
|
167
|
+
self._properties = value
|
|
168
|
+
|
|
169
|
+
@property
|
|
170
|
+
def data_quality(self):
|
|
171
|
+
return self._data_quality
|
|
172
|
+
|
|
173
|
+
@data_quality.setter
|
|
174
|
+
def data_quality(self, value):
|
|
175
|
+
if value is None:
|
|
176
|
+
self._data_quality = None
|
|
177
|
+
return
|
|
178
|
+
if not isinstance(value, dict):
|
|
179
|
+
raise ValueError('dataQuality should be of type dict!')
|
|
180
|
+
self._data_quality = value
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def observations(self):
|
|
184
|
+
return self._observations
|
|
185
|
+
|
|
186
|
+
@observations.setter
|
|
187
|
+
def observations(self, values):
|
|
188
|
+
if values is None:
|
|
189
|
+
self._observations = None
|
|
190
|
+
return
|
|
191
|
+
if isinstance(values, list) and all(isinstance(os, observation.Observation) for os in values):
|
|
192
|
+
entity_class = entity_type.EntityTypes['Observation']['class']
|
|
193
|
+
self._observations = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
194
|
+
return
|
|
195
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
196
|
+
any((not isinstance(os, observation.Observation)) for os in values.entities):
|
|
197
|
+
raise ValueError('observations should be a list of Observation')
|
|
198
|
+
self._observations = values
|
|
199
|
+
|
|
200
|
+
def get_observations(self):
|
|
201
|
+
result = self.service.observations()
|
|
202
|
+
result.parent = self
|
|
203
|
+
return result
|
|
204
|
+
|
|
205
|
+
@property
|
|
206
|
+
def relations(self):
|
|
207
|
+
return self._relations
|
|
208
|
+
|
|
209
|
+
@relations.setter
|
|
210
|
+
def relations(self, values):
|
|
211
|
+
if values is None:
|
|
212
|
+
self._relations = None
|
|
213
|
+
return
|
|
214
|
+
if isinstance(values, list) and all(isinstance(rs, relation.Relation) for rs in values):
|
|
215
|
+
entity_class = entity_type.EntityTypes['Relation']['class']
|
|
216
|
+
self._relations = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
217
|
+
return
|
|
218
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
219
|
+
any((not isinstance(rs, relation.Relation)) for rs in values.entities):
|
|
220
|
+
raise ValueError('relations should be a list of Relation')
|
|
221
|
+
self._relations = values
|
|
222
|
+
|
|
223
|
+
def get_relations(self):
|
|
224
|
+
result = self.service.relations()
|
|
225
|
+
result.parent = self
|
|
226
|
+
return result
|
|
227
|
+
|
|
228
|
+
@property
|
|
229
|
+
def campaigns(self):
|
|
230
|
+
return self._campaigns
|
|
231
|
+
|
|
232
|
+
@campaigns.setter
|
|
233
|
+
def campaigns(self, values):
|
|
234
|
+
if values is None:
|
|
235
|
+
self._campaigns = None
|
|
236
|
+
return
|
|
237
|
+
if isinstance(values, list) and all(isinstance(ps, campaign.Campaign) for ps in values):
|
|
238
|
+
entity_class = entity_type.EntityTypes['Campaign']['class']
|
|
239
|
+
self._campaigns = entity_list.EntityList(entity_class=entity_class, entities=values)
|
|
240
|
+
return
|
|
241
|
+
if not isinstance(values, entity_list.EntityList) or \
|
|
242
|
+
any((not isinstance(ps, campaign.Campaign)) for ps in values.entities):
|
|
243
|
+
raise ValueError('campaigns should be a list of Campaign')
|
|
244
|
+
self._campaigns = values
|
|
245
|
+
|
|
246
|
+
def get_campaigns(self):
|
|
247
|
+
result = self.service.campaigns()
|
|
248
|
+
result.parent = self
|
|
249
|
+
return result
|
|
250
|
+
|
|
251
|
+
@property
|
|
252
|
+
def party(self):
|
|
253
|
+
return self._party
|
|
254
|
+
|
|
255
|
+
@party.setter
|
|
256
|
+
def party(self, value):
|
|
257
|
+
if value is None or isinstance(value, party.Party):
|
|
258
|
+
self._party = value
|
|
259
|
+
return
|
|
260
|
+
raise ValueError('party should be of type Party!')
|
|
261
|
+
|
|
262
|
+
def get_party(self):
|
|
263
|
+
result = self.service.party()
|
|
264
|
+
result.parent = self
|
|
265
|
+
return result
|
|
266
|
+
|
|
267
|
+
@property
|
|
268
|
+
def license(self):
|
|
269
|
+
return self._license
|
|
270
|
+
|
|
271
|
+
@license.setter
|
|
272
|
+
def license(self, value):
|
|
273
|
+
if value is None or isinstance(value, license.License):
|
|
274
|
+
self._license = value
|
|
275
|
+
return
|
|
276
|
+
raise ValueError('license should be of type License!')
|
|
277
|
+
|
|
278
|
+
def get_license(self):
|
|
279
|
+
result = self.service.license()
|
|
280
|
+
result.parent = self
|
|
281
|
+
return result
|
|
282
|
+
|
|
283
|
+
def ensure_service_on_children(self, service):
|
|
284
|
+
if self.observations is not None:
|
|
285
|
+
self.observations.set_service(service)
|
|
286
|
+
if self.relations is not None:
|
|
287
|
+
self.relations.set_service(service)
|
|
288
|
+
if self.campaigns is not None:
|
|
289
|
+
self.campaigns.set_service(service)
|
|
290
|
+
if self.party is not None:
|
|
291
|
+
self.party.set_service(service)
|
|
292
|
+
if self.license is not None:
|
|
293
|
+
self.license.set_service(service)
|
|
294
|
+
|
|
295
|
+
def __eq__(self, other):
|
|
296
|
+
if other is None:
|
|
297
|
+
return False
|
|
298
|
+
if not isinstance(other, type(self)):
|
|
299
|
+
return False
|
|
300
|
+
if id(self) == id(other):
|
|
301
|
+
return True
|
|
302
|
+
if self.name != other.name:
|
|
303
|
+
return False
|
|
304
|
+
if self.description != other.description:
|
|
305
|
+
return False
|
|
306
|
+
if self.purpose != other.purpose:
|
|
307
|
+
return False
|
|
308
|
+
if self.terms_of_use != other.terms_of_use:
|
|
309
|
+
return False
|
|
310
|
+
if self.privacy_policy != other.privacy_policy:
|
|
311
|
+
return False
|
|
312
|
+
if self.creation_time is not None and other.creation_time is not None and datetime.fromisoformat(self.creation_time) != datetime.fromisoformat(other.creation_time):
|
|
313
|
+
return False
|
|
314
|
+
if self.end_time is not None and other.end_time is not None and datetime.fromisoformat(self.end_time) != datetime.fromisoformat(other.end_time):
|
|
315
|
+
return False
|
|
316
|
+
if self.properties != other.properties:
|
|
317
|
+
return False
|
|
318
|
+
if self.data_quality != other.data_quality:
|
|
319
|
+
return False
|
|
320
|
+
|
|
321
|
+
return True
|
|
322
|
+
|
|
323
|
+
def __ne__(self, other):
|
|
324
|
+
return not self == other
|
|
325
|
+
|
|
326
|
+
def __getstate__(self):
|
|
327
|
+
data = super().__getstate__()
|
|
328
|
+
if self.name is not None and self.name != '':
|
|
329
|
+
data['name'] = self.name
|
|
330
|
+
if self.description is not None and self.description != '':
|
|
331
|
+
data['description'] = self.description
|
|
332
|
+
if self.purpose is not None and self.purpose != '':
|
|
333
|
+
data['purpose'] = self.purpose
|
|
334
|
+
if self.terms_of_use is not None and self.terms_of_use != '':
|
|
335
|
+
data['termsOfUse'] = self.terms_of_use
|
|
336
|
+
if self.privacy_policy is not None and self.privacy_policy != '':
|
|
337
|
+
data['privacyPolicy'] = self.privacy_policy
|
|
338
|
+
if self.creation_time is not None:
|
|
339
|
+
data['creationTime'] = datetime.fromisoformat(self.creation_time)
|
|
340
|
+
if self.end_time is not None:
|
|
341
|
+
data['endTime'] = datetime.fromisoformat(self.end_time)
|
|
342
|
+
if self.properties is not None and self.properties != {}:
|
|
343
|
+
data['properties'] = self.properties
|
|
344
|
+
if self.data_quality is not None and self.data_quality != {}:
|
|
345
|
+
data['dataQuality'] = self.data_quality
|
|
346
|
+
if self.party is not None:
|
|
347
|
+
data['Party'] = self.party
|
|
348
|
+
if self.license is not None:
|
|
349
|
+
data['License'] = self.license
|
|
350
|
+
if self._observations is not None and len(self.observations.entities) > 0:
|
|
351
|
+
data['Observations'] = self.observations.__getstate__()
|
|
352
|
+
if self._relations is not None and len(self.relations.entities) > 0:
|
|
353
|
+
data['Relations'] = self.relations.__getstate__()
|
|
354
|
+
if self._campaigns is not None and len(self.campaigns.entities) > 0:
|
|
355
|
+
data['Campaigns'] = self.campaigns.__getstate__()
|
|
356
|
+
return data
|
|
357
|
+
|
|
358
|
+
def __setstate__(self, state):
|
|
359
|
+
super().__setstate__(state)
|
|
360
|
+
self.name = state.get("name", None)
|
|
361
|
+
self.description = state.get("description", None)
|
|
362
|
+
self.purpose = state.get("purpose", None)
|
|
363
|
+
self.terms_of_use = state.get("termsOfUse", None)
|
|
364
|
+
self.privacy_policy = state.get("privacyPolicy", None)
|
|
365
|
+
self.creation_time = state.get("creationTime", None)
|
|
366
|
+
self.end_time = state.get("endTime", None)
|
|
367
|
+
self.properties = state.get("properties", None)
|
|
368
|
+
self.data_quality = state.get("dataQuality", None)
|
|
369
|
+
|
|
370
|
+
if state.get("Party", None) is not None:
|
|
371
|
+
self.party = party.Party()
|
|
372
|
+
self.party.__setstate__(state["Party"])
|
|
373
|
+
if state.get("License", None) is not None:
|
|
374
|
+
self.license = license.License()
|
|
375
|
+
self.license.__setstate__(state["License"])
|
|
376
|
+
|
|
377
|
+
if state.get("Observations", None) is not None and isinstance(state["Observations"], list):
|
|
378
|
+
entity_class = entity_type.EntityTypes['Observation']['class']
|
|
379
|
+
self.observations = utils.transform_json_to_entity_list(state['Observations'], entity_class)
|
|
380
|
+
self.observations.next_link = state.get("Observations@iot.nextLink", None)
|
|
381
|
+
self.observations.count = state.get("Observations@iot.count", None)
|
|
382
|
+
if state.get("Campaigns", None) is not None and isinstance(state["Campaigns"], list):
|
|
383
|
+
entity_class = entity_type.EntityTypes['Campaign']['class']
|
|
384
|
+
self.campaigns = utils.transform_json_to_entity_list(state['Campaigns'], entity_class)
|
|
385
|
+
self.campaigns.next_link = state.get("Campaigns@iot.nextLink", None)
|
|
386
|
+
self.campaigns.count = state.get("Campaigns@iot.count", None)
|
|
387
|
+
if state.get("Relations", None) is not None and isinstance(state["Relations"], list):
|
|
388
|
+
entity_class = entity_type.EntityTypes['Relation']['class']
|
|
389
|
+
self.relations = utils.transform_json_to_entity_list(state['Relations'], entity_class)
|
|
390
|
+
self.relations.next_link = state.get("Relations@iot.nextLink", None)
|
|
391
|
+
self.relations.count = state.get("Relations@iot.count", None)
|
|
392
|
+
|
|
393
|
+
def get_dao(self, service):
|
|
394
|
+
return ObservationGroupDao(service)
|
|
395
|
+
|
|
396
|
+
def clone(self):
|
|
397
|
+
entity = self.__class__()
|
|
398
|
+
entity.id = self.id
|
|
399
|
+
return entity
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from frost_sta_client.model import observedproperty
|
|
2
|
+
from staplus_client.dao.observedproperty import ObservedPropertyDao
|
|
3
|
+
class ObservedProperty(observedproperty.ObservedProperty):
|
|
4
|
+
def clone(self):
|
|
5
|
+
entity = self.__class__()
|
|
6
|
+
entity.id = self.id
|
|
7
|
+
return entity
|
|
8
|
+
|
|
9
|
+
def get_datastreams(self):
|
|
10
|
+
result = self.service.datastreams()
|
|
11
|
+
result.parent = self
|
|
12
|
+
return result
|
|
13
|
+
|
|
14
|
+
def get_multi_datastreams(self):
|
|
15
|
+
result = self.service.multi_datastreams()
|
|
16
|
+
result.parent = self
|
|
17
|
+
return result
|
|
18
|
+
|
|
19
|
+
def get_dao(self, service):
|
|
20
|
+
return ObservedPropertyDao(service)
|