From 3c132a32cd8b77aebb9df338a69d5bf7c2160d9e Mon Sep 17 00:00:00 2001 From: lsetiawan Date: Fri, 5 Jan 2018 12:31:33 -0800 Subject: [PATCH 1/7] fix builtins in annotations and results --- odm2api/ODM2/services/readService.py | 57 +++++++++++++++------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index a7ed9f9..3d5db70 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -38,6 +38,8 @@ from sqlalchemy import distinct, exists +import warnings + __author__ = 'sreeder' @@ -145,7 +147,7 @@ def resultExists(self, result): return None # Annotations - def getAnnotations(self, type=None, codes=None, ids=None): + def getAnnotations(self, annottype=None, codes=None, ids=None, **kwargs): """ * Pass Nothing - return a list of all objects * Pass AnnotationTypeCV - return a list of all objects of the fiven type @@ -155,34 +157,38 @@ def getAnnotations(self, type=None, codes=None, ids=None): """ # TODO What keywords do I use for type. a = Annotations - if type: - if type == 'action': + if 'type' in kwargs: + warnings.warn( + "The parameter 'type' is deprecated. Please use the annottype parameter instead.") + annottype = kwargs['type'] + if annottype: + if annottype == 'action': a = ActionAnnotations - elif type == 'categoricalresultvalue': + elif annottype == 'categoricalresultvalue': a = CategoricalResultValueAnnotations - elif type == 'equipmentannotation': + elif annottype == 'equipmentannotation': a = EquipmentAnnotations - elif type == 'measurementresultvalue': + elif annottype == 'measurementresultvalue': a = MeasurementResultValueAnnotations - elif type == 'method': + elif annottype == 'method': a = MethodAnnotations - elif type == 'pointcoverageresultvalue': + elif annottype == 'pointcoverageresultvalue': a = PointCoverageResultValueAnnotations - elif type == 'profileresultvalue': + elif annottype == 'profileresultvalue': a = ProfileResultValueAnnotations - elif type == 'result': + elif annottype == 'result': a = ResultAnnotations - elif type == 'samplingfeature': + elif annottype == 'samplingfeature': a = SamplingFeatureAnnotations - elif type == 'sectionresultvalue': + elif annottype == 'sectionresultvalue': a = SectionResultValueAnnotations - elif type == 'spectraresultvalue': + elif annottype == 'spectraresultvalue': a = SpectraResultValueAnnotations - elif type == 'timeseriesresultvalue': + elif annottype == 'timeseriesresultvalue': a = TimeSeriesResultValueAnnotations - elif type == 'trajectoryresultvalue': + elif annottype == 'trajectoryresultvalue': a = TrajectoryResultValueAnnotations - elif type == 'transectresultvalue': + elif annottype == 'transectresultvalue': a = TransectResultValueAnnotations try: query = self._session.query(a) @@ -678,8 +684,8 @@ def getAffiliations(self, ids=None, personfirst=None, personlast=None, orgcode=N return None # Results - def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=None, simulationid=None, sfid=None, - variableid=None, siteid=None, sfids=None, sfuuids=None, sfcodes=None): + def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simulationid=None, + variableid=None, siteid=None, sfids=None, sfuuids=None, sfcodes=None, **kwargs): # TODO what if user sends in both type and actionid vs just actionid """Retrieve a list of Result objects. @@ -694,7 +700,6 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N uuids (list, optional): List of UUIDs string. actionid (int, optional): ActionID. simulationid (int, optional): SimulationID. - sfid (int, optional): SamplingFeatureID. variableid (int, optional): VariableID. siteid (int, optional): SiteID. - goes through related features table and finds all of results recorded at the given site @@ -719,11 +724,10 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N """ query = self._session.query(Results) - if type: - import warnings + if 'type' in kwargs: warnings.warn( - "The parameter 'type' is no longer be supported. Please use the restype parameter instead.") - query = query.filter_by(ResultTypeCV=type) + "The parameter 'type' is deprecated. Please use the restype parameter instead.") + restype = kwargs['type'] if restype: query = query.filter_by(ResultTypeCV=restype) if variableid: @@ -739,10 +743,9 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N .filter_by(SimulationID=simulationid) if actionid: query = query.join(FeatureActions).filter_by(ActionID=actionid) - if sfid: - import warnings - warnings.warn("The parameter 'sfid' is no longer be supported. Please use the sfids parameter and send in a list.") - query = query.join(FeatureActions).filter_by(SamplingFeatureID=sfid) + if 'sfid' in kwargs: + warnings.warn("The parameter 'sfid' is deprecated. Please use the sfids parameter and send in a list.") + query = query.join(FeatureActions).filter_by(SamplingFeatureID=kwargs['sfid']) if sfids or sfcodes or sfuuids: sf_list = self.getSamplingFeatures(ids=sfids, codes=sfcodes, uuids=sfuuids) sfids = [] From edb02fab2b6a144611408d3200452dd400320072 Mon Sep 17 00:00:00 2001 From: lsetiawan Date: Fri, 5 Jan 2018 13:05:58 -0800 Subject: [PATCH 2/7] Fix the rest of the builtins, added warnings --- odm2api/ODM2/services/readService.py | 113 ++++++++++++++++++--------- 1 file changed, 74 insertions(+), 39 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 3d5db70..394b5b0 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -158,8 +158,8 @@ def getAnnotations(self, annottype=None, codes=None, ids=None, **kwargs): # TODO What keywords do I use for type. a = Annotations if 'type' in kwargs: - warnings.warn( - "The parameter 'type' is deprecated. Please use the annottype parameter instead.") + warnings.warn('The parameter \'type\' is deprecated. Please use the annottype parameter instead.', + DeprecationWarning, stacklevel=2) annottype = kwargs['type'] if annottype: if annottype == 'action': @@ -385,7 +385,7 @@ def getVariables(self, ids=None, codes=None, sitecode=None, results=False): return None # Method - def getMethods(self, ids=None, codes=None, type=None): + def getMethods(self, ids=None, codes=None, medtype=None, **kwargs): """ * Pass nothing - returns full list of method objects * Pass a list of MethodIDs - returns a single method object for each given id @@ -393,13 +393,17 @@ def getMethods(self, ids=None, codes=None, type=None): * Pass a MethodType - returns a list of method objects of the given MethodType """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the medtype parameter instead.', + DeprecationWarning, stacklevel=2) + medtype = kwargs['type'] q = self._session.query(Methods) if ids: q = q.filter(Methods.MethodID.in_(ids)) if codes: q = q.filter(Methods.MethodCode.in_(codes)) - if type: - q = q.filter_by(MethodTypeCV=type) + if medtype: + q = q.filter_by(MethodTypeCV=medtype) try: return q.all() @@ -442,7 +446,8 @@ def getProcessingLevels(self, ids=None, codes=None): return None # Sampling Feature - def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=None, results=False): + def getSamplingFeatures(self, ids=None, codes=None, uuids=None, + sftype=None, wkt=None, results=False, **kwargs): """Retrieve a list of Sampling Feature objects. If no arguments are passed to the function, or their values are None, @@ -452,7 +457,7 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N ids (list, optional): List of SamplingFeatureIDs. codes (list, optional): List of SamplingFeature Codes. uuids (list, optional): List of UUIDs string. - type (str, optional): Type of Sampling Feature from + sftype (str, optional): Type of Sampling Feature from `controlled vocabulary name `_. wkt (str, optional): SamplingFeature Well Known Text. results (bool, optional): Whether or not you want to return only the @@ -473,6 +478,10 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N >>> READ.getSamplingFeatures(type='Site', results=True) """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the sftype parameter instead.', + DeprecationWarning, stacklevel=2) + sftype = kwargs['type'] if results: try: fas = [x[0] for x in self._session.query(distinct(Results.FeatureActionID)).all()] @@ -487,8 +496,8 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N q = self._session.query(SamplingFeatures) - if type: - q = q.filter_by(SamplingFeatureTypeCV=type) + if sftype: + q = q.filter_by(SamplingFeatureTypeCV=sftype) if ids: q = q.filter(SamplingFeatures.SamplingFeatureID.in_(ids)) if codes: @@ -535,7 +544,7 @@ def getRelatedSamplingFeatures(self, sfid=None, rfid=None, relationshiptype=None # Action - def getActions(self, ids=None, type=None, sfid=None): + def getActions(self, ids=None, acttype=None, sfid=None, **kwargs): """ * Pass nothing - returns a list of all Actions * Pass a list of Action ids - returns a list of Action objects @@ -544,12 +553,16 @@ def getActions(self, ids=None, type=None, sfid=None): associated with that Sampling feature ID, Found through featureAction table """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the acttype parameter instead.', + DeprecationWarning, stacklevel=2) + acttype = kwargs['type'] a = Actions - if type == 'equipment': + if acttype == 'equipment': a = EquipmentActions - elif type == 'calibration': + elif acttype == 'calibration': a = CalibrationActions - elif type == 'maintenance': + elif acttype == 'maintenance': a = MaintenanceActions q = self._session.query(a) @@ -581,7 +594,7 @@ def getRelatedActions(self, actionid=None): return None # Unit - def getUnits(self, ids=None, name=None, type=None): + def getUnits(self, ids=None, name=None, unittype=None, **kwargs): """ * Pass nothing - returns a list of all units objects * Pass a list of UnitsID - returns a single units object for the given id @@ -589,13 +602,17 @@ def getUnits(self, ids=None, name=None, type=None): * Pass a type- returns a list of all objects of the given type """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the unittype parameter instead.', + DeprecationWarning, stacklevel=2) + unittype = kwargs['type'] q = self._session.query(Units) if ids: q = q.filter(Units.UnitsID.in_(ids)) if name: q = q.filter(Units.UnitsName.ilike(name)) - if type: - q = q.filter(Units.UnitsTypeCV.ilike(type)) + if unittype: + q = q.filter(Units.UnitsTypeCV.ilike(unittype)) try: return q.all() except Exception as e: @@ -725,8 +742,8 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula query = self._session.query(Results) if 'type' in kwargs: - warnings.warn( - "The parameter 'type' is deprecated. Please use the restype parameter instead.") + warnings.warn('The parameter \'type\' is deprecated. Please use the restype parameter instead.', + DeprecationWarning, stacklevel=2) restype = kwargs['type'] if restype: query = query.filter_by(ResultTypeCV=restype) @@ -744,7 +761,9 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula if actionid: query = query.join(FeatureActions).filter_by(ActionID=actionid) if 'sfid' in kwargs: - warnings.warn("The parameter 'sfid' is deprecated. Please use the sfids parameter and send in a list.") + warnings.warn('The parameter \'sfid\' is deprecated. ' + 'Please use the sfids parameter instead and send in a list.', + DeprecationWarning, stacklevel=2) query = query.join(FeatureActions).filter_by(SamplingFeatureID=kwargs['sfid']) if sfids or sfcodes or sfuuids: sf_list = self.getSamplingFeatures(ids=sfids, codes=sfcodes, uuids=sfuuids) @@ -1011,7 +1030,7 @@ def getResultsDataQuality(self): # TODO Equipment Schema Queries # Equipment - def getEquipment(self, codes=None, type=None, sfid=None, actionid=None): + def getEquipment(self, codes=None, equiptype=None, sfid=None, actionid=None, **kwargs): """ * Pass nothing - returns a list of all Equipment objects * Pass a list of EquipmentCodes- return a list of all Equipment objects that match each of the codes @@ -1020,6 +1039,10 @@ def getEquipment(self, codes=None, type=None, sfid=None, actionid=None): * Pass an ActionID - returns a single Equipment object """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the equiptype parameter instead.', + DeprecationWarning, stacklevel=2) + equiptype = kwargs['type'] e = self._session.query(Equipment) if sfid: e = e.join(EquipmentUsed) \ @@ -1108,25 +1131,29 @@ def RelatedEquipment(self, code=None): return r.all() # Extension Properties - def getExtensionProperties(self, type=None): + def getExtensionProperties(self, exptype=None, **kwargs): """ * Pass nothing - return a list of all objects * Pass type- return a list of all objects of the given type """ # Todo what values to use for extensionproperties type + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the exptype parameter instead.', + DeprecationWarning, stacklevel=2) + exptype = kwargs['type'] e = ExtensionProperties - if type == 'action': + if exptype == 'action': e = ActionExtensionPropertyValues - elif type == 'citation': + elif exptype == 'citation': e = CitationExtensionPropertyValues - elif type == 'method': + elif exptype == 'method': e = MethodExtensionPropertyValues - elif type == 'result': + elif exptype == 'result': e = ResultExtensionPropertyValues - elif type == 'samplingfeature': + elif exptype == 'samplingfeature': e = SamplingFeatureExtensionPropertyValues - elif type == 'variable': + elif exptype == 'variable': e = VariableExtensionPropertyValues try: return self._session.query(e).all() @@ -1135,28 +1162,32 @@ def getExtensionProperties(self, type=None): return None # External Identifiers - def getExternalIdentifiers(self, type=None): + def getExternalIdentifiers(self, eitype=None, **kwargs): """ * Pass nothing - return a list of all objects * Pass type- return a list of all objects of the given type """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the eitype parameter instead.', + DeprecationWarning, stacklevel=2) + eitype = kwargs['type'] e = ExternalIdentifierSystems - if type.lowercase == 'citation': + if eitype.lowercase == 'citation': e = CitationExternalIdentifiers - elif type == 'method': + elif eitype == 'method': e = MethodExternalIdentifiers - elif type == 'person': + elif eitype == 'person': e = PersonExternalIdentifiers - elif type == 'referencematerial': + elif eitype == 'referencematerial': e = ReferenceMaterialExternalIdentifiers - elif type == 'samplingfeature': + elif eitype == 'samplingfeature': e = SamplingFeatureExternalIdentifiers - elif type == 'spatialreference': + elif eitype == 'spatialreference': e = SpatialReferenceExternalIdentifiers - elif type == 'taxonomicclassifier': + elif eitype == 'taxonomicclassifier': e = TaxonomicClassifierExternalIdentifiers - elif type == 'variable': + elif eitype == 'variable': e = VariableExternalIdentifiers try: return self._session.query(e).all() @@ -1372,16 +1403,20 @@ def getModels(self, codes=None): print('Error running Query: {}'.format(e)) return None - def getRelatedModels(self, id=None, code=None): + def getRelatedModels(self, modid=None, code=None, **kwargs): """ getRelatedModels(self, id=None, code=None) * Pass a ModelID - get a list of converter objects related to the converter having ModelID * Pass a ModelCode - get a list of converter objects related to the converter having ModeCode """ + if 'id' in kwargs: + warnings.warn('The parameter \'id\' is deprecated. Please use the modid parameter instead.', + DeprecationWarning, stacklevel=2) + modid = kwargs['type'] m = self._session.query(Models).select_from(RelatedModels).join(RelatedModels.ModelObj) - if id: - m = m.filter(RelatedModels.ModelID == id) + if modid: + m = m.filter(RelatedModels.ModelID == modid) if code: m = m.filter(Models.ModelCode == code) From c493d61ff9bd476871f14c1389447064445b4ccd Mon Sep 17 00:00:00 2001 From: lsetiawan Date: Fri, 5 Jan 2018 13:15:37 -0800 Subject: [PATCH 3/7] Fix mistype --- odm2api/ODM2/services/readService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 394b5b0..32dea3b 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -1413,7 +1413,7 @@ def getRelatedModels(self, modid=None, code=None, **kwargs): if 'id' in kwargs: warnings.warn('The parameter \'id\' is deprecated. Please use the modid parameter instead.', DeprecationWarning, stacklevel=2) - modid = kwargs['type'] + modid = kwargs['id'] m = self._session.query(Models).select_from(RelatedModels).join(RelatedModels.ModelObj) if modid: m = m.filter(RelatedModels.ModelID == modid) From 2d92edd3b425c6339a2c7c8769892394d421bdb2 Mon Sep 17 00:00:00 2001 From: lsetiawan Date: Fri, 5 Jan 2018 12:31:33 -0800 Subject: [PATCH 4/7] fix builtins in annotations and results --- odm2api/ODM2/services/readService.py | 57 +++++++++++++++------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index eabcaf3..9f45793 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -38,6 +38,8 @@ from sqlalchemy import distinct, exists +import warnings + __author__ = 'sreeder' @@ -158,7 +160,7 @@ def resultExists(self, result): return None # Annotations - def getAnnotations(self, type=None, codes=None, ids=None): + def getAnnotations(self, annottype=None, codes=None, ids=None, **kwargs): """ * Pass Nothing - return a list of all objects * 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): """ # TODO What keywords do I use for type. a = Annotations - if type: - if type == 'action': + if 'type' in kwargs: + warnings.warn( + "The parameter 'type' is deprecated. Please use the annottype parameter instead.") + annottype = kwargs['type'] + if annottype: + if annottype == 'action': a = ActionAnnotations - elif type == 'categoricalresultvalue': + elif annottype == 'categoricalresultvalue': a = CategoricalResultValueAnnotations - elif type == 'equipmentannotation': + elif annottype == 'equipmentannotation': a = EquipmentAnnotations - elif type == 'measurementresultvalue': + elif annottype == 'measurementresultvalue': a = MeasurementResultValueAnnotations - elif type == 'method': + elif annottype == 'method': a = MethodAnnotations - elif type == 'pointcoverageresultvalue': + elif annottype == 'pointcoverageresultvalue': a = PointCoverageResultValueAnnotations - elif type == 'profileresultvalue': + elif annottype == 'profileresultvalue': a = ProfileResultValueAnnotations - elif type == 'result': + elif annottype == 'result': a = ResultAnnotations - elif type == 'samplingfeature': + elif annottype == 'samplingfeature': a = SamplingFeatureAnnotations - elif type == 'sectionresultvalue': + elif annottype == 'sectionresultvalue': a = SectionResultValueAnnotations - elif type == 'spectraresultvalue': + elif annottype == 'spectraresultvalue': a = SpectraResultValueAnnotations - elif type == 'timeseriesresultvalue': + elif annottype == 'timeseriesresultvalue': a = TimeSeriesResultValueAnnotations - elif type == 'trajectoryresultvalue': + elif annottype == 'trajectoryresultvalue': a = TrajectoryResultValueAnnotations - elif type == 'transectresultvalue': + elif annottype == 'transectresultvalue': a = TransectResultValueAnnotations try: query = self._session.query(a) @@ -691,8 +697,8 @@ def getAffiliations(self, ids=None, personfirst=None, personlast=None, orgcode=N return None # Results - def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=None, simulationid=None, sfid=None, - variableid=None, siteid=None, sfids=None, sfuuids=None, sfcodes=None): + def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simulationid=None, + variableid=None, siteid=None, sfids=None, sfuuids=None, sfcodes=None, **kwargs): # TODO what if user sends in both type and actionid vs just actionid """Retrieve a list of Result objects. @@ -707,7 +713,6 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N uuids (list, optional): List of UUIDs string. actionid (int, optional): ActionID. simulationid (int, optional): SimulationID. - sfid (int, optional): SamplingFeatureID. variableid (int, optional): VariableID. siteid (int, optional): SiteID. - goes through related features table and finds all of results recorded at the given site @@ -732,11 +737,10 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N """ query = self._session.query(Results) - if type: - import warnings + if 'type' in kwargs: warnings.warn( - "The parameter 'type' is no longer be supported. Please use the restype parameter instead.") - query = query.filter_by(ResultTypeCV=type) + "The parameter 'type' is deprecated. Please use the restype parameter instead.") + restype = kwargs['type'] if restype: query = query.filter_by(ResultTypeCV=restype) if variableid: @@ -752,10 +756,9 @@ def getResults(self, ids=None, type=None, restype = None, uuids=None, actionid=N .filter_by(SimulationID=simulationid) if actionid: query = query.join(FeatureActions).filter_by(ActionID=actionid) - if sfid: - import warnings - warnings.warn("The parameter 'sfid' is no longer be supported. Please use the sfids parameter and send in a list.") - query = query.join(FeatureActions).filter_by(SamplingFeatureID=sfid) + if 'sfid' in kwargs: + warnings.warn("The parameter 'sfid' is deprecated. Please use the sfids parameter and send in a list.") + query = query.join(FeatureActions).filter_by(SamplingFeatureID=kwargs['sfid']) if sfids or sfcodes or sfuuids: sf_list = self.getSamplingFeatures(ids=sfids, codes=sfcodes, uuids=sfuuids) sfids = [] From b8224814427680d22f9a3f19560b42abe3ced2b2 Mon Sep 17 00:00:00 2001 From: lsetiawan Date: Fri, 5 Jan 2018 13:05:58 -0800 Subject: [PATCH 5/7] Fix the rest of the builtins, added warnings --- odm2api/ODM2/services/readService.py | 113 ++++++++++++++++++--------- 1 file changed, 74 insertions(+), 39 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 9f45793..7f8e694 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -171,8 +171,8 @@ def getAnnotations(self, annottype=None, codes=None, ids=None, **kwargs): # TODO What keywords do I use for type. a = Annotations if 'type' in kwargs: - warnings.warn( - "The parameter 'type' is deprecated. Please use the annottype parameter instead.") + warnings.warn('The parameter \'type\' is deprecated. Please use the annottype parameter instead.', + DeprecationWarning, stacklevel=2) annottype = kwargs['type'] if annottype: if annottype == 'action': @@ -398,7 +398,7 @@ def getVariables(self, ids=None, codes=None, sitecode=None, results=False): return None # Method - def getMethods(self, ids=None, codes=None, type=None): + def getMethods(self, ids=None, codes=None, medtype=None, **kwargs): """ * Pass nothing - returns full list of method objects * Pass a list of MethodIDs - returns a single method object for each given id @@ -406,13 +406,17 @@ def getMethods(self, ids=None, codes=None, type=None): * Pass a MethodType - returns a list of method objects of the given MethodType """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the medtype parameter instead.', + DeprecationWarning, stacklevel=2) + medtype = kwargs['type'] q = self._session.query(Methods) if ids: q = q.filter(Methods.MethodID.in_(ids)) if codes: q = q.filter(Methods.MethodCode.in_(codes)) - if type: - q = q.filter_by(MethodTypeCV=type) + if medtype: + q = q.filter_by(MethodTypeCV=medtype) try: return q.all() @@ -455,7 +459,8 @@ def getProcessingLevels(self, ids=None, codes=None): return None # Sampling Feature - def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=None, results=False): + def getSamplingFeatures(self, ids=None, codes=None, uuids=None, + sftype=None, wkt=None, results=False, **kwargs): """Retrieve a list of Sampling Feature objects. If no arguments are passed to the function, or their values are None, @@ -465,7 +470,7 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N ids (list, optional): List of SamplingFeatureIDs. codes (list, optional): List of SamplingFeature Codes. uuids (list, optional): List of UUIDs string. - type (str, optional): Type of Sampling Feature from + sftype (str, optional): Type of Sampling Feature from `controlled vocabulary name `_. wkt (str, optional): SamplingFeature Well Known Text. results (bool, optional): Whether or not you want to return only the @@ -486,6 +491,10 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N >>> READ.getSamplingFeatures(type='Site', results=True) """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the sftype parameter instead.', + DeprecationWarning, stacklevel=2) + sftype = kwargs['type'] if results: try: fas = [x[0] for x in self._session.query(distinct(Results.FeatureActionID)).all()] @@ -500,8 +509,8 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N q = self._session.query(SamplingFeatures) - if type: - q = q.filter_by(SamplingFeatureTypeCV=type) + if sftype: + q = q.filter_by(SamplingFeatureTypeCV=sftype) if ids: q = q.filter(SamplingFeatures.SamplingFeatureID.in_(ids)) if codes: @@ -548,7 +557,7 @@ def getRelatedSamplingFeatures(self, sfid=None, rfid=None, relationshiptype=None # Action - def getActions(self, ids=None, type=None, sfid=None): + def getActions(self, ids=None, acttype=None, sfid=None, **kwargs): """ * Pass nothing - returns a list of all Actions * Pass a list of Action ids - returns a list of Action objects @@ -557,12 +566,16 @@ def getActions(self, ids=None, type=None, sfid=None): associated with that Sampling feature ID, Found through featureAction table """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the acttype parameter instead.', + DeprecationWarning, stacklevel=2) + acttype = kwargs['type'] a = Actions - if type == 'equipment': + if acttype == 'equipment': a = EquipmentActions - elif type == 'calibration': + elif acttype == 'calibration': a = CalibrationActions - elif type == 'maintenance': + elif acttype == 'maintenance': a = MaintenanceActions q = self._session.query(a) @@ -594,7 +607,7 @@ def getRelatedActions(self, actionid=None): return None # Unit - def getUnits(self, ids=None, name=None, type=None): + def getUnits(self, ids=None, name=None, unittype=None, **kwargs): """ * Pass nothing - returns a list of all units objects * Pass a list of UnitsID - returns a single units object for the given id @@ -602,13 +615,17 @@ def getUnits(self, ids=None, name=None, type=None): * Pass a type- returns a list of all objects of the given type """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the unittype parameter instead.', + DeprecationWarning, stacklevel=2) + unittype = kwargs['type'] q = self._session.query(Units) if ids: q = q.filter(Units.UnitsID.in_(ids)) if name: q = q.filter(Units.UnitsName.ilike(name)) - if type: - q = q.filter(Units.UnitsTypeCV.ilike(type)) + if unittype: + q = q.filter(Units.UnitsTypeCV.ilike(unittype)) try: return q.all() except Exception as e: @@ -738,8 +755,8 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula query = self._session.query(Results) if 'type' in kwargs: - warnings.warn( - "The parameter 'type' is deprecated. Please use the restype parameter instead.") + warnings.warn('The parameter \'type\' is deprecated. Please use the restype parameter instead.', + DeprecationWarning, stacklevel=2) restype = kwargs['type'] if restype: query = query.filter_by(ResultTypeCV=restype) @@ -757,7 +774,9 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula if actionid: query = query.join(FeatureActions).filter_by(ActionID=actionid) if 'sfid' in kwargs: - warnings.warn("The parameter 'sfid' is deprecated. Please use the sfids parameter and send in a list.") + warnings.warn('The parameter \'sfid\' is deprecated. ' + 'Please use the sfids parameter instead and send in a list.', + DeprecationWarning, stacklevel=2) query = query.join(FeatureActions).filter_by(SamplingFeatureID=kwargs['sfid']) if sfids or sfcodes or sfuuids: sf_list = self.getSamplingFeatures(ids=sfids, codes=sfcodes, uuids=sfuuids) @@ -1024,7 +1043,7 @@ def getResultsDataQuality(self): # TODO Equipment Schema Queries # Equipment - def getEquipment(self, codes=None, type=None, sfid=None, actionid=None): + def getEquipment(self, codes=None, equiptype=None, sfid=None, actionid=None, **kwargs): """ * Pass nothing - returns a list of all Equipment objects * Pass a list of EquipmentCodes- return a list of all Equipment objects that match each of the codes @@ -1033,6 +1052,10 @@ def getEquipment(self, codes=None, type=None, sfid=None, actionid=None): * Pass an ActionID - returns a single Equipment object """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the equiptype parameter instead.', + DeprecationWarning, stacklevel=2) + equiptype = kwargs['type'] e = self._session.query(Equipment) if sfid: e = e.join(EquipmentUsed) \ @@ -1121,25 +1144,29 @@ def RelatedEquipment(self, code=None): return r.all() # Extension Properties - def getExtensionProperties(self, type=None): + def getExtensionProperties(self, exptype=None, **kwargs): """ * Pass nothing - return a list of all objects * Pass type- return a list of all objects of the given type """ # Todo what values to use for extensionproperties type + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the exptype parameter instead.', + DeprecationWarning, stacklevel=2) + exptype = kwargs['type'] e = ExtensionProperties - if type == 'action': + if exptype == 'action': e = ActionExtensionPropertyValues - elif type == 'citation': + elif exptype == 'citation': e = CitationExtensionPropertyValues - elif type == 'method': + elif exptype == 'method': e = MethodExtensionPropertyValues - elif type == 'result': + elif exptype == 'result': e = ResultExtensionPropertyValues - elif type == 'samplingfeature': + elif exptype == 'samplingfeature': e = SamplingFeatureExtensionPropertyValues - elif type == 'variable': + elif exptype == 'variable': e = VariableExtensionPropertyValues try: return self._session.query(e).all() @@ -1148,28 +1175,32 @@ def getExtensionProperties(self, type=None): return None # External Identifiers - def getExternalIdentifiers(self, type=None): + def getExternalIdentifiers(self, eitype=None, **kwargs): """ * Pass nothing - return a list of all objects * Pass type- return a list of all objects of the given type """ + if 'type' in kwargs: + warnings.warn('The parameter \'type\' is deprecated. Please use the eitype parameter instead.', + DeprecationWarning, stacklevel=2) + eitype = kwargs['type'] e = ExternalIdentifierSystems - if type.lowercase == 'citation': + if eitype.lowercase == 'citation': e = CitationExternalIdentifiers - elif type == 'method': + elif eitype == 'method': e = MethodExternalIdentifiers - elif type == 'person': + elif eitype == 'person': e = PersonExternalIdentifiers - elif type == 'referencematerial': + elif eitype == 'referencematerial': e = ReferenceMaterialExternalIdentifiers - elif type == 'samplingfeature': + elif eitype == 'samplingfeature': e = SamplingFeatureExternalIdentifiers - elif type == 'spatialreference': + elif eitype == 'spatialreference': e = SpatialReferenceExternalIdentifiers - elif type == 'taxonomicclassifier': + elif eitype == 'taxonomicclassifier': e = TaxonomicClassifierExternalIdentifiers - elif type == 'variable': + elif eitype == 'variable': e = VariableExternalIdentifiers try: return self._session.query(e).all() @@ -1394,16 +1425,20 @@ def getModels(self, codes=None): print('Error running Query: {}'.format(e)) return None - def getRelatedModels(self, id=None, code=None): + def getRelatedModels(self, modid=None, code=None, **kwargs): """ getRelatedModels(self, id=None, code=None) * Pass a ModelID - get a list of converter objects related to the converter having ModelID * Pass a ModelCode - get a list of converter objects related to the converter having ModeCode """ + if 'id' in kwargs: + warnings.warn('The parameter \'id\' is deprecated. Please use the modid parameter instead.', + DeprecationWarning, stacklevel=2) + modid = kwargs['type'] m = self._session.query(Models).select_from(RelatedModels).join(RelatedModels.ModelObj) - if id: - m = m.filter(RelatedModels.ModelID == id) + if modid: + m = m.filter(RelatedModels.ModelID == modid) if code: m = m.filter(Models.ModelCode == code) From 005f4233736c79f7fc9a6bb6c9e62fe64e1240c6 Mon Sep 17 00:00:00 2001 From: lsetiawan Date: Fri, 5 Jan 2018 13:15:37 -0800 Subject: [PATCH 6/7] Fix mistype --- odm2api/ODM2/services/readService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index 7f8e694..e7450c7 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -1435,7 +1435,7 @@ def getRelatedModels(self, modid=None, code=None, **kwargs): if 'id' in kwargs: warnings.warn('The parameter \'id\' is deprecated. Please use the modid parameter instead.', DeprecationWarning, stacklevel=2) - modid = kwargs['type'] + modid = kwargs['id'] m = self._session.query(Models).select_from(RelatedModels).join(RelatedModels.ModelObj) if modid: m = m.filter(RelatedModels.ModelID == modid) From 335254173ff63af893ae7f008b8ca65921e0d9fa Mon Sep 17 00:00:00 2001 From: lsetiawan Date: Fri, 5 Jan 2018 14:35:57 -0800 Subject: [PATCH 7/7] Add kwargs checking, show warnings for unexpected --- odm2api/ODM2/services/readService.py | 33 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index e7450c7..f5fca82 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -139,6 +139,19 @@ def _get_columns(self, model): return dict(columns) + def _check_kwargs(self, args, kwargs): + """Internal helper function to check for unused keyword arguments + + Args: + args (list): List of expected, valid arguments. + kwargs (dict): Dictionary of keyword arguments from user + Returns: + None + """ + invkwd = filter(lambda x: x not in args, kwargs.keys()) + if invkwd: + warnings.warn('Got unexpected keyword argument(s) {}'.format(','.join(invkwd)), stacklevel=2) + # Exists functions def resultExists(self, result): """ @@ -170,6 +183,7 @@ def getAnnotations(self, annottype=None, codes=None, ids=None, **kwargs): """ # TODO What keywords do I use for type. a = Annotations + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the annottype parameter instead.', DeprecationWarning, stacklevel=2) @@ -398,7 +412,7 @@ def getVariables(self, ids=None, codes=None, sitecode=None, results=False): return None # Method - def getMethods(self, ids=None, codes=None, medtype=None, **kwargs): + def getMethods(self, ids=None, codes=None, methodtype=None, **kwargs): """ * Pass nothing - returns full list of method objects * Pass a list of MethodIDs - returns a single method object for each given id @@ -406,17 +420,19 @@ def getMethods(self, ids=None, codes=None, medtype=None, **kwargs): * Pass a MethodType - returns a list of method objects of the given MethodType """ + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the medtype parameter instead.', DeprecationWarning, stacklevel=2) - medtype = kwargs['type'] + methodtype = kwargs['type'] + q = self._session.query(Methods) if ids: q = q.filter(Methods.MethodID.in_(ids)) if codes: q = q.filter(Methods.MethodCode.in_(codes)) - if medtype: - q = q.filter_by(MethodTypeCV=medtype) + if methodtype: + q = q.filter_by(MethodTypeCV=methodtype) try: return q.all() @@ -491,6 +507,7 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, >>> READ.getSamplingFeatures(type='Site', results=True) """ + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the sftype parameter instead.', DeprecationWarning, stacklevel=2) @@ -566,6 +583,7 @@ def getActions(self, ids=None, acttype=None, sfid=None, **kwargs): associated with that Sampling feature ID, Found through featureAction table """ + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the acttype parameter instead.', DeprecationWarning, stacklevel=2) @@ -615,6 +633,7 @@ def getUnits(self, ids=None, name=None, unittype=None, **kwargs): * Pass a type- returns a list of all objects of the given type """ + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the unittype parameter instead.', DeprecationWarning, stacklevel=2) @@ -753,7 +772,7 @@ def getResults(self, ids=None, restype = None, uuids=None, actionid=None, simula """ query = self._session.query(Results) - + self._check_kwargs(['type', 'sfid'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the restype parameter instead.', DeprecationWarning, stacklevel=2) @@ -1052,6 +1071,7 @@ def getEquipment(self, codes=None, equiptype=None, sfid=None, actionid=None, **k * Pass an ActionID - returns a single Equipment object """ + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the equiptype parameter instead.', DeprecationWarning, stacklevel=2) @@ -1151,6 +1171,7 @@ def getExtensionProperties(self, exptype=None, **kwargs): """ # Todo what values to use for extensionproperties type + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the exptype parameter instead.', DeprecationWarning, stacklevel=2) @@ -1181,6 +1202,7 @@ def getExternalIdentifiers(self, eitype=None, **kwargs): * Pass type- return a list of all objects of the given type """ + self._check_kwargs(['type'], kwargs) if 'type' in kwargs: warnings.warn('The parameter \'type\' is deprecated. Please use the eitype parameter instead.', DeprecationWarning, stacklevel=2) @@ -1432,6 +1454,7 @@ def getRelatedModels(self, modid=None, code=None, **kwargs): * Pass a ModelCode - get a list of converter objects related to the converter having ModeCode """ + self._check_kwargs(['id'], kwargs) if 'id' in kwargs: warnings.warn('The parameter \'id\' is deprecated. Please use the modid parameter instead.', DeprecationWarning, stacklevel=2)