def create_collection_items( user: InternalUserDTO, collection_uuid: UUID, items: List[ItemDTO], replace: bool = False, ) -> List[ItemDTO]: collection = Collection.find_writeable_or_fail(user, collection_uuid) if replace: Item.where(collection_uuid=collection.uuid).delete() new_items: List[Item] = [ Item(**{ **item.to_dict(), **{ "uuid": uuid4() } }) for item in items ] Item.session.bulk_save_objects(new_items) Item.session.commit() uuids = [] for item in new_items: if isinstance(item.uuid, str): uuids.append(UUID(item.uuid)) else: uuids.append(item.uuid) fetched_items = Item.find_writeable(user, uuids) return to_models(fetched_items, ItemDTO)
def get_series_metrics(user: InternalUserDTO, series_uuid: UUID, filter_params: dict) -> List[MetricDTO]: series = Series.find_or_fail(series_uuid) Item.find_readable_or_fail(user, series.item_uuid) metrics_dtos = Metric.find_by_series_uuid(series.uuid, filter_params) metrics = [Metric(**m.to_dict()) for m in metrics_dtos] return to_models(metrics, MetricDTO)
def update_items(user: InternalUserDTO, items_update: List[ItemDTO]) -> List[ItemDTO]: items = Item.find_writeable(user, [item.uuid for item in items_update]) for item in items: item_new = [ item_new for item_new in items_update if str(item_new.uuid) == str(item.uuid) ][0] item.properties = item_new.properties item.geometry = item_new.geometry item.save() Item.session.commit() return to_models(items, ItemDTO)
def get_users() -> List[UserDTO]: return to_models(User.all(), UserDTO)
def get_providers() -> List[ProviderDTO]: providers = Provider.all() return to_models(providers, ProviderDTO)
def get_item_series(user: InternalUserDTO, item_uuid: UUID) -> List[SeriesDTO]: Item.find_readable_or_fail(user, item_uuid) series_dtos = Series.find_by_item_uuid(item_uuid) series = [Series(**s.to_dict()) for s in series_dtos] return to_models(series, SeriesDTO)
def get_all_accessable_collections(user: InternalUserDTO) -> List[CollectionDTO]: collections = Collection.find_readable(user) return to_models(collections, CollectionDTO)
def get_all_readable_acls(user: InternalUserDTO) -> List[ACLDTO]: acls = ACL.find_accessable(user) return to_models(acls, ACLDTO)