Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply property filter on mapping analysis #3239

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,20 @@ function meta::analytics::mapping::modelCoverage::analyze(
let mapClassMappingsIds = $map->classMappings().id;
pair($map, list($classMappings->filter(cm | $cm.id->in($mapClassMappingsIds))));
));
let propertyFilter = {p:AbstractProperty<Any>[1] | true};
let entities = $classMappings->map(cm |
$cm->match([
o:OperationSetImplementation[1] |
let subTypeMappings = $o->resolveOperation($mapping)->concatenate($operations->filter(op | $op.class->superTypes()->contains($o.class)));
buildInheritanceEntities($o, $o, [], $subTypeMappings, '', $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, $o.root, true, $config);,
buildInheritanceEntities($o, $o, [], $subTypeMappings, '', $propertyFilter, $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, $o.root, true, $config);,
a:meta::pure::mapping::aggregationAware::AggregationAwareSetImplementation[1] |
buildEntity(
$a.mainSetImplementation.class, buildEntityName($a.mainSetImplementation), $a.mainSetImplementation, $a.mainSetImplementation->allPropertyMappings(), $rootClassMappings, $allClasses,
$a.mainSetImplementation.class, buildEntityName($a.mainSetImplementation), $a.mainSetImplementation, $a.mainSetImplementation->allPropertyMappings(), $propertyFilter, $rootClassMappings, $allClasses,
$allProperties, $inheritanceMap, $mappingToClassMappings, $a.root, $config
),
i:InstanceSetImplementation[1] |
buildEntity(
$i.class, buildEntityName($i), $i, $i->getPropertyMappings($classMappings), $rootClassMappings, $allClasses,
$i.class, buildEntityName($i), $i, $i->getPropertyMappings($classMappings), $propertyFilter, $rootClassMappings, $allClasses,
$allProperties, $inheritanceMap, $mappingToClassMappings, $i.root, $config
);,
an:Any[1] | []
Expand All @@ -150,7 +151,7 @@ function meta::analytics::mapping::modelCoverage::analyze(
let superTypes = $operations->filter(o | $o.class->superTypes()->contains($op.class));
let namePrefix = $i.entityPath->split('@')->at(0);
let uniqueTypes = $subTypes->concatenate($superTypes)->removeDuplicatesBy(t | $t.class);
buildInheritanceEntities($op, $op, [], $uniqueTypes, $namePrefix, $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, false, false, $config);
buildInheritanceEntities($op, $op, [], $uniqueTypes, $namePrefix, $propertyFilter, $rootClassMappings, $allClasses, $allProperties, $inheritanceMap, $mappingToClassMappings, false, false, $config);
)->removeDuplicatesBy(x | $x.path);
let mappedEntities = $entities->concatenate($inheritanceEntities);
if ($returnLightGraph == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import meta::pure::mapping::*;

function meta::analytics::mapping::modelCoverage::test::generateModelCoverageAnalytics(mapping: Mapping[1]): MappingModelCoverageAnalysisResult[1]
{
meta::analytics::mapping::modelCoverage::analyze($mapping, false, false, false);
meta::analytics::mapping::modelCoverage::analyze($mapping, true, true, false);
YannanGao-gs marked this conversation as resolved.
Show resolved Hide resolved
}

function meta::analytics::mapping::modelCoverage::test::generateModelCoverageAnalyticsWithMappedEntityInfo(mapping: Mapping[1]): MappingModelCoverageAnalysisResult[1]
Expand All @@ -36,7 +36,12 @@ function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCove
assertContains($mappedEntityForFirm.properties.name, 'employeeSize');
// embedded relational mapping
assertContains($mappedEntityForFirm.properties.name, 'employees');
println($result, 5);
YannanGao-gs marked this conversation as resolved.
Show resolved Hide resolved
assertContains($result.mappedEntities.path, $mappedEntityForFirm.properties->filter(p|$p.name == 'employees')->toOne()->cast(@EntityMappedProperty).entityPath);


let mappedEntityForLegalEntity = $result.mappedEntities->filter(mp|$mp.path == 'meta::analytics::mapping::modelCoverage::test::LegalEntity');
assert($mappedEntityForLegalEntity.properties->size() == 2);
}

function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCoverage::test::testSimpleRelationalInheritanceMappingCoverage():Boolean[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import meta::analytics::class::modelCoverage::utility::*;
import meta::relational::metamodel::*;
import meta::relational::mapping::*;
import meta::analytics::mapping::modelCoverage::*;
import meta::pure::mapping::*;
Expand Down Expand Up @@ -241,6 +243,7 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
target:String[1],
setImplementation:SetImplementation[1],
propertyMappings:PropertyMapping[*],
propertyFilter:Function<{AbstractProperty<Any>[1]->Boolean[1]}>[1],
rootClassMappings:SetImplementation[*],
classMap:Map<Class<Any>, ClassInfo>[1],
propertiesMap:Map<AbstractProperty<Any>, PropertyInfo>[1],
Expand All @@ -259,7 +262,7 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
|| $pm->match([semi: meta::relational::mapping::SemiStructuredRelationalPropertyMapping[1] | false, rpm:InstanceSetImplementation[1] | true, a: PropertyMapping[1] | false])
// handle SemiStructuredRelationalPropertyMapping manually to take care of automapped properties
|| $pm.targetSetImplementationId->in($rootClassMappings.id))
);
)->filter(pm | $propertyFilter->eval($pm.property));

let properties = $supportedPropertyMappings->processPropertyMappings($rootClassMappings, $inheritanceMap, $propertiesMap, $config);

Expand All @@ -277,7 +280,8 @@ function meta::analytics::mapping::modelCoverage::buildEntity(
&& !$p->meta::pure::milestoning::isRangeMilestoningProperty()
&& ($rootClassMappings.class->contains($returnType)
|| $returnType == $class
|| $returnType->instanceOf(PrimitiveType));
|| $returnType->instanceOf(PrimitiveType))
&& $propertyFilter->eval($p);
)
->map(qp |
let qualifiedPropertyType = $qp.genericType.rawType->toOne();
Expand Down Expand Up @@ -373,6 +377,7 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
seenInheritanceTypes: Class<Any>[*],
mappings:SetImplementation[*],
namePrefix: String[1],
originalPropertyFilter:Function<{AbstractProperty<Any>[1]->Boolean[1]}>[1],
rootClassMappings:SetImplementation[*],
classMap:Map<Class<Any>, ClassInfo>[1],
propertiesMap:Map<AbstractProperty<Any>, PropertyInfo>[1],
Expand Down Expand Up @@ -412,6 +417,14 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
i:InstanceSetImplementation[1] | $i->allPropertyMappings()
]);

let propertyFilter = {a:AbstractProperty<Any>[1] |
let ownerClass = $a->ownerClass();
if ($mapping.class == $baseMapping.class,
| $ownerClass->in($mapping.class->superTypes()->concatenate($mapping.class)),
| $ownerClass == $mapping.class || $ownerClass->in($mapping.class->superTypes(false)->removeAll($seenInheritanceTypes)))
&& $originalPropertyFilter->eval($a);
};

let inheritanceTypes = $mapping->match([
o:OperationSetImplementation[1] | $seenInheritanceTypes->add($o.class),
i:InstanceSetImplementation[1] | $seenInheritanceTypes
Expand All @@ -420,12 +433,12 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
let name = $namePrefix + if ($isBase, | $mapping->buildEntityName(),| $class->createInheritanceName());

let entities = buildEntity($class, $name, $mapping,
$mappedProperties, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $config);
$mappedProperties, $propertyFilter, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $config);

let rootEntity = $entities->at(0);
let currentMappings = $mappings->filter(m | $m.class->in($specs));
let inheritanceEntities = $currentMappings->map(cm |
$baseMapping->buildInheritanceEntitiesImpl($cm, $inheritanceTypes, $mappings, $namePrefix, $rootClassMappings, $classMap, $propertiesMap,
$baseMapping->buildInheritanceEntitiesImpl($cm, $inheritanceTypes, $mappings, $namePrefix, $originalPropertyFilter, $rootClassMappings, $classMap, $propertiesMap,
$inheritanceMap, $mappingClassMappings, false, false, $config);
);

Expand All @@ -446,6 +459,7 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
seenInheritanceTypes: Class<Any>[*],
mappings:SetImplementation[*],
namePrefix: String[1],
originalPropertyFilter:Function<{AbstractProperty<Any>[1]->Boolean[1]}>[1],
rootClassMappings:SetImplementation[*],
classMap:Map<Class<Any>, ClassInfo>[1],
propertiesMap:Map<AbstractProperty<Any>, PropertyInfo>[1],
Expand All @@ -457,7 +471,7 @@ function <<access.private>> meta::analytics::mapping::modelCoverage::buildInheri
):MappedEntity[*]
{
let entities = buildInheritanceEntitiesImpl($baseMapping, $mapping, $seenInheritanceTypes, $mappings,
$namePrefix, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $isBase, $config);
$namePrefix, $originalPropertyFilter, $rootClassMappings, $classMap, $propertiesMap, $inheritanceMap, $mappingClassMappings, $isRootEntity, $isBase, $config);

$entities->map(e | ^$e(properties = $e.properties->removeDuplicatesBy(x | $x.name)));
}
Loading