Skip to content

Commit

Permalink
Added fullUrl unique check to $extract
Browse files Browse the repository at this point in the history
  • Loading branch information
qscgyjqscgyj committed Feb 27, 2025
1 parent 3368d36 commit 785c5fe
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 99 deletions.
8 changes: 7 additions & 1 deletion app/sdc/extract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from aiohttp import ClientSession, web
from funcy.seqs import flatten

from .utils import check_mappers_bundles_full_url_duplicates


async def get_external_service_bundle(session, service, template, context):
async with session.post(
Expand All @@ -17,12 +19,16 @@ async def get_external_service_bundle(session, service, template, context):


async def execute_mappers_bundles(client, mappers_bundles):
flatted_mappers_bundles = list(flatten(bundle["entry"] for bundle in mappers_bundles))

check_mappers_bundles_full_url_duplicates(flatted_mappers_bundles)

not_transaction = any(bundle.get("type") != "transaction" for bundle in mappers_bundles)

result_bundle = {
"resourceType": "Bundle",
"type": "batch" if not_transaction else "transaction",
"entry": list(flatten(bundle["entry"] for bundle in mappers_bundles)),
"entry": flatted_mappers_bundles,
}

return await client.execute("/", data=result_bundle)
Expand Down
23 changes: 23 additions & 0 deletions app/sdc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,26 @@ def validate_context(context_definition, env):
)
if len(errors) > 0:
raise ConstraintCheckOperationOutcome(errors)


def check_mappers_bundles_full_url_duplicates(flatted_mappers_bundles):
full_urls_set = set()

for bundle in flatted_mappers_bundles:
full_url = bundle.get("fullUrl")

if full_url is None:
continue

if full_url in full_urls_set:
raise ConstraintCheckOperationOutcome(
[
{
"severity": "error",
"key": "duplicate-full-url",
"human": f"Duplicate fullUrl '{full_url}' in mappers bundles",
}
]
)

full_urls_set.add(full_url)
Loading

0 comments on commit 785c5fe

Please sign in to comment.