| 81 | |
| 82 | |
| 83 | class TreeDisplay(object): |
| 84 | def __init__(self): |
| 85 | self.tree = Tree() |
| 86 | self.root_identifier = "GRAPH" |
| 87 | self.tree.create_node(identifier=self.root_identifier) |
| 88 | |
| 89 | def parse_property_type(self, property): |
| 90 | actual_instance = property.actual_instance |
| 91 | if isinstance(actual_instance, PrimitiveType): |
| 92 | return actual_instance.primitive_type |
| 93 | elif isinstance(actual_instance, StringType): |
| 94 | return "string" |
| 95 | else: |
| 96 | return str(actual_instance) |
| 97 | |
| 98 | def create_graph_node(self, graph, recursive=True): |
| 99 | # graph name must be unique |
| 100 | self.tree.create_node( |
| 101 | tag=f"{graph.name}(identifier: {graph.id})", |
| 102 | identifier=graph.id, |
| 103 | parent=self.root_identifier, |
| 104 | ) |
| 105 | if recursive: |
| 106 | self.create_schema_node(graph) |
| 107 | |
| 108 | def create_schema_node(self, graph): |
| 109 | schema_identifier = f"{graph.id}_schema" |
| 110 | self.tree.create_node( |
| 111 | tag="schema", identifier=schema_identifier, parent=graph.id |
| 112 | ) |
| 113 | # vertex type |
| 114 | vertex_type_identifier = f"{schema_identifier}_vertex_types" |
| 115 | self.tree.create_node( |
| 116 | tag="vertex types", |
| 117 | identifier=vertex_type_identifier, |
| 118 | parent=schema_identifier, |
| 119 | ) |
| 120 | if graph.var_schema is not None and graph.var_schema.vertex_types is not None: |
| 121 | for vertex in graph.var_schema.vertex_types: |
| 122 | vertex_identifier = f"{vertex_type_identifier}_{vertex.type_name}" |
| 123 | self.tree.create_node( |
| 124 | tag=f"{vertex.type_name}", |
| 125 | identifier=vertex_identifier, |
| 126 | parent=vertex_type_identifier, |
| 127 | ) |
| 128 | # property |
| 129 | if vertex.properties is not None: |
| 130 | for p in vertex.properties: |
| 131 | is_primary_key = ( |
| 132 | True if p.property_name in vertex.primary_keys else False |
| 133 | ) |
| 134 | property_identifier = f"{vertex_identifier}_{p.property_name}" |
| 135 | tag = "Property(name: {0}, type: {1}, is_primary_key: {2})".format( |
| 136 | p.property_name, |
| 137 | self.parse_property_type(p.property_type), |
| 138 | is_primary_key, |
| 139 | ) |
| 140 | self.tree.create_node( |