Search in sources :

Example 1 with Filter

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.

the class AssociationProcessor method getPropertyNameForLeftSideOfQualifiedPropertyFilter.

private static String getPropertyNameForLeftSideOfQualifiedPropertyFilter(Association association, QualifiedProperty qualifiedProperty, ValueSpecification instance, Context context, ProcessorSupport processorSupport) {
    String functionName = instance instanceof FunctionExpression ? ((FunctionExpression) instance)._functionName() : null;
    String propertyNameForLeftSideOfQualifiedPropertyFilter;
    if ("filter".equals(functionName)) {
        ValueSpecification leftSideOfFilter = ((FunctionExpression) instance)._parametersValues().toList().getFirst();
        CoreInstance propertyName = leftSideOfFilter instanceof FunctionExpression ? ((FunctionExpression) leftSideOfFilter)._propertyName()._valuesCoreInstance().toList().getFirst() : null;
        ValueSpecification variableExpression = leftSideOfFilter instanceof FunctionExpression ? ((FunctionExpression) leftSideOfFilter)._parametersValues().toList().getFirst() : null;
        String variableExpressionName = variableExpression instanceof VariableExpression ? ((VariableExpression) variableExpression)._name() : null;
        if (!"this".equals(variableExpressionName)) {
            throw new PureCompilationException(instance.getSourceInformation(), validQualifiedPropertyInAssociationMsg() + qualifiedPropertyCompileErrorMsgPrefix(association, qualifiedProperty) + " left side of filter should refer to '$this' not '" + variableExpressionName + "'");
        }
        propertyNameForLeftSideOfQualifiedPropertyFilter = Objects.requireNonNull(propertyName).getName();
    } else {
        ValueSpecification firstParamValue = instance instanceof FunctionExpression ? ((FunctionExpression) instance)._parametersValues().toList().getFirst() : null;
        if (firstParamValue != null) {
            propertyNameForLeftSideOfQualifiedPropertyFilter = getPropertyNameForLeftSideOfQualifiedPropertyFilter(association, qualifiedProperty, firstParamValue, context, processorSupport);
        } else {
            throw new PureCompilationException(qualifiedProperty.getSourceInformation(), validQualifiedPropertyInAssociationMsg() + qualifiedPropertyCompileErrorMsgPrefix(association, qualifiedProperty) + " does not use the 'filter' function");
        }
    }
    return propertyNameForLeftSideOfQualifiedPropertyFilter;
}
Also used : FunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.FunctionExpression) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) PureCompilationException(org.finos.legend.pure.m4.exception.PureCompilationException)

Example 2 with Filter

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.

the class AbstractTestIncrementalCompilation method test3.

@Test
public void test3() {
    FastList<String> processed = FastList.newList();
    FastList<String> notProcessed = FastList.newList();
    processed.add("start__Any_MANY_");
    notProcessed.add("myFunc__Any_MANY_");
    RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("sourceId1.pure", "Enum my::Gender\n" + "{\n" + "   MALE, FEMALE\n" + "}\n" + "\n" + "Class my::Person\n" + "{\n" + "   firstName   :   String[0..1];\n" + "   lastName    :   String[0..1];\n" + "   gender      :   my::Gender[0..1];\n" + "}").createInMemorySource("sourceId2.pure", "function myFunc():Any[*]\n" + "{\n" + "   let set = \n" + "   [\n" + "      ^my::Person(firstName = 'Marie', lastName='Random', gender = my::Gender.FEMALE),\n" + "      ^my::Person(firstName = 'John', lastName='Doe', gender = my::Gender.MALE)\n" + "   ];\n" + "   $set->filter(p|$p.gender == my::Gender.FEMALE).lastName;\n" + "}").createInMemorySource("sourceId3.pure", "function start():Any[*]\n" + "{\n" + "   assert( myFunc() == 'Random', |'');\n" + "}").executeFunction("start():Any[*]"), new RuntimeTestScriptBuilder().updateSource("sourceId1.pure", "Enum my::Gender\n" + "{\n" + "   FEMALE\n" + "}\n" + "\n" + "Class my::Person\n" + "{\n" + "   firstName   :   String[0..1];\n" + "   lastName    :   String[0];\n" + "   gender      :   my::Gender[0..1];\n" + "}\n").compileWithExpectedCompileFailureAndAssertions("Multiplicity Error: [1] is not compatible with [0]", "sourceId2.pure", 5, 48, FastList.newListWith("start__Any_MANY_", "myFunc__Any_MANY_"), FastList.<String>newList(), FastList.newListWith("my::Person, my::Gender")).updateSource("sourceId1.pure", "Enum my::Gender\n" + "{\n" + "   MALE, FEMALE\n" + "}\n" + "\n" + "Class my::Person\n" + "{\n" + "   firstName   :   String[0..1];\n" + "   lastName    :   String[0..1];\n" + "   gender      :   my::Gender[0..1];\n" + "}").executeFunction("start():Any[*]"), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
}
Also used : RuntimeTestScriptBuilder(org.finos.legend.pure.m3.RuntimeTestScriptBuilder) Test(org.junit.Test)

Example 3 with Filter

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.

the class TestPureRuntimeGraph method testPureRuntimeChangeEnumeration.

@Test
public void testPureRuntimeChangeEnumeration() {
    String source = "Class EntityWithLocations\n" + "{\n" + "    locations : Location[*];\n" + "    locationsByType(types:GeographicEntityType[*])\n" + "    {\n" + "        $this.locations->filter(l | $types->exists(type | is($l.type, $type)))\n" + "    }:Location[*];\n" + "}\n" + "Class Location\n" + "{\n" + "    type : GeographicEntityType[1];\n" + "}\n";
    String enumSource = "Enum GeographicEntityType\n" + "{\n" + "    CITY,\n" + "    COUNTRY\n" + "}";
    String enumSource2 = "Enum GeographicEntityType\n" + "{\n" + "    CITY,\n" + "    COUNTRY,\n" + "    REGION\n" + "}";
    RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("source1.pure", source).createInMemorySource("source2.pure", enumSource).createInMemorySource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), new RuntimeTestScriptBuilder().updateSource("source2.pure", enumSource2).compile().updateSource("source2.pure", enumSource).compile(), this.runtime, this.functionExecution, Lists.fixedSize.<FunctionExecutionStateVerifier>of());
}
Also used : RuntimeTestScriptBuilder(org.finos.legend.pure.m3.RuntimeTestScriptBuilder) Test(org.junit.Test)

Example 4 with Filter

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.

the class TestPureRuntimeGraph method testPureRuntimeAddEnumVar.

@Test
public void testPureRuntimeAddEnumVar() {
    String source = "Class EntityWithLocations\n" + "{\n" + "    locations : Location[*];\n" + "    locationsByType(types:GeographicEntityType[*])\n" + "    {\n" + "        $this.locations->filter(l | $types->exists(type | is($l.type, $type)))\n" + "    }:Location[*];\n" + "}\n" + "Class Location\n" + "{\n" + "    type : GeographicEntityType[1];\n" + "}\n";
    String enumSource = "Enum GeographicEntityType\n" + "{\n" + "    CITY,\n" + "    COUNTRY\n" + "}";
    RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("source1.pure", source).createInMemorySource("source2.pure", enumSource).createInMemorySource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), new RuntimeTestScriptBuilder().updateSource("userId.pure", "function test():Boolean[1]{let x = GeographicEntityType.CITY; print(#{EntityWithLocations{locationsByType($x)}}#,0);true;}").compile().updateSource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), this.runtime, this.functionExecution, Lists.fixedSize.<FunctionExecutionStateVerifier>of());
}
Also used : RuntimeTestScriptBuilder(org.finos.legend.pure.m3.RuntimeTestScriptBuilder) Test(org.junit.Test)

Example 5 with Filter

use of org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter in project legend-pure by finos.

the class TestPureRuntimeGraph method testPureRuntimeChangeEnum.

@Test
public void testPureRuntimeChangeEnum() {
    String source = "Class EntityWithLocations\n" + "{\n" + "    locations : Location[*];\n" + "    locationsByType(types:GeographicEntityType[*])\n" + "    {\n" + "        $this.locations->filter(l | $types->exists(type | is($l.type, $type)))\n" + "    }:Location[*];\n" + "}\n" + "Class Location\n" + "{\n" + "    type : GeographicEntityType[1];\n" + "}\n";
    String enumSource = "Enum GeographicEntityType\n" + "{\n" + "    CITY,\n" + "    COUNTRY\n" + "}";
    RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("source1.pure", source).createInMemorySource("source2.pure", enumSource).createInMemorySource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), new RuntimeTestScriptBuilder().updateSource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.COUNTRY)}}#,0);true;}").compile().updateSource("userId.pure", "function test():Boolean[1]{print(#{EntityWithLocations{locationsByType(GeographicEntityType.CITY)}}#,0);true;}").compile(), this.runtime, this.functionExecution, Lists.fixedSize.<FunctionExecutionStateVerifier>of());
}
Also used : RuntimeTestScriptBuilder(org.finos.legend.pure.m3.RuntimeTestScriptBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 RuntimeTestScriptBuilder (org.finos.legend.pure.m3.RuntimeTestScriptBuilder)13 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)12 LambdaFunction (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction)8 Filter (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Filter)8 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)7 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)7 RichIterable (org.eclipse.collections.api.RichIterable)5 ListIterable (org.eclipse.collections.api.list.ListIterable)5 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)5 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)5 PureCompilationException (org.finos.legend.pure.m4.exception.PureCompilationException)5 List (java.util.List)4 Objects (java.util.Objects)4 Lists (org.eclipse.collections.impl.factory.Lists)4 Root_meta_pure_metamodel_function_LambdaFunction_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_LambdaFunction_Impl)4 Root_meta_pure_metamodel_type_generics_GenericType_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl)4 Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl)4 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)4 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)4