Skip to content

Commit 9592471

Browse files
committed
Fix getSamplingFeatureDataset
1 parent 2b08624 commit 9592471

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

odm2api/ODM2/services/readService.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,27 @@ def __init__(self, samplingfeature, datasetresults, relatedfeatures):
9797

9898
def assignDatasets(self, datasetresults):
9999
self.datasets = {}
100-
for dsr in datasetresults:
101-
if dsr.DataSetObj not in self.datasets:
102-
#if the dataset is not in the dictionary, add it and the first result
103-
self.datasets[dsr.DataSetObj]=[]
104-
res = dsr.ResultObj
105-
# res.FeatureActionObj = None
106-
self.datasets[dsr.DataSetObj].append(res)
107-
else:
108-
#if the dataset is in the dictionary, append the result object to the list
109-
res = dsr.ResultObj
110-
# res.FeatureActionObj = None
111-
self.datasets[dsr.DataSetObj].append(res)
100+
if datasetresults:
101+
for dsr in datasetresults:
102+
if dsr.DataSetObj not in self.datasets:
103+
#if the dataset is not in the dictionary, add it and the first result
104+
self.datasets[dsr.DataSetObj]=[]
105+
res = dsr.ResultObj
106+
# res.FeatureActionObj = None
107+
self.datasets[dsr.DataSetObj].append(res)
108+
else:
109+
#if the dataset is in the dictionary, append the result object to the list
110+
res = dsr.ResultObj
111+
# res.FeatureActionObj = None
112+
self.datasets[dsr.DataSetObj].append(res)
112113

113114

114115
def assignRelatedFeatures(self, relatedfeatures):
115116
self.related_features = {}
116-
for related in relatedfeatures:
117-
if related.SamplingFeatureTypeCV == 'Site':
118-
self.related_features = related
117+
if relatedfeatures:
118+
for related in relatedfeatures:
119+
if related.SamplingFeatureTypeCV == 'Site':
120+
self.related_features = related
119121

120122

121123

@@ -887,7 +889,7 @@ def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None):
887889
return None
888890

889891

890-
def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None, type=None):
892+
def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None, sftype=None):
891893
"""
892894
Retrieve a list of Datasets associated with the given sampling feature data.
893895
@@ -899,7 +901,8 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
899901
uuids (list, optional): List of UUIDs string.
900902
dstype (str, optional): Type of Dataset from
901903
`controlled vocabulary name <http://vocabulary.odm2.org/datasettype/>`_.
902-
904+
sftype (str, optional): Type of SamplingFeature from
905+
`controlled vocabulary name <http://vocabulary.odm2.org/samplingfeaturetype/>`_.
903906
904907
Returns:
905908
list: List of DataSetsResults Objects associated with the given sampling feature
@@ -911,18 +914,19 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
911914
>>> READ.getSamplingFeatureDatasets(uuids=['a6f114f1-5416-4606-ae10-23be32dbc202',
912915
... '5396fdf3-ceb3-46b6-aaf9-454a37278bb4'])
913916
>>> READ.getSamplingFeatureDatasets(dstype='singleTimeSeries')
917+
>>> READ.getSamplingFeatureDatasets(sftype='Specimen')
914918
915919
"""
916920

917921

918922
# make sure one of the three arguments has been sent in
919-
# if all(v is None for v in [ids, codes, uuids, type]):
920-
# raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode OR samplingFeatureType '
921-
# 'argument')
923+
if all(v is None for v in [ids, codes, uuids, sftype]):
924+
raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode OR samplingFeatureType '
925+
'argument')
922926

923927
sf_query = self._session.query(SamplingFeatures)
924-
if type:
925-
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureTypeCV == type)
928+
if sftype:
929+
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureTypeCV == sftype)
926930
if ids:
927931
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureID.in_(ids))
928932
if codes:
@@ -934,7 +938,6 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
934938
for sf in sf_query.all():
935939
sf_list.append(sf)
936940

937-
sfds = None
938941
try:
939942
sfds=[]
940943
for sf in sf_list:

0 commit comments

Comments
 (0)