Skip to content

Commit 89d2abf

Browse files
author
Dominick Leppich
committed
fix: relation column logic bug
1 parent 8b56306 commit 89d2abf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

migration/lib/mets_manipulator.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ def process_vocabulary_reference_by_value(self, node):
181181
entity_type = None
182182
for sibling in parent:
183183
if sibling.attrib['name'] == 'RelationEntityType':
184-
entity_type = sibling.text
184+
entity_type = sibling.text.lower()
185185
break
186186

187-
entity_type_in_relation_count = vocabulary_name.count(entity_type)
187+
entity_type_in_relation_count = vocabulary_name.lower().count(entity_type)
188188
if entity_type_in_relation_count == 1:
189189
# Find out relation direction
190190
separator_position = vocabulary_name.index('-')
191-
entity_type_position = vocabulary_name.index(entity_type)
191+
entity_type_position = vocabulary_name.lower().index(entity_type)
192192

193193
# use second column of vocabulary: `Reverse relationship` (The relation vocabulary is specified from `A->B`, the relation references an entity of type `A` and is therefore of type `B`)
194194
if entity_type_position < separator_position:
@@ -197,9 +197,11 @@ def process_vocabulary_reference_by_value(self, node):
197197
else:
198198
search_field='Relationship type'
199199
inverse_search_field='Reverse relationship'
200-
else:
200+
elif entity_type_in_relation_count == 2:
201201
search_field='Relationship type'
202202
inverse_search_field='Reverse relationship'
203+
else:
204+
raise Exception(f'Unable to perform relation column logic on relation [{vocabulary_name}] with search entity: {entity_type}')
203205

204206
try:
205207
# First, try to find the value in the correct column
@@ -227,7 +229,7 @@ def process_vocabulary_reference_by_value(self, node):
227229
new_value = self.ctx.extract_preferred_language(translated_main_values)
228230

229231
#dump_node(node)
230-
logging.warn(f'Relation is saved in the wrong direction, correct direction found and corrected: "{old_value}" -> "{new_value}"')
232+
logging.warn(f'Relation [{vocabulary_name}] is saved in the wrong direction, correct direction found and corrected: "{old_value}" -> "{new_value}"')
231233
node.text = new_value
232234

233235
else:

0 commit comments

Comments
 (0)