Commit 69817e5a authored by Alexander Lercher's avatar Alexander Lercher

Merge remote-tracking branch 'origin/feature/community-detection-pipeline'...

Merge remote-tracking branch 'origin/feature/community-detection-pipeline' into feature/community-detection-pipeline
parents 0f441888 fd78b68b
paths:
#####
# 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:
security:
- JwtRegular: []
......@@ -22,98 +49,111 @@ paths:
responses:
'200':
description: "Successful Request"
/schemas:
#####
# TABLES
#####
/tables:
get:
security:
- JwtRegular: []
operationId: "routes.schema.all"
operationId: "routes.tables.all"
tags:
- "Schemas"
summary: "Get all Use-Cases"
description: "Get all Use-Cases"
- "Tables"
summary: "Get all Tables"
description: "Get all Tables"
responses:
'200':
description: "Successful Request"
/use-cases/{use_case}/schema:
post:
delete:
security:
- JwtRegular: []
operationId: "routes.schema.add_complete"
operationId: "routes.tables.delete_all"
tags:
- "Schemas"
summary: "Add a new schema with mappings to the DB"
description: "Add a new schema with mappings to the DB"
- "Tables"
summary: "Delete all Tables"
description: "Delete all Tables"
responses:
'200':
description: "Successful Request"
/use-cases/{use_case}/tables:
get:
security:
- JwtRegular: []
operationId: "routes.tables.all_for_use_case"
tags:
- "Tables"
summary: "Get all Tables for one Use-Case"
description: "Get all Tables for one Use-Case"
parameters:
- name: "use_case"
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: "Object"
in: "body"
required: true
schema:
type: object
additionalProperties:
type: string
example:
name: name
dough: dough//type
responses:
'200':
description: "Successful Request"
'400':
description: "Schema already exists or missing field in request"
get:
post:
security:
- JwtRegular: []
operationId: "routes.schema.get_for_use_case"
operationId: "routes.tables.add_complete"
tags:
- "Schemas"
summary: "Get the Schema assigned to the Use-Case"
description: "Get the Schema assigned to the Use-Case"
- "Tables"
summary: "Adds a Table identified by it's name for one Use-Case"
description: "Adds a Table identified by it's name for one Use-Case"
parameters:
- name: "use_case"
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"
- in: body
name: "Object"
required: true
schema:
$ref: '#/definitions/Table'
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
'400':
description: "Table with the name already exists or missing fields in the request."
delete:
security:
- JwtAdmin: []
operationId: "routes.schema.delete_for_use_case"
operationId: "routes.tables.delete_all_for_use_case"
tags:
- "Schemas"
summary: "Delete the Schema assigned to the Use-Case"
description: "Delete the Schema assigned to the Use-Case"
- "Tables"
summary: "Delete all Tables for a Use-Case"
description: "Delete all Tables for a Use-Case"
parameters:
- name: "use_case"
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"
responses:
'200':
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:
security:
- JwtRegular: []
operationId: "routes.schema.add_mapping"
operationId: "routes.tables.put_mapping"
tags:
- "Schemas"
summary: "Adds an attribute mapping to the Schema of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
- "Tables"
summary: "Adds an attribute mapping to a Table of the Use-Case"
description: "Adds an attribute mapping to a Table of the Use-Case"
parameters:
- name: "use_case"
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
type: "string"
- in: body
......@@ -124,6 +164,15 @@ paths:
responses:
'200':
description: "Successful Request"
#####
# END-TABLES
#####
#####
# LAYERS
#####
/layers:
get:
security:
......@@ -166,39 +215,24 @@ paths:
description: "Successful Request"
'400':
description: "Bad structure in request body or Layer already exists"
/use-cases/{use_case}/layers:
get:
/use-cases/{use_case}/table/{table}/layers/{name}/cluster-mapping:
put:
security:
- JwtRegular: []
operationId: "routes.layer.get_all_for_use_case"
operationId: "routes.layer.add_cluster_mapping"
tags:
- "Layers"
summary: "Retrieves all layers belonging to the given Use-Case"
description: "Retrieves all layers belonging to the given Use-Case"
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"
description: "Name of the Use-Case the layer belongs to"
description: "Name of the Use-Case the Table belongs to"
required: true
type: "string"
responses:
'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"
- name: "table"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
description: "Name of the Table the Layer belongs to"
required: true
type: "string"
- name: "name"
......@@ -206,77 +240,45 @@ paths:
description: "Name of the Layer"
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:
'200':
description: "Successful Request"
'404':
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':
description: "Layer already exists"
description: "Field in request is missing or attribute does not exist in the Layer"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_one"
operationId: "routes.layer.delete_cluster_mapping"
tags:
- "Layers"
summary: "Delete one Layer from the DB"
description: "Delete one Layer from the DB"
summary: "Deletes a cluster-attribute mapping from the selected layer"
description: "Deletes a cluster-attribute mapping from the selected layer"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to delete"
required: true
type: "string"
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
description: "Name of the Use-Case the Table belongs to"
required: true
type: "string"
responses:
'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"
- name: "table"
in: "path"
description: "Name of the Use-Case the layer belongs to"
description: "Name of the Table the Layer belongs to"
required: true
type: "string"
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
description: "Name of the Layer"
required: true
type: "string"
- in: body
......@@ -296,95 +298,85 @@ paths:
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
delete:
/use-cases/{use_case}/layers:
get:
security:
- JwtRegular: []
operationId: "routes.layer.delete_cluster_mapping"
operationId: "routes.layer.get_all_for_use_case"
tags:
- "Layers"
summary: "Deletes a cluster-attribute mapping from the selected layer"
description: "Deletes a cluster-attribute mapping from the selected layer"
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 layer belongs to"
required: true
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:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
/use-cases/{use_case}/layers/mapping:
put:
description: "Use-Case does not exist"
/use-cases/{use_case}/table/{table}/layers/{name}:
get:
security:
- JwtRegular: []
operationId: "routes.layer.add_mapping_for_all"
operationId: "routes.layer.one"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each Layer of the Use-Case"
description: "Adds an attribute mapping to the each Layer of the Use-Case"
summary: "Retrieve one Layer from the DB"
description: "Retrieve one Layer from the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
description: "Name of the Use-Case the Table belongs to"
required: true
type: "string"
- in: body
name: "Object"
- name: "table"
in: "path"
description: "Name of the Table the Layer belongs to"
required: true
schema:
$ref: '#/definitions/LayerMapping'
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
'404':
description: "Layer does not exist"
delete:
security:
- JwtAdmin: []
operationId: "routes.layer.delete_mapping_for_all"
- JwtRegular: []
operationId: "routes.layer.delete_one"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all Layers of the Use-Case"
description: "Deletes an attribute mapping for all Layers of the Use-Case"
summary: "Delete one Layer from the DB"
description: "Delete one Layer from the DB"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Layer belongs to"
description: "Name of the Use-Case the Table belongs to"
required: true
type: "string"
- in: body
name: "Object"
- name: "table"
in: "path"
description: "Name of the Table the Layer belongs to"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
type: "string"
- name: "name"
in: "path"
description: "Name of the Layer"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
'404':
description: "Layer does not exist"
/use-cases/{use_case}/layers/{name}/mapping:
put:
security:
......@@ -458,6 +450,23 @@ definitions:
internal:
type: string
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:
type: "object"
required:
......@@ -472,18 +481,22 @@ definitions:
example: "arrival_unix_timestamp_utc"
Layer:
type: "object"
required:
- name
required:
- use_case
- table
- name
- cluster_properties
- properties
properties:
use_case:
type: string
example: "use_case_1"
table:
type: string
example: "table1"
name:
type: string
example: "layer1"
use_case:
type: string
example: "car-sharing"
cluster_properties:
type: array
items:
......
......@@ -7,7 +7,7 @@ class LayerAdapter:
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
......@@ -20,6 +20,7 @@ class LayerAdapter:
self.name = name
self.properties = properties
self.use_case = use_case
self.table = table
for prop in cluster_properties:
if prop not in properties:
......@@ -86,7 +87,8 @@ class LayerAdapter:
"name": self.name,
"properties": self.properties,
"cluster_properties": self.cluster_properties,
"use_case": self.use_case
"use_case": self.use_case,
"table": self.table
}
@staticmethod
......@@ -101,6 +103,7 @@ class LayerAdapter:
return LayerAdapter(
user_dict["name"],
user_dict["use_case"],
user_dict["table"],
user_dict["properties"],
user_dict["cluster_properties"]
)
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
from typing import Dict
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.mappings = mappings
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
def from_serializable_dict(data: Dict):
return Table(data["name"])
\ No newline at end of file
return Table(
data["use_case"],
data["name"],
data["mappings"]
)
# 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
......@@ -14,7 +14,7 @@ class Repository(MongoRepositoryBase):
def __init__(self):
super().__init__(netconst.BUSINESS_LOGIC_DB_HOSTNAME,
netconst.BUSINESS_LOGIC_DB_PORT,
'rest-gateway-db')
'business-logic-db')
self._adapter_collection = 'layer_adapters'
self._use_case_collection = 'use_cases'
......@@ -29,8 +29,8 @@ class Repository(MongoRepositoryBase):
return [LayerAdapter.from_serializable_dict(row) for row in list(result)]
def one(self, name : str, use_case: str) -> LayerAdapter:
result = list(super().get_entries(self._adapter_collection, selection={"name": name, "use_case": use_case}))
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}))
if len(result) == 1:
return LayerAdapter.from_serializable_dict(result[0])
......@@ -43,19 +43,15 @@ class Repository(MongoRepositoryBase):
def add(self, adapter : LayerAdapter):
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):
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):
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: str):
def delete(self, adapter : LayerAdapter):
collection = self._database[self._adapter_collection]
collection.delete_many({"name": name, "use_case": use_case})
\ No newline at end of file
collection.delete_many({"name": adapter.name, "use_case": adapter.use_case, "table": adapter.table})
\ No newline at end of file
# 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()})
# 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
......@@ -13,7 +13,7 @@ class UseCaseRepository(MongoRepositoryBase):
def __init__(self):
super().__init__(netconst.BUSINESS_LOGIC_DB_HOSTNAME,
netconst.BUSINESS_LOGIC_DB_PORT,
'rest-gateway-db')
'business-logic-db')
self._use_case_collection = 'use_cases'
......@@ -30,6 +30,17 @@ class UseCaseRepository(MongoRepositoryBase):
collection = self._database[self._use_case_collection]
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):
use_cases = self.all()
......@@ -37,5 +48,4 @@ class UseCaseRepository(MongoRepositoryBase):
if len(existing_use_cases) == 0:
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
#global imports
from db.entities.layer_adapter import LayerAdapter
from db.repository import Repository
from db.schema_repository import SchemaRepository
from db.table_repository import TableRepository
from db.use_case_repository import UseCaseRepository
from services.layer_adapter_service import LayerAdapterService
import json
from flask import Response, request
schema_repository = SchemaRepository()
table_repository = TableRepository()
layer_repository = Repository()
use_case_repository = UseCaseRepository()
def 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)
return [layer.to_serializable_dict() for layer in layer_repository.all_for_use_case(use_case)]
layer_repository.delete_all()
return Response(status=200)
def add_complete():
'''
......@@ -28,21 +30,33 @@ def add_complete():
'''
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:
return Response(status=400, response=f"Field missing! Fields required: (name, properties, cluster_properties)")
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, table), present:({data.keys()})")
use_case = data["use_case"]
table_name = data["table"]
layer_name = data["name"]
use_case_repository.put(data["use_case"])
layer = layer_repository.one(data["name"], data["use_case"])
table = table_repository.get_for_use_case_and_name(use_case, table_name)
if table == None:
return Response(status=400, response="Table does not exist!")
layer = layer_repository.one(layer_name, use_case, table.name)
if layer != None:
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:
layer_new = LayerAdapter.from_serializable_dict(data)
except BaseException as e:
print(f"Exception: {e}")
return Response(status=400)
return Response(status=400, response=f"{e}")
try:
LayerAdapterService.add_complete(layer_new)
......@@ -51,49 +65,17 @@ def add_complete():
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_case: str):
def add_cluster_mapping(use_case: str, table: str, name: str):
'''
add a mapped property to the list of properties to cluster with
@params:
name - Required : unique identifier for the layer
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_case)
layer = layer_repository.one(name, use_case)
layer = layer_repository.one(name, use_case, table)
if layer == None:
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):
except:
return Response(status=400, response=f'{data["attribute"]} is no attribute in the layer!')
def delete_cluster_mapping(name: str, use_case: str):
def delete_cluster_mapping(use_case: str, table: str, name: str):
'''
remove a mapped property from the list of properties to cluster with
@params:
name - Required : unique identifier for the layer
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_case)
layer = layer_repository.one(name, use_case)
layer = layer_repository.one(name, use_case, table)
if layer == None:
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):
print(e)
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:
use_case - Required : String-identifier for the use-case
def get_all_for_use_case(use_case: str):
'''
get all layers assigned to the given 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
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):
def one(use_case: str, table: str, name: str):
'''
delete a mapping from each layer in the use-case
fetch a single layer from the DB
@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_case)
layer = layer_repository.one(name, use_case, table)
data = request.json
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)
if layer == None:
return Response(status=404, response=f"Layer with name '{name}' does not exist!")
return Response(status=200)
return Response(status=200, response=json.dumps(layer.to_serializable_dict()))
def delete_mapping(name: str, use_case: str):
def delete_mapping(use_case: str, table: str, name: str):
'''
delete a mapping from the layer identified by the internal representation
@params:
name - Required : unique identifier for the layer
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_case)
layer = layer_repository.one(name, use_case)
layer = layer_repository.one(name, use_case, table)
if layer == None:
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):
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
@params:
name - Required : unique identifier for the layer
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_case)
......@@ -246,36 +194,33 @@ def add_mapping(name: str, use_case: str):
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!')
table = table_repository.get_for_use_case_and_name(use_case, table)
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_repository.update(layer)
return Response(status=200)
def delete_one(name: str, use_case: str):
def delete_one(use_case: str, table: str, name: str):
'''
delete a layer and all its mappings from the Db
@params:
name - Required : unique identifier for the layer
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_case)
layer = layer_repository.one(name, use_case)
layer = layer_repository.one(name, use_case, table)
if layer == None:
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)
\ No newline at end of file
#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
#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
# global imports
from db.entities.layer_adapter import LayerAdapter
from db.use_case_repository import UseCaseRepository
from db.table_repository import TableRepository
from db.repository import Repository
from db.schema_repository import SchemaRepository
from services.layer_adapter_service import LayerAdapterService
import json
from flask import Response, request
use_case_repository = UseCaseRepository()
schema_repository = SchemaRepository()
table_repository = TableRepository()
repository = Repository()
def all():
......@@ -20,5 +18,21 @@ def all():
def delete_all():
use_case_repository.delete_all()
repository.delete_all()
schema_repository.delete_all()
return Response(status=200)
\ No newline at end of file
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)
#global imports
from db.repository import Repository
from db.schema_repository import SchemaRepository
from db.table_repository import TableRepository
from db.use_case_repository import UseCaseRepository
from db.entities.layer_adapter import LayerAdapter
from db.entities.schema import Schema
from db.entities.table import Table
from typing import List
class LayerAdapterService:
_schema_repository = SchemaRepository()
_table_repository = TableRepository()
_layer_repository = Repository()
_use_case_repository = UseCaseRepository()
......@@ -18,10 +18,11 @@ class LayerAdapterService:
'''
checks if the given layer has correct mappings regarding the schema of the use_case
'''
schema = LayerAdapterService._schema_repository.put(layer.use_case)
for p in layer.properties:
if p not in schema.mappings:
raise ValueError(f'{p} is not existent in the schema!')
# TODO implement with tables
# schema = LayerAdapterService._schema_repository.put(layer.use_case)
# for p in layer.properties:
# if p not in schema.mappings:
# raise ValueError(f'{p} is not existent in the schema!')
@staticmethod
def add_complete(layer: LayerAdapter):
......@@ -39,6 +40,6 @@ class LayerAdapterService:
def delete_all_use_cases():
# TODO
LayerAdapterService._layer_repository.delete_all_use_cases()
LayerAdapterService._schema_repository.delete_all()
LayerAdapterService._table_repository.delete_all()
LayerAdapterService._use_case_repository.delete_all()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment