Skip to content
Snippets Groups Projects
Commit 82a22b15 authored by Cornelia Michlits's avatar Cornelia Michlits
Browse files

#104 change respose messages

Former-commit-id: bb995377
parent bab0733b
No related branches found
No related tags found
1 merge request!42Fixed the query service tests
...@@ -40,13 +40,12 @@ def suggest(): ...@@ -40,13 +40,12 @@ def suggest():
try: try:
unit = str(input_json['ustring']) unit = str(input_json['ustring'])
offset = int(input_json['offset']) offset = int(input_json['offset'])
res = list_units(unit,offset) res = list_units(stringmapper(unit),offset)
return jsonify(res), 200 return jsonify(res), 200
except Exception as e: except Exception as e:
print(e) print(e)
#str(print_exc()) res = {"success": False, "message": str(e)}
res = {"success": False, "message": "Unknown error"+str(e)+unit} return jsonify(res), 500
return jsonify(res)
@app.route('/api/units/validate', methods=["POST"], endpoint='validate') @app.route('/api/units/validate', methods=["POST"], endpoint='validate')
@swag_from('validate.yml') @swag_from('validate.yml')
...@@ -55,9 +54,10 @@ def valitate(): ...@@ -55,9 +54,10 @@ def valitate():
try: try:
unit = str(input_json['ustring']) unit = str(input_json['ustring'])
res = validator(stringmapper(unit)) res = validator(stringmapper(unit))
return str(res), 200
except Exception as e: except Exception as e:
print(e) print(e)
res = {"success": False, "message": "Unknown error"+str(e)+unit} res = {"success": False, "message": str(e)}
return jsonify(res) return jsonify(res)
@app.route('/api/units/geturi', methods=["POST"], endpoint='geturi') @app.route('/api/units/geturi', methods=["POST"], endpoint='geturi')
...@@ -67,10 +67,11 @@ def geturi(): ...@@ -67,10 +67,11 @@ def geturi():
try: try:
name = str(input_json['uname']) name = str(input_json['uname'])
res = get_uri(name) res = get_uri(name)
return jsonify(res), 200
except Exception as e: except Exception as e:
print(e) print(e)
res = {"success": False, "message": "Unknown error"+str(e)+unit} res = {"success": False, "message": str(e)}
return jsonify(res) return jsonify(res), 500
rest_server_port = 5010 rest_server_port = 5010
eureka_client.init(eureka_server=os.getenv('EUREKA_SERVER', 'http://localhost:9090/eureka/'), eureka_client.init(eureka_server=os.getenv('EUREKA_SERVER', 'http://localhost:9090/eureka/'),
......
...@@ -18,14 +18,14 @@ rdf_schema = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#') ...@@ -18,14 +18,14 @@ rdf_schema = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#')
r={} r={}
def list_units(string,offset=0): def list_units(string,offset=0):
if bool(re.match('^[a-zA-Z0-9]+$',string)): if bool(re.match('^[a-zA-Z0-9\\s]+$',string)):
l_query = """ l_query = """
SELECT ?symbol ?name ?comment SELECT ?symbol ?name ?comment
WHERE { WHERE {
?unit om:symbol ?symbol . ?unit om:symbol ?symbol .
?unit <http://www.w3.org/2000/01/rdf-schema#label> ?name . ?unit <http://www.w3.org/2000/01/rdf-schema#label> ?name .
?unit <http://www.w3.org/2000/01/rdf-schema#comment> ?comment . ?unit <http://www.w3.org/2000/01/rdf-schema#comment> ?comment .
FILTER regex(str(?unit),\""""+string+"""\","i") FILTER (regex(str(?unit),\""""+string+"""\","i") && lang(?name)="en")
} LIMIT 10 OFFSET """+str(offset) } LIMIT 10 OFFSET """+str(offset)
qres = g.query(l_query) qres = g.query(l_query)
units = list() units = list()
......
...@@ -16,10 +16,10 @@ def validator(value): ...@@ -16,10 +16,10 @@ def validator(value):
#input str #input str
tmp = str(om)+value tmp = str(om)+value
t_uri = rdflib.term.URIRef(tmp) t_uri = rdflib.term.URIRef(tmp)
if next(g.triples((t_uri,None,om.Unit)), _exhausted) is _exhausted and next(g.triples((t_uri,None,om.PrefixedUnit)),_exhausted) is _exhausted and next(g.triples((t_uri,None,om.UnitDivision)),_exhausted) is _exhausted: if next(g.triples((t_uri,None,om.Unit)), _exhausted) is _exhausted and next(g.triples((t_uri,None,om.PrefixedUnit)),_exhausted) is _exhausted and next(g.triples((t_uri,None,None)),_exhausted) is _exhausted:
return {"valid": False} return False
else: else:
return {"valid": True} return True
def stringmapper(thisstring): def stringmapper(thisstring):
if ' ' in thisstring: if ' ' in thisstring:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment