Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Python Unified Device Interface
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WZL-IQS-Public
Sensor Interfacing Language (SOIL)
Python Unified Device Interface
Commits
d74eeabe
Commit
d74eeabe
authored
1 year ago
by
Matthias Stefan Bodenbenner
Browse files
Options
Downloads
Patches
Plain Diff
implemented resolving requests of profiles
parent
eebbf91f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/http/server.py
+14
-11
14 additions, 11 deletions
src/http/server.py
src/soil/component.py
+23
-0
23 additions, 0 deletions
src/soil/component.py
src/soil/element.py
+12
-0
12 additions, 0 deletions
src/soil/element.py
with
49 additions
and
11 deletions
src/http/server.py
+
14
−
11
View file @
d74eeabe
...
...
@@ -19,6 +19,7 @@ from ..soil.figure import Figure
from
..soil.function
import
Function
from
..soil.measurement
import
Measurement
from
..soil.parameter
import
Parameter
from
..soil.semantics
import
Semantics
from
..soil.stream
import
StreamScheduler
from
..utils
import
root_logger
from
..utils
import
serialize
...
...
@@ -125,9 +126,8 @@ class HTTPServer(object):
return
queried_attributes
def
prepare_response
(
self
,
body
:
Union
[
Dict
,
rdflib
.
Graph
],
element
:
Element
,
status
:
int
=
200
,
query
:
MultiDict
=
None
):
query
:
MultiDict
=
None
,
semantic
:
bool
=
False
):
dataformat
=
self
.
_dataformat
semantic
=
False
if
query
is
not
None
and
'
format
'
in
query
and
query
[
'
format
'
]
in
[
'
json
'
,
'
xml
'
,
'
turtle
'
]:
dataformat
=
query
[
'
format
'
]
if
query
is
not
None
and
'
semantic
'
in
query
and
query
[
'
semantic
'
]
in
[
'
data
'
,
'
metadata
'
,
'
profile
'
]:
...
...
@@ -171,6 +171,7 @@ class HTTPServer(object):
logger
.
info
(
"
GET Request from {}
"
.
format
(
request
.
url
))
logger
.
debug
(
'
Request: {}
'
.
format
(
request
))
logger
.
debug
(
'
Query Parameters: {}
'
.
format
(
request
.
query_string
))
splitted_request
=
HTTPServer
.
parse_uuids
(
request
)
keys
=
self
.
_filter_query
(
request
.
query
)
# determine whether a semantic answer is expected
...
...
@@ -178,9 +179,11 @@ class HTTPServer(object):
if
request
.
query
is
not
None
and
'
semantic
'
in
request
.
query
and
request
.
query
[
'
semantic
'
]
in
[
'
data
'
,
'
metadata
'
,
'
profile
'
]:
semantic
=
request
.
query
[
'
semantic
'
]
# retrieving the element
if
len
(
splitted_request
)
>
0
and
splitted_request
[
0
]
==
Semantics
.
prefix
:
item
,
semantic
=
self
.
root
.
resolve_semantic_path
(
splitted_request
[
1
:])
else
:
try
:
item
=
self
.
root
[
HTTPServer
.
parse_uuids
(
request
)
]
item
=
self
.
root
[
splitted_
request
]
except
KeyError
as
e
:
logger
.
error
(
traceback
.
format_exc
())
response
=
{
'
error
'
:
str
(
e
)}
...
...
@@ -200,7 +203,7 @@ class HTTPServer(object):
response
=
{
'
error
'
:
str
(
e
)}
status
=
500
logger
.
error
(
'
Response: {}
'
.
format
(
response
))
return
self
.
prepare_response
(
response
,
item
,
status
=
status
,
query
=
request
.
query
)
return
self
.
prepare_response
(
response
,
item
,
status
=
status
,
query
=
request
.
query
,
semantic
=
semantic
is
not
None
)
async
def
post
(
self
,
request
):
logger
.
info
(
"
POST Request from {}
"
.
format
(
request
.
url
))
...
...
This diff is collapsed.
Click to expand it.
src/soil/component.py
+
23
−
0
View file @
d74eeabe
...
...
@@ -393,3 +393,26 @@ class Component(Element):
else
:
raise
DeviceException
(
'
The provided kind of semantic information cannot be returned.
'
)
return
result
def
resolve_semantic_path
(
self
,
path
:
List
[
str
]):
if
len
(
path
)
==
0
:
raise
ChildNotFoundException
(
'
Could not resolve the semantic path.
'
)
# first try to resolve whether it is a path to a profile
if
path
[
0
]
==
f
'
{
self
.
_profilename
}
Shape
'
:
if
len
(
path
)
==
1
:
return
self
,
'
profile
'
else
:
for
child
in
self
.
children
:
try
:
return
child
.
resolve_semantic_path
(
path
)
except
ChildNotFoundException
:
continue
# TODO resolve data or metadata terms
raise
ChildNotFoundException
(
'
Could not resolve the semantic path.
'
)
This diff is collapsed.
Click to expand it.
src/soil/element.py
+
12
−
0
View file @
d74eeabe
...
...
@@ -5,6 +5,7 @@ from typing import Any, Dict, List
import
rdflib
from
.error
import
ChildNotFoundException
from
..utils.constants
import
BASE_UUID_PATTERN
,
HTTP_GET
from
..utils.error
import
SerialisationException
...
...
@@ -110,3 +111,14 @@ class Element(ABC):
@abstractmethod
def
serialize_semantics
(
self
,
kind
:
str
)
->
rdflib
.
Graph
:
...
def
resolve_semantic_path
(
self
,
path
:
List
[
str
])
->
(
'
Element
'
,
str
):
if
len
(
path
)
==
0
:
raise
ChildNotFoundException
(
'
Could not resolve the semantic path.
'
)
if
path
[
0
]
==
f
'
{
self
.
_profilename
}
Shape
'
and
len
(
path
)
==
1
:
return
self
,
'
profile
'
else
:
raise
ChildNotFoundException
(
'
Could not resolve the semantic path.
'
)
# TODO resolve data or metadata terms
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