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

Splitted layer info and layer nodes

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