Commit 0edf8deb authored by Alexander Lercher's avatar Alexander Lercher

Splitted layer info and layer nodes

parent bd4aa55b
......@@ -80,7 +80,8 @@ paths:
400:
description: "Invalid input"
# Layers
#region Layers
/layers:
post:
operationId: "routes.layers.post"
......@@ -89,7 +90,7 @@ paths:
summary: "Add a new layer or overwrite an existing one"
parameters:
- in: body
name: "Layer"
name: "layer"
description: "The layer data to be added"
required: true
schema:
......@@ -111,41 +112,92 @@ paths:
schema:
$ref: "#/definitions/LayerCollection"
/layers/names:
/layers/{name}:
get:
operationId: "routes.layers.get_names"
operationId: "routes.layers.get_by_name"
tags:
- "Layers"
summary: "Get all layer names"
parameters: []
summary: "Get layer data for layer-name"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to return"
required: true
type: "string"
responses:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/Layer"
404:
description: "Layer not found"
/layers/{name}/nodes:
get:
operationId: "routes.layers.get_nodes"
tags:
- "Layers"
summary: "Get all nodes for the layer"
parameters:
- name: "name"
in: "path"
description: "Name of the layer"
required: true
type: "string"
responses:
200:
description: "Successful operation"
schema:
type: object
404:
description: "Layer not found"
post:
operationId: "routes.layers.post_nodes"
tags:
- "Layers"
summary: "Adds a single or multiple nodes to the layer"
parameters:
- name: "name"
in: "path"
description: "Name of the layer"
required: true
type: "string"
- name: "node"
in: body
description: "The node(s) to be added"
required: true
schema:
type: array
items:
type: string
type: object
responses:
201:
description: "Successful operation"
400:
description: "Invalid input"
/layers/{name}:
/layers/{name}/clusters:
get:
operationId: "routes.layers.get_by_name"
operationId: "routes.clustersets.get_by_name2"
tags:
- "Layers"
summary: "Get layer data for layer-name"
summary: "Get all clusters for the layer"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to return"
description: "Name of the layer"
required: true
type: "string"
responses:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/Layer"
$ref: "#/definitions/ClusterCollection"
404:
description: "Layer not found"
#endregion
# Clusters
# TODO remove partially
/location-clusters:
......@@ -200,6 +252,7 @@ paths:
# 200:
# description: "Successful operation"
# TODO remove
/clustersets:
get:
operationId: "routes.clustersets.get"
......@@ -248,6 +301,7 @@ paths:
404:
description: "Clusterset not found"
# TODO remove
/user-cluster-graphs:
get:
......@@ -350,6 +404,11 @@ definitions:
"UniqueID": "a95075f5042b1b27060080156d87fe34ec7e712c5e57ec9159bc0668543f156a"
"UserID": "a95075f5042b1b27060080156d87fe34ec7e712c"
ClusterCollection:
type: array
items:
$ref: "#/definitions/Cluster"
LocationCluster:
type: object
properties:
......@@ -416,10 +475,10 @@ definitions:
properties:
LayerName:
type: string
Nodes:
type: array
items:
type: object
# Nodes:
# type: array
# items:
# type: object
Properties:
type: array
items:
......@@ -430,10 +489,10 @@ definitions:
properties:
layer_name:
type: string
nodes:
type: array
items:
type: object
# nodes:
# type: array
# items:
# type: object
properties:
type: array
items:
......
......@@ -17,15 +17,12 @@ class Layer:
def to_serializable_dict(self, for_db=False) -> Dict:
return {
"layer_name": self.layer_name,
"properties": self.properties,
"nodes": json.dumps(self.nodes) if for_db else self.nodes
"properties": self.properties
}
def from_serializable_dict(self, layer_info: Dict, from_db=False):
self.layer_name = layer_info['layer_name']
self.properties = layer_info['properties']
self.nodes = json.loads(layer_info["nodes"]) \
if from_db else layer_info["nodes"]
def __repr__(self):
return json.dumps(self.to_serializable_dict())
......
......@@ -21,9 +21,10 @@ class Repository(MongoRepositoryBase):
self._location_cluster_collection = 'location_cluster'
self._time_cluster_collection = 'time_cluster'
self._user_cluster_graph_collection = 'user_cluster_graph'
self._layer_collection = 'layer'
self._clusterset_collection = 'cluster_set'
self._time_slice_collection = 'time_slice'
self._layer_collection = 'layer-new'
self._layer_nodes_collection = 'layer_nodes-new'
self._clusterset_collection = 'cluster_set-new'
self._time_slice_collection = 'time_slice-new'
self.agi_repo = AgiRepository()
......@@ -88,6 +89,18 @@ class Repository(MongoRepositoryBase):
return entries[0]
else:
return None
def add_layer_node(self, node: dict):
super().insert_entry(self._layer_nodes_collection, node)
def add_layer_nodes(self, nodes:List[dict]):
super().insert_many(self._layer_nodes_collection, nodes)
def get_layer_nodes(self, layer_name: str):
'''Returns a json'''
entries = super().get_entries(self._layer_nodes_collection, selection={'layer_name': layer_name}, projection={'_id': 0})
return [e for e in entries]
#endregion
#region ClusterSet
......
......@@ -10,8 +10,16 @@ def get():
def get_names():
return repo.get_clusterset_names()
def get_by_name(layername):
res = repo.get_clusterset(layername)
def get_by_name2(name):
res = repo.get_clusterset(name)
if res is not None:
return res.to_serializable_dict()
else:
return Response(status=404)
def get_by_name(name):
res = repo.get_clusterset(name)
if res is not None:
return res.to_serializable_dict()
else:
......
......@@ -4,15 +4,18 @@ from db.entities import Layer
repo = Repository()
#region layers
def post():
'''Insert a new layer or overwrite an existing one.'''
# TODO overwrite
body = request.json
_insert_layer(body)
return Response(status=201)
def _insert_layer(layer_data: dict):
# convert object keys from ext source
'''Converts object keys from external source and inserts into database.'''
layer_data['layer_name'] = layer_data.pop('LayerName')
layer_data['nodes'] = layer_data.pop('Nodes')
# layer_data['nodes'] = layer_data.pop('Nodes')
layer_data['properties'] = layer_data.pop('Properties')
repo.add_layer(Layer(layer_data))
......@@ -20,12 +23,27 @@ def _insert_layer(layer_data: dict):
def get():
return [l.to_serializable_dict() for l in repo.get_layers()]
def get_names():
return repo.get_layer_names()
def get_by_name(name):
res = repo.get_layer(name)
if res is not None:
return res.to_serializable_dict()
else:
return Response(status=404)
#endregion
#region nodes
def get_nodes(name):
res = repo.get_layer_nodes(name)
# print(res)
return res
def post_nodes(name):
body = request.json
for node in body:
node['layer_name'] = name
repo.add_layer_nodes(body)
return Response(status=201)
#endregion nodes
\ No newline at end of file
......@@ -19,6 +19,10 @@ class MongoRepositoryBase:
collection = self._database[collection_name]
collection.insert_one(content)
def insert_many(self, collection_name, content: list):
collection = self._database[collection_name]
collection.insert_many(content)
def get_entries(self, collection_name, selection: dict = {}, projection: dict = {'_': 0}) -> cursor.Cursor:
collection = self._database[collection_name]
return collection.find(selection, projection)
......
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