Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
553c2da8
Commit
553c2da8
authored
Sep 24, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SemanticLinking] changed MessageHandler to work with tables
parent
faa91428
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
21 deletions
+139
-21
routes.yml
...-hub/semantic-linking-microservice/app/configs/routes.yml
+90
-7
layer.py
...ub/semantic-linking-microservice/app/db/entities/layer.py
+6
-1
repository.py
...ta-hub/semantic-linking-microservice/app/db/repository.py
+18
-4
MessageHandler.py
...ntic-linking-microservice/app/messaging/MessageHandler.py
+7
-1
layers.py
...ta-hub/semantic-linking-microservice/app/routes/layers.py
+5
-2
nodes.py
...ata-hub/semantic-linking-microservice/app/routes/nodes.py
+13
-6
No files found.
src/data-hub/semantic-linking-microservice/app/configs/routes.yml
View file @
553c2da8
...
...
@@ -19,11 +19,11 @@ paths:
description
:
"
Successful
echo
of
request
data"
# nodes region
/use-cases/{use_case}/
layers/{layer_name}/
nodes
:
/use-cases/{use_case}/nodes
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.nodes.nodes_for_use_case
_and_layer
"
operationId
:
"
routes.nodes.nodes_for_use_case"
tags
:
-
"
Nodes"
summary
:
"
Get
all
nodes
for
a
Layer"
...
...
@@ -33,6 +33,54 @@ paths:
description
:
"
Name
of
the
requested
Use-Case"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/NodeCollection"
/use-cases/{use_case}/tables/{table_name}/nodes
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.nodes.nodes_for_use_case_and_table"
tags
:
-
"
Nodes"
summary
:
"
Get
all
nodes
for
a
Layer"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
requested
Use-Case"
required
:
true
type
:
"
string"
-
name
:
"
table_name"
in
:
"
path"
description
:
"
Name
of
Table
the
layer
belongs
to"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/NodeCollection"
/use-cases/{use_case}/tables/{table_name}/layers/{layer_name}/nodes
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.nodes.nodes_for_use_case_and_table_and_layer"
tags
:
-
"
Nodes"
summary
:
"
Get
all
nodes
for
a
Layer"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
requested
Use-Case"
required
:
true
type
:
"
string"
-
name
:
"
table_name"
in
:
"
path"
description
:
"
Name
of
Table
the
layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
layer_name"
in
:
"
path"
description
:
"
Name
of
the
requested
Layer"
...
...
@@ -42,9 +90,7 @@ paths:
'
200'
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/Node"
'
404'
:
description
:
"
No
nodes
found"
$ref
:
"
#/definitions/NodeCollection"
# endregion nodes
# Layers region
...
...
@@ -61,12 +107,38 @@ paths:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/LayerCollection"
/use-cases/{use_case}/tables/{table_name}/layers
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layers.get_by_use_case_and_table"
tags
:
-
"
Layers"
summary
:
"
Get
single
layer
data"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
requested
Use-Case"
required
:
true
type
:
"
string"
-
name
:
"
table_name"
in
:
"
path"
description
:
"
Name
of
Table
the
Layer
belongs
to"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/LayerCollection"
/use-cases/{use_case}/layers/{name}
:
/use-cases/{use_case}/
tables/{table_name}/
layers/{name}
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layers.get_by_name_and_use_case"
operationId
:
"
routes.layers.get_by_name_and_use_case
_and_table
"
tags
:
-
"
Layers"
summary
:
"
Get
single
layer
data"
...
...
@@ -76,6 +148,11 @@ paths:
description
:
"
Name
of
the
requested
Use-Case"
required
:
true
type
:
"
string"
-
name
:
"
table_name"
in
:
"
path"
description
:
"
Name
of
Table
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
requested
layer"
...
...
@@ -138,6 +215,8 @@ definitions:
properties
:
use_case
:
type
:
string
table
:
type
:
string
layer_name
:
type
:
string
properties
:
...
...
@@ -148,6 +227,10 @@ definitions:
type
:
array
items
:
type
:
string
NodeCollection
:
type
:
array
items
:
$ref
:
"
#/definitions/Node"
LayerCollection
:
type
:
array
items
:
...
...
src/data-hub/semantic-linking-microservice/app/db/entities/layer.py
View file @
553c2da8
...
...
@@ -36,7 +36,12 @@ class Layer:
def
from_serializable_dict
(
self
,
layer_info
:
Dict
,
from_db
=
False
):
self
.
layer_name
=
layer_info
[
'layer_name'
]
self
.
properties
=
layer_info
[
'properties'
]
self
.
table
=
layer_info
[
"table"
]
if
"table"
in
layer_info
.
keys
():
self
.
table
=
layer_info
[
"table"
]
else
:
self
.
table
=
"Unknown"
self
.
use_case
=
layer_info
[
"use_case"
]
if
"use_case"
in
layer_info
.
keys
()
else
None
self
.
total_properties
=
layer_info
[
"total_properties"
]
if
"total_properties"
in
layer_info
.
keys
()
else
None
...
...
src/data-hub/semantic-linking-microservice/app/db/repository.py
View file @
553c2da8
...
...
@@ -49,8 +49,11 @@ class Repository(MongoRepositoryBase):
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
,
selection
=
{
'use_case'
:
use_case
})
return
[
Layer
(
e
)
for
e
in
entries
]
def
get_layers_by_name_and_use_case
(
self
,
layer_name
:
str
,
use_case
:
str
)
->
Layer
:
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
,
selection
=
{
'layer_name'
:
layer_name
,
'use_case'
:
use_case
})
def
get_layers_use_case_and_table
(
self
,
use_case
:
str
,
table
:
str
)
->
Layer
:
return
[
Layer
(
e
)
for
e
in
list
(
super
()
.
get_entries
(
self
.
_layer_collection
,
selection
=
{
'use_case'
:
use_case
,
'table'
:
table
}))]
def
get_layers_by_name_and_use_case_and_table
(
self
,
layer_name
:
str
,
use_case
:
str
,
table
:
str
)
->
Layer
:
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
,
selection
=
{
'layer_name'
:
layer_name
,
'use_case'
:
use_case
,
'table'
:
table
})
entries
=
list
(
entries
)
# materialize
if
len
(
entries
)
>
1
:
LOGGER
.
error
(
f
"Use case + layer name was not unique for {use_case} and {layer_name}."
)
...
...
@@ -77,9 +80,20 @@ class Repository(MongoRepositoryBase):
projection
=
{
'_id'
:
0
})
return
[
e
for
e
in
entries
]
def
get_layer_nodes_with_use_case
(
self
,
layer_name
:
str
,
use_case
:
str
)
->
List
[
Dict
]:
def
get_nodes_for_use_case
(
self
,
use_case
:
str
)
->
List
[
Dict
]:
entries
=
super
()
.
get_entries
(
self
.
_layer_nodes_collection
,
selection
=
{
'use_case'
:
use_case
},
projection
=
{
'_id'
:
0
})
return
list
(
entries
)
def
get_nodes_for_use_case_and_table
(
self
,
use_case
:
str
,
table
:
str
)
->
List
[
Dict
]:
'''Returns all nodes for the layer.'''
entries
=
super
()
.
get_entries
(
self
.
_layer_nodes_collection
,
selection
=
{
'use_case'
:
use_case
,
'table'
:
table
},
projection
=
{
'_id'
:
0
})
return
list
(
entries
)
def
get_nodes_for_use_case_and_table_and_layer
(
self
,
layer_name
:
str
,
use_case
:
str
,
table
:
str
)
->
List
[
Dict
]:
'''Returns all nodes for the layer.'''
entries
=
super
()
.
get_entries
(
self
.
_layer_nodes_collection
,
selection
=
{
'layer_name'
:
layer_name
,
'use_case'
:
use_case
},
entries
=
super
()
.
get_entries
(
self
.
_layer_nodes_collection
,
selection
=
{
'layer_name'
:
layer_name
,
'use_case'
:
use_case
,
'table'
:
table
},
projection
=
{
'_id'
:
0
})
return
list
(
entries
)
...
...
src/data-hub/semantic-linking-microservice/app/messaging/MessageHandler.py
View file @
553c2da8
...
...
@@ -78,6 +78,11 @@ class MessageHandler:
if
len
(
layers
)
==
0
:
layers
=
self
.
_fetch_layer_information
(
use_case
,
table
)
# if there are no layers, abort
if
len
(
layers
)
==
0
:
LOGGER
.
warning
(
f
"No layers available for '{use_case}'.'{table}', ignoring trace."
)
return
nodes
=
[]
for
layer
in
layers
:
...
...
@@ -91,7 +96,8 @@ class MessageHandler:
node
[
"use_case"
]
=
layer
.
use_case
nodes
.
append
(
node
)
self
.
_repository
.
add_layer_nodes
(
nodes
)
if
len
(
nodes
)
>
0
:
self
.
_repository
.
add_layer_nodes
(
nodes
)
def
handle_new_traces_available
(
self
):
# get all traces and call the Processor
...
...
src/data-hub/semantic-linking-microservice/app/routes/layers.py
View file @
553c2da8
...
...
@@ -16,8 +16,11 @@ def get_by_name(name):
else
:
return
Response
(
status
=
404
)
def
get_by_name_and_use_case
(
name
:
str
,
use_case
:
str
):
res
=
repo
.
get_layers_by_name_and_use_case
(
name
,
use_case
)
def
get_by_use_case_and_table
(
use_case
:
str
,
table_name
:
str
):
return
[
layer
.
to_serializable_dict
()
for
layer
in
repo
.
get_layers_use_case_and_table
(
use_case
,
table_name
)]
def
get_by_name_and_use_case_and_table
(
name
:
str
,
use_case
:
str
,
table_name
:
str
):
res
=
repo
.
get_layers_by_name_and_use_case_and_table
(
name
,
use_case
,
table_name
)
if
res
is
not
None
:
return
res
.
to_serializable_dict
()
else
:
...
...
src/data-hub/semantic-linking-microservice/app/routes/nodes.py
View file @
553c2da8
...
...
@@ -8,9 +8,16 @@ repo = Repository()
#region nodes
def
nodes_for_use_case_and_layer
(
layer_name
:
str
,
use_case
:
str
)
->
List
[
Dict
]:
res
=
repo
.
get_layer_nodes_with_use_case
(
layer_name
,
use_case
)
if
res
is
not
None
and
len
(
res
)
>
0
:
return
res
else
:
return
Response
(
status
=
404
)
\ No newline at end of file
def
nodes_for_use_case
(
use_case
:
str
)
->
List
[
Dict
]:
res
=
repo
.
get_nodes_for_use_case
(
use_case
)
return
res
def
nodes_for_use_case_and_table
(
use_case
:
str
,
table_name
:
str
)
->
List
[
Dict
]:
res
=
repo
.
get_nodes_for_use_case_and_table
(
use_case
,
table_name
)
return
res
def
nodes_for_use_case_and_table_and_layer
(
layer_name
:
str
,
use_case
:
str
,
table_name
:
str
)
->
List
[
Dict
]:
res
=
repo
.
get_nodes_for_use_case_and_table_and_layer
(
layer_name
,
use_case
,
table_name
)
return
res
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment