Skip to content

Commit

Permalink
Fix bug in json internalize (binding) flow when dealing with inherite…
Browse files Browse the repository at this point in the history
…d properties (#3260)

Co-authored-by: Sai Sriharsha Annepu <[email protected]>
  • Loading branch information
Paarth002 and gs-ssh16 authored Nov 21, 2024
1 parent b8d9ce6 commit 93bd0c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ function meta::external::format::shared::executionPlan::extractPackageableElemen
)->concatenate($p.subType),
s:SubTypeGraphFetchTree[1] | $s.subTypeClass
])->cast(@PackageableElement);
$classesFromTree->concatenate($tree.subTrees->map(s | $s->extractPackageableElementFromTree()))->concatenate($tree.subTypeTrees->map(s | $s->extractPackageableElementFromTree()));
let specializations = $classesFromTree->filter(c | $c->instanceOf(Class))->map(c | $c->cast(@Class<Any>)->meta::pure::functions::meta::findAllSpecializations())->filter(x | $x->elementToPath() != Any->elementToPath());
let generalizations = $classesFromTree->filter(c | $c->instanceOf(Class))->map(c | $c->cast(@Class<Any>)->meta::pure::functions::meta::getAllTypeGeneralisations())->filter(x | $x->elementToPath() != Any->elementToPath())
->filter(x | $x->instanceOf(PackageableElement))->cast(@PackageableElement);
let currentLevelClasses = $classesFromTree->concatenate($specializations)->concatenate($generalizations)->removeDuplicates({a, b | $a->elementToPath() == $b->elementToPath()});

$currentLevelClasses->concatenate($tree.subTrees->map(s | $s->extractPackageableElementFromTree()))->concatenate($tree.subTypeTrees->map(s | $s->extractPackageableElementFromTree()));
}

function <<access.private>> meta::external::format::shared::executionPlan::getFunctionProcessor(f:SimpleFunctionExpression[1], extensions:meta::pure::extension::Extension[*]):meta::pure::metamodel::function::Function<{FunctionExpression[1], ExternalFormatPlanGenerationState[1], Extension[*], DebugContext[1] -> ExecutionNode[1]}>[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ function <<meta::pure::profiles::test.Test, meta::pure::profiles::test.AlloyOnly
assertEquals('{"defects":[],"source":{"number":1,"record":"{\\\"firstName\\\":\\\"John\\\",\\\"lastName\\\":\\\"Doe\\\",\\\"firm\\\":{\\\"legalName\\\":\\\"Firm A\\\"}}"},"value":{"firstName":"John","lastName":"Doe"}}', $result);
}

function <<meta::pure::profiles::test.Test, meta::pure::profiles::test.AlloyOnly>> meta::external::format::json::executionPlan::test::simple::testSimpleJsonQueryWithChildSubType(): Boolean[1]
{
let query = {data:String[1]| Target.all()->graphFetch(#{Target{targetProductId}}#)->serialize(#{Target{targetProductId}}#)->from(M2MMappingWithChild, Source->getRuntimeWithModelQueryConnection('application/json', $data))};

let result = meta::external::format::json::executionPlan::test::executeJsonSchemaBindingQuery($query, pair('data', '{"@type": "Source", "child": {"@type": "ProductExtended", "productId": "123"}}'));

assertEquals('{"builder":{"_type":"json"},"values":{"targetProductId":"123"}}', $result);
}

function <<meta::pure::profiles::test.Test, meta::pure::profiles::test.AlloyOnly>> meta::external::format::json::executionPlan::test::simple::testM2MChainingWithJson(): Boolean[1]
{
let binding = getTestBinding();
Expand Down Expand Up @@ -357,6 +366,20 @@ Class meta::external::format::json::executionPlan::test::simple::Product
description: String[1];
}

Class meta::external::format::json::executionPlan::test::simple::ProductExtended extends meta::external::format::json::executionPlan::test::simple::Product
{
}

Class meta::external::format::json::executionPlan::test::simple::Target
{
targetProductId: String[1];
}

Class meta::external::format::json::executionPlan::test::simple::Source
{
child: meta::external::format::json::executionPlan::test::simple::Product[1];
}

Class meta::external::format::json::executionPlan::test::simple::Synonym
{
name: String[1];
Expand Down Expand Up @@ -507,6 +530,15 @@ Mapping meta::external::format::json::executionPlan::test::simple::M2MMapping2
}
)

Mapping meta::external::format::json::executionPlan::test::simple::M2MMappingWithChild
(
meta::external::format::json::executionPlan::test::simple::Target: Pure
{
~src meta::external::format::json::executionPlan::test::simple::Source
targetProductId: $src.child.productId
}
)

Mapping meta::external::format::json::executionPlan::test::simple::M2MCrossStoreMapping
(
meta::external::format::json::executionPlan::test::simple::Trade[trade_set]: Pure
Expand Down

0 comments on commit 93bd0c4

Please sign in to comment.