def download_studies(self):
        ret_data, retcode = self.study_api_instance.download_studies(
            user=self._user, auths=self._auths)
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=ret_data, status=retcode))

        return ret_data
    def update_study(self, study_code, study_detail):
        ret_data, retcode = self.study_api_instance.update_study(
            study_code, study_detail, user=self._user, auths=self._auths)
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=ret_data, status=retcode))

        return ret_data
    def delete_sampling_event(self, sampling_event_id):

        ret, retcode = self.se_api_instance.delete_sampling_event(
            sampling_event_id, user=self._user, auths=self._auths)

        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=ret, status=retcode))
    def get_country_metadata(self, country_value):
        metadata, retcode = self.metadata_api_instance.get_country_metadata(
            country_value, user=self._user, auths=self._auths)

        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=metadata, status=retcode))

        return metadata
    def create_sampling_event(self, sampling_event):

        created, retcode = self.se_api_instance.create_sampling_event(
            sampling_event, user=self._user, auths=self._auths)

        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=f'"{created}"\n', status=retcode))

        return created
    def download_sampling_event(self, sampling_event_id):

        existing, retcode = self.se_api_instance.download_sampling_event(
            sampling_event_id, user=self._user, auths=self._auths)

        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=existing, status=retcode))

        return existing
    def download_partner_location(self, partner_name):

        ret, retcode = self.location_api_instance.download_partner_location(
            partner_name, user=self._user, auths=self._auths)

        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=ret, status=retcode))

        return ret
    def update_location(self, location_id, location):

        updated, retcode = self.location_api_instance.update_location(
            location_id, location, user=self._user, auths=self._auths)

        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=updated, status=retcode))

        return updated
    def merge_individuals(self, individual_id1, individual_id2):

        found_events, retcode = self.i_api_instance.merge_individuals(
            individual_id1, individual_id2, user=self._user, auths=self._auths)

        self._logger.debug("PUT /v1/individual/{}/{} {}".format(
            individual_id1, individual_id2, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def download_sampling_events_by_location(self, location_id):

        found_events, retcode = self.se_api_instance.download_sampling_events_by_location(
            location_id, start=0, count=0, user=self._user, auths=self._auths)

        self._logger.debug("GET /v1/samplingEvents/location/{} {}".format(
            location_id, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def download_individual(self, individual_id):

        found_events, retcode = self.i_api_instance.download_individual(
            individual_id, user=self._user, auths=self._auths)

        self._logger.debug("GET /v1/individual/{} {}".format(
            individual_id, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def download_location(self, location_id):

        ret, retcode = self.location_api_instance.download_location(
            location_id, user=self._user, auths=self._auths)

        self._logger.debug("GET /v1/location/{} {}".format(
            location_id, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=ret, status=retcode))

        return ret
    def delete_assay_datum(self, assay_datum_id):

        found_events, retcode = self.ad_api_instance.delete_assay_datum(
            assay_datum_id, user=self._user, auths=self._auths)

        self._logger.debug("DELETE /v1/derivativeSample/{}  {}".format(
            assay_datum_id, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def create_individual(self, individual):

        found_events, retcode = self.i_api_instance.create_individual(
            individual, user=self._user, auths=self._auths)

        self._logger.debug("POST /v1/individual {} {}".format(
            individual, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def download_derivative_sample(self, derivative_sample_id):

        found_events, retcode = self.ds_api_instance.download_derivative_sample(
            derivative_sample_id, user=self._user, auths=self._auths)

        self._logger.debug("GET /v1/derivativeSample/{}  {}".format(
            derivative_sample_id, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def delete_original_sample(self, original_sample_id):

        found_events, retcode = self.os_api_instance.delete_original_sample(
            original_sample_id, user=self._user, auths=self._auths)

        self._logger.debug("DELETE /v1/originalSample/{}  {}".format(
            original_sample_id, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def delete_event_set(self, event_set_id):

        api_response, retcode = self.es_api_instance.delete_event_set(
            event_set_id, user=self._user, auths=self._auths)

        if retcode >= 400:
            if retcode != 422:  # Already exists
                self._logger.debug(
                    "Exception when calling EventSetApi->delete_event_set: \n")
                raise ApiException(
                    http_resp=HTTPResponse(body=api_response, status=retcode))

        return api_response
    def update_sampling_event(self, sampling_event_id, sampling_event):
        ret, retcode = self.se_api_instance.update_sampling_event(
            sampling_event_id,
            sampling_event,
            user=self._user,
            auths=self._auths)

        self._logger.debug("POST /v1/samplingEvent/{} {}".format(
            sampling_event_id, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=f'"{ret}"\n', status=retcode))

        return ret
    def merge_sampling_events(self, sampling_event_id1, sampling_event_id2):
        ret, retcode = self.se_api_instance.merge_sampling_events(
            sampling_event_id1,
            sampling_event_id2,
            user=self._user,
            auths=self._auths)

        self._logger.debug("PUT /v1/samplingEvent/merge/{}/{} {}".format(
            sampling_event_id1, sampling_event_id2, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=ret, status=retcode))

        return ret
    def merge_original_samples(self, original_sample_id1, original_sample_id2):

        found_events, retcode = self.os_api_instance.merge_original_samples(
            original_sample_id1,
            original_sample_id2,
            user=self._user,
            auths=self._auths)

        self._logger.debug("PUT /v1/originalSample/{}/{} {}".format(
            original_sample_id1, original_sample_id2, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def download_sampling_events_by_study(self,
                                          study_name,
                                          start=None,
                                          count=None):

        found_events, retcode = self.se_api_instance.download_sampling_events_by_study(
            study_name, start, count, user=self._user, auths=self._auths)

        self._logger.debug("GET /v1/samplingEvents/study/{} {}".format(
            study_name, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def download_assay_data_by_attr(self, attr_type, attr_value):

        found_events, retcode = self.ad_api_instance.download_assay_data_by_attr(
            attr_type,
            urllib.parse.quote_plus(attr_value),
            user=self._user,
            auths=self._auths)

        self._logger.debug("GET /v1/derivativeSamples/attr/{}/{} {}".format(
            attr_type, attr_value, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def merge_derivative_samples(self, derivative_sample_id1,
                                 derivative_sample_id2):

        found_events, retcode = self.ds_api_instance.merge_derivative_samples(
            derivative_sample_id1,
            derivative_sample_id2,
            user=self._user,
            auths=self._auths)

        self._logger.debug("PUT /v1/derivativeSample/merge/{}/{} {}".format(
            derivative_sample_id1, derivative_sample_id2, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
    def download_individuals_by_attr(self, prop_name, prop_value, study_name):

        found_events, retcode = self.i_api_instance.download_individuals_by_attr(
            prop_name,
            urllib.parse.quote_plus(prop_value),
            study_name,
            user=self._user,
            auths=self._auths)

        self._logger.debug("GET /v1/individuals/attr/{}/{} {}".format(
            prop_name, prop_value, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events
示例#25
0
    def create_response(self, ret, retcode, response_type=None):

        if retcode >= 400:
            raise ApiException(status=retcode, reason='')

        if ret and response_type:
            if isinstance(ret, Model):
                response_dict = ret.to_dict()
            else:
                response_dict = ret

            resp_data = json.dumps(response_dict,
                                   ensure_ascii=False,
                                   cls=JSONEncoder)
            mr = MockResponse(resp_data, retcode)
            response = RESTResponse(mr)
            ret = self.api_client.deserialize(response, response_type)

        return ret
    def download_sampling_events_by_event_set(self,
                                              event_set_name,
                                              start=None,
                                              count=None):

        found_events, retcode = self.se_api_instance.download_sampling_events_by_event_set(
            urllib.parse.quote_plus(event_set_name),
            start,
            count,
            user=self._user,
            auths=self._auths)

        self._logger.debug("GET /v1/samplingEvents/event_set/{} {}".format(
            event_set_name, retcode))
        if retcode >= 400:
            raise ApiException(
                http_resp=HTTPResponse(body=found_events, status=retcode))

        return found_events