Skip to content

Commit 74ec3e0

Browse files
committed
It was not possible to create single observations.
The create method of the ObservationDao only accepted data arrays. I have inserted a switch to make it possible to create single observations or data arrays.
1 parent 2f304d4 commit 74ec3e0

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

frost_sta_client/dao/observation.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,23 @@ def __init__(self, service):
3434
"""
3535
base.BaseDao.__init__(self, service, EntityTypes["Observation"])
3636

37-
def create(self, data_array):
38-
url = self.service.url.copy()
39-
url.path.add(self.CREATE_OBSERVATIONS)
40-
logging.debug('Posting to ' + str(url.url))
41-
json_dict = transform_entity_to_json_dict(data_array.value)
42-
try:
43-
response = self.service.execute('post', url, json=json_dict)
44-
except requests.exceptions.HTTPError as e:
45-
error_json = e.response.json()
46-
error_message = error_json['message']
47-
logging.error("Creating {} failed with status-code {}, {}".format("Data Array",
37+
def create(self, entity):
38+
if isinstance(entity, frost_sta_client.model.observation.Observation):
39+
super().create(entity)
40+
else:
41+
# entity is probably a data array
42+
url = self.service.url.copy()
43+
url.path.add(self.CREATE_OBSERVATIONS)
44+
logging.debug('Posting to ' + str(url.url))
45+
json_dict = transform_entity_to_json_dict(entity.value)
46+
try:
47+
response = self.service.execute('post', url, json=json_dict)
48+
except requests.exceptions.HTTPError as e:
49+
error_json = e.response.json()
50+
error_message = error_json['message']
51+
logging.error("Creating {} failed with status-code {}, {}".format("Data Array",
4852
e.response.status_code,
4953
error_message))
50-
response_text_as_list = json.loads(response.text)
51-
result = [frost_sta_client.model.observation.Observation(self_link=link) for link in response_text_as_list]
52-
return result
54+
response_text_as_list = json.loads(response.text)
55+
result = [frost_sta_client.model.observation.Observation(self_link=link) for link in response_text_as_list]
56+
return result

0 commit comments

Comments
 (0)