Skip to content

Commit

Permalink
Populate mappedEntityInfo when returnMappedEntityInfo flag is true (#…
Browse files Browse the repository at this point in the history
…2435)

* Populate mappedEntityInfo when returnMappedEntityInfo flag is true

* Update variable name
  • Loading branch information
gayathrir11 authored Nov 3, 2023
1 parent 1358bcf commit 6f27518
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ function meta::analytics::mapping::modelCoverage::test::generateModelCoverageAna
meta::analytics::mapping::modelCoverage::analyze($mapping, false, false, false);
}

function meta::analytics::mapping::modelCoverage::test::generateModelCoverageAnalyticsWithMappedEntityInfo(mapping: Mapping[1]): MappingModelCoverageAnalysisResult[1]
{
meta::analytics::mapping::modelCoverage::analyze($mapping, true, false, false);
}

// Relational
function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCoverage::test::testSimpleRelationalMappingCoverage():Boolean[1]
{
Expand Down Expand Up @@ -111,6 +116,41 @@ function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCove
assertContains($result.mappedEntities.path, 'meta::analytics::mapping::modelCoverage::test::Target_meta::analytics::mapping::modelCoverage::test::Source_autoMapped_shared');
}


function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCoverage::test::testAutoMappedComplexPropertiesMappingCoverageWithMappedEntityInfo():Boolean[1]
{
let grammar = 'Class meta::analytics::mapping::modelCoverage::test::Target\n'+
'{\n'+
' tgtId: String[1];\n'+
' shared: meta::analytics::mapping::modelCoverage::test::Shared[1];\n'+
'}\n'+
'Class meta::analytics::mapping::modelCoverage::test::Shared\n'+
'{\n'+
' sharedId: String[1];\n'+
'}\n'+
'Class meta::analytics::mapping::modelCoverage::test::Source\n'+
'{\n'+
' srcId: String[1];\n'+
' shared: meta::analytics::mapping::modelCoverage::test::Shared[1];\n'+
'}\n'+
'###Mapping\n'+
'Mapping meta::analytics::mapping::modelCoverage::test::simpleAutoMappedMapping\n'+
'(\n'+
' *meta::analytics::mapping::modelCoverage::test::Target:Pure\n'+
' {\n'+
' ~src meta::analytics::mapping::modelCoverage::test::Source\n'+
' tgtId: $src.srcId,\n'+
' shared: $src.shared\n'+
' }\n'+
')\n';
let elements = meta::legend::compileLegendGrammar($grammar);
let autoMappedMapping = $elements->filter(e|$e->instanceOf(Mapping))->at(0)->cast(@Mapping);
let result = meta::analytics::mapping::modelCoverage::test::generateModelCoverageAnalyticsWithMappedEntityInfo($autoMappedMapping);
assert($result.mappedEntities->size() == 2);
assertContains($result.mappedEntities.path, 'meta::analytics::mapping::modelCoverage::test::Target_meta::analytics::mapping::modelCoverage::test::Source_autoMapped_shared');
assert($result.mappedEntities->filter(m |$m.info->isNotEmpty())->size() == 2);
}

function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCoverage::test::testCyclicalAutoMappedComplexPropertiesMappingCoverage():Boolean[1]
{
let grammar = 'Class meta::analytics::mapping::modelCoverage::test::Target\n'+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
let srcClassPath = if($pureInstanceSetImplementation.srcClass->isNotEmpty(),|$pureInstanceSetImplementation.srcClass->toOne()->cast(@Class<Any>)->elementToPath(),|'');
$targetClassPath + '_' + $srcClassPath;,
|$pm.targetSetImplementationId);
processAutoMappedPropertyMapping($pm.property->cast(@AbstractProperty<Any>), $id + '_autoMapped_', $config, []););
processAutoMappedPropertyMapping($pm.property->cast(@AbstractProperty<Any>), $id + '_autoMapped_', $isRootEntity, $config, []););
let autoMappedPrimitiveProperties = if($setImplementation->instanceOf(PureInstanceSetImplementation),
|buildAutoMappedProperty($class, if($setImplementation->cast(@PureInstanceSetImplementation).srcClass->isEmpty(),|[],|$setImplementation->cast(@PureInstanceSetImplementation).srcClass->cast(@Class<Any>)->toOne()), $properties, $config),
|buildAutoMappedProperty($class, if($setImplementation->cast(@PureInstanceSetImplementation).srcClass->isEmpty(),|[],|$setImplementation->cast(@PureInstanceSetImplementation).srcClass->cast(@Class<Any>)->toOne()), $properties, $isRootEntity, $config),
|[]);
buildEntity(
$class,
Expand All @@ -318,6 +318,7 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
function meta::analytics::mapping::modelCoverage::processAutoMappedPropertyMapping(
property: AbstractProperty<Any>[1],
prefix: String[1],
isRootEntity: Boolean[1],
config: AnalysisConfiguration[1],
visited: Pair<Class<Any>, String>[*]
): AutoMappedHelperClass[1]
Expand All @@ -344,8 +345,9 @@ function meta::analytics::mapping::modelCoverage::processAutoMappedPropertyMappi
| ^MappedPropertyInfo(type = $property.genericType.rawType->toOne()->mapType(), multiplicity = $property.multiplicity->toOne()),
| []));
let newVisited = $visited->concatenate([^Pair<Class<Any>, String>(first = $property.genericType.rawType->toOne()->cast(@Class<Any>), second = $entityPath)]);
let children = $property.genericType.rawType->toOne()->cast(@Class<Any>).properties->map(p | $p->processAutoMappedPropertyMapping($entityPath + '_' , $config, $newVisited));
let currentMappedEntity = ^MappedEntity(path=$entityPath, properties = $children->map(c|$c.mappedProperties));
let propertyType = $property.genericType.rawType->toOne()->cast(@Class<Any>);
let children = $propertyType.properties->map(p | $p->processAutoMappedPropertyMapping($entityPath + '_' , $isRootEntity, $config, $newVisited));
let currentMappedEntity = ^MappedEntity(path=$entityPath, properties = $children->map(c|$c.mappedProperties), info = if($config.returnMappedEntityInfo == true, | ^MappedEntityInfo(isRootEntity = $isRootEntity, classPath = $propertyType->elementToPath()), | []));
^AutoMappedHelperClass(mappedProperties = [$entityMappedProp], mappedEntities=[$currentMappedEntity]->concatenate($children->map(c|$c.mappedEntities)));
);
)
Expand All @@ -355,6 +357,7 @@ function meta::analytics::mapping::modelCoverage::buildAutoMappedProperty(
class:Class<Any>[1],
srcClass: Class<Any>[0..1],
mappedProperties: MappedProperty[*],
isRootEntity: Boolean[1],
config: AnalysisConfiguration[1]
): MappedProperty[*]
{
Expand Down

0 comments on commit 6f27518

Please sign in to comment.