Skip to content

Commit

Permalink
Updated OclExport.to_resource_list to better handle sources/collections
Browse files Browse the repository at this point in the history
  • Loading branch information
paynejd committed Oct 9, 2020
1 parent d0a8a08 commit f51c40c
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions ocldev/oclexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,15 @@ def get_full_export(self):
""" Return full contents of export as a python dictionary """
return self._export_json

def to_resource_list(self, do_clean_for_bulk_import=False,
def to_resource_list(self, do_clean_for_bulk_import=False, do_include_concepts=True,
do_incldue_mappings=True, do_include_references=False,
do_include_repo=False, do_include_repo_version=False):
"""
Return all concepts, mappings, and (optionally) the repository and repository version
as an OclJsonResourceList. If `do_clean_for_bulk_import` is true:
- if the repository type is "Source Version", concepts and mappings are included
- if the repository type is "Collection", references (and not concepts and mappings)
are included
- only attributes required to import an equivalent resource via bulk import
are included
Return all resources in an OclExport as an as an OclJsonResourceList. By default, only
concepts and mappings are included regardless of whether it is a Source or Collection
export. Use the arguments to include references, the repository and repository version,
or to omit concepts or mappings. If `do_clean_for_bulk_import` is true, only attributes
required to import an equivalent resource via bulk import are included in each resource.
"""
if not self._export_json:
return None
Expand All @@ -197,10 +196,9 @@ def to_resource_list(self, do_clean_for_bulk_import=False,
repo.pop(attr_key, '')
resource_list.append(repo)

# Prepare for bulk import
if do_clean_for_bulk_import:
# Add concepts
if repo_type == 'Source':
# Add concepts
if do_include_concepts:
if do_clean_for_bulk_import:
allowed_attr_keys = [
'concept_class', 'datatype', 'descriptions', 'external_id', 'extras', 'id', 'names',
'owner', 'owner_type', 'retired', 'source', 'type']
Expand All @@ -210,9 +208,12 @@ def to_resource_list(self, do_clean_for_bulk_import=False,
if attr_key not in allowed_attr_keys:
new_concept.pop(attr_key)
resource_list.append(new_concept)
else:
resource_list.append(self._concepts)

# Add mappings
if repo_type == 'Source':
# Add mappings
if do_incldue_mappings:
if do_clean_for_bulk_import:
allowed_attr_keys = [
'external_id', 'extras', 'from_concept_url', 'id', 'map_type', 'owner',
'owner_type', 'retired', 'source', 'to_concept_code', 'to_concept_url',
Expand All @@ -226,8 +227,11 @@ def to_resource_list(self, do_clean_for_bulk_import=False,
if attr_key not in allowed_attr_keys:
new_mapping.pop(attr_key)
resource_list.append(new_mapping)
else:
resource_list.append(self._mappings)

# Add references
# Add references
if do_include_references:
if 'references' in self._export_json and repo_type == 'Collection':
import re
compiled_regex = re.compile(r'^' + OclExport.RESOURCE_PATTERN + '$')
Expand All @@ -244,10 +248,6 @@ def to_resource_list(self, do_clean_for_bulk_import=False,
'owner_type': self._export_json['type'],
'data': {'expressions': reference_expressions}
})
else:
# Add all concepts and mappings without modifying
resource_list.append(self._concepts)
resource_list.append(self._mappings)

# Add resource for repository version
if do_include_repo_version:
Expand Down

0 comments on commit f51c40c

Please sign in to comment.