コード例 #1
0
    def get_objects(self, api_root, id_, filter_args, allowed_filters,
                    start_index, end_index):
        if api_root in self.data:
            api_info = self._get(api_root)
            collections = api_info.get("collections", [])

            objs = []
            for collection in collections:
                if "id" in collection and id_ == collection["id"]:

                    if filter_args:
                        full_filter = BasicFilter(filter_args)
                        objs.extend(
                            full_filter.process_filter(
                                collection.get("objects", []),
                                allowed_filters,
                                collection.get("manifest", []),
                            ), )
                    else:
                        objs.extend(collection.get("objects", []))

            count = len(objs)
            result = objs[start_index:end_index]

            return count, create_bundle(result)
コード例 #2
0
    def get_object(self, api_root, collection_id, object_id, filter_args,
                   allowed_filters):
        objects = self.get_objects_without_bundle(api_root, collection_id,
                                                  filter_args, allowed_filters)

        req_object = [i for i in objects if i['id'] == object_id]

        if len(req_object) == 1:
            return create_bundle(req_object)
コード例 #3
0
    def get_objects(self, api_root, collection_id, filter_args,
                    allowed_filters, start_index, end_index):
        # print('start_index: {}, end_index: {}'.format(start_index, end_index))

        objects = self.get_objects_without_bundle(api_root, collection_id,
                                                  filter_args, allowed_filters)

        objects.sort(key=lambda x: datetime.datetime.strptime(
            x['modified'], '%Y-%m-%dT%H:%M:%S.%fZ'))

        count = len(objects)

        objects = objects if end_index == -1 else objects[start_index:end_index]

        return count, create_bundle(objects)
コード例 #4
0
 def get_objects(self, api_root, id_, filter_args, allowed_filters):
     # TODO: Handle if mongodb is not available
     api_root_db = self.client[api_root]
     objects = api_root_db["objects"]
     full_filter = MongoDBFilter(filter_args, {"_collection_id": id_},
                                 allowed_filters)
     objects_found = full_filter.process_filter(
         objects, allowed_filters, {
             "mongodb_collection": api_root_db["manifests"],
             "_collection_id": id_
         })
     for obj in objects_found:
         if obj:
             obj.pop("_id", None)
             obj.pop("_collection_id", None)
     return create_bundle(objects_found)
コード例 #5
0
    def get_object(self, api_root, id_, object_id, filter_args,
                   allowed_filters):
        if api_root in self.data:
            api_info = self._get(api_root)
            collections = api_info.get("collections", [])

            objs = []
            for collection in collections:
                if "id" in collection and id_ == collection["id"]:
                    for obj in collection.get("objects", []):
                        if object_id == obj["id"]:
                            objs.append(obj)
                if filter_args:
                    full_filter = BasicFilter(filter_args)
                    objs = full_filter.process_filter(
                        objs, allowed_filters, collection.get("manifest", []))
            return create_bundle(objs)
コード例 #6
0
 def get_objects(self, api_root, id_, filter_args, allowed_filters):
     api_root_db = self.client[api_root]
     objects = api_root_db["objects"]
     full_filter = MongoDBFilter(filter_args, {"_collection_id": id_},
                                 allowed_filters)
     # Note: error handling was not added to following call as mongo will
     # handle (user supplied) filters gracefully if they don't exist
     objects_found = full_filter.process_filter(
         objects, allowed_filters, {
             "mongodb_collection": api_root_db["manifests"],
             "_collection_id": id_
         })
     for obj in objects_found:
         if obj:
             obj.pop("_id", None)
             obj.pop("_collection_id", None)
     return create_bundle(objects_found)
コード例 #7
0
    def get_objects(self, api_root, id_, filter_args, allowed_filters):
        if api_root in self.data:
            api_info = self._get(api_root)
            collections = api_info.get("collections", [])

            objs = []
            for collection in collections:
                if "id" in collection and id_ == collection["id"]:

                    if filter_args:
                        full_filter = BasicFilter(filter_args)
                        objs.extend(
                            full_filter.process_filter(
                                collection.get("objects", []), allowed_filters,
                                collection.get("manifest", [])))
                    else:
                        objs.extend(collection.get("objects", []))
            return create_bundle(objs)
コード例 #8
0
 def get_object(self, api_root, id_, object_id, filter_args,
                allowed_filters):
     api_root_db = self.client[api_root]
     objects = api_root_db["objects"]
     full_filter = MongoDBFilter(filter_args, {
         "_collection_id": id_,
         "id": object_id
     }, allowed_filters)
     count, objects_found = full_filter.process_filter(
         objects, allowed_filters, {
             "mongodb_collection": api_root_db["manifests"],
             "_collection_id": id_
         })
     if objects_found:
         for obj in objects_found:
             if obj:
                 obj.pop("_id", None)
                 obj.pop("_collection_id", None)
     return create_bundle(objects_found)