Exemplo n.º 1
0
    def index(self, trans, limit=500, offset=0, history_id=None, **kwd):
        """
        GET /api/datasets/

        Search datasets or collections using a query system

        :rtype:     list
        :returns:   dictionaries containing summary of dataset or dataset_collection information

        The list returned can be filtered by using two optional parameters:

            :q:
                string, generally a property name to filter by followed
                by an (often optional) hyphen and operator string.

            :qv:

                string, the value to filter by

        ..example::

            To filter the list to only those created after 2015-01-29,
            the query string would look like:
                '?q=create_time-gt&qv=2015-01-29'

            Multiple filters can be sent in using multiple q/qv pairs:
                '?q=create_time-gt&qv=2015-01-29&q=name-contains&qv=experiment-1'

        The list returned can be paginated using two optional parameters:
            limit:  integer, defaults to no value and no limit (return all)
                    how many items to return
            offset: integer, defaults to 0 and starts at the beginning
                    skip the first ( offset - 1 ) items and begin returning
                    at the Nth item

        ..example:
            limit and offset can be combined. Skip the first two and return five:
                '?limit=5&offset=3'

        The list returned can be ordered using the optional parameter:
            order:  string containing one of the valid ordering attributes followed
                    (optionally) by '-asc' or '-dsc' (default) for ascending and descending
                    order respectively. Orders can be stacked as a comma-
                    separated list of values.
                    Allowed ordering attributes are: 'create_time', 'extension',
                    'hid', 'history_id', 'name', 'update_time'.
                    'order' defaults to 'create_time'.

        ..example:
            To sort by name descending then create time descending:
                '?order=name-dsc,create_time'

        """
        serialization_params = parse_serialization_params(**kwd)
        filter_parameters = FilterQueryParams(**kwd)
        filter_parameters.limit = filter_parameters.limit or limit
        filter_parameters.offset = filter_parameters.offset or offset
        return self.service.index(trans, history_id, serialization_params,
                                  filter_parameters)
Exemplo n.º 2
0
def get_filter_query_params(
    q: Optional[List[str]] = Query(
        default=None,
        title="Filter Query",
        description=
        "Generally a property name to filter by followed by an (often optional) hyphen and operator string.",
        example="create_time-gt",
    ),
    qv: Optional[List[str]] = Query(
        default=None,
        title="Filter Value",
        description="The value to filter by.",
        example="2015-01-29",
    ),
    offset: Optional[int] = Query(
        default=0,
        ge=0,
        title="Offset",
        description=
        "Starts at the beginning skip the first ( offset - 1 ) items and begin returning at the Nth item",
    ),
    limit: Optional[int] = Query(
        default=None,
        ge=1,
        title="Limit",
        description="The maximum number of items to return.",
    ),
    order: Optional[str] = Query(
        default=None,
        title="Order",
        description=
        ("String containing one of the valid ordering attributes followed (optionally) "
         "by '-asc' or '-dsc' for ascending and descending order respectively. "
         "Orders can be stacked as a comma-separated list of values."),
        example="name-dsc,create_time",
    ),
) -> FilterQueryParams:
    """
    This function is meant to be used as a Dependency.
    See https://fastapi.tiangolo.com/tutorial/dependencies/#first-steps
    """
    return FilterQueryParams(
        q=q,
        qv=qv,
        offset=offset,
        limit=limit,
        order=order,
    )
Exemplo n.º 3
0
    def build_filter_params(
        self,
        query_params: FilterQueryParams,
        filter_attr_key: str = 'q',
        filter_value_key: str = 'qv',
        attr_op_split_char: str = '-',
    ) -> List[Tuple[str, str, str]]:
        """
        Builds a list of tuples containing filtering information in the form of (attribute, operator, value).
        """
        DEFAULT_OP = 'eq'
        qdict = query_params.dict(exclude_defaults=True)
        if filter_attr_key not in qdict:
            return []
        # precondition: attrs/value pairs are in-order in the qstring
        attrs = qdict.get(filter_attr_key)
        if not isinstance(attrs, list):
            attrs = [attrs]
        # ops are strings placed after the attr strings and separated by a split char (e.g. 'create_time-lt')
        # ops are optional and default to 'eq'
        reparsed_attrs = []
        ops = []
        for attr in attrs:
            op = DEFAULT_OP
            if attr_op_split_char in attr:
                # note: only split the last (e.g. q=community-tags-in&qv=rna yields ( 'community-tags', 'in', 'rna' )
                attr, op = attr.rsplit(attr_op_split_char, 1)
            ops.append(op)
            reparsed_attrs.append(attr)
        attrs = reparsed_attrs

        values = qdict.get(filter_value_key, [])
        if not isinstance(values, list):
            values = [values]
        # TODO: it may be more helpful to the consumer if we error on incomplete 3-tuples
        #   (instead of relying on zip to shorten)
        return list(zip(attrs, ops, values))
Exemplo n.º 4
0
    def index(self, trans, history_id, **kwd):
        """
        GET /api/histories/{history_id}/contents

        return a list of HDA data for the history with the given ``id``

        .. note:: Anonymous users are allowed to get their current history contents

        If Ids is not given, index returns a list of *summary* objects for
        every HDA associated with the given `history_id`.

        If ids is given, index returns a *more complete* json object for each
        HDA in the ids list.

        :type   history_id: str
        :param  history_id: encoded id string of the HDA's History
        :type   ids:        str
        :param  ids:        (optional) a comma separated list of encoded `HDA` ids
        :param  types:      (optional) kinds of contents to index (currently just
                            dataset, but dataset_collection will be added shortly).
        :type   types:      str

        :rtype:     list
        :returns:   dictionaries containing summary or detailed HDA information
        """
        index_params = parse_index_query_params(**kwd)
        legacy_params = parse_legacy_index_query_params(**kwd)
        # Sometimes the `v=dev` version is called with `details` or `dataset_details`
        index_params.dataset_details = index_params.dataset_details or legacy_params.dataset_details
        serialization_params = parse_serialization_params(**kwd)
        filter_parameters = FilterQueryParams(**kwd)
        return self.service.index(
            trans, history_id,
            index_params,
            legacy_params,
            serialization_params, filter_parameters
        )
Exemplo n.º 5
0
    def archive(self, trans, history_id, filename='', format='zip', dry_run=True, **kwd):
        """
        archive( self, trans, history_id, filename='', format='zip', dry_run=True, **kwd )
        * GET /api/histories/{history_id}/contents/archive/{id}
        * GET /api/histories/{history_id}/contents/archive/{filename}.{format}
            build and return a compressed archive of the selected history contents

        :type   filename:  string
        :param  filename:  (optional) archive name (defaults to history name)
        :type   dry_run:   boolean
        :param  dry_run:   (optional) if True, return the archive and file paths only
                           as json and not an archive file

        :returns:   archive file for download

        .. note:: this is a volatile endpoint and settings and behavior may change.
        """
        dry_run = util.string_as_bool(dry_run)
        filter_parameters = FilterQueryParams(**kwd)
        archive = self.service.archive(trans, history_id, filter_parameters, filename, dry_run)
        if not isinstance(archive, HistoryContentsArchiveDryRunResult):
            trans.response.headers.update(archive.get_headers())
            return archive.response()
        return archive