Skip to content

Commit

Permalink
Merge pull request #340 from flaxandteal/fix/remap-and-merge
Browse files Browse the repository at this point in the history
Fix/remap and merge
  • Loading branch information
taylorn01 authored Jul 17, 2024
2 parents d90318a + 6b81ac5 commit e4eceeb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions coral/utils/merge_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def merge_default(self, base_node_value, merge_node_value):

def merge_resource_instance_list(self, base_node_value, merge_node_value):
resource_map = {}
if not base_node_value:
base_node_value = []
if not merge_node_value:
merge_node_value = []
for resource in base_node_value:
if resource["resourceId"] not in resource_map:
resource_map[resource["resourceId"]] = resource
Expand Down
29 changes: 22 additions & 7 deletions coral/utils/remap_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,35 @@ def remap_resources(self, user):
data[destination_node_id] = data[data_node_id]
del data[data_node_id]

new_tile = Tile(
tileid=uuid.uuid4(),
# In the unlikely event that a tile exists on the brand new destination
# resource (had a case where a function was creating a tile). This will find
# it and update it rather than create it.
#
# FIXME: this is only needed for cardinality 1 tiles. Many tiles should just create a new tile
#
destination_tile = Tile.objects.filter(
resourceinstance=self.destination_resource,
parenttile=parent_tile,
data=data,
nodegroup=destination_nodegroup,
)
new_tile.save()
).first()

if destination_tile:
destination_tile.data = data
else:
destination_tile = Tile(
tileid=uuid.uuid4(),
resourceinstance=self.destination_resource,
parenttile=parent_tile,
data=data,
nodegroup=destination_nodegroup,
)

destination_tile.save()

# If this is true, it means the parent tile had data and needed
# that data to be remapped. We then add into the created parent
# tiles dictionary for child tiles to look up
if tile_nodegroup_id in self.parent_nodegroup_ids:
self.created_parent_tiles[str(tile.tileid)] = new_tile
self.created_parent_tiles[str(tile.tileid)] = destination_tile

return {
"remapped": True,
Expand Down

0 comments on commit e4eceeb

Please sign in to comment.