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
fd78b68b
Commit
fd78b68b
authored
Sep 24, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BusinessLogic] expanded 'Schema' to 'Table'
parent
bc4462e8
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
435 additions
and
504 deletions
+435
-504
routes.yml
...on-hub/business-logic-microservice/app/configs/routes.yml
+184
-171
layer_adapter.py
...iness-logic-microservice/app/db/entities/layer_adapter.py
+5
-2
schema.py
...hub/business-logic-microservice/app/db/entities/schema.py
+0
-23
table.py
...-hub/business-logic-microservice/app/db/entities/table.py
+18
-4
layer_repository.py
...ub/business-logic-microservice/app/db/layer_repository.py
+0
-23
repository.py
...tion-hub/business-logic-microservice/app/db/repository.py
+7
-11
schema_repository.py
...b/business-logic-microservice/app/db/schema_repository.py
+0
-61
table_repository.py
...ub/business-logic-microservice/app/db/table_repository.py
+47
-0
use_case_repository.py
...business-logic-microservice/app/db/use_case_repository.py
+13
-3
layer.py
...ation-hub/business-logic-microservice/app/routes/layer.py
+71
-126
schema.py
...tion-hub/business-logic-microservice/app/routes/schema.py
+0
-65
tables.py
...tion-hub/business-logic-microservice/app/routes/tables.py
+60
-0
use_case.py
...on-hub/business-logic-microservice/app/routes/use_case.py
+21
-7
layer_adapter_service.py
...-logic-microservice/app/services/layer_adapter_service.py
+9
-8
No files found.
src/participation-hub/business-logic-microservice/app/configs/routes.yml
View file @
fd78b68b
paths
:
paths
:
#####
# USE-CASES
#####
/use-cases
:
/use-cases
:
post
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.use_case.add"
tags
:
-
"
Use-Cases"
summary
:
"
Adds
a
new
Use-Case"
description
:
"
Adds
a
new
Use-Case"
parameters
:
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
type
:
object
properties
:
name
:
type
:
string
example
:
"
use_case_1"
description
:
"
Unique
name
for
the
Use-Case"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
400'
:
description
:
"
Use-Case
already
exists"
get
:
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
...
@@ -22,98 +49,111 @@ paths:
...
@@ -22,98 +49,111 @@ paths:
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
/schemas
:
#####
# TABLES
#####
/tables
:
get
:
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
schema
.all"
operationId
:
"
routes.
tables
.all"
tags
:
tags
:
-
"
Schema
s"
-
"
Table
s"
summary
:
"
Get
all
Use-Cas
es"
summary
:
"
Get
all
Tabl
es"
description
:
"
Get
all
Use-Cas
es"
description
:
"
Get
all
Tabl
es"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
/use-cases/{use_case}/schema
:
delete
:
post
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.tables.delete_all"
tags
:
-
"
Tables"
summary
:
"
Delete
all
Tables"
description
:
"
Delete
all
Tables"
responses
:
'
200'
:
description
:
"
Successful
Request"
/use-cases/{use_case}/tables
:
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
schema.add_complet
e"
operationId
:
"
routes.
tables.all_for_use_cas
e"
tags
:
tags
:
-
"
Schema
s"
-
"
Table
s"
summary
:
"
Add
a
new
schema
with
mappings
to
the
DB
"
summary
:
"
Get
all
Tables
for
one
Use-Case
"
description
:
"
Add
a
new
schema
with
mappings
to
the
DB
"
description
:
"
Get
all
Tables
for
one
Use-Case
"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
Object"
in
:
"
body"
required
:
true
schema
:
type
:
object
additionalProperties
:
type
:
string
example
:
name
:
name
dough
:
dough//type
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
400'
:
post
:
description
:
"
Schema
already
exists
or
missing
field
in
request"
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
schema.get_for_use_cas
e"
operationId
:
"
routes.
tables.add_complet
e"
tags
:
tags
:
-
"
Schema
s"
-
"
Table
s"
summary
:
"
Get
the
Schema
assigned
to
th
e
Use-Case"
summary
:
"
Adds
a
Table
identified
by
it's
name
for
on
e
Use-Case"
description
:
"
Get
the
Schema
assigned
to
th
e
Use-Case"
description
:
"
Adds
a
Table
identified
by
it's
name
for
on
e
Use-Case"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/Table'
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
40
4
'
:
'
40
0
'
:
description
:
"
Schema
does
not
exist
"
description
:
"
Table
with
the
name
already
exists
or
missing
fields
in
the
request.
"
delete
:
delete
:
security
:
security
:
-
JwtAdmin
:
[]
-
JwtAdmin
:
[]
operationId
:
"
routes.
schema.delete
_for_use_case"
operationId
:
"
routes.
tables.delete_all
_for_use_case"
tags
:
tags
:
-
"
Schema
s"
-
"
Table
s"
summary
:
"
Delete
the
Schema
assigned
to
the
Use-Case"
summary
:
"
Delete
all
Tables
for
a
Use-Case"
description
:
"
Delete
the
Schema
assigned
to
the
Use-Case"
description
:
"
Delete
all
Tables
for
a
Use-Case"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
/use-cases/{use_case}/schema/mapping
:
'
400'
:
description
:
"
Table
with
the
name
already
exists
or
missing
fields
in
the
request."
/use-cases/{use_case}/table/{name}/mapping
:
put
:
put
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
schema.add
_mapping"
operationId
:
"
routes.
tables.put
_mapping"
tags
:
tags
:
-
"
Schema
s"
-
"
Table
s"
summary
:
"
Adds
an
attribute
mapping
to
the
Schema
of
the
Use-Case"
summary
:
"
Adds
an
attribute
mapping
to
a
Table
of
the
Use-Case"
description
:
"
Adds
an
attribute
mapping
to
the
each
Layer
of
the
Use-Case"
description
:
"
Adds
an
attribute
mapping
to
a
Table
of
the
Use-Case"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Table"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -124,6 +164,15 @@ paths:
...
@@ -124,6 +164,15 @@ paths:
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
#####
# END-TABLES
#####
#####
# LAYERS
#####
/layers
:
/layers
:
get
:
get
:
security
:
security
:
...
@@ -166,39 +215,24 @@ paths:
...
@@ -166,39 +215,24 @@ paths:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
400'
:
'
400'
:
description
:
"
Bad
structure
in
request
body
or
Layer
already
exists"
description
:
"
Bad
structure
in
request
body
or
Layer
already
exists"
/use-cases/{use_case}/
layers
:
/use-cases/{use_case}/
table/{table}/layers/{name}/cluster-mapping
:
ge
t
:
pu
t
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.
get_all_for_use_case
"
operationId
:
"
routes.layer.
add_cluster_mapping
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Retrieves
all
layers
belonging
to
the
given
Use-Case
"
summary
:
"
Selects
a
property
of
the
Layer
as
cluster
property
"
description
:
"
Retrieves
all
layers
belonging
to
the
given
Use-Case
"
description
:
"
Selects
a
property
of
the
Layer
as
cluster
property
"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
responses
:
-
name
:
"
table"
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Use-Case
does
not
exist"
/use-cases/{use_case}/layers/{name}
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.one"
tags
:
-
"
Layers"
summary
:
"
Retrieve
one
Layer
from
the
DB"
description
:
"
Retrieve
one
Layer
from
the
DB"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Cas
e
the
Layer
belongs
to"
description
:
"
Name
of
the
Tabl
e
the
Layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
name"
-
name
:
"
name"
...
@@ -206,77 +240,45 @@ paths:
...
@@ -206,77 +240,45 @@ paths:
description
:
"
Name
of
the
Layer"
description
:
"
Name
of
the
Layer"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
type
:
object
properties
:
attribute
:
type
:
string
example
:
"
end_time"
description
:
"
Internal
name
of
the
attribute"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
post
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.add_empty"
tags
:
-
"
Layers"
summary
:
"
Adds
an
empty
Layer
to
the
DB"
description
:
"
Adds
an
empty
Layer
to
the
DB"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
new
Layer"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
400'
:
'
400'
:
description
:
"
Layer
already
exists
"
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer
"
delete
:
delete
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.delete_
one
"
operationId
:
"
routes.layer.delete_
cluster_mapping
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Delete
one
Layer
from
the
DB
"
summary
:
"
Delete
s
a
cluster-attribute
mapping
from
the
selected
layer
"
description
:
"
Delete
one
Layer
from
the
DB
"
description
:
"
Delete
s
a
cluster-attribute
mapping
from
the
selected
layer
"
parameters
:
parameters
:
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
layer
to
delete"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
responses
:
-
name
:
"
table"
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
/use-cases/{use_case}/cluster-mapping/layers/{name}
:
put
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.add_cluster_mapping"
tags
:
-
"
Layers"
summary
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
description
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
l
ayer
belongs
to"
description
:
"
Name
of
the
Table
the
L
ayer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
name"
-
name
:
"
name"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)
"
description
:
"
Name
of
the
Layer
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -296,95 +298,85 @@ paths:
...
@@ -296,95 +298,85 @@ paths:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
delete
:
/use-cases/{use_case}/layers
:
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.
delete_cluster_mapping
"
operationId
:
"
routes.layer.
get_all_for_use_case
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Deletes
a
cluster-attribute
mapping
from
the
selected
layer
"
summary
:
"
Retrieves
all
layers
belonging
to
the
given
Use-Case
"
description
:
"
Deletes
a
cluster-attribute
mapping
from
the
selected
layer
"
description
:
"
Retrieves
all
layers
belonging
to
the
given
Use-Case
"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)"
required
:
true
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
type
:
object
properties
:
attribute
:
type
:
string
example
:
"
end_time"
description
:
"
Internal
name
of
the
attribute"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Layer
does
not
exist"
description
:
"
Use-Case
does
not
exist"
'
400'
:
/use-cases/{use_case}/table/{table}/layers/{name}
:
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
get
:
/use-cases/{use_case}/layers/mapping
:
put
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.
add_mapping_for_all
"
operationId
:
"
routes.layer.
one
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Adds
an
attribute
mapping
to
the
each
Layer
of
the
Use-Case
"
summary
:
"
Retrieve
one
Layer
from
the
DB
"
description
:
"
Adds
an
attribute
mapping
to
the
each
Layer
of
the
Use-Case
"
description
:
"
Retrieve
one
Layer
from
the
DB
"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
name
:
"
table"
name
:
"
Object"
in
:
"
path"
description
:
"
Name
of
the
Table
the
Layer
belongs
to"
required
:
true
required
:
true
schema
:
type
:
"
string"
$ref
:
'
#/definitions/LayerMapping'
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Layer"
required
:
true
type
:
"
string"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
40
0
'
:
'
40
4
'
:
description
:
"
Field
in
request
is
missing
"
description
:
"
Layer
does
not
exist
"
delete
:
delete
:
security
:
security
:
-
Jwt
Admin
:
[]
-
Jwt
Regular
:
[]
operationId
:
"
routes.layer.delete_
mapping_for_all
"
operationId
:
"
routes.layer.delete_
one
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Delete
s
an
attribute
mapping
for
all
Layers
of
the
Use-Case
"
summary
:
"
Delete
one
Layer
from
the
DB
"
description
:
"
Delete
s
an
attribute
mapping
for
all
Layers
of
the
Use-Case
"
description
:
"
Delete
one
Layer
from
the
DB
"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Table
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
name
:
"
table"
name
:
"
Object"
in
:
"
path"
description
:
"
Name
of
the
Table
the
Layer
belongs
to"
required
:
true
required
:
true
schema
:
type
:
"
string"
type
:
object
-
name
:
"
name"
properties
:
in
:
"
path"
internal
:
description
:
"
Name
of
the
Layer"
type
:
string
required
:
true
example
:
"
end_time
"
type
:
"
string
"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
40
0
'
:
'
40
4
'
:
description
:
"
Field
in
request
is
missing
"
description
:
"
Layer
does
not
exist
"
/use-cases/{use_case}/layers/{name}/mapping
:
/use-cases/{use_case}/layers/{name}/mapping
:
put
:
put
:
security
:
security
:
...
@@ -458,6 +450,23 @@ definitions:
...
@@ -458,6 +450,23 @@ definitions:
internal
:
internal
:
type
:
string
type
:
string
example
:
"
end_time"
example
:
"
end_time"
Table
:
type
:
"
object"
required
:
-
name
-
mappings
properties
:
name
:
type
:
string
example
:
"
table1"
mappings
:
type
:
object
additionalProperties
:
type
:
string
example
:
name
:
resolved_property
dough
:
some//path//through//json[0]
Mapping
:
Mapping
:
type
:
"
object"
type
:
"
object"
required
:
required
:
...
@@ -473,17 +482,21 @@ definitions:
...
@@ -473,17 +482,21 @@ definitions:
Layer
:
Layer
:
type
:
"
object"
type
:
"
object"
required
:
required
:
-
name
-
use_case
-
use_case
-
table
-
name
-
cluster_properties
-
cluster_properties
-
properties
-
properties
properties
:
properties
:
use_case
:
type
:
string
example
:
"
use_case_1"
table
:
type
:
string
example
:
"
table1"
name
:
name
:
type
:
string
type
:
string
example
:
"
layer1"
example
:
"
layer1"
use_case
:
type
:
string
example
:
"
car-sharing"
cluster_properties
:
cluster_properties
:
type
:
array
type
:
array
items
:
items
:
...
...
src/participation-hub/business-logic-microservice/app/db/entities/layer_adapter.py
View file @
fd78b68b
...
@@ -7,7 +7,7 @@ class LayerAdapter:
...
@@ -7,7 +7,7 @@ class LayerAdapter:
attributes from the dataset correspond to each one
attributes from the dataset correspond to each one
'''
'''
def
__init__
(
self
,
name
:
str
,
use_case
:
str
,
properties
:
List
[
str
],
cluster_properties
:
List
[
str
]):
def
__init__
(
self
,
name
:
str
,
use_case
:
str
,
table
:
str
,
properties
:
List
[
str
],
cluster_properties
:
List
[
str
]):
'''
'''
Creates a new instance of LayerAdapter
Creates a new instance of LayerAdapter
...
@@ -20,6 +20,7 @@ class LayerAdapter:
...
@@ -20,6 +20,7 @@ class LayerAdapter:
self
.
name
=
name
self
.
name
=
name
self
.
properties
=
properties
self
.
properties
=
properties
self
.
use_case
=
use_case
self
.
use_case
=
use_case
self
.
table
=
table
for
prop
in
cluster_properties
:
for
prop
in
cluster_properties
:
if
prop
not
in
properties
:
if
prop
not
in
properties
:
...
@@ -86,7 +87,8 @@ class LayerAdapter:
...
@@ -86,7 +87,8 @@ class LayerAdapter:
"name"
:
self
.
name
,
"name"
:
self
.
name
,
"properties"
:
self
.
properties
,
"properties"
:
self
.
properties
,
"cluster_properties"
:
self
.
cluster_properties
,
"cluster_properties"
:
self
.
cluster_properties
,
"use_case"
:
self
.
use_case
"use_case"
:
self
.
use_case
,
"table"
:
self
.
table
}
}
@
staticmethod
@
staticmethod
...
@@ -101,6 +103,7 @@ class LayerAdapter:
...
@@ -101,6 +103,7 @@ class LayerAdapter:
return
LayerAdapter
(
return
LayerAdapter
(
user_dict
[
"name"
],
user_dict
[
"name"
],
user_dict
[
"use_case"
],
user_dict
[
"use_case"
],
user_dict
[
"table"
],
user_dict
[
"properties"
],
user_dict
[
"properties"
],
user_dict
[
"cluster_properties"
]
user_dict
[
"cluster_properties"
]
)
)
src/participation-hub/business-logic-microservice/app/db/entities/schema.py
deleted
100644 → 0
View file @
bc4462e8
from
typing
import
Dict
class
Schema
:
def
__init__
(
self
,
use_case
:
str
,
mappings
:
Dict
[
str
,
str
]):
self
.
use_case
=
use_case
self
.
mappings
=
mappings
def
add_mapping
(
self
,
internal
:
str
,
external
:
str
):
if
internal
not
in
self
.
mappings
.
keys
():
self
.
mappings
[
internal
]
=
external
def
to_serializable_dict
(
self
)
->
Dict
:
return
{
"use_case"
:
self
.
use_case
,
"mappings"
:
self
.
mappings
}
@
staticmethod
def
from_serializable_dict
(
serializable_dict
:
Dict
):
return
Schema
(
serializable_dict
[
"use_case"
],
serializable_dict
[
"mappings"
]
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/db/entities/table.py
View file @
fd78b68b
from
typing
import
Dict
from
typing
import
Dict
class
Table
:
class
Table
:
def
__init__
(
self
,
name
):
def
__init__
(
self
,
use_case
:
str
,
name
:
str
,
mappings
:
Dict
[
str
,
str
]):
self
.
use_case
=
use_case
self
.
name
=
name
self
.
name
=
name
self
.
mappings
=
mappings
def
to_serializable_dict
(
self
)
->
Dict
:
def
to_serializable_dict
(
self
)
->
Dict
:
return
{
"name"
:
self
.
name
}
return
{
"name"
:
self
.
name
,
"use_case"
:
self
.
use_case
,
"mappings"
:
self
.
mappings
}
def
add_mapping
(
self
,
internal
:
str
,
external
:
str
):
if
internal
not
in
self
.
mappings
.
keys
():
self
.
mappings
[
internal
]
=
external
@
staticmethod
@
staticmethod
def
from_serializable_dict
(
data
:
Dict
):
def
from_serializable_dict
(
data
:
Dict
):
return
Table
(
data
[
"name"
])
return
Table
(
\ No newline at end of file
data
[
"use_case"
],
data
[
"name"
],
data
[
"mappings"
]
)
src/participation-hub/business-logic-microservice/app/db/layer_repository.py
deleted
100644 → 0
View file @
bc4462e8
# global imports (dont't worry, red is normal)
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.table
import
Table
import
pymongo
import
json
from
typing
import
List
,
Dict
class
TableRepository
(
MongoRepositoryBase
):
'''This is a repository for MongoDb.'''
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'rest-gateway-db'
)
self
.
_table_collection
=
'tables'
def
add_one
(
self
,
table
:
Table
):
super
()
.
insert_entry
(
self
.
_table_collection
,
table
.
to_serializable_dict
())
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/db/repository.py
View file @
fd78b68b
...
@@ -14,7 +14,7 @@ class Repository(MongoRepositoryBase):
...
@@ -14,7 +14,7 @@ class Repository(MongoRepositoryBase):
def
__init__
(
self
):
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'
rest-gateway
-db'
)
'
business-logic
-db'
)
self
.
_adapter_collection
=
'layer_adapters'
self
.
_adapter_collection
=
'layer_adapters'
self
.
_use_case_collection
=
'use_cases'
self
.
_use_case_collection
=
'use_cases'
...
@@ -29,8 +29,8 @@ class Repository(MongoRepositoryBase):
...
@@ -29,8 +29,8 @@ class Repository(MongoRepositoryBase):
return
[
LayerAdapter
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
return
[
LayerAdapter
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
one
(
self
,
name
:
str
,
use_case
:
str
)
->
LayerAdapter
:
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
}))
result
=
list
(
super
()
.
get_entries
(
self
.
_adapter_collection
,
selection
=
{
"name"
:
name
,
"use_case"
:
use_case
,
"table"
:
table
}))
if
len
(
result
)
==
1
:
if
len
(
result
)
==
1
:
return
LayerAdapter
.
from_serializable_dict
(
result
[
0
])
return
LayerAdapter
.
from_serializable_dict
(
result
[
0
])
...
@@ -44,18 +44,14 @@ class Repository(MongoRepositoryBase):
...
@@ -44,18 +44,14 @@ class Repository(MongoRepositoryBase):
def
add
(
self
,
adapter
:
LayerAdapter
):
def
add
(
self
,
adapter
:
LayerAdapter
):
super
()
.
insert_entry
(
self
.
_adapter_collection
,
adapter
.
to_serializable_dict
())
super
()
.
insert_entry
(
self
.
_adapter_collection
,
adapter
.
to_serializable_dict
())
def
add_empty
(
self
,
name
:
str
,
use_case
:
str
):
adapter
=
LayerAdapter
(
name
,
use_case
,
[],
[])
super
()
.
insert_entry
(
self
.
_adapter_collection
,
adapter
.
to_serializable_dict
())
def
update_use_case
(
self
,
adapter
:
LayerAdapter
,
use_case
:
str
):
def
update_use_case
(
self
,
adapter
:
LayerAdapter
,
use_case
:
str
):
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
.
update_one
({
"name"
:
adapter
.
name
,
"use_case"
:
use_case
},
{
"$set"
:
adapter
.
to_serializable_dict
()})
collection
.
update_one
({
"name"
:
adapter
.
name
,
"use_case"
:
use_case
,
"table"
:
adapter
.
table
},
{
"$set"
:
adapter
.
to_serializable_dict
()})
def
update
(
self
,
adapter
:
LayerAdapter
):
def
update
(
self
,
adapter
:
LayerAdapter
):
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
.
update_one
({
"name"
:
adapter
.
name
,
"use_case"
:
adapter
.
use_case
},
{
"$set"
:
adapter
.
to_serializable_dict
()})
collection
.
update_one
({
"name"
:
adapter
.
name
,
"use_case"
:
adapter
.
use_case
,
"table"
:
adapter
.
table
},
{
"$set"
:
adapter
.
to_serializable_dict
()})
def
delete
_all_with_name_and_use_case
(
self
,
name
:
str
,
use_case
:
st
r
):
def
delete
(
self
,
adapter
:
LayerAdapte
r
):
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
.
delete_many
({
"name"
:
name
,
"use_case"
:
use_case
})
collection
.
delete_many
({
"name"
:
adapter
.
name
,
"use_case"
:
adapter
.
use_case
,
"table"
:
adapter
.
table
})
\ No newline at end of file
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/db/schema_repository.py
deleted
100644 → 0
View file @
bc4462e8
# global imports (dont't worry, red is normal)
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.schema
import
Schema
from
db.use_case_repository
import
UseCaseRepository
import
pymongo
import
json
from
typing
import
List
,
Dict
class
SchemaRepository
(
MongoRepositoryBase
):
'''This is a repository for MongoDb.'''
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'rest-gateway-db'
)
self
.
_schema_collection
=
'schemas'
def
all
(
self
)
->
List
[
Schema
]:
result
=
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
})
return
[
Schema
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
add
(
self
,
schema
:
Schema
):
super
()
.
insert_entry
(
self
.
_schema_collection
,
schema
.
to_serializable_dict
())
def
get_for_use_case
(
self
,
use_case
:
str
)
->
Schema
:
self
.
put
(
use_case
)
result
=
list
(
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
}))
if
len
(
result
)
>
1
:
raise
ValueError
(
"No more than 1 Schema allowed per use-case!"
)
if
len
(
result
)
==
1
:
return
Schema
.
from_serializable_dict
(
result
[
0
])
return
None
def
put
(
self
,
use_case
:
str
):
result
=
list
(
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
}))
if
len
(
result
)
==
0
:
schema
=
Schema
(
use_case
,
mappings
=
{})
self
.
add
(
schema
)
else
:
schema
=
Schema
.
from_serializable_dict
(
result
[
0
])
return
schema
def
delete_for_use_case
(
self
,
use_case
:
str
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
delete_many
({
"use_case"
:
use_case
})
def
delete_all
(
self
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
delete_many
({})
def
update
(
self
,
schema
:
Schema
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
update_one
({
"use_case"
:
schema
.
use_case
},
{
"$set"
:
schema
.
to_serializable_dict
()})
src/participation-hub/business-logic-microservice/app/db/table_repository.py
0 → 100644
View file @
fd78b68b
# global imports (dont't worry, red is normal)
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.table
import
Table
from
typing
import
Dict
,
List
class
TableRepository
(
MongoRepositoryBase
):
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'business-logic-db'
)
self
.
_collection
=
'tables'
def
get_all
(
self
)
->
List
[
Table
]:
result
=
super
()
.
get_entries
(
self
.
_collection
,
projection
=
{
'_id'
:
False
})
return
[
Table
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
get_all_for_use_case
(
self
,
use_case
:
str
)
->
List
[
Table
]:
result
=
super
()
.
get_entries
(
self
.
_collection
,
selection
=
{
'use_case'
:
use_case
},
projection
=
{
'_id'
:
False
})
return
[
Table
.
from_serializable_dict
(
row
)
for
row
in
result
]
def
get_for_use_case_and_name
(
self
,
use_case
:
str
,
name
:
str
)
->
Table
:
result
=
list
(
super
()
.
get_entries
(
self
.
_collection
,
selection
=
{
"use_case"
:
use_case
,
"name"
:
name
},
projection
=
{
'_id'
:
False
}))
if
len
(
result
)
==
1
:
return
Table
.
from_serializable_dict
(
result
[
0
])
if
len
(
result
)
==
0
:
return
None
raise
ValueError
(
"No more than 1 Schema allowed per use-case!"
)
def
add
(
self
,
table
:
Table
):
super
()
.
insert_entry
(
self
.
_collection
,
table
.
to_serializable_dict
())
def
delete_for_use_case
(
self
,
use_case
:
str
):
collection
=
self
.
_database
[
self
.
_collection
]
collection
.
delete_many
({
"use_case"
:
use_case
})
def
delete_all
(
self
):
collection
=
self
.
_database
[
self
.
_collection
]
collection
.
delete_many
({})
def
update
(
self
,
table
:
Table
):
collection
=
self
.
_database
[
self
.
_collection
]
collection
.
update_one
({
"use_case"
:
table
.
use_case
,
"name"
:
table
.
name
},
{
"$set"
:
table
.
to_serializable_dict
()})
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/db/use_case_repository.py
View file @
fd78b68b
...
@@ -13,7 +13,7 @@ class UseCaseRepository(MongoRepositoryBase):
...
@@ -13,7 +13,7 @@ class UseCaseRepository(MongoRepositoryBase):
def
__init__
(
self
):
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'
rest-gateway
-db'
)
'
business-logic
-db'
)
self
.
_use_case_collection
=
'use_cases'
self
.
_use_case_collection
=
'use_cases'
...
@@ -30,6 +30,17 @@ class UseCaseRepository(MongoRepositoryBase):
...
@@ -30,6 +30,17 @@ class UseCaseRepository(MongoRepositoryBase):
collection
=
self
.
_database
[
self
.
_use_case_collection
]
collection
=
self
.
_database
[
self
.
_use_case_collection
]
collection
.
delete_many
({
"name"
:
name
})
collection
.
delete_many
({
"name"
:
name
})
def
get_by_name
(
self
,
name
:
str
):
result
=
list
(
super
()
.
get_entries
(
self
.
_use_case_collection
,
{
"name"
:
name
}))
if
len
(
result
)
==
1
:
return
UseCase
.
from_serializable_dict
(
result
[
0
])
if
len
(
result
)
==
0
:
return
None
raise
ValueError
(
"More than one Use-Case in the DB!"
)
def
put
(
self
,
use_case_name
:
str
):
def
put
(
self
,
use_case_name
:
str
):
use_cases
=
self
.
all
()
use_cases
=
self
.
all
()
...
@@ -38,4 +49,3 @@ class UseCaseRepository(MongoRepositoryBase):
...
@@ -38,4 +49,3 @@ class UseCaseRepository(MongoRepositoryBase):
if
len
(
existing_use_cases
)
==
0
:
if
len
(
existing_use_cases
)
==
0
:
use_case
=
UseCase
(
use_case_name
)
use_case
=
UseCase
(
use_case_name
)
super
()
.
insert_entry
(
self
.
_use_case_collection
,
use_case
.
to_serializable_dict
())
super
()
.
insert_entry
(
self
.
_use_case_collection
,
use_case
.
to_serializable_dict
())
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/routes/layer.py
View file @
fd78b68b
#global imports
#global imports
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.layer_adapter
import
LayerAdapter
from
db.repository
import
Repository
from
db.repository
import
Repository
from
db.
schema_repository
import
Schema
Repository
from
db.
table_repository
import
Table
Repository
from
db.use_case_repository
import
UseCaseRepository
from
db.use_case_repository
import
UseCaseRepository
from
services.layer_adapter_service
import
LayerAdapterService
from
services.layer_adapter_service
import
LayerAdapterService
import
json
import
json
from
flask
import
Response
,
request
from
flask
import
Response
,
request
schema_repository
=
Schema
Repository
()
table_repository
=
Table
Repository
()
layer_repository
=
Repository
()
layer_repository
=
Repository
()
use_case_repository
=
UseCaseRepository
()
use_case_repository
=
UseCaseRepository
()
def
all
():
def
all
():
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all
()]
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all
()]
def
get_all_for_use_case
(
use_case
:
str
):
def
delete_all_layers
():
'''
'''
get all layers assigned to the given use_case
delete all layers from the DB
'''
'''
use_case_repository
.
put
(
use_case
)
layer_repository
.
delete_all
()
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all_for_use_case
(
use_case
)]
return
Response
(
status
=
200
)
def
add_complete
():
def
add_complete
():
'''
'''
...
@@ -28,21 +30,33 @@ def add_complete():
...
@@ -28,21 +30,33 @@ def add_complete():
'''
'''
data
=
request
.
json
data
=
request
.
json
if
"name"
not
in
data
or
"properties"
not
in
data
or
"cluster_properties"
not
in
data
or
"use_case"
not
in
data
:
if
"name"
not
in
data
or
"properties"
not
in
data
or
"cluster_properties"
not
in
data
or
"use_case"
not
in
data
or
"table"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (name, properties, cluster_properties)"
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (name, properties, cluster_properties, table), present:({data.keys()})"
)
use_case
=
data
[
"use_case"
]
table_name
=
data
[
"table"
]
layer_name
=
data
[
"name"
]
table
=
table_repository
.
get_for_use_case_and_name
(
use_case
,
table_name
)
use_case_repository
.
put
(
data
[
"use_case"
])
if
table
==
None
:
layer
=
layer_repository
.
one
(
data
[
"name"
],
data
[
"use_case"
])
return
Response
(
status
=
400
,
response
=
"Table does not exist!"
)
layer
=
layer_repository
.
one
(
layer_name
,
use_case
,
table
.
name
)
if
layer
!=
None
:
if
layer
!=
None
:
return
Response
(
status
=
400
,
response
=
f
'Layer with name "{data["name"]}" already exists!'
)
return
Response
(
status
=
400
,
response
=
f
'Layer with name "{data["name"]}" already exists!'
)
# check if schema contains mapping
# check if table contains mapping
for
prop
in
data
[
"properties"
]:
if
prop
not
in
table
.
mappings
.
keys
():
return
Response
(
status
=
400
,
response
=
f
"'{prop}' is no property of the Table!"
)
try
:
try
:
layer_new
=
LayerAdapter
.
from_serializable_dict
(
data
)
layer_new
=
LayerAdapter
.
from_serializable_dict
(
data
)
except
BaseException
as
e
:
except
BaseException
as
e
:
print
(
f
"Exception: {e}"
)
print
(
f
"Exception: {e}"
)
return
Response
(
status
=
400
)
return
Response
(
status
=
400
,
response
=
f
"{e}"
)
try
:
try
:
LayerAdapterService
.
add_complete
(
layer_new
)
LayerAdapterService
.
add_complete
(
layer_new
)
...
@@ -51,49 +65,17 @@ def add_complete():
...
@@ -51,49 +65,17 @@ def add_complete():
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
def
one
(
name
:
str
,
use_case
:
str
):
'''
fetch a single layer from the DB
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
layer
.
to_serializable_dict
()))
def
add_empty
(
name
:
str
,
use_case
:
str
):
'''
add an empty layer to the DB
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
if
layer_repository
.
one
(
name
,
use_case
)
!=
None
:
return
Response
(
status
=
400
,
response
=
f
"Layer with name '{name}' already exists!"
)
layer_repository
.
add_empty
(
name
,
use_case
)
return
Response
(
status
=
200
)
def
add_cluster_mapping
(
name
:
str
,
use_cas
e
:
str
):
def
add_cluster_mapping
(
use_case
:
str
,
table
:
str
,
nam
e
:
str
):
'''
'''
add a mapped property to the list of properties to cluster with
add a mapped property to the list of properties to cluster with
@params:
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the Use-Case the Layer belongs to
use_case - Required : String-identifier for the use-case
table - Required : unique identifier of the Table the Layer belongs to
name - Required : unique identifier for the Layer
'''
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
,
table
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
...
@@ -110,17 +92,16 @@ def add_cluster_mapping(name: str, use_case: str):
...
@@ -110,17 +92,16 @@ def add_cluster_mapping(name: str, use_case: str):
except
:
except
:
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
def
delete_cluster_mapping
(
name
:
str
,
use_cas
e
:
str
):
def
delete_cluster_mapping
(
use_case
:
str
,
table
:
str
,
nam
e
:
str
):
'''
'''
remove a mapped property from the list of properties to cluster with
remove a mapped property from the list of properties to cluster with
@params:
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the Use-Case the Layer belongs to
use_case - Required : String-identifier for the use-case
table - Required : unique identifier of the Table the Layer belongs to
name - Required : unique identifier for the Layer
'''
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
,
table
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
...
@@ -138,76 +119,42 @@ def delete_cluster_mapping(name: str, use_case: str):
...
@@ -138,76 +119,42 @@ def delete_cluster_mapping(name: str, use_case: str):
print
(
e
)
print
(
e
)
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
def
add_mapping_for_all
(
use_case
:
str
):
'''
add a new mapping to each layer of the use-case
@params:
def
get_all_for_use_case
(
use_case
:
str
):
use_case - Required : String-identifier for the use-case
'''
get all layers assigned to the given use_case
'''
'''
use_case_repository
.
put
(
use_case
)
use_case_repository
.
put
(
use_case
)
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all_for_use_case
(
use_case
)]
data
=
request
.
json
def
one
(
use_case
:
str
,
table
:
str
,
name
:
str
):
if
"internal"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
# check if schema contains mapping
schema
=
schema_repository
.
put
(
use_case
)
if
data
[
"internal"
]
not
in
schema
.
mappings
:
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not existent in the schema!'
)
layers
=
layer_repository
.
all_for_use_case
(
use_case
)
for
layer
in
layers
:
layer
.
add_mapping
(
data
[
"internal"
])
try
:
LayerAdapterService
.
check_layer
(
layer
)
except
ValueError
as
e
:
return
Response
(
status
=
400
,
response
=
f
"{e}"
)
layer_repository
.
update
(
layer
)
return
Response
(
status
=
200
)
def
delete_mapping_for_all
(
use_case
:
str
):
'''
'''
delete a mapping from each layer in the use-case
fetch a single layer from the DB
@params:
@params:
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the Use-Case the Layer belongs to
table - Required : unique identifier of the Table the Layer belongs to
name - Required : unique identifier for the Layer
'''
'''
use_case_repository
.
put
(
use_cas
e
)
layer
=
layer_repository
.
one
(
name
,
use_case
,
tabl
e
)
data
=
request
.
json
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
if
"internal"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
layers
=
layer_repository
.
all_for_use_case
(
use_case
)
for
layer
in
layers
:
try
:
layer
.
delete_mapping
(
data
[
"internal"
])
except
ValueError
:
continue
layer_repository
.
update
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
layer
.
to_serializable_dict
())
)
def
delete_mapping
(
name
:
str
,
use_cas
e
:
str
):
def
delete_mapping
(
use_case
:
str
,
table
:
str
,
nam
e
:
str
):
'''
'''
delete a mapping from the layer identified by the internal representation
delete a mapping from the layer identified by the internal representation
@params:
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the Use-Case the Layer belongs to
use_case - Required : String-identifier for the use-case
table - Required : unique identifier of the Table the Layer belongs to
name - Required : unique identifier for the Layer
'''
'''
use_case_repository
.
put
(
use_case
)
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
,
table
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
...
@@ -225,13 +172,14 @@ def delete_mapping(name: str, use_case: str):
...
@@ -225,13 +172,14 @@ def delete_mapping(name: str, use_case: str):
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
def
add_mapping
(
name
:
str
,
use_case
:
str
):
def
add_mapping
(
name
:
str
,
table
:
str
,
use_case
:
str
):
'''
'''
add a new mapping to the layer identified by name
add a new mapping to the layer identified by name
@params:
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the Use-Case the Layer belongs to
use_case - Required : String-identifier for the use-case
table - Required : unique identifier of the Table the Layer belongs to
name - Required : unique identifier for the Layer
'''
'''
use_case_repository
.
put
(
use_case
)
use_case_repository
.
put
(
use_case
)
...
@@ -246,36 +194,33 @@ def add_mapping(name: str, use_case: str):
...
@@ -246,36 +194,33 @@ def add_mapping(name: str, use_case: str):
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
# check if schema contains mapping
# check if schema contains mapping
schema
=
schema_repository
.
put
(
use_case
)
table
=
table_repository
.
get_for_use_case_and_name
(
use_case
,
table
)
if
data
[
"internal"
]
not
in
schema
.
mappings
:
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not existent in the schema!'
)
if
table
==
None
:
return
Response
(
status
=
400
,
response
=
f
'Table does not exist.'
)
if
data
[
"internal"
]
not
in
table
.
mappings
:
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not existent in the table!'
)
layer
.
add_mapping
(
data
[
"internal"
])
layer
.
add_mapping
(
data
[
"internal"
])
layer_repository
.
update
(
layer
)
layer_repository
.
update
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
def
delete_one
(
name
:
str
,
use_cas
e
:
str
):
def
delete_one
(
use_case
:
str
,
table
:
str
,
nam
e
:
str
):
'''
'''
delete a layer and all its mappings from the Db
delete a layer and all its mappings from the Db
@params:
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the Use-Case the Layer belongs to
use_case - Required : String-identifier for the use-case
table - Required : unique identifier of the Table the Layer belongs to
name - Required : unique identifier for the Layer
'''
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
,
table
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
layer_repository
.
delete_all_with_name_and_use_case
(
layer
)
layer_repository
.
delete
(
layer
)
return
Response
(
status
=
200
)
def
delete_all_layers
():
'''
delete all layers from the DB
'''
layer_repository
.
delete_all
()
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
src/participation-hub/business-logic-microservice/app/routes/schema.py
deleted
100644 → 0
View file @
bc4462e8
#global imports
from
db.entities.schema
import
Schema
from
db.entities.layer_adapter
import
LayerAdapter
from
db.schema_repository
import
SchemaRepository
from
db.use_case_repository
import
UseCaseRepository
from
services.layer_adapter_service
import
LayerAdapterService
import
json
from
flask
import
Response
,
request
use_case_repository
=
UseCaseRepository
()
schema_repository
=
SchemaRepository
()
def
all
():
return
[
schema
.
to_serializable_dict
()
for
schema
in
schema_repository
.
all
()]
def
add_complete
(
use_case
:
str
):
mappings
=
request
.
json
reference
=
schema_repository
.
get_for_use_case
(
use_case
)
if
reference
!=
None
and
len
(
reference
.
mappings
)
>
0
:
return
Response
(
status
=
400
,
response
=
"Schema already exists."
)
schema_repository
.
delete_for_use_case
(
use_case
)
schema_dict
=
{
"use_case"
:
use_case
,
"mappings"
:
mappings
}
schema_repository
.
add
(
Schema
.
from_serializable_dict
(
schema_dict
))
return
Response
(
status
=
200
)
def
get_for_use_case
(
use_case
:
str
):
use_case_repository
.
put
(
use_case
)
schema
=
schema_repository
.
get_for_use_case
(
use_case
)
if
schema
!=
None
:
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
schema
.
to_serializable_dict
()))
return
Response
(
status
=
404
,
response
=
f
"Schema {use_case} does not exist"
)
def
delete_for_use_case
(
use_case
:
str
):
schema_repository
.
delete_for_use_case
(
use_case
)
return
Response
(
status
=
200
)
def
add_mapping
(
use_case
:
str
):
use_case_repository
.
put
(
use_case
)
data
=
request
.
json
if
"internal"
not
in
data
or
"external"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal, external)"
)
schema
=
schema_repository
.
get_for_use_case
(
use_case
)
if
schema
==
None
:
print
(
"schema not there, creating it..."
)
schema
=
schema_repository
.
put
(
use_case
)
schema
.
add_mapping
(
data
[
"internal"
],
data
[
"external"
])
schema_repository
.
update
(
schema
)
return
Response
(
status
=
200
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/routes/tables.py
0 → 100644
View file @
fd78b68b
#global imports
from
db.table_repository
import
TableRepository
from
db.use_case_repository
import
UseCaseRepository
from
db.entities.table
import
Table
from
flask
import
Response
,
request
table_repository
=
TableRepository
()
use_case_repository
=
UseCaseRepository
()
def
all
():
return
[
t
.
to_serializable_dict
()
for
t
in
table_repository
.
get_all
()]
def
all_for_use_case
(
use_case
:
str
):
return
[
t
.
to_serializable_dict
()
for
t
in
table_repository
.
get_all_for_use_case
(
use_case
)]
def
put_mapping
(
use_case
:
str
,
name
:
str
):
body
=
request
.
json
if
"internal"
not
in
body
or
"external"
not
in
body
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal, external)"
)
table
=
table_repository
.
get_for_use_case_and_name
(
use_case
,
name
)
if
table
==
None
:
print
(
"table not there, creating it..."
)
table
=
table_repository
.
add
(
Table
(
use_case
,
name
,
{}))
table
.
add_mapping
(
body
[
"internal"
],
body
[
"external"
])
table_repository
.
update
(
table
)
return
Response
(
status
=
200
)
def
add_complete
(
use_case
:
str
):
body
=
request
.
json
body
[
"use_case"
]
=
use_case
# check if fields are present
if
"name"
not
in
body
or
"mappings"
not
in
body
:
return
Response
(
status
=
400
,
response
=
"Field missing! Fields required: (name, mappings)"
)
# check if table exists
table_reference
=
table_repository
.
get_for_use_case_and_name
(
body
[
"use_case"
],
body
[
"name"
])
if
table_reference
!=
None
:
return
Response
(
status
=
400
,
response
=
"Table already exists!"
)
use_case_repository
.
put
(
body
[
"use_case"
])
table_new
=
Table
.
from_serializable_dict
(
body
)
table_repository
.
add
(
table_new
)
return
Response
(
status
=
200
)
def
delete_all_for_use_case
(
use_case
:
str
):
table_repository
.
delete_for_use_case
(
use_case
)
return
Response
(
status
=
200
)
def
delete_all
():
table_repository
.
delete_all
()
return
Response
(
status
=
200
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/routes/use_case.py
View file @
fd78b68b
# global imports
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.layer_adapter
import
LayerAdapter
from
db.use_case_repository
import
UseCaseRepository
from
db.use_case_repository
import
UseCaseRepository
from
db.table_repository
import
TableRepository
from
db.repository
import
Repository
from
db.repository
import
Repository
from
db.schema_repository
import
SchemaRepository
from
services.layer_adapter_service
import
LayerAdapterService
from
services.layer_adapter_service
import
LayerAdapterService
import
json
import
json
from
flask
import
Response
,
request
from
flask
import
Response
,
request
use_case_repository
=
UseCaseRepository
()
use_case_repository
=
UseCaseRepository
()
schema_repository
=
Schema
Repository
()
table_repository
=
Table
Repository
()
repository
=
Repository
()
repository
=
Repository
()
def
all
():
def
all
():
...
@@ -20,5 +18,21 @@ def all():
...
@@ -20,5 +18,21 @@ def all():
def
delete_all
():
def
delete_all
():
use_case_repository
.
delete_all
()
use_case_repository
.
delete_all
()
repository
.
delete_all
()
repository
.
delete_all
()
schema_repository
.
delete_all
()
table_repository
.
delete_all
()
return
Response
(
status
=
200
)
def
add
():
body
=
request
.
json
if
"name"
not
in
body
.
keys
():
return
Response
(
status
=
400
,
response
=
"Field missing! Fields required: (name)"
)
name
=
body
[
"name"
]
# check if use-case exists
reference
=
use_case_repository
.
get_by_name
(
name
)
if
not
reference
==
None
:
return
Response
(
status
=
400
,
response
=
"Use-Case already exists!"
)
use_case_repository
.
put
(
name
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
src/participation-hub/business-logic-microservice/app/services/layer_adapter_service.py
View file @
fd78b68b
#global imports
#global imports
from
db.repository
import
Repository
from
db.repository
import
Repository
from
db.
schema_repository
import
Schema
Repository
from
db.
table_repository
import
Table
Repository
from
db.use_case_repository
import
UseCaseRepository
from
db.use_case_repository
import
UseCaseRepository
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.
schema
import
Schema
from
db.entities.
table
import
Table
from
typing
import
List
from
typing
import
List
class
LayerAdapterService
:
class
LayerAdapterService
:
_
schema_repository
=
Schema
Repository
()
_
table_repository
=
Table
Repository
()
_layer_repository
=
Repository
()
_layer_repository
=
Repository
()
_use_case_repository
=
UseCaseRepository
()
_use_case_repository
=
UseCaseRepository
()
...
@@ -18,10 +18,11 @@ class LayerAdapterService:
...
@@ -18,10 +18,11 @@ class LayerAdapterService:
'''
'''
checks if the given layer has correct mappings regarding the schema of the use_case
checks if the given layer has correct mappings regarding the schema of the use_case
'''
'''
schema
=
LayerAdapterService
.
_schema_repository
.
put
(
layer
.
use_case
)
# TODO implement with tables
for
p
in
layer
.
properties
:
# schema = LayerAdapterService._schema_repository.put(layer.use_case)
if
p
not
in
schema
.
mappings
:
# for p in layer.properties:
raise
ValueError
(
f
'{p} is not existent in the schema!'
)
# if p not in schema.mappings:
# raise ValueError(f'{p} is not existent in the schema!')
@
staticmethod
@
staticmethod
def
add_complete
(
layer
:
LayerAdapter
):
def
add_complete
(
layer
:
LayerAdapter
):
...
@@ -39,6 +40,6 @@ class LayerAdapterService:
...
@@ -39,6 +40,6 @@ class LayerAdapterService:
def
delete_all_use_cases
():
def
delete_all_use_cases
():
# TODO
# TODO
LayerAdapterService
.
_layer_repository
.
delete_all_use_cases
()
LayerAdapterService
.
_layer_repository
.
delete_all_use_cases
()
LayerAdapterService
.
_
schema
_repository
.
delete_all
()
LayerAdapterService
.
_
table
_repository
.
delete_all
()
LayerAdapterService
.
_use_case_repository
.
delete_all
()
LayerAdapterService
.
_use_case_repository
.
delete_all
()
\ 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