Skip to content
Snippets Groups Projects
Commit 9738f2b2 authored by Benjamin Becker's avatar Benjamin Becker
Browse files

refactoring

parent c4bcc858
No related branches found
No related tags found
No related merge requests found
...@@ -269,22 +269,36 @@ def tag_string_convert(key, data, errors, context): ...@@ -269,22 +269,36 @@ def tag_string_convert(key, data, errors, context):
def convert_subjectID_to_subjectText(key, data, errors, context): def convert_subjectID_to_subjectText(key, data, errors, context):
#if _extract_value(data, 'is_collection'):
# return
subject_id = _extract_value(data, 'subject') subject_id = _extract_value(data, 'subject')
subject_text_file = config.get('ckanext.tpsh.subject.mapping') default_subject_mapping_file_path = '/usr/lib/ckan/default/src/ckanext-odsh/subject_mapping.json'
subject_mapping_file_path = config.get(
'ckanext.odsh.subject_mapping_file_path', default_subject_mapping_file_path)
try: try:
with open(subject_text_file) as mapping_json: with open(subject_mapping_file_path) as mapping_json:
subject_mapping = json.loads(mapping_json.read()) subject_mapping = json.loads(mapping_json.read())
except Exception: except IOError as err:
raise Exception("Could not load subject mapping file!") log.error(
'Could not load subject mapping file from {}'
.format(subject_mapping_file_path)
)
raise
except ValueError as err:
log.error(
'Could not convert subject mapping file from json. \nSubject mapping file: {}'
.format(subject_mapping_file_path)
)
raise
try: if subject_id in subject_mapping:
subject_text = subject_mapping[subject_id] subject_text = subject_mapping[subject_id]
except: else:
log.exception('Subject_id: ' + subject_id +' not found') log.warning(
'Subject_id "{}" not found in subject mapping dictionary.\nSubject mapping file: {}'
.format(subject_id, subject_mapping_file_path)
)
subject_text = "" subject_text = ""
new_index = next_extra_index(data) new_index = next_extra_index(data)
data[('extras', new_index, 'key')] = 'subject_text' data[('extras', new_index, 'key')] = 'subject_text'
data[('extras', new_index, 'value')] = subject_text data[('extras', new_index, 'value')] = subject_text
......
{
"http://d-nb.info/gnd/4146704-8": "Broschüre",
"http://d-nb.info/gnd/4156966-0" : "Geschäftsverteilungsplan"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment