Skip to content

Commit

Permalink
fixup! Refactor the AnVIL plugin's manifest config
Browse files Browse the repository at this point in the history
  • Loading branch information
dsotirho-ucsc committed Oct 11, 2024
1 parent c0bf30e commit 9112f93
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/azul/plugins/metadata/anvil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def _field_mapping(self) -> MetadataPlugin._FieldMapping:
]
},
# These field names are hard-coded in the implementation of
# the repository service/controller.
# the repository service/controller. Also, these field paths
# have a brittle coupling that must be maintained to the
# field lookups in `self.manifest_config`.
**{
# Not in schema
'version': 'fileVersion',
Expand Down Expand Up @@ -273,14 +275,12 @@ def facets(self) -> Sequence[str]:
def manifest_config(self) -> ManifestConfig:
result = defaultdict(dict)

# This is used to modify the field names from how they are specified in
# the field mapping. Keys are field paths in an ES hit, and values are
# the desired manifest column name, or None to omit the column from the
# manifest.
custom_field_names = {
('contents', 'files', 'uuid'): None,
('contents', 'files', 'version'): None,
}
# Note that there is a brittle coupling that must be maintained between
# the fields listed here and those used in `self._field_mapping`.
fields_to_omit_from_manifest = [
('contents', 'files', 'uuid'),
('contents', 'files', 'version'),
]

def recurse(mapping: MetadataPlugin._FieldMapping, path: FieldPath):
for path_element, name_or_type in mapping.items():
Expand All @@ -290,15 +290,16 @@ def recurse(mapping: MetadataPlugin._FieldMapping, path: FieldPath):
elif isinstance(name_or_type, str):
if new_path == ('entity_id',):
pass
elif new_path in custom_field_names:
result[path][path_element] = custom_field_names.pop(new_path)
elif new_path in fields_to_omit_from_manifest:
result[path][path_element] = None
fields_to_omit_from_manifest.remove(new_path)
else:
result[path][path_element] = name_or_type
else:
assert False, (path, path_element, name_or_type)

recurse(self._field_mapping, ())
assert len(custom_field_names) == 0, custom_field_names
assert len(fields_to_omit_from_manifest) == 0, fields_to_omit_from_manifest
# The file URL is synthesized from the `uuid` and `version` fields.
# Above, we already configured these two fields to be omitted from the
# manifest since they are not informative to the user.
Expand Down

0 comments on commit 9112f93

Please sign in to comment.