Exemple #1
0
 def post(self, aligned_volume_name: str):
     """Create a new annotation table"""
     check_aligned_volume(aligned_volume_name)
     data = request.parsed_obj
     db = get_db(aligned_volume_name)
     metadata_dict = data.get("metadata")
     logging.info(metadata_dict)
     description = metadata_dict.get("description")
     if metadata_dict.get("user_id", None) is None:
         metadata_dict["user_id"] = str(g.auth_user["id"])
     if description is None:
         msg = "Table description required"
         abort(404, msg)
     else:
         table_name = data.get("table_name")
         headers = None
         if not table_name.islower():
             headers = {
                 "Warning":
                 f'201 - "Table name "{table_name}" needs to be lower case. Table will be posted to the database as "{table_name.lower()}"'
             }
             table_name = table_name.lower()
         schema_type = data.get("schema_type")
         table_name = table_name.lower().replace(" ", "_")
         try:
             table_info = db.create_annotation_table(
                 table_name, schema_type, **metadata_dict)
         except (TableAlreadyExists):
             abort(400, f"Table {table_name} already exists")
     return Response(table_info, headers=headers)
Exemple #2
0
    def delete(self, aligned_volume_name: str, table_name: str, **kwargs):
        """Delete annotations"""
        check_aligned_volume(aligned_volume_name)
        db = get_db(aligned_volume_name)
        metadata = db.get_table_metadata(table_name)
        if metadata["user_id"] != str(g.auth_user["id"]):
            resp = Response("Unauthorized: You did not create this table", 401)
            return resp
        data = request.parsed_obj

        ids = data.get("annotation_ids")

        db = get_db(aligned_volume_name)

        deleted_ids = db.delete_annotation(table_name, ids)

        if deleted_ids is None:
            return f"annotation_id {ids} not in table {table_name}", 404

        return deleted_ids, 200
Exemple #3
0
    def get(self, aligned_volume_name: str, table_name: str, **kwargs):
        """Get annotations by list of IDs"""
        check_aligned_volume(aligned_volume_name)
        args = annotation_parser.parse_args()

        annotation_ids = args["annotation_ids"]

        db = get_db(aligned_volume_name)

        annotations = db.get_annotations(table_name, annotation_ids)

        if annotations is None:
            msg = f"annotation_id {annotation_ids} not in {table_name}"
            abort(404, msg)

        return annotations, 200
Exemple #4
0
    def put(self, aligned_volume_name: str, table_name: str, **kwargs):
        """Update annotations"""
        check_aligned_volume(aligned_volume_name)
        db = get_db(aligned_volume_name)
        metadata = db.get_table_metadata(table_name)
        if metadata["user_id"] != str(g.auth_user["id"]):
            resp = Response("Unauthorized: You did not create this table", 401)
            return resp
        data = request.parsed_obj

        annotations = data.get("annotations")

        new_ids = []

        for annotation in annotations:
            updated_id = db.update_annotation(table_name, annotation)
            new_ids.append(updated_id)

        return new_ids, 200
Exemple #5
0
    def post(self, aligned_volume_name: str, table_name: str, **kwargs):
        """Insert annotations"""
        check_aligned_volume(aligned_volume_name)
        db = get_db(aligned_volume_name)
        metadata = db.get_table_metadata(table_name)
        if metadata["user_id"] != str(g.auth_user["id"]):
            resp = Response("Unauthorized: You did not create this table", 401)
            return resp
        data = request.parsed_obj
        annotations = data.get("annotations")

        try:
            inserted_ids = db.insert_annotations(table_name, annotations)
        except AnnotationInsertLimitExceeded as limit_error:
            logging.error(f"INSERT LIMIT EXCEEDED {limit_error}")
            abort(413, limit_error)
        except Exception as error:
            logging.error(f"INSERT FAILED {annotations}")
            abort(404, error)

        return inserted_ids, 200
Exemple #6
0
 def get(self, aligned_volume_name: str, table_name: str) -> int:
     """Get count of rows of an annotation table"""
     check_aligned_volume(aligned_volume_name)
     db = get_db(aligned_volume_name)
     return db.get_annotation_table_size(table_name), 200
Exemple #7
0
 def delete(self, aligned_volume_name: str, table_name: str) -> bool:
     """Delete an annotation table (marks for deletion, will suspend materialization, admin only)"""
     check_aligned_volume(aligned_volume_name)
     db = get_db(aligned_volume_name)
     is_deleted = db.delete_table(table_name)
     return is_deleted, 200
Exemple #8
0
 def get(self, aligned_volume_name: str,
         table_name: str) -> FullMetadataSchema:
     """Get metadata for a given table"""
     check_aligned_volume(aligned_volume_name)
     db = get_db(aligned_volume_name)
     return db.get_table_metadata(table_name), 200
Exemple #9
0
 def get(self, aligned_volume_name: str):
     """Get list of annotation tables for a aligned_volume"""
     check_aligned_volume(aligned_volume_name)
     db = get_db(aligned_volume_name)
     tables = db._get_existing_table_names()
     return tables, 200
Exemple #10
0
def test_create_db(app_config, mocker):
    with app_config.app_context():
        db = get_db("test_aligned_volume")
        logging.info(db.__dict__)
        assert db.__dict__["aligned_volume"] == "test_aligned_volume"