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
21e89a22
Commit
21e89a22
authored
Sep 01, 2020
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
404 if layers/nodes dont exist (
#11
)
parent
8296faab
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
35 deletions
+44
-35
swagger.yml
...hub/semantic-linking-microservice/app/configs/swagger.yml
+8
-2
swagger_local.yml
...mantic-linking-microservice/app/configs/swagger_local.yml
+8
-2
repository.py
...ta-hub/semantic-linking-microservice/app/db/repository.py
+13
-20
layers.py
...ta-hub/semantic-linking-microservice/app/routes/layers.py
+10
-10
nodes.py
...ata-hub/semantic-linking-microservice/app/routes/nodes.py
+5
-1
No files found.
src/data-hub/semantic-linking-microservice/app/configs/swagger.yml
View file @
21e89a22
...
...
@@ -60,6 +60,8 @@ paths:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/Node"
'
404'
:
description
:
"
No
nodes
found"
# endregion nodes
# Layers region
...
...
@@ -101,6 +103,8 @@ paths:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/Layer"
'
404'
:
description
:
"
Layer
not
found"
/use-cases/{use_case}/layers
:
get
:
...
...
@@ -109,7 +113,7 @@ paths:
operationId
:
"
routes.layers.get_by_use_case"
tags
:
-
"
Layers"
summary
:
"
Get
single
layer
data
"
summary
:
"
Get
all
layer
data
for
single
use
case
"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
...
...
@@ -120,7 +124,9 @@ paths:
'
200'
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/Layer"
$ref
:
"
#/definitions/LayerCollection"
'
404'
:
description
:
"
No
layers
found"
# endregion layers
definitions
:
...
...
src/data-hub/semantic-linking-microservice/app/configs/swagger_local.yml
View file @
21e89a22
...
...
@@ -52,6 +52,8 @@ paths:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/Node"
'
404'
:
description
:
"
No
nodes
found"
# endregion nodes
# Layers region
...
...
@@ -90,13 +92,15 @@ paths:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/Layer"
'
404'
:
description
:
"
Layer
not
found"
/use-cases/{use_case}/layers
:
get
:
operationId
:
"
routes.layers.get_by_use_case"
tags
:
-
"
Layers"
summary
:
"
Get
single
layer
data
"
summary
:
"
Get
all
layer
data
for
single
use
case
"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
...
...
@@ -107,7 +111,9 @@ paths:
'
200'
:
description
:
"
Successful
operation"
schema
:
$ref
:
"
#/definitions/Layer"
$ref
:
"
#/definitions/LayerCollection"
'
404'
:
description
:
"
No
layers
found"
# endregion layers
definitions
:
...
...
src/data-hub/semantic-linking-microservice/app/db/repository.py
View file @
21e89a22
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.layer
import
Layer
from
db.entities.raw_data
import
Raw_Dataset
from
db.entities
import
Layer
import
pymongo
import
json
from
typing
import
List
,
Dict
# init logging to file
import
logging
LOG_FORMAT
=
(
'
%(levelname) -5
s
%(asctime)
s
%(name)
s:
%(funcName) -35
s
%(lineno) -5
d:
%(message)
s'
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
LOG_FORMAT
)
LOGGER
=
logging
.
getLogger
(
__name__
)
class
Repository
(
MongoRepositoryBase
):
'''This is a repository for MongoDb.'''
...
...
@@ -14,27 +19,12 @@ class Repository(MongoRepositoryBase):
super
()
.
__init__
(
netconst
.
SEMANTIC_LINKING_DB_HOSTNAME
,
netconst
.
SEMANTIC_LINKING_DB_PORT
,
'semanticLinkingDb'
)
self
.
_raw_dataset
=
'raw_dataset'
self
.
_layer_collection
=
'layers'
self
.
_layer_nodes_collection
=
'layer_nodes'
self
.
_clusters_collection
=
'clusters'
self
.
_time_slice_collection
=
'time_slices'
#region Raw_data
def
add_raw_data
(
self
,
dataset
:
Raw_Dataset
):
super
()
.
insert_entry
(
self
.
_raw_dataset
,
dataset
.
to_serializable_dict
())
def
get_all_raw_data
(
self
)
->
List
[
Raw_Dataset
]:
entries
=
super
()
.
get_entries
(
self
.
_raw_dataset
)
return
[
Raw_Dataset
(
e
)
for
e
in
entries
]
def
get_raw_data
(
self
,
usecase_name
)
->
Raw_Dataset
:
entries
=
super
()
.
get_entries
(
self
.
_raw_dataset
,
selection
=
{
'usecase_name'
:
usecase_name
})
return
[
Raw_Dataset
(
e
)
for
e
in
entries
]
# end region
# region Layers
def
add_layer
(
self
,
layer
:
Layer
):
super
()
.
insert_entry
(
self
.
_layer_collection
,
layer
.
to_serializable_dict
(
for_db
=
True
))
...
...
@@ -50,7 +40,6 @@ class Repository(MongoRepositoryBase):
def
get_layer
(
self
,
layer_name
)
->
Layer
:
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
,
selection
=
{
'layer_name'
:
layer_name
})
entries
=
[
Layer
(
e
)
for
e
in
entries
]
if
entries
is
not
None
and
len
(
entries
)
>
0
:
return
entries
[
0
]
else
:
...
...
@@ -60,9 +49,13 @@ 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
)
->
L
ist
[
Layer
]
:
def
get_layers_by_name_and_use_case
(
self
,
layer_name
:
str
,
use_case
:
str
)
->
L
ayer
:
entries
=
super
()
.
get_entries
(
self
.
_layer_collection
,
selection
=
{
'layer_name'
:
layer_name
,
'use_case'
:
use_case
})
return
[
Layer
(
e
)
for
e
in
entries
]
entries
=
list
(
entries
)
# materialize
if
len
(
entries
)
>
1
:
LOGGER
.
error
(
f
"Use case + layer name was not unique for {use_case} and {layer_name}."
)
return
None
return
Layer
(
entries
[
0
])
if
len
(
entries
)
==
1
else
None
def
delete_layer
(
self
,
layer_name
:
str
):
collection
=
self
.
_database
[
self
.
_layer_collection
]
...
...
src/data-hub/semantic-linking-microservice/app/routes/layers.py
View file @
21e89a22
...
...
@@ -17,17 +17,17 @@ def get_by_name(name):
return
Response
(
status
=
404
)
def
get_by_name_and_use_case
(
name
:
str
,
use_case
:
str
):
return
[
layer
.
to_serializable_dict
()
for
layer
in
repo
.
get_layers_by_name_and_use_case
(
name
,
use_case
)]
res
=
repo
.
get_layers_by_name_and_use_case
(
name
,
use_case
)
if
res
is
not
None
:
return
res
.
to_serializable_dict
()
else
:
return
Response
(
status
=
404
)
def
get_by_use_case
(
use_case
:
str
):
return
[
layer
.
to_serializable_dict
()
for
layer
in
repo
.
get_layers_by_use_case
(
use_case
)]
res
=
[
layer
.
to_serializable_dict
()
for
layer
in
repo
.
get_layers_by_use_case
(
use_case
)]
if
res
is
not
None
and
len
(
res
)
>
0
:
return
res
else
:
return
Response
(
status
=
404
)
#endregion
#region nodes
def
get_nodes
(
name
):
res
=
repo
.
get_layer_nodes
(
name
)
# print(res)
return
res
#endregion nodes
\ No newline at end of file
src/data-hub/semantic-linking-microservice/app/routes/nodes.py
View file @
21e89a22
...
...
@@ -9,4 +9,8 @@ repo = Repository()
#region nodes
def
nodes_for_use_case_and_layer
(
layer_name
:
str
,
use_case
:
str
)
->
List
[
Dict
]:
return
repo
.
get_layer_nodes_with_use_case
(
layer_name
,
use_case
)
\ No newline at end of file
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
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