Skip to content

Commit

Permalink
Merge pull request #837 from ajstanley/main
Browse files Browse the repository at this point in the history
added override to assign media types by media use
  • Loading branch information
mjordan authored Nov 11, 2024
2 parents 12a81dc + 46ba983 commit dacfe2d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
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

0 comments on commit dacfe2d

Please sign in to comment.