Skip to content

Commit

Permalink
ext references for vocabs import hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Sep 22, 2023
1 parent 1e10396 commit a94daa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 11 additions & 5 deletions openatlas/api/import_scripts/vocabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ def fetch_top_groups(
hierarchy,
'custom', form_data['classes'],
form_data['multiple'])
exact_match_id = get_exact_match().id
name = group[0].rsplit('/', 1)[-1]
ref.link('P67', hierarchy, name, type_id=exact_match_id)
import_member(
group[0],
id_,
form_data['language'],
ref,
hierarchy)
count.append(group[0])
if Type.check_hierarchy_exists(group[1]):
duplicates.append(group[0])
if (Type.check_hierarchy_exists(group[1])
and group[0] in form_data['top_concepts']):
duplicates.append(group[1])
return count, duplicates


Expand All @@ -55,15 +59,14 @@ def import_member(
lang: str,
ref: ReferenceSystem,
super_: Optional[Entity], ) -> bool:
exact_match_id = get_exact_match().id
req = vocabs_requests(id_, 'groupMembers', {'uri': uri, 'lang': lang})
child = None
for member in req['members']:
name = member['uri'].rsplit('/', 1)[-1]
if super_:
child = Entity.insert('type', member['prefLabel'])
child.link('P127', super_)
ref.link('P67', child, name, type_id=exact_match_id)
ref.link('P67', child, name, type_id=get_exact_match().id)
if member['hasMembers']:
import_member(member['uri'], id_, lang, ref, child)
return True
Expand All @@ -88,6 +91,9 @@ def fetch_top_level(
hierarchy,
'custom', form_data['classes'],
form_data['multiple'])
exact_match_id = get_exact_match().id
name = entry['uri'].rsplit('/', 1)[-1]
ref.link('P67', hierarchy, name, type_id=exact_match_id)
entry['subs'] = import_children(
entry['uri'],
id_,
Expand All @@ -96,7 +102,7 @@ def fetch_top_level(
hierarchy)
count.append(entry)
if Type.check_hierarchy_exists(entry['label']):
duplicates.append(entry)
duplicates.append(entry['label'])
return count, duplicates


Expand Down
11 changes: 5 additions & 6 deletions openatlas/views/vocabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,19 @@ class ImportVocabsHierarchyForm(FlaskForm):
'classes': form.classes.data,
'multiple': form.multiple.data,
'language': form.language.data}

try:
results = import_vocabs_data(id_, form_data, details, category)
count = len(results[0])
Transaction.commit()
g.logger.log('info', 'import', f'import: {count} top concepts')
for duplicate in results[1]:
g.logger.log(
'notice',
'import',
f'Did not import {duplicate["label"]}, duplicate.')
import_str = f"{_('import of')}: {count} {_('top concepts')}"
if results[1]:
import_str += f'. {_("Check log for not imported concepts")}'
for duplicate in results[1]:
g.logger.log(
'info',
'import',
f'Did not import "{duplicate}", duplicate.')
flash(import_str, 'info')
except Exception as e: # pragma: no cover
Transaction.rollback()
Expand Down

0 comments on commit a94daa4

Please sign in to comment.