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
faa91428
Commit
faa91428
authored
Sep 24, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BusinessLogic] Additional Endpoint to retrieve all layers for a table
parent
f42805b4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
27 deletions
+65
-27
layer.py
...ub/semantic-linking-microservice/app/db/entities/layer.py
+3
-0
repository.py
...ta-hub/semantic-linking-microservice/app/db/repository.py
+4
-4
MessageHandler.py
...ntic-linking-microservice/app/messaging/MessageHandler.py
+11
-9
test_pipeline.py
.../semantic-linking-microservice/app/tests/test_pipeline.py
+10
-9
routes.yml
...on-hub/business-logic-microservice/app/configs/routes.yml
+28
-3
repository.py
...tion-hub/business-logic-microservice/app/db/repository.py
+6
-1
layer.py
...ation-hub/business-logic-microservice/app/routes/layer.py
+3
-1
No files found.
src/data-hub/semantic-linking-microservice/app/db/entities/layer.py
View file @
faa91428
...
...
@@ -20,6 +20,7 @@ class Layer:
"properties"
:
self
.
properties
,
"use_case"
:
self
.
use_case
,
"total_properties"
:
self
.
total_properties
,
"table"
:
self
.
table
}
@
staticmethod
...
...
@@ -29,11 +30,13 @@ class Layer:
layer
.
properties
=
layer_info
[
"cluster_properties"
]
layer
.
total_properties
=
layer_info
[
"properties"
]
layer
.
use_case
=
layer_info
[
"use_case"
]
layer
.
table
=
layer_info
[
"table"
]
return
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"
]
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 @
faa91428
...
...
@@ -33,8 +33,8 @@ class Repository(MongoRepositoryBase):
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
)
return
[
Layer
(
e
)
for
e
in
entries
]
def
get_layers_for_use_case
(
self
,
use_cas
e
:
str
)
->
List
[
Layer
]:
result
=
super
()
.
get_entries
(
self
.
_layer_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
})
def
get_layers_for_use_case
_and_table
(
self
,
use_case
:
str
,
tabl
e
:
str
)
->
List
[
Layer
]:
result
=
super
()
.
get_entries
(
self
.
_layer_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
,
"table"
:
table
})
return
[
Layer
(
e
)
for
e
in
result
]
def
get_layer
(
self
,
layer_name
)
->
Layer
:
...
...
@@ -57,9 +57,9 @@ class Repository(MongoRepositoryBase):
return
None
return
Layer
(
entries
[
0
])
if
len
(
entries
)
==
1
else
None
def
delete_layer
(
self
,
layer
_name
:
st
r
):
def
delete_layer
(
self
,
layer
:
Laye
r
):
collection
=
self
.
_database
[
self
.
_layer_collection
]
collection
.
delete_one
({
"layer_name"
:
layer
_nam
e
})
collection
.
delete_one
({
"layer_name"
:
layer
.
layer_name
,
"use_case"
:
layer
.
use_case
,
"table"
:
layer
.
tabl
e
})
def
delete_layers_for_use_case
(
self
,
use_case
:
str
):
collection
=
self
.
_database
[
self
.
_layer_collection
]
...
...
src/data-hub/semantic-linking-microservice/app/messaging/MessageHandler.py
View file @
faa91428
...
...
@@ -36,12 +36,12 @@ class MessageHandler:
else
:
LOGGER
.
info
(
"Message Type could not be processed"
)
def
_fetch_layer_information
(
self
,
use_case
:
str
)
->
List
[
Layer
]:
def
_fetch_layer_information
(
self
,
use_case
:
str
,
table
:
str
)
->
List
[
Layer
]:
# fetch token for authentication
jwt_token
=
TokenManager
.
getInstance
()
.
getToken
()
# query schema information
url
=
f
'https://{netconst.BUSINESS_LOGIC_HOSTNAME}:{netconst.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/layers'
url
=
f
'https://{netconst.BUSINESS_LOGIC_HOSTNAME}:{netconst.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/
tables/{table}/
layers'
response
=
requests
.
get
(
url
,
...
...
@@ -51,31 +51,32 @@ class MessageHandler:
)
if
response
.
status_code
!=
200
:
raise
ValueError
(
"no schema information available
"
)
raise
ValueError
(
f
"no schema information available {response.status_code}
"
)
layers
=
[
Layer
.
from_business_logic_dict
(
row
)
for
row
in
json
.
loads
(
response
.
text
)]
# update local DB, insert each layer that does not already exists
for
layer
in
layers
:
print
(
f
"Add layer to DB: {layer.to_serializable_dict(for_db=True)}"
)
self
.
_repository
.
delete_layer
(
layer
.
layer_name
)
self
.
_repository
.
delete_layer
(
layer
)
self
.
_repository
.
add_layer
(
layer
)
return
layers
def
handle_new_trace
(
self
,
content
:
Dict
):
if
"use_case"
not
in
content
.
keys
()
or
"id"
not
in
content
.
keys
()
or
"properties"
not
in
content
.
keys
():
LOGGER
.
error
(
f
"Missing fields in trace, required fields: (use_case, id, properties), given fields: ({content.keys()})"
)
if
"use_case"
not
in
content
.
keys
()
or
"id"
not
in
content
.
keys
()
or
"properties"
not
in
content
.
keys
()
or
"table"
not
in
content
.
keys
()
:
LOGGER
.
error
(
f
"Missing fields in trace, required fields: (use_case, id, properties
, table
), given fields: ({content.keys()})"
)
return
use_case
=
content
[
"use_case"
]
table
=
content
[
"table"
]
# fetch layer information
layers
=
self
.
_repository
.
get_layers_for_use_case
(
use_cas
e
)
layers
=
self
.
_repository
.
get_layers_for_use_case
_and_table
(
use_case
,
tabl
e
)
# if no local layers are found, fetch information from server
if
len
(
layers
)
==
0
:
layers
=
self
.
_fetch_layer_information
(
use_case
)
layers
=
self
.
_fetch_layer_information
(
use_case
,
table
)
nodes
=
[]
...
...
@@ -86,7 +87,8 @@ class MessageHandler:
node
[
prop
]
=
content
[
"properties"
][
prop
]
node
[
"layer_name"
]
=
layer
.
layer_name
node
[
"use_case"
]
=
use_case
node
[
"table"
]
=
layer
.
table
node
[
"use_case"
]
=
layer
.
use_case
nodes
.
append
(
node
)
self
.
_repository
.
add_layer_nodes
(
nodes
)
...
...
src/data-hub/semantic-linking-microservice/app/tests/test_pipeline.py
View file @
faa91428
...
...
@@ -25,15 +25,16 @@ class Test_Pipeline(unittest.TestCase):
return
{
"type"
:
"new-trace"
,
"content"
:
{
"use_case"
:
"debug"
,
"id"
:
"b38c916a73747abba1d01dbe11ee15714c90d42b23b8328cafc1667e60045e7b"
,
"properties"
:
{
"name"
:
"Margherita"
,
"dough"
:
False
,
"sauce"
:
"tomato"
,
"combined_name"
:
"Margheritawheat"
,
"UniqueID"
:
"b38c916a73747abba1d01dbe11ee15714c90d42b23b8328cafc1667e60045e7b"
,
"dough_type"
:
"wheat"
'use_case'
:
'debug'
,
'table'
:
'pizza'
,
'id'
:
'9e1e0983ada4e79de324a80b5f35f681c3e5016b08e1d6612c17892ade17e2c0'
,
'properties'
:
{
'UniqueID'
:
'9e1e0983ada4e79de324a80b5f35f681c3e5016b08e1d6612c17892ade17e2c0'
,
'cheese'
:
False
,
'dough'
:
'wheat'
,
'name'
:
'Margherita'
,
'sauce'
:
'tomato'
,
'sugar'
:
0.0
}
}
}
...
...
src/participation-hub/business-logic-microservice/app/configs/routes.yml
View file @
faa91428
...
...
@@ -136,7 +136,7 @@ paths:
description
:
"
Successful
Request"
'
400'
:
description
:
"
Table
with
the
name
already
exists
or
missing
fields
in
the
request."
/use-cases/{use_case}/table/{name}/mapping
:
/use-cases/{use_case}/table
s
/{name}/mapping
:
put
:
security
:
-
JwtRegular
:
[]
...
...
@@ -215,7 +215,32 @@ paths:
description
:
"
Successful
Request"
'
400'
:
description
:
"
Bad
structure
in
request
body
or
Layer
already
exists"
/use-cases/{use_case}/table/{table}/layers/{name}/cluster-mapping
:
/use-cases/{use_case}/tables/{table}/layers
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.get_layers_for_use_case_and_table"
tags
:
-
"
Layers"
summary
:
"
Retrieves
all
layers
belonging
to
the
given
Use-Case"
description
:
"
Retrieves
all
layers
belonging
to
the
given
Use-Case"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
table"
in
:
"
path"
description
:
"
Name
of
the
Table
the
Layer
belongs
to"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Use-Case
or
Table
do
not
exist"
/use-cases/{use_case}/tables/{table}/layers/{name}/cluster-mapping
:
put
:
security
:
-
JwtRegular
:
[]
...
...
@@ -318,7 +343,7 @@ paths:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Use-Case
does
not
exist"
/use-cases/{use_case}/table/{table}/layers/{name}
:
/use-cases/{use_case}/table
s
/{table}/layers/{name}
:
get
:
security
:
-
JwtRegular
:
[]
...
...
src/participation-hub/business-logic-microservice/app/db/repository.py
View file @
faa91428
...
...
@@ -24,11 +24,16 @@ class Repository(MongoRepositoryBase):
return
[
LayerAdapter
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
all_for_use_case
(
self
,
use_case
:
str
)
->
List
[
Dict
]:
def
all_for_use_case
(
self
,
use_case
:
str
)
->
List
[
LayerAdapter
]:
result
=
super
()
.
get_entries
(
self
.
_adapter_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
})
return
[
LayerAdapter
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
all_for_use_case_and_table
(
self
,
use_case
:
str
,
table
:
str
)
->
List
[
LayerAdapter
]:
result
=
super
()
.
get_entries
(
self
.
_adapter_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
,
"table"
:
table
})
return
[
LayerAdapter
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
one
(
self
,
name
:
str
,
use_case
:
str
,
table
:
str
)
->
LayerAdapter
:
result
=
list
(
super
()
.
get_entries
(
self
.
_adapter_collection
,
selection
=
{
"name"
:
name
,
"use_case"
:
use_case
,
"table"
:
table
}))
...
...
src/participation-hub/business-logic-microservice/app/routes/layer.py
View file @
faa91428
...
...
@@ -23,7 +23,6 @@ def delete_all_layers():
layer_repository
.
delete_all
()
return
Response
(
status
=
200
)
def
add_complete
():
'''
add a layer already containing attribute mappings to the BD.
...
...
@@ -224,3 +223,6 @@ def delete_one(use_case: str, table: str, name: str):
layer_repository
.
delete
(
layer
)
return
Response
(
status
=
200
)
def
get_layers_for_use_case_and_table
(
use_case
:
str
,
table
:
str
):
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all_for_use_case_and_table
(
use_case
,
table
)]
\ 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