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

#104 change respose messages

parent 16ebdf41
No related branches found
No related tags found
4 merge requests!81New stable release,!43Merge dev to master,!33Draft: merge dev to master,!32Add units-service to dev
......@@ -40,13 +40,12 @@ def suggest():
try:
unit = str(input_json['ustring'])
offset = int(input_json['offset'])
res = list_units(unit,offset)
res = list_units(stringmapper(unit),offset)
return jsonify(res), 200
except Exception as e:
print(e)
#str(print_exc())
res = {"success": False, "message": "Unknown error"+str(e)+unit}
return jsonify(res)
res = {"success": False, "message": str(e)}
return jsonify(res), 500
@app.route('/api/units/validate', methods=["POST"], endpoint='validate')
@swag_from('validate.yml')
......@@ -55,9 +54,10 @@ def valitate():
try:
unit = str(input_json['ustring'])
res = validator(stringmapper(unit))
return str(res), 200
except Exception as e:
print(e)
res = {"success": False, "message": "Unknown error"+str(e)+unit}
res = {"success": False, "message": str(e)}
return jsonify(res)
@app.route('/api/units/geturi', methods=["POST"], endpoint='geturi')
......@@ -67,10 +67,11 @@ def geturi():
try:
name = str(input_json['uname'])
res = get_uri(name)
return jsonify(res), 200
except Exception as e:
print(e)
res = {"success": False, "message": "Unknown error"+str(e)+unit}
return jsonify(res)
res = {"success": False, "message": str(e)}
return jsonify(res), 500
rest_server_port = 5010
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#')
r={}
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 = """
SELECT ?symbol ?name ?comment
WHERE {
?unit om:symbol ?symbol .
?unit <http://www.w3.org/2000/01/rdf-schema#label> ?name .
?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)
qres = g.query(l_query)
units = list()
......
......@@ -16,10 +16,10 @@ def validator(value):
#input str
tmp = str(om)+value
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:
return {"valid": False}
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 False
else:
return {"valid": True}
return True
def stringmapper(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