Skip to content

Commit 2d92edd

Browse files
committed
fix builtins in annotations and results
1 parent cb30fbe commit 2d92edd

1 file changed

Lines changed: 30 additions & 27 deletions

File tree

odm2api/ODM2/services/readService.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
from sqlalchemy import distinct, exists
4040

41+
import warnings
42+
4143
__author__ = 'sreeder'
4244

4345

@@ -158,7 +160,7 @@ def resultExists(self, result):
158160
return None
159161

160162
# Annotations
161-
def getAnnotations(self, type=None, codes=None, ids=None):
163+
def getAnnotations(self, annottype=None, codes=None, ids=None, **kwargs):
162164
"""
163165
* Pass Nothing - return a list of all objects
164166
* Pass AnnotationTypeCV - return a list of all objects of the fiven type
@@ -168,34 +170,38 @@ def getAnnotations(self, type=None, codes=None, ids=None):
168170
"""
169171
# TODO What keywords do I use for type.
170172
a = Annotations
171-
if type:
172-
if type == 'action':
173+
if 'type' in kwargs:
174+
warnings.warn(
175+
"The parameter 'type' is deprecated. Please use the annottype parameter instead.")
176+
annottype = kwargs['type']
177+
if annottype:
178+
if annottype == 'action':
173179
a = ActionAnnotations
174-
elif type == 'categoricalresultvalue':
180+
elif annottype == 'categoricalresultvalue':
175181
a = CategoricalResultValueAnnotations
176-
elif type == 'equipmentannotation':
182+
elif annottype == 'equipmentannotation':
177183
a = EquipmentAnnotations
178-
elif type == 'measurementresultvalue':
184+
elif annottype == 'measurementresultvalue':
179185
a = MeasurementResultValueAnnotations
180-
elif type == 'method':
186+
elif annottype == 'method':
181187
a = MethodAnnotations
182-
elif type == 'pointcoverageresultvalue':
188+
elif annottype == 'pointcoverageresultvalue':
183189
a = PointCoverageResultValueAnnotations
184-
elif type == 'profileresultvalue':
190+
elif annottype == 'profileresultvalue':
185191
a = ProfileResultValueAnnotations
186-
elif type == 'result':
192+
elif annottype == 'result':
187193
a = ResultAnnotations
188-
elif type == 'samplingfeature':
194+
elif annottype == 'samplingfeature':
189195
a = SamplingFeatureAnnotations
190-
elif type == 'sectionresultvalue':
196+
elif annottype == 'sectionresultvalue':
191197
a = SectionResultValueAnnotations
192-
elif type == 'spectraresultvalue':
198+
elif annottype == 'spectraresultvalue':
193199
a = SpectraResultValueAnnotations
194-
elif type == 'timeseriesresultvalue':
200+
elif annottype == 'timeseriesresultvalue':
195201
a = TimeSeriesResultValueAnnotations
196-
elif type == 'trajectoryresultvalue':
202+
elif annottype == 'trajectoryresultvalue':
197203
a = TrajectoryResultValueAnnotations
198-
elif type == 'transectresultvalue':
204+
elif annottype == 'transectresultvalue':
199205
a = TransectResultValueAnnotations
200206
try:
201207
query = self._session.query(a)
@@ -691,8 +697,8 @@ def getAffiliations(self, ids=None, personfirst=None, personlast=None, orgcode=N
691697
return None
692698

693699
# Results
694-
def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=None, simulationid=None, sfid=None,
695-
variableid=None, siteid=None, sfids=None, sfuuids=None, sfcodes=None):
700+
def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simulationid=None,
701+
variableid=None, siteid=None, sfids=None, sfuuids=None, sfcodes=None, **kwargs):
696702

697703
# TODO what if user sends in both type and actionid vs just actionid
698704
"""Retrieve a list of Result objects.
@@ -707,7 +713,6 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N
707713
uuids (list, optional): List of UUIDs string.
708714
actionid (int, optional): ActionID.
709715
simulationid (int, optional): SimulationID.
710-
sfid (int, optional): SamplingFeatureID.
711716
variableid (int, optional): VariableID.
712717
siteid (int, optional): SiteID. - goes through related features table and finds all of results
713718
recorded at the given site
@@ -732,11 +737,10 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N
732737
"""
733738
query = self._session.query(Results)
734739

735-
if type:
736-
import warnings
740+
if 'type' in kwargs:
737741
warnings.warn(
738-
"The parameter 'type' is no longer be supported. Please use the restype parameter instead.")
739-
query = query.filter_by(ResultTypeCV=type)
742+
"The parameter 'type' is deprecated. Please use the restype parameter instead.")
743+
restype = kwargs['type']
740744
if restype:
741745
query = query.filter_by(ResultTypeCV=restype)
742746
if variableid:
@@ -752,10 +756,9 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N
752756
.filter_by(SimulationID=simulationid)
753757
if actionid:
754758
query = query.join(FeatureActions).filter_by(ActionID=actionid)
755-
if sfid:
756-
import warnings
757-
warnings.warn("The parameter 'sfid' is no longer be supported. Please use the sfids parameter and send in a list.")
758-
query = query.join(FeatureActions).filter_by(SamplingFeatureID=sfid)
759+
if 'sfid' in kwargs:
760+
warnings.warn("The parameter 'sfid' is deprecated. Please use the sfids parameter and send in a list.")
761+
query = query.join(FeatureActions).filter_by(SamplingFeatureID=kwargs['sfid'])
759762
if sfids or sfcodes or sfuuids:
760763
sf_list = self.getSamplingFeatures(ids=sfids, codes=sfcodes, uuids=sfuuids)
761764
sfids = []

0 commit comments

Comments
 (0)