Skip to content

Commit

Permalink
Revert "Revert "OpenConceptLab/ocl_issues#1588 | Can except OCL Sourc…
Browse files Browse the repository at this point in the history
…e version export for import into same or different owner and as same or different version""

This reverts commit 5d86616.
  • Loading branch information
snyaggarwal committed Jul 24, 2023
1 parent efc7433 commit 32d11f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion core/importers/input_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from zipfile import ZipFile

import requests
from ocldev.oclexporttoimportconverter import OCLExportToImportConverter
from ocldev.oclcsvtojsonconverter import OclStandardCsvToJsonConverter
from pydash import get, compact

Expand All @@ -19,10 +20,11 @@ class ImportContentParser:
2. Processes json/csv/zip file url from 'file_url' arg
3. Processes json/csv/zip file from 'file' arg
"""
def __init__(self, content=None, file_url=None, file=None):
def __init__(self, content=None, file_url=None, file=None, **kwargs):
self.content = content
self.file_url = file_url
self.file = file
self.kwargs = kwargs
self.file_name = get(self, 'file.name') if self.file else None
self.errors = []
self.extracted_file = None
Expand Down Expand Up @@ -81,6 +83,20 @@ def set_content(self):
self.content = self.content.decode('utf-8')
if self.is_csv_file:
self.set_csv_content()
if self.is_ocl_source_version_export():
converter = OCLExportToImportConverter(
content=self.content,
return_output=True,
version=self.kwargs.get('version', None),
owner=self.kwargs.get('owner', None),
owner_type=self.kwargs.get('owner_type', None)
)
converter.process()
self.content = converter.result

def is_ocl_source_version_export(self):
return isinstance(self.content, str) and self.content.startswith(
'{"type": "Source Version"') and '"concepts":' in self.content and '"mappings":' in self.content

def set_csv_content(self):
try:
Expand Down
5 changes: 4 additions & 1 deletion core/importers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ def post(self, request, import_queue=None):
parser = ImportContentParser(
file=get(request.data, 'file') if is_upload else None,
file_url=get(request.data, 'file_url') if is_file_url else None,
content=get(request.data, 'data') if is_data else None
content=get(request.data, 'data') if is_data else None,
owner=get(request.data, 'owner') or None,
owner_type=get(request.data, 'owner_type') or None,
version=get(request.data, 'version') or None,
)
parser.parse()
if parser.errors:
Expand Down

0 comments on commit 32d11f7

Please sign in to comment.