Search in sources :

Example 1 with ExecuteInput

use of org.finos.legend.engine.shared.core.api.model.ExecuteInput in project legend-engine by finos.

the class TestM2MGrammarCompileAndExecute method testM2MGraphWithAssociations.

@Test
public void testM2MGraphWithAssociations() {
    PureModelContextData contextData = PureGrammarParser.newInstance().parseModel("" + "Class test::Company\n" + "{\n" + "    name : String[1];\n" + "}\n" + "\n" + "Class test::Employee\n" + "{\n" + "    fullName : String[1];\n" + "}\n" + "\n" + "Class test::Firm\n" + "{\n" + "    name : String[1];\n" + "}\n" + "\n" + "Class test::Person\n" + "{\n" + "    firstName : String[1];\n" + "    lastName : String[1];\n" + "}\n" + "\n" + "Association test::Company_Employee\n" + "{\n" + "    company : test::Company[1];\n" + "    employees : test::Employee[*];\n" + "}\n" + "\n" + "Association test::FirmPerson\n" + "{\n" + "    firm : test::Firm[1];\n" + "    people : test::Person[*];\n" + "}\n" + "\n" + "###Mapping\n" + "Mapping test::FirmToCompany\n" + "(\n" + "   *test::Company[test_Company] : Pure\n" + "    {\n" + "     ~src test::Firm\n" + "     name: $src.name,\n" + "     employees[test_Employee]: $src.people\n" + "    }\n" + "\n" + "   *test::Employee[test_Employee] : Pure\n" + "    {\n" + "     ~src test::Person\n" + "     fullName: $src.firstName + ' ' + $src.lastName\n" + "    }\n" + ")");
    RootGraphFetchTree fetchTree = rootGFT("test::Company", propertyGFT("name"), propertyGFT("employees", propertyGFT("fullName")));
    Lambda lambda = lambda(apply(SERIALIZE, apply(GRAPH_FETCH, apply(GET_ALL, clazz("test::Company")), fetchTree), fetchTree));
    ExecuteInput input = new ExecuteInput();
    input.clientVersion = "vX_X_X";
    input.model = contextData;
    input.mapping = "test::FirmToCompany";
    input.function = lambda;
    input.runtime = runtimeValue(jsonModelConnection("test::Firm", "{\"name\":\"Metalurgy Inc\", \"people\":[{\"firstName\":\"Jane\",\"lastName\":\"Doe\"},{\"firstName\":\"Johny\",\"lastName\":\"Doe\"}]}\""));
    input.context = context();
    runTest(input);
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) ExecuteInput(org.finos.legend.engine.shared.core.api.model.ExecuteInput) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 2 with ExecuteInput

use of org.finos.legend.engine.shared.core.api.model.ExecuteInput in project legend-engine by finos.

the class TestM2MGrammarCompileAndExecute method testM2MSimpleStringJoin.

@Test
public void testM2MSimpleStringJoin() {
    PureModelContextData contextData = PureGrammarParser.newInstance().parseModel("" + "Class test::Person\n" + "{\n" + "   fullName: String[1];\n" + "}" + "\n" + "Class test::S_Person\n" + "{\n" + "   firstName: String[1];\n" + "   lastName: String[1];\n" + "}" + "\n" + "###Mapping\n" + "Mapping test::combineNames\n" + "(\n" + "   *test::Person[test_Person] : Pure\n" + "            {\n" + "               ~src test::S_Person\n" + "               fullName : $src.firstName + ' ' + $src.lastName\n" + "            }\n" + ")\n");
    RootGraphFetchTree fetchTree = rootGFT("test::Person");
    Lambda lambda = lambda(apply(SERIALIZE, apply(GRAPH_FETCH, apply(GET_ALL, clazz("test::Person")), fetchTree), fetchTree));
    ExecuteInput input = new ExecuteInput();
    input.clientVersion = "vX_X_X";
    input.model = contextData;
    input.mapping = "test::combineNames";
    input.function = lambda;
    input.runtime = runtimeValue(jsonModelConnection("test::S_Person", "{\"firstName\":\"Jane\",\"lastName\":\"Doe\"}"));
    input.context = context();
    runTest(input);
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) ExecuteInput(org.finos.legend.engine.shared.core.api.model.ExecuteInput) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 3 with ExecuteInput

use of org.finos.legend.engine.shared.core.api.model.ExecuteInput in project legend-engine by finos.

the class TestM2MGrammarCompileAndExecute method testM2MBigDecimalValue.

@Test
public void testM2MBigDecimalValue() throws IOException {
    PureModelContextData contextData = PureGrammarParser.newInstance().parseModel("" + "Class test::A\n" + "{\n" + "   d: Decimal[1];\n" + "}" + "\n" + "Class test::S_A\n" + "{\n" + "   d: Decimal[1];\n" + "}" + "\n" + "###Mapping\n" + "Mapping test::decimalMapping\n" + "(\n" + "   *test::A : Pure\n" + "            {\n" + "               ~src test::S_A\n" + "               d : $src.d\n" + "            }\n" + ")\n");
    RootGraphFetchTree fetchTree = rootGFT("test::A", propertyGFT("d"));
    Lambda lambda = lambda(apply(SERIALIZE, apply(GRAPH_FETCH, apply(GET_ALL, clazz("test::A")), fetchTree), fetchTree));
    ExecuteInput input = new ExecuteInput();
    input.clientVersion = "vX_X_X";
    input.model = contextData;
    input.mapping = "test::decimalMapping";
    input.function = lambda;
    input.runtime = runtimeValue(jsonModelConnection("test::S_A", "{\"d\": 999999999999999999.9333339999}"));
    input.context = context();
    String json = responseAsString(runTest(input));
    assertEquals("{\"builder\":{\"_type\":\"json\"},\"values\":{\"d\":999999999999999999.9333339999}}", json);
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) ExecuteInput(org.finos.legend.engine.shared.core.api.model.ExecuteInput) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 4 with ExecuteInput

use of org.finos.legend.engine.shared.core.api.model.ExecuteInput in project legend-engine by finos.

the class TestM2MGrammarCompileAndExecute method testHandlesDerived.

@Test
public void testHandlesDerived() throws IOException {
    String derivedPure;
    try (BufferedReader buffer = new BufferedReader(new InputStreamReader(TestM2MGrammarCompileAndExecute.class.getResourceAsStream("derived.pure")))) {
        derivedPure = buffer.lines().collect(Collectors.joining("\n"));
    }
    PureModelContextData contextData = PureGrammarParser.newInstance().parseModel(derivedPure);
    RootGraphFetchTree fetchTree = rootGFT("test::FirstEmployee", propertyGFT("name"));
    Lambda lambda = lambda(apply(SERIALIZE, apply(GRAPH_FETCH, apply(GET_ALL, clazz("test::FirstEmployee")), fetchTree), fetchTree));
    ExecuteInput input = new ExecuteInput();
    input.clientVersion = "vX_X_X";
    input.model = contextData;
    input.mapping = "test::m1";
    input.function = lambda;
    input.runtime = runtimeValue(jsonModelConnection("test::Firm", "{\"name\": \"firm1\", \"employees\": [{\"firstName\": \"Jane\", \"lastName\": \"Doe\"}]}"));
    input.context = context();
    String json = responseAsString(runTest(input));
    assertEquals("{\"builder\":{\"_type\":\"json\"},\"values\":{\"name\":\"Doe\"}}", json);
}
Also used : RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) ExecuteInput(org.finos.legend.engine.shared.core.api.model.ExecuteInput) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Aggregations

PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)4 Lambda (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)4 RootGraphFetchTree (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree)4 ExecuteInput (org.finos.legend.engine.shared.core.api.model.ExecuteInput)4 Test (org.junit.Test)4 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1