Exemplo n.º 1
0
    def get(self):
        """HTTP GET handler.

        """
        def _validate_criteria():
            """Validates url request params.

            """
            if len(self.drs_path.split(_DRS_SEPERATOR)) == 1:
                raise ValueError("A DRS path must contain at least one element")
            if len(self.drs_path.split(_DRS_SEPERATOR)) > _MAX_DRS_KEYS:
                msg = "A DRS path must consist of a maximum {0} keys"
                raise ValueError(msg.format(_MAX_DRS_KEYS))


        def _set_drs_keys():
            """Sets the DRS keys to be used to search db.

            """
            self.drs_keys = [i for i in self.drs_path.split(_DRS_SEPERATOR)
                             if len(i) and i.upper() != self.project.upper()]


        def _set_data():
            """Pulls data from db.

            """
            db.session.start(config.db)
            self.docs = db.dao.get_document_by_drs_keys(
              self.project,
              self.drs_keys[0] if len(self.drs_keys) > 0 else None,
              self.drs_keys[1] if len(self.drs_keys) > 1 else None,
              self.drs_keys[2] if len(self.drs_keys) > 2 else None,
              self.drs_keys[3] if len(self.drs_keys) > 3 else None,
              self.drs_keys[4] if len(self.drs_keys) > 4 else None,
              self.drs_keys[5] if len(self.drs_keys) > 5 else None,
              self.drs_keys[6] if len(self.drs_keys) > 6 else None,
              self.drs_keys[7] if len(self.drs_keys) > 7 else None
              )


        # Process request.
        process_request(self, [
            lambda: parse_params(self, _PARAMS),
            _validate_criteria,
            _set_drs_keys,
            _set_data,
            lambda: set_output(self, self.docs)
            ])
Exemplo n.º 2
0
    def get(self):
        """HTTP GET handler.

        """
        def _set_data():
            """Pulls data from db.

            """
            db.session.start(config.db)
            self.docs = db.dao.get_document(self.id, self.version, self.project)


        # Process request.
        process_request(self, [
            lambda: parse_params(self, _PARAMS),
            _set_data,
            lambda: set_output(self, self.docs)
            ])
Exemplo n.º 3
0
    def get(self):
        """HTTP GET handler.

        """
        def _validate_criteria():
            """Validates url request params.

            """
            # Set search manager.
            self.handler = utils.external_id.get(self.project, self.external_type)
            if not self.handler:
                raise ValueError("External ID type is unsupported.")

            # Validate external id.
            if not self.handler.is_valid(self.external_id):
                raise ValueError("Request parameter externalID: is invalid.")


        def _set_external_id():
            """Sets parsed external identifier.

            """
            self.external_id = self.handler.get_parsed(self.external_id)


        def _set_data():
            """Pulls data from db.

            """
            db.session.start(config.db)
            self.docs = self.handler.do_search(self.project, self.external_id)


        # Process request.
        process_request(self, [
            lambda: parse_params(self, _PARAMS),
            _validate_criteria,
            _set_external_id,
            _set_data,
            lambda: set_output(self, self.docs)
            ])