Skip to content

Commit

Permalink
Fix bugs in file tag transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jarosenb committed Dec 19, 2023
1 parent 97110b7 commit 034c341
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions designsafe/apps/projects_v2/migration_utils/graph_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ def construct_publication_graph(project_id, version=None) -> nx.DiGraph:
)
entity_dirname = f"{entity_name_slug}--{slugify(entity_title)}"

if parent_node == "NODE_ROOT":
# Publishable entities have a "data" folder in Bagit semantics.
child_path = Path(parent_base_path) / entity_dirname
else:
if parent_node in pub_graph.successors("NODE_ROOT"):
# Publishable entities have a "data" folder in Bagit ontology.
child_path = Path(parent_base_path) / "data" / entity_dirname
else:
child_path = Path(parent_base_path) / entity_dirname

pub_graph.nodes[child_node]["basePath"] = str(child_path)

Expand Down Expand Up @@ -238,8 +238,9 @@ def transform_pub_entities(project_id, version=None):

for _, node_data in pub_graph.nodes.items():
node_entity = next(e for e in entity_listing if e["uuid"] == node_data["uuid"])
data_path = str(Path(node_data["basePath"]) / "data")
new_entity_value = transform_entity(
node_entity, base_pub_meta, node_data["basePath"]
node_entity, base_pub_meta, data_path
)
node_data["value"] = new_entity_value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,23 @@ def update_file_tag_paths(entity: dict, base_path: str) -> list[FileTagDict]:
updated_tags = []
is_type_other = entity["value"].get("projectType", None) == "other"
if is_type_other:
pub_mapping = {"/": base_path}
# type Other is a special case since all files are associated at the root.
path_mapping = {"": base_path}
else:
pub_mapping = {
path_mapping = {
file_obj["path"]: str(Path(base_path) / Path(file_obj["path"]).name)
for file_obj in entity["fileObjs"]
}

for tag in tags:
if not tag.get("path", None):
#print(entity)
updated_tags.append(tag)
# If there is no path, we can't recover the tag.
continue
tag_path_prefixes = (p for p in pub_mapping if tag["path"].startswith(p))
tag_path_prefixes = [p for p in path_mapping if tag["path"].startswith(p)]

for prefix in tag_path_prefixes:
updated_tags.append(
{**tag, "path": tag["path"].replace(prefix, pub_mapping[prefix], 1)}
{**tag, "path": tag["path"].replace(prefix, path_mapping[prefix], 1)}
)

return updated_tags
Expand Down

0 comments on commit 034c341

Please sign in to comment.