Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added override to assign media types by media use #837

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions WorkbenchConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def get_default_config(self):
"csv_value_templates_rand_length": 5,
"allow_csv_value_templates_if_field_empty": [],
"remind_user_to_run_check": False,
"media_type_by_media_use": False,
}

# Tests validity and existence of configuration file path.
Expand Down
7 changes: 7 additions & 0 deletions i7Import/i7ImportUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, config_location):
"start": 0,
"rows": 100000,
"secure_ssl_only": True,
"pids": False,
}

def get_config(self):
Expand Down Expand Up @@ -181,6 +182,12 @@ def get_default_metadata_solr_request(self):
fedora_collections.append(f'{fedora_prefix}"{collection}"')
fq_string = "&fq=" + " or ".join(fedora_collections)
query = f"{query}{fq_string}"
if self.config["pids"]:
pids_to_use = []
for candidate in self.config["pids"]:
pids_to_use.append(f"PID:{candidate}")
fq_string = "&fq=" + " or ".join(pids_to_use)
query = f"{query}{fq_string}"

# Get the populated CSV from Solr, with the object namespace and field list filters applied.
return query
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/set_media_type_test/multi_types_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ media_types_override:
- sometextmedia: ['txt']

secure_ssl_only: false

media_type_by_media_use:
- https://projects.iq.harvard.edu/fits: fits_technical_metadata
8 changes: 8 additions & 0 deletions workbench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def set_media_type(config, filepath, file_fieldname, csv_row):
"""
if "media_type" in config:
return config["media_type"]
if config["media_type_by_media_use"] and len(config["media_type_by_media_use"]) > 0:
additional_files = get_additional_files_config(config)
media_url = additional_files.get(file_fieldname)
if file_fieldname in additional_files:
for entry in config["media_type_by_media_use"]:
for key, value in entry.items():
if key == media_url:
return value

# Determine if the incomtimg filepath matches a registered eEmbed media type.
oembed_media_type = get_oembed_url_media_type(config, filepath)
Expand Down