Commit b1778896 authored by Dmitrii Valuiskii (EPAM)'s avatar Dmitrii Valuiskii (EPAM) Committed by Siarhei Khaletski (EPAM)
Browse files

GONRG-1910: fix bug with ingesting master data with pre-defined id

parent b223c6c8
Pipeline #29989 passed with stages
in 8 minutes and 47 seconds
......@@ -93,9 +93,14 @@ class ManifestIntegrity(object):
entities_ids.append(elem["id"])
self.entities_ids = set(entities_ids)
def _decompose_ids(self, id_value: str) -> Optional[IdStructure]:
def _decompose_ref_id(self, id_value: str) -> Optional[IdStructure]:
"""
Util method for separating id and version from id field value
Util method for separating id and version from referential field value.
Ex: {namespace}:reference-data--FacilityType:Well:12345 ->
{
"id": {namespace}:reference-data--FacilityType:Well,
"version": 12345
}
"""
separate_id = IdStructure()
if id_value.endswith(":"):
......@@ -105,11 +110,16 @@ class ManifestIntegrity(object):
separate_id.id = id_value[:-len(separate_id.version) - 1]
else:
separate_id.id = id_value
if separate_id.id in self.entities_ids:
return None
return separate_id
def _combine_ids(self) -> List[str]:
def _is_entity_present_in_manifest(self, id_value: str) -> bool:
"""check if entity with specified id value presents in the current processed manifest
"""
if id_value in self.entities_ids:
return True
return False
def _combine_ids_with_versions(self) -> List[str]:
"""
Util method for combining id and version values
"""
......@@ -132,8 +142,10 @@ class ManifestIntegrity(object):
for pattern in self.patterns:
ids_for_validation.extend(self._match_id_with_pattern(pattern, manifest_str))
for id_for_validation in ids_for_validation:
decompose_id = self._decompose_ids(id_for_validation)
if decompose_id:
decompose_id = None
if not self._is_entity_present_in_manifest(id_for_validation):
decompose_id = self._decompose_ref_id(id_for_validation)
if decompose_id and not self._is_entity_present_in_manifest(decompose_id.id):
self.ids_for_validation.append(decompose_id)
result = [elem.id for elem in self.ids_for_validation]
logger.debug(f"Extracted reference ids: {result}")
......@@ -149,7 +161,7 @@ class ManifestIntegrity(object):
search_handler = ExtendedSearchId(self.search_url, ids_for_validation, self.token_refresher, self.context)
returned_ids = search_handler.search_records()
ids_for_validation = self._combine_ids()
ids_for_validation = self._combine_ids_with_versions()
if set(ids_for_validation).issubset(returned_ids):
return True
......
......@@ -86,6 +86,12 @@ class TestIntegrityProvider:
IdStructure(id="osdu:reference-data--FacilityType:Well",
version="12345"),
id="Extract id Facility Type"),
pytest.param(
MANIFEST_WELLLOG_PATH,
"osdu:reference-data--FacilityType:Well:2:12345",
IdStructure(id="osdu:reference-data--FacilityType:Well:2",
version="12345"),
id="Extract id Facility Type with colon inside ID"),
]
)
def test_extract_references_wpc(self, monkeypatch,
......@@ -93,5 +99,5 @@ class TestIntegrityProvider:
conf_path: str,
raw_id: str,
decompose_id: dict):
extracted_id = manifest_integrity._decompose_ids(raw_id)
extracted_id = manifest_integrity._decompose_ref_id(raw_id)
assert extracted_id == decompose_id
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment