コード例 #1
0
    def _build_ds_query(self, discovery_query, id_only=True):
        query_exp = discovery_query["query"] or {}
        index = query_exp.get("index", "resources_index")
        ds_name = DATASTORE_MAP.get(index, None)
        ds_profile = PROFILE_MAP.get(ds_name, None)
        # TODO: Enable service defined indexes in addition to standard indexes
        if ds_name is None:
            raise BadRequest("Unknown index: %s" % index)
        limit = discovery_query.get("limit", 0)
        skip = discovery_query.get("skip", 0)
        order = discovery_query.get("order", None)

        qb = DatastoreQueryBuilder(limit=limit, skip=skip, id_only=id_only, profile=ds_profile)
        where = None
        for qm in self._qmatchers:
            where = qm(discovery_query, qb)
            if where:
                break
        if where is None:
            raise BadRequest("Query had no matcher")

        if index == "data_products_index":
            filter_types = ["DataProduct", "DataProcess", "Deployment", "InstrumentDevice", "InstrumentModel",
                            "InstrumentAgentInstance", "InstrumentAgent", "PlatformDevice", "PlatformModel",
                            "PlatformAgentInstance", "PlatformAgent", "PlatformSite", "Observatory", "UserRole",
                            "Org", "Attachment", "ExternalDatasetAgent", "ExternalDatasetAgentInstance",
                            "Asset", "EventDuration"]
            where = qb.and_(where, qb.in_(DQ.ATT_TYPE, *filter_types), qb.neq(DQ.RA_LCSTATE, "DELETED"))

        order_by = None
        if order:
            order_list = []
            if type(order) is dict:
                for col, colsort in order.iteritems():
                    order_list.append((col, colsort))
            elif type(order) in (list, tuple):
                for column in order:
                    if type(column) in (list, tuple):
                        col, colsort = column
                    else:
                        col, colsort = column, "asc"
                    order_list.append((col, colsort))
            order_by = qb.order_by(order_list)

        qb.build_query(where=where, order_by=order_by)
        return qb.get_query(), ds_name
コード例 #2
0
    def _build_ds_query(self, discovery_query, id_only=True):
        query_exp = discovery_query["query"] or {}
        index = query_exp.get("index", "resources_index")
        ds_name = DATASTORE_MAP.get(index, None)
        ds_profile = PROFILE_MAP.get(ds_name, None)
        # TODO: Enable service defined indexes in addition to standard indexes
        if ds_name is None:
            raise BadRequest("Unknown index: %s" % index)
        limit = discovery_query.get("limit", 0)
        skip = discovery_query.get("skip", 0)
        order = discovery_query.get("order", None)

        qb = DatastoreQueryBuilder(limit=limit,
                                   skip=skip,
                                   id_only=id_only,
                                   profile=ds_profile)
        where = None
        for qm in self._qmatchers:
            where = qm(discovery_query, qb)
            if where:
                break
        if where is None:
            raise BadRequest("Query had no matcher")

        order_by = None
        if order:
            order_list = []
            if type(order) is dict:
                for col, colsort in order.iteritems():
                    order_list.append((col, colsort))
            elif type(order) in (list, tuple):
                for column in order:
                    if type(column) in (list, tuple):
                        col, colsort = column
                    else:
                        col, colsort = column, "asc"
                    order_list.append((col, colsort))
            order_by = qb.order_by(order_list)

        qb.build_query(where=where, order_by=order_by)
        return qb.get_query(), ds_name
コード例 #3
0
ファイル: ds_discovery.py プロジェクト: edwardhunter/scioncc
    def _build_ds_query(self, discovery_query, id_only=True):
        query_exp = discovery_query["query"] or {}
        index = query_exp.get("index", "resources_index")
        ds_name = DATASTORE_MAP.get(index, None)
        ds_profile = PROFILE_MAP.get(ds_name, None)
        # TODO: Enable service defined indexes in addition to standard indexes
        if ds_name is None:
            raise BadRequest("Unknown index: %s" % index)
        limit = discovery_query.get("limit", 0)
        skip = discovery_query.get("skip", 0)
        order = discovery_query.get("order", None)

        qb = DatastoreQueryBuilder(limit=limit, skip=skip, id_only=id_only, profile=ds_profile)
        where = None
        for qm in self._qmatchers:
            where = qm(discovery_query, qb)
            if where:
                break
        if where is None:
            raise BadRequest("Query had no matcher")

        order_by = None
        if order:
            order_list = []
            if type(order) is dict:
                for col, colsort in order.iteritems():
                    order_list.append((col, colsort))
            elif type(order) in (list, tuple):
                for column in order:
                    if type(column) in (list, tuple):
                        col, colsort = column
                    else:
                        col, colsort = column, "asc"
                    order_list.append((col, colsort))
            order_by = qb.order_by(order_list)

        qb.build_query(where=where, order_by=order_by)
        return qb.get_query(), ds_name