-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinspection.py
More file actions
executable file
·30 lines (23 loc) · 1.16 KB
/
inspection.py
File metadata and controls
executable file
·30 lines (23 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from data.inspection.LiInspection import LiInspection
from py2neo import Node, Relationship
from data.access.datastore import EntryDoesExistExeption, find_node, neo4j_transaction
def list():
query = "MATCH (s:Ship) -[:HAS_INSPECTION]-> (i:Inspection) RETURN DISTINCT s.name+' on '+i.date as i, i.id as id"
with neo4j_transaction() as tx:
return {i['i']: i['id'] for i in tx.run(query)}
def create(inspection: LiInspection, fail_on_exists = False) -> Node:
inspection_node = find_node(inspection.label, id=inspection.id)
if inspection_node:
if fail_on_exists:
raise EntryDoesExistExeption("Inspection exists already.")
else:
return inspection_node
ship_node = find_node("Ship", imo=inspection.imo)
if not ship_node:
raise ValueError(f"Ship with imo {inspection.imo} not found")
inspection_node = Node(inspection.label, id=inspection.id, imo=inspection.imo, date=inspection.date)
inspection_relation = Relationship(ship_node, "HAS_INSPECTION", inspection_node)
with neo4j_transaction() as tx:
tx.create(inspection_node)
tx.create(inspection_relation)
return inspection_node