All Downloads are FREE. Search and download functionalities are using the official Maven repository.

core_analytics_mapping.modelCoverage.analyticsHelper.pure Maven / Gradle / Ivy

There is a newer version: 4.57.1
Show newest version
// Copyright 2022 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import meta::pure::mapping::*;
import meta::analytics::mapping::modelCoverage::*;
import meta::analytics::mapping::modelCoverage::utility::*;
import meta::pure::milestoning::*;

Class <> meta::analytics::mapping::modelCoverage::PropertyInfo
{
   name: String[1];
   multiplicity: Multiplicity[1];
}

Class <> meta::analytics::mapping::modelCoverage::ClassInfo
{
  qualifiedProperties: QualifiedProperty[*];
}

function meta::analytics::mapping::modelCoverage::getRealProperty(property:AbstractProperty[1]):AbstractProperty[1]
{
   if ($property->isEdgePointProperty(),
      |
         let properties = $property->getMilestonedGeneratedQualifiedPropertiesForEdgePointProperty();
         $properties->tail()->fold({current, p |
            let currentNumberOfParameters = $current.classifierGenericType.typeArguments.rawType->cast(@FunctionType).parameters->evaluateAndDeactivate()->size();
            let numberOfParameters = $p.classifierGenericType.typeArguments.rawType->cast(@FunctionType).parameters->evaluateAndDeactivate()->size();
            if ($currentNumberOfParameters > $numberOfParameters, | $current, | $p);
         }, $properties->first())->toOne();,
      | $property);
}

function <> meta::analytics::mapping::modelCoverage::buildPropertyInfo(p:AbstractProperty[1]):PropertyInfo[1]
{
   ^PropertyInfo(name = $p->originalPropertyNameForEdgePointProperty()->toOne(), multiplicity = $p.multiplicity);
}

function <> meta::analytics::mapping::modelCoverage::getPropertyInfo(property:AbstractProperty[1], map:Map, PropertyInfo>[1]):PropertyInfo[1]
{
   let pi = $map->get($property);
   if ($pi->isEmpty(), | $property->getRealProperty()->buildPropertyInfo(), | $pi->toOne());
}

function meta::analytics::mapping::modelCoverage::getAllPropertyInfo(classMappings:SetImplementation[*], rootClassMappings:SetImplementation[*]):Map, PropertyInfo>[1]
{
   let allQualifiedProperties = $classMappings.class
      ->removeDuplicates()
      ->map(c | $c->qualifiedProperties())
      ->removeDuplicates()
      ->filter(qp |
               let returnType = $qp->functionReturnType().rawType->toOne();
               $qp->isSupportedProperty() &&
               (
                  $rootClassMappings.class->contains($returnType)
                  || $returnType->instanceOf(PrimitiveType)
               );
   );

   newMap(
      $classMappings->filter(c | $c->instanceOf(InstanceSetImplementation))->cast(@InstanceSetImplementation)
      ->map(x|$x->allPropertyMappings()).property
      ->removeDuplicates()
      ->map(p | $p->getRealProperty())
      ->concatenate($allQualifiedProperties)
      ->map(p | pair($p, $p->buildPropertyInfo()))
   );
}

function <> meta::analytics::mapping::modelCoverage::buildClassInfo(class:Class[1]):ClassInfo[1]
{
   ^ClassInfo(qualifiedProperties = $class->qualifiedProperties())
}

function <> meta::analytics::mapping::modelCoverage::getClassInfo(class:Class[1], map:Map, ClassInfo>[1]):ClassInfo[1]
{
   let ci = $map->get($class);
   if ($ci->isEmpty(), | $class->buildClassInfo(), | $ci->toOne());
}

function meta::analytics::mapping::modelCoverage::getAllClassInfo(classMappings:SetImplementation[*]):Map, ClassInfo>[1]
{
   newMap($classMappings.class->removeDuplicates()->map(class |
      pair($class, $class->buildClassInfo())
   ));
}

function <> meta::analytics::mapping::modelCoverage::isSimpleQualifiedProperty(property : QualifiedProperty[1]) : Boolean[1]
{
   $property->functionType().parameters->size() == 1;
}

function <> meta::analytics::mapping::modelCoverage::isSupportedProperty(property : AbstractProperty[1]) : Boolean[1]
{
   !$property.genericType.rawType->isEmpty() && //Not sure why this is required, but needed for compiled mode
      $property->match([
         qp:QualifiedProperty[1] |
            if ($qp->hasGeneratedMilestoningPropertyStereotype(),
               | false,
               | if($qp->isSimpleQualifiedProperty(),
                 | true,
                 |
                    let parameters = $qp->functionType().parameters;

                    let supportedParameters = $parameters->drop(1)->evaluateAndDeactivate()->filter({param|
                       let paramRawType = $param.genericType.rawType;
                       $paramRawType->size() == 1 &&
                          ($paramRawType->match([ e:Enumeration[1]|true, a:Any[1] | false]) || $paramRawType->toOne()->mapToSupportedType()->size() == 1);
                    });

                    $parameters->size() == $supportedParameters->size() + 1;
                 )
               );
            ,
            ap:AbstractProperty[1]|
               let t = $ap.genericType.rawType->toOne();
               if ($t->instanceOf(PrimitiveType),
                  | $t->mapToSupportedType()->isNotEmpty(),
                  | true
                  );

         ])
}

function <> meta::analytics::mapping::modelCoverage::getIncludes(m:Mapping[1]):Mapping[*]
{
   $m.includes.included->concatenate($m.includes->map(i | $i.included->getIncludes()));
}

function <> meta::analytics::mapping::modelCoverage::createInheritanceName(type:Type[1]):String[1]
{
   '@' + $type->elementToPath()
}

function meta::analytics::mapping::modelCoverage::mapToSupportedType(type: Type[1]): MappedPropertyType[0..1]
{
   let typePair = [
      pair(Number, MappedPropertyType.Float), //TODO This is a hack as Number is not yet supported on client
      pair(Boolean, MappedPropertyType.Boolean),
      pair(DateTime, MappedPropertyType.DateTime),
      pair(StrictDate, MappedPropertyType.Date),
      pair(Date, MappedPropertyType.DateTime),
      pair(String, MappedPropertyType.String),
      pair(Enum, MappedPropertyType.Enumeration),
      pair(Float, MappedPropertyType.Float),
      pair(Integer, MappedPropertyType.Integer),
      pair(Decimal, MappedPropertyType.Decimal)
   ]->findValues($type)->first();
}

function meta::analytics::mapping::modelCoverage::mapType(type: Type[1]):MappedPropertyType[1]
{
  let result = $type->mapToSupportedType();
  if($result->size() == 1,|$result->toOne(),|MappedPropertyType.Unknown);
}

function meta::analytics::mapping::modelCoverage::reRoot(classMappings:SetImplementation[*], m:Mapping[1]):SetImplementation[*]
{
   let rootClassMappings = $classMappings->filter(cm | $cm.root);
   let nonRootClassMappings = $classMappings->filter(cm | !$cm.root);
   let adjustedRootClassMappings = $rootClassMappings
      ->groupBy(cm | $cm.class)
      ->keyValues()
      ->sort({x,y|$x.first->elementToPath()->compare($y.first->elementToPath())})
      ->map(kv |
         $kv.second.values->map(v |
            let root = if ($kv.second.values->size() > 1,
                           | $m->rootClassMappingByClass($kv.first),
                           | $v);

            ^$v(root = $root.id == $v.id);
         )
      );
   $adjustedRootClassMappings->concatenate($nonRootClassMappings)->removeDuplicatesBy(cm | $cm.id);
}

function <> meta::analytics::mapping::modelCoverage::buildEntityName(s:SetImplementation[1]):String[1]
{
   if ($s.root, | $s.class->elementToPath(), | $s.id)
}

function meta::analytics::mapping::modelCoverage::getPropertyMappings(i:InstanceSetImplementation[1], classMappings:SetImplementation[*]):PropertyMapping[*]
{
   $i->match([
      o:OtherwiseEmbeddedSetImplementation[1] |
         let targetPropertyMappings = $classMappings
            ->filter(cm | $cm.id == $o.otherwisePropertyMapping.targetSetImplementationId)
            ->cast(@InstanceSetImplementation)->toOne()
            ->allPropertyMappings()->filter(pm | !$pm.property->in($o->allPropertyMappings().property));
            
         $o->allPropertyMappings()->concatenate($targetPropertyMappings);,
      i:InstanceSetImplementation[1] | $i->allPropertyMappings()
   ]);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy