Skip to content

Commit

Permalink
Rename to "grouping_node"
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Nov 14, 2024
1 parent 41e267e commit b674f6b
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
14 changes: 7 additions & 7 deletions arches/app/models/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def add_node(self, node, nodegroups=None):
node.ontologyclass = nodeobj.get("ontologyclass", "")
node.datatype = nodeobj.get("datatype", "")
node.nodegroup_id = nodeobj.get("nodegroup_id", "")
node.nodegroup_root_id = nodeobj.get("nodegroup_root_id", node.nodegroup_id)
node.grouping_node_id = nodeobj.get("grouping_node_id", node.nodegroup_id)
node.config = nodeobj.get("config", None)
node.issearchable = nodeobj.get("issearchable", True)
node.isrequired = nodeobj.get("isrequired", False)
Expand All @@ -373,7 +373,7 @@ def add_node(self, node, nodegroups=None):
node.nodegroup = self.get_or_create_nodegroup(
nodegroupid=node.nodegroup_id
)
node.nodegroup_root_id = node.nodegroup_id
node.grouping_node_id = node.nodegroup_id
if nodegroups is not None and str(node.nodegroup_id) in nodegroups:
node.nodegroup.cardinality = nodegroups[str(node.nodegroup_id)][
"cardinality"
Expand All @@ -386,7 +386,7 @@ def add_node(self, node, nodegroups=None):
]["parentnodegroup_id"]
else:
node.nodegroup = None
node.nodegroup_root = None
node.grouping_node = None

node.graph = self

Expand Down Expand Up @@ -616,7 +616,7 @@ def save(self, validate=True, nodeid=None):

if nodeid is not None:
node = self.nodes[nodeid]
node.nodegroup_root_id = node.nodegroup_id
node.grouping_node_id = node.nodegroup_id
branch_publication_id = node.sourcebranchpublication_id
self.update_es_node_mapping(node, datatype_factory, se)
self.create_node_alias(node)
Expand Down Expand Up @@ -645,7 +645,7 @@ def save(self, validate=True, nodeid=None):

else:
for node in self.nodes.values():
node.nodegroup_root_id = node.nodegroup_id
node.grouping_node_id = node.nodegroup_id
self.update_es_node_mapping(node, datatype_factory, se)
node.save()

Expand Down Expand Up @@ -2647,7 +2647,7 @@ def _update_source_nodegroup_hierarchy(nodegroup):
"graph_id",
"nodeid",
"nodegroup_id",
"nodegroup_root_id",
"grouping_node_id",
"source_identifier_id",
"is_collector",
]:
Expand All @@ -2661,7 +2661,7 @@ def _update_source_nodegroup_hierarchy(nodegroup):
source_node.nodegroup_id = (
future_node_nodegroup_node.source_identifier_id
)
source_node.nodegroup_root_id = (
source_node.grouping_node_id = (
future_card_nodegroup_node.source_identifier_id
)

Expand Down
6 changes: 3 additions & 3 deletions arches/app/models/migrations/11613_add_node_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
("models", "11613_node_nodegroup_root"),
("models", "11613_node_grouping_node"),
]

operations = [
Expand All @@ -24,10 +24,10 @@ class Migration(migrations.Migration):
constraint=models.CheckConstraint(
condition=models.Q(
("istopnode", True),
("nodegroup_root__isnull", False),
("grouping_node__isnull", False),
_connector="OR",
),
name="has_nodegroup_root_or_istopnode",
name="has_grouping_node_or_istopnode",
),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ class Migration(migrations.Migration):
("models", "10437_node_alias_not_null"),
]

def set_nodegroup_root(apps, schema_editor):
def set_grouping_node(apps, schema_editor):
Node = apps.get_model("models", "Node")
all_but_top_nodes = Node.objects.exclude(istopnode=True)
for node in all_but_top_nodes:
assert node.nodegroup_id is not None, f"Missing nodegroup for {node!r}"
node.nodegroup_root_id = node.nodegroup_id
Node.objects.bulk_update(all_but_top_nodes, ["nodegroup_root_id"])
node.grouping_node_id = node.nodegroup_id
Node.objects.bulk_update(all_but_top_nodes, ["grouping_node_id"])

PublishedGraph = apps.get_model("models", "PublishedGraph")
published_graphs = PublishedGraph.objects.all()
for published_graph in published_graphs:
for node_dict in published_graph.serialized_graph["nodes"]:
node_dict["nodegroup_root_id"] = node_dict["nodegroup_id"]
node_dict["grouping_node_id"] = node_dict["nodegroup_id"]
PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"])

def remove_nodegroup_root(apps, schema_editor):
def remove_grouping_node(apps, schema_editor):
PublishedGraph = apps.get_model("models", "PublishedGraph")
published_graphs = PublishedGraph.objects.all()
for published_graph in published_graphs:
for node_dict in published_graph.serialized_graph["nodes"]:
node_dict.pop("nodegroup_root_id", None)
node_dict.pop("grouping_node_id", None)
PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"])

operations = [
migrations.AddField(
model_name="node",
name="nodegroup_root",
name="grouping_node",
field=models.ForeignKey(
blank=True,
null=True,
Expand All @@ -46,5 +46,5 @@ def remove_nodegroup_root(apps, schema_editor):
to="models.node",
),
),
migrations.RunPython(set_nodegroup_root, remove_nodegroup_root),
migrations.RunPython(set_grouping_node, remove_grouping_node),
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="node",
constraint=models.CheckConstraint(
condition=models.Q(("nodegroup_root_id", models.F("nodegroup_id"))),
name="nodegroup_root_matches_nodegroup",
condition=models.Q(("grouping_node_id", models.F("nodegroup_id"))),
name="grouping_node_matches_nodegroup",
),
),
]
18 changes: 9 additions & 9 deletions arches/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def __init__(self, *args, **kwargs):
graph = models.ForeignKey(
GraphModel, db_column="graphid", blank=True, null=True, on_delete=models.CASCADE
)
nodegroup_root = models.ForeignKey(
grouping_node = models.ForeignKey(
"self",
blank=True,
null=True,
Expand Down Expand Up @@ -915,15 +915,15 @@ def __init__(self, *args, **kwargs):
def clean(self):
if not self.alias:
Graph.objects.get(pk=self.graph_id).create_node_alias(self)
if not self.nodegroup_root_id:
self.nodegroup_root_id = self.nodegroup_id
if not self.grouping_node_id:
self.grouping_node_id = self.nodegroup_id

def save(self, **kwargs):
if not self.alias or not self.nodegroup_root_id:
if not self.alias or not self.grouping_node_id:
self.clean()
add_to_update_fields(kwargs, "alias")
add_to_update_fields(kwargs, "hascustomalias")
add_to_update_fields(kwargs, "nodegroup_root_id")
add_to_update_fields(kwargs, "grouping_node_id")
if self.pk == self.source_identifier_id:
self.source_identifier_id = None
add_to_update_fields(kwargs, "source_identifier_id")
Expand All @@ -944,12 +944,12 @@ class Meta:
name="has_nodegroup_or_istopnode",
),
models.CheckConstraint(
condition=Q(istopnode=True) | Q(nodegroup_root__isnull=False),
name="has_nodegroup_root_or_istopnode",
condition=Q(istopnode=True) | Q(grouping_node__isnull=False),
name="has_grouping_node_or_istopnode",
),
models.CheckConstraint(
condition=Q(nodegroup_root_id=models.F("nodegroup_id")),
name="nodegroup_root_matches_nodegroup",
condition=Q(grouping_node_id=models.F("nodegroup_id")),
name="grouping_node_matches_nodegroup",
),
]

Expand Down
6 changes: 3 additions & 3 deletions tests/models/graph_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def setUpTestData(cls):
"istopnode": True,
"name": "Node",
"nodegroup_id": "20000000-0000-0000-0000-100000000001",
"nodegroup_root_id": "20000000-0000-0000-0000-100000000001",
"grouping_node_id": "20000000-0000-0000-0000-100000000001",
"nodeid": "20000000-0000-0000-0000-100000000001",
"ontologyclass": "http://www.cidoc-crm.org/cidoc-crm/E1_CRM_Entity",
},
Expand All @@ -133,7 +133,7 @@ def setUpTestData(cls):
"istopnode": False,
"name": "Node Type",
"nodegroup_id": "20000000-0000-0000-0000-100000000001",
"nodegroup_root_id": "20000000-0000-0000-0000-100000000001",
"grouping_node_id": "20000000-0000-0000-0000-100000000001",
"nodeid": "20000000-0000-0000-0000-100000000002",
"ontologyclass": "http://www.cidoc-crm.org/cidoc-crm/E55_Type",
},
Expand Down Expand Up @@ -1281,7 +1281,7 @@ def test_update_empty_graph_from_editable_future_graph(self):
if key not in [
"graph_id",
"nodegroup_id",
"nodegroup_root_id",
"grouping_node_id",
"nodeid",
"source_identifier_id",
]:
Expand Down
4 changes: 2 additions & 2 deletions tests/models/resource_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,15 @@ def test_self_referring_resource_instance_descriptor(self):
pk=nodegroup.pk,
graph=graph,
nodegroup=nodegroup,
nodegroup_root_id=nodegroup.pk,
grouping_node_id=nodegroup.pk,
name="String Node",
datatype="string",
istopnode=False,
)
resource_instance_node = models.Node.objects.create(
graph=graph,
nodegroup=nodegroup,
nodegroup_root_id=nodegroup.pk,
grouping_node_id=nodegroup.pk,
name="Resource Node",
datatype="resource-instance",
istopnode=False,
Expand Down
2 changes: 1 addition & 1 deletion tests/models/tile_model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_check_for_missing_nodes(self):
name="Required file list",
datatype="file-list",
nodegroup=node_group,
nodegroup_root_id=node_group.pk,
grouping_node_id=node_group.pk,
isrequired=True,
istopnode=False,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/views/graph_manager_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def setUpTestData(cls):
"istopnode": False,
"name": "Node Type",
"nodegroup_id": "20000000-0000-0000-0000-100000000001",
"nodegroup_root_id": "20000000-0000-0000-0000-100000000001",
"grouping_node_id": "20000000-0000-0000-0000-100000000001",
"nodeid": "20000000-0000-0000-0000-100000000002",
"ontologyclass": "http://www.cidoc-crm.org/cidoc-crm/E55_Type",
},
Expand Down

0 comments on commit b674f6b

Please sign in to comment.