Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DBRepo
Manage
Activity
Members
Labels
Plan
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FAIR Data Austria DB Repository
DBRepo
Commits
82a22b15
Commit
82a22b15
authored
Dec 7, 2021
by
Cornelia Michlits
Browse files
Options
Downloads
Patches
Plain Diff
#104 change respose messages
Former-commit-id:
bb995377
parent
bab0733b
No related branches found
No related tags found
1 merge request
!42
Fixed the query service tests
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
fda-units-service/app.py
+10
-9
10 additions, 9 deletions
fda-units-service/app.py
fda-units-service/list.py
+2
-2
2 additions, 2 deletions
fda-units-service/list.py
fda-units-service/validate.py
+3
-3
3 additions, 3 deletions
fda-units-service/validate.py
with
15 additions
and
14 deletions
fda-units-service/app.py
+
10
−
9
View file @
82a22b15
...
@@ -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/
'
),
...
...
This diff is collapsed.
Click to expand it.
fda-units-service/list.py
+
2
−
2
View file @
82a22b15
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
fda-units-service/validate.py
+
3
−
3
View file @
82a22b15
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment