Skip to content

Commit

Permalink
apply property filter on mapping analysis (#3239)
Browse files Browse the repository at this point in the history
  • Loading branch information
YannanGao-gs authored Nov 12, 2024
1 parent fafb603 commit ef4cef5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
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 @@ -37,15 +37,18 @@ function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCove
// embedded relational mapping
assertContains($mappedEntityForFirm.properties.name, 'employees');
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]
{
let result = meta::analytics::mapping::modelCoverage::test::generateModelCoverageAnalytics(meta::analytics::mapping::modelCoverage::test::sampleRelationalMapping);
let mappedEntityForLegalEntity = $result.mappedEntities->filter(mp|$mp.path == 'meta::analytics::mapping::modelCoverage::test::LegalEntity');
assert($mappedEntityForLegalEntity.properties->size() == 4);
assert($mappedEntityForLegalEntity.properties->size() == 2);
assertContains($mappedEntityForLegalEntity.properties->filter(p|$p->instanceOf(EntityMappedProperty))->cast(@EntityMappedProperty).entityPath, '@meta::analytics::mapping::modelCoverage::test::Firm');
assertContains($mappedEntityForLegalEntity.properties->filter(p|$p->instanceOf(EntityMappedProperty))->cast(@EntityMappedProperty).entityPath, 'meta_analytics_mapping_modelCoverage_test_Firm_employees');
assertContains($mappedEntityForLegalEntity.properties->filter(p|$p->instanceOf(EntityMappedProperty))->cast(@EntityMappedProperty).entityPath, 'meta::analytics::mapping::modelCoverage::test::Address');
}

function <<meta::pure::profiles::test.Test>> meta::analytics::mapping::modelCoverage::test::testSimpleRelationalUnionMappingCoverage():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)));
}

0 comments on commit ef4cef5

Please sign in to comment.