diff --git a/fda-units-service/app.py b/fda-units-service/app.py index 58cd365190edacf5745d2b690e54d5e2b5542be9..06460a4ff24f46aec81180a03d72fe09eefe9a54 100644 --- a/fda-units-service/app.py +++ b/fda-units-service/app.py @@ -87,7 +87,7 @@ def validate(unit): except Exception as e: logging.error(e) res = {"success": False, "message": str(e)} - return jsonify(res) + return jsonify(res), 500 @app.route('/api/units/uri/<uname>', methods=["GET"], endpoint='uri') @@ -141,7 +141,7 @@ def save_column_concept(): res = {"success": False, "message": str(e)} return jsonify(res), 500 -@app.route('/api/units/getconcept/<cname>', methods=["GET"], endpoint='get_concept') +@app.route('/api/ontologies/getconcept/<cname>', methods=["GET"], endpoint='get_concept') @swag_from('getconcept.yml') def get_concept(cname): logging.debug('endpoint get concept, cname=%s, body=%s', cname, request) @@ -156,33 +156,33 @@ def get_concept(cname): ONTOLOGIES_DIRECTORY = 'ontologies' -@app.route('/api/ontologies', methods=["POST"], endpoint='upload_onto') -@swag_from('ontologie.yml') +@app.route('/api/ontology', methods=["POST"], endpoint='upload_onto') +@swag_from('ontologies.yml') def post_ontologies(): if 'file' not in request.files: return "no file", 500 file = request.files['file'] if file.filename == '': - return "no file selected", 500 + return "no file selected", 400 if file and allowed_file(file.filename): filename = secure_filename(file.filename) if ontology_exists(Path(filename).stem): - return "ontology name already exists", 500 + return "ontology name already exists", 409 setup_ontology_dir() file.save(os.path.join(ONTOLOGIES_DIRECTORY, filename)) logging.debug('created ontology: %s', filename) - return "created", 200 + return "created", 201 @app.route('/api/ontologies', methods=["GET"], endpoint='get_ontos') -@swag_from('ontologies.yml') +@swag_from('ontology.yml') def get_ontologies(): print(list_ontologies()) return jsonify(list_ontologies()) -@app.route('/api/ontologies/<name>', methods=["GET"], endpoint='get_onto') -@swag_from('ontologie.yml') -def get_ontologies(name): - ontology = get_ontology(name) +@app.route('/api/ontologies/<o_name>', methods=["GET"], endpoint='get_onto') +@swag_from('ontologybyname.yml') +def get_ontologies(o_name): + ontology = get_ontology(o_name) if ontology is None: return "ontology does not exist", 404 return ontology diff --git a/fda-units-service/onto_feat.py b/fda-units-service/onto_feat.py index 8b13d7cd5e95b033c6a44d4157ee29f4d7f87fd2..5fb56a70d7193d9f7129d4cd616f2d3867d74439 100644 --- a/fda-units-service/onto_feat.py +++ b/fda-units-service/onto_feat.py @@ -3,6 +3,7 @@ import glob import sys import os from pathlib import Path +import rdflib ALLOWED_EXTENSIONS = {'ttl', 'nt'} diff --git a/fda-units-service/us-yml/getconcept.yml b/fda-units-service/us-yml/getconcept.yml index 6def46d690bc053059242fe57259363bd2659bde..1a2e13c2645766c9a6e08cbc2deeac0b8a8bddc1 100644 --- a/fda-units-service/us-yml/getconcept.yml +++ b/fda-units-service/us-yml/getconcept.yml @@ -8,7 +8,7 @@ parameters: - in: "path" type: "string" name: "cname" - description: "Enter a table name or attribute name.ยด" + description: "Enter a concept name." required: true responses: 200: diff --git a/fda-units-service/us-yml/ontologie.yml b/fda-units-service/us-yml/ontologie.yml deleted file mode 100644 index 3e5edc56014eede029262bb9be7481d5e21bd206..0000000000000000000000000000000000000000 --- a/fda-units-service/us-yml/ontologie.yml +++ /dev/null @@ -1,18 +0,0 @@ -summary: "Get ontology" -description: "This is a simple API for getting ontologies (.nt, .ttl files) used in DB-Repo." -consumes: -- "application/json" -produces: -- "application/json" -parameters: -- name: file - required: false - in: formData - type: file -responses: - 200: - description: "OK" - 201: - description: "Created" - 405: - description: "Invalid input" \ No newline at end of file diff --git a/fda-units-service/us-yml/ontologies.yml b/fda-units-service/us-yml/ontologies.yml index 348024df3b1b283eaad118947f6879e075dda7ae..2934080935f4d9e268032df872f1c04765cc235b 100644 --- a/fda-units-service/us-yml/ontologies.yml +++ b/fda-units-service/us-yml/ontologies.yml @@ -1,11 +1,22 @@ -summary: "Get list of ontologies" -description: "This is a simple API for getting the list of all ontologies contained in DB-Repo." +summary: "Post / Upload ontology" +description: "This is a simple API for posting ontologies (.nt, .ttl files) to DB-Repo." consumes: - "application/json" produces: - "application/json" +parameters: +- name: file + required: false + in: formData + type: file responses: 200: description: "OK" + 201: + description: "Created" + 400: + description: "Bad request" 405: - description: "Invalid input" \ No newline at end of file + description: "Invalid input" + 409: + description: "Conflict" \ No newline at end of file diff --git a/fda-units-service/us-yml/ontology.yml b/fda-units-service/us-yml/ontology.yml new file mode 100644 index 0000000000000000000000000000000000000000..2ea5c02e4c2bea0c231d287f84f138cca8502a20 --- /dev/null +++ b/fda-units-service/us-yml/ontology.yml @@ -0,0 +1,11 @@ +summary: "Get ontology" +description: "This is a simple API for listing all ontologies (.nt, .ttl files) used in DB-Repo." +consumes: +- "application/json" +produces: +- "application/json" +responses: + 200: + description: "OK" + 405: + description: "Invalid input" \ No newline at end of file diff --git a/fda-units-service/us-yml/ontologybyname.yml b/fda-units-service/us-yml/ontologybyname.yml new file mode 100644 index 0000000000000000000000000000000000000000..ccccc3fee93622b2f06d76f73b92417ace91d7dc --- /dev/null +++ b/fda-units-service/us-yml/ontologybyname.yml @@ -0,0 +1,19 @@ +summary: "Get ontology" +description: "This is a simple API for getting a certain ontologies (.nt, .ttl files) stored in DB-Repo." +consumes: +- "application/json" +produces: +- "application/json" +parameters: + - name: o_name + in: path + required: true + type: string + default: "VOCAB_QUDT-UNITS-ALL-v2.1" +responses: + 200: + description: "OK" + 404: + description: "Not found" + 405: + description: "Invalid input" diff --git a/fda-units-service/us-yml/suggest.yml b/fda-units-service/us-yml/suggest.yml index b47a657ae9b0c886a4c6161d5e194623d9ef2027..62696fe99cb48a7cb7316e300d3f64cb5ca45e62 100644 --- a/fda-units-service/us-yml/suggest.yml +++ b/fda-units-service/us-yml/suggest.yml @@ -7,7 +7,7 @@ produces: parameters: - in: "body" name: "body" - description: "to-do description" + description: "Json containing ustring, i.e., string of a unit, and an offset." required: true schema: type: "object" diff --git a/fda-units-service/us-yml/validate.yml b/fda-units-service/us-yml/validate.yml index 01cbb337c1a66d5356e99214c4ca59215fc00f5f..81ac877ead7042278df387b467dcb8aaa2a0992d 100644 --- a/fda-units-service/us-yml/validate.yml +++ b/fda-units-service/us-yml/validate.yml @@ -8,7 +8,7 @@ parameters: - in: "path" type: "string" name: "unit" - description: "to-do description" + description: "Validates unit against om-2." required: true responses: 200: