Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1122 | concept cascade | refactoring and cl…
Browse files Browse the repository at this point in the history
…eaning up
  • Loading branch information
snyaggarwal committed Nov 24, 2021
1 parent fc3b8c5 commit 2535075
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/bundles/models.py
Expand Up @@ -110,7 +110,7 @@ def set_total(self):

def cascade(self):
self.set_cascade_parameters()
result = self.root.get_cascaded_resources(
result = self.root.cascade(
source_mappings=self.cascade_method == SOURCE_MAPPINGS,
source_to_concepts=self.cascade_method == SOURCE_TO_CONCEPTS,
mappings_criteria=self.mappings_criteria,
Expand Down
14 changes: 8 additions & 6 deletions core/concepts/models.py
Expand Up @@ -884,13 +884,14 @@ def delete(self, using=None, keep_parents=False):
LocalizedText.objects.filter(description_locales=self).delete()
return super().delete(using=using, keep_parents=keep_parents)

def get_cascaded_resources( # pylint: disable=too-many-arguments
def cascade( # pylint: disable=too-many-arguments
self, source_mappings=True, source_to_concepts=True, mappings_criteria=None,
cascade_mappings=True, cascade_hierarchy=True, cascade_levels='*',
include_mappings=True, max_results=1000
):
result = self.__get_cascaded_resources(
source_mappings, source_to_concepts, mappings_criteria, cascade_mappings, cascade_hierarchy, include_mappings
result = self.get_cascaded_resources(
source_mappings, source_to_concepts, mappings_criteria,
cascade_mappings, cascade_hierarchy, include_mappings
)
cascaded = []

Expand All @@ -901,8 +902,9 @@ def iterate(level):
if cascaded:
not_cascaded = not_cascaded.exclude(id__in=cascaded)
for concept in not_cascaded:
res = concept.__get_cascaded_resources(
source_mappings, source_to_concepts, mappings_criteria, cascade_mappings, cascade_hierarchy, include_mappings
res = concept.get_cascaded_resources(
source_mappings, source_to_concepts, mappings_criteria,
cascade_mappings, cascade_hierarchy, include_mappings
)
cascaded.append(concept.id)
result['concepts'] |= res['concepts']
Expand All @@ -913,7 +915,7 @@ def iterate(level):

return result

def __get_cascaded_resources(
def get_cascaded_resources( # pylint: disable=too-many-arguments
self, source_mappings=True, source_to_concepts=True, mappings_criteria=None,
cascade_mappings=True, cascade_hierarchy=True, include_mappings=True
):
Expand Down
2 changes: 1 addition & 1 deletion core/concepts/views.py
Expand Up @@ -15,7 +15,7 @@
from core.bundles.serializers import BundleSerializer
from core.common.constants import (
HEAD, INCLUDE_INVERSE_MAPPINGS_PARAM, INCLUDE_RETIRED_PARAM, ACCESS_TYPE_NONE)
from core.common.exceptions import Http409, Http400, Http405
from core.common.exceptions import Http409, Http405
from core.common.mixins import ListWithHeadersMixin, ConceptDictionaryMixin
from core.common.swagger_parameters import (
q_param, limit_param, sort_desc_param, page_param, exact_match_param, sort_asc_param, verbose_param,
Expand Down
6 changes: 4 additions & 2 deletions core/integration_tests/tests_concepts.py
Expand Up @@ -972,7 +972,8 @@ def test_get_200(self): # pylint: disable=too-many-statements
])
)

response = self.client.get(concept1.uri + '$cascade/?method=sourceToConcepts&mapTypes=map_type1&cascadeLevels=0')
response = self.client.get(
concept1.uri + '$cascade/?method=sourceToConcepts&mapTypes=map_type1&cascadeLevels=0')

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['entry']), 3)
Expand All @@ -985,7 +986,8 @@ def test_get_200(self): # pylint: disable=too-many-statements
])
)

response = self.client.get(concept1.uri + '$cascade/?method=sourceToConcepts&excludeMapTypes=map_type1&cascadeLevels=0')
response = self.client.get(
concept1.uri + '$cascade/?method=sourceToConcepts&excludeMapTypes=map_type1&cascadeLevels=0')

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['entry']), 2)
Expand Down

0 comments on commit 2535075

Please sign in to comment.