Search in sources :

Example 1 with Root_meta_data_DataElement

use of org.finos.legend.pure.generated.Root_meta_data_DataElement in project legend-engine by finos.

the class PackageableElementSecondPassBuilder method visit.

@Override
public PackageableElement visit(DataElement dataElement) {
    String fullPath = context.pureModel.buildPackageString(dataElement._package, dataElement.name);
    Root_meta_data_DataElement compiled = (Root_meta_data_DataElement) context.pureModel.getPackageableElement(fullPath);
    ProcessingContext processingContext = new ProcessingContext("Data '" + fullPath + "' Second Pass");
    Root_meta_data_Data compiledData = EmbeddedDataCompilerHelper.compileEmbeddedData(dataElement.data, context, processingContext);
    if (compiledData instanceof Root_meta_data_DataElementReference) {
        throw new EngineException("Cannot use Data element reference in a Data element", dataElement.data.sourceInformation, EngineErrorType.COMPILATION);
    }
    compiled._data(compiledData);
    return null;
}
Also used : Root_meta_data_Data(org.finos.legend.pure.generated.Root_meta_data_Data) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Root_meta_data_DataElementReference(org.finos.legend.pure.generated.Root_meta_data_DataElementReference) Root_meta_data_DataElement(org.finos.legend.pure.generated.Root_meta_data_DataElement)

Example 2 with Root_meta_data_DataElement

use of org.finos.legend.pure.generated.Root_meta_data_DataElement in project legend-engine by finos.

the class TestDataCompilationFromGrammar method testTextDataCompilation.

@Test
public void testTextDataCompilation() {
    Pair<PureModelContextData, PureModel> result = test("###Data\n" + "Data <<meta::pure::profiles::typemodifiers.abstract>> {doc.doc = 'something'} meta::data::MyData\n" + "Text #{\n" + "  contentType: 'application/json';\n" + "  data: '{\"some\":\"data\"}';\n" + "}#\n");
    PackageableElement element = result.getTwo().getPackageableElement("meta::data::MyData");
    Assert.assertTrue(element instanceof Root_meta_data_DataElement);
    Root_meta_data_DataElement dataElement = (Root_meta_data_DataElement) element;
    Assert.assertTrue(dataElement._data() instanceof Root_meta_data_TextData);
    Root_meta_data_TextData textData = (Root_meta_data_TextData) dataElement._data();
    Assert.assertEquals("application/json", textData._contentType());
    Assert.assertEquals("{\"some\":\"data\"}", textData._data());
}
Also used : PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) Root_meta_data_TextData(org.finos.legend.pure.generated.Root_meta_data_TextData) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Root_meta_data_DataElement(org.finos.legend.pure.generated.Root_meta_data_DataElement) Test(org.junit.Test)

Example 3 with Root_meta_data_DataElement

use of org.finos.legend.pure.generated.Root_meta_data_DataElement in project legend-engine by finos.

the class TestDataCompilationFromGrammar method testBinaryDataCompilation.

@Test
public void testBinaryDataCompilation() {
    Pair<PureModelContextData, PureModel> result = test("###Data\n" + "Data <<meta::pure::profiles::typemodifiers.abstract>> {doc.doc = 'something'} meta::data::MyData\n" + "Binary #{\n" + "  contentType: 'application/x-protobuf';\n" + "  data: '1B4A 9DEA 230F FF20';\n" + "}#\n");
    PackageableElement element = result.getTwo().getPackageableElement("meta::data::MyData");
    Assert.assertTrue(element instanceof Root_meta_data_DataElement);
    Root_meta_data_DataElement dataElement = (Root_meta_data_DataElement) element;
    Assert.assertTrue(dataElement._data() instanceof Root_meta_data_BinaryData);
    Root_meta_data_BinaryData binaryData = (Root_meta_data_BinaryData) dataElement._data();
    Assert.assertEquals("application/x-protobuf", binaryData._contentType());
    Assert.assertEquals("1B4A9DEA230FFF20", binaryData._hexData());
}
Also used : PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) Root_meta_data_BinaryData(org.finos.legend.pure.generated.Root_meta_data_BinaryData) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Root_meta_data_DataElement(org.finos.legend.pure.generated.Root_meta_data_DataElement) Test(org.junit.Test)

Example 4 with Root_meta_data_DataElement

use of org.finos.legend.pure.generated.Root_meta_data_DataElement in project legend-engine by finos.

the class TestDataCompilationFromGrammar method testPureCollectionDataCompilation.

@Test
public void testPureCollectionDataCompilation() {
    Pair<PureModelContextData, PureModel> result = test("###Pure\n" + "Enum enums::Gender\n" + "{\n" + "  MALE, FEMALE, OTHER\n" + "}\n" + "Class my::Address\n" + "{\n" + "  street : String[1];\n" + "}\n" + "Class my::Person\n" + "{\n" + "  givenNames  : String[*];\n" + "  lastName    : String[1];\n" + "  dateOfBirth : StrictDate[1];\n" + "  timeOfBirth : StrictTime[1];\n" + "  timeOfDeath : DateTime[0..1];\n" + "  isAlive     : Boolean[1];\n" + "  height      : Float[1];\n" + "  girth       : Decimal[1];\n" + "  shoeSize    : Integer[1];\n" + "  score1      : Integer[1];\n" + "  score2      : Float[1];\n" + "  score3      : Decimal[1];\n" + "  gender      : enums::Gender[1];\n" + "  address     : my::Address[1];\n" + "}\n" + "\n" + "###Data\n" + "Data <<meta::pure::profiles::typemodifiers.abstract>> {doc.doc = 'something'} meta::data::MyData\n" + "PureCollection #{\n" + "  data: [\n" + "    ^my::Person(\n" + "      givenNames  = ['Fred', 'William'],\n" + "      lastName    = 'Bloggs',\n" + "      dateOfBirth = %2001-03-12,\n" + "      timeOfBirth = %12:23,\n" + "      timeOfDeath = %2020-09-11T12:56:24.487,\n" + "      isAlive     = false,\n" + "      height      = 1.76,\n" + "      girth       = 0.98D,\n" + "      shoeSize    = 10,\n" + "      score1      = -1,\n" + "      score2      = -1.3,\n" + "      score3      = -1.8D,\n" + "      gender      = enums::Gender.MALE,\n" + "      address     = ^my::Address(street = 'A Road')\n" + "    ),\n" + "    ^my::Person(\n" + "      givenNames  = 'Jane',\n" + "      lastName    = 'Doe',\n" + "      dateOfBirth = %1984-04-22,\n" + "      timeOfBirth = %19:41:21,\n" + "      isAlive     = true,\n" + "      height      = 1.61,\n" + "      girth       = 0.81D,\n" + "      shoeSize    = 4,\n" + "      score1      = -1,\n" + "      score2      = -1.3,\n" + "      score3      = -1.8D,\n" + "      gender      = enums::Gender.FEMALE,\n" + "      address     = ^my::Address(street = 'B Road')\n" + "    )\n" + "  ];\n" + "}#\n");
    PackageableElement element = result.getTwo().getPackageableElement("meta::data::MyData");
    Assert.assertTrue(element instanceof Root_meta_data_DataElement);
    Root_meta_data_DataElement dataElement = (Root_meta_data_DataElement) element;
    Assert.assertTrue(dataElement._data() instanceof Root_meta_data_PureCollectionData);
    Root_meta_data_PureCollectionData pureCollectionData = (Root_meta_data_PureCollectionData) dataElement._data();
    InstanceValue collection = pureCollectionData._collection();
    Assert.assertEquals(2, collection._values().size());
    Assert.assertTrue(collection._values().allSatisfy(SimpleFunctionExpression.class::isInstance));
}
Also used : PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) Root_meta_data_PureCollectionData(org.finos.legend.pure.generated.Root_meta_data_PureCollectionData) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Root_meta_data_DataElement(org.finos.legend.pure.generated.Root_meta_data_DataElement) Test(org.junit.Test)

Aggregations

Root_meta_data_DataElement (org.finos.legend.pure.generated.Root_meta_data_DataElement)4 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)3 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)3 PackageableElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement)3 Test (org.junit.Test)3 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)1 Root_meta_data_BinaryData (org.finos.legend.pure.generated.Root_meta_data_BinaryData)1 Root_meta_data_Data (org.finos.legend.pure.generated.Root_meta_data_Data)1 Root_meta_data_DataElementReference (org.finos.legend.pure.generated.Root_meta_data_DataElementReference)1 Root_meta_data_PureCollectionData (org.finos.legend.pure.generated.Root_meta_data_PureCollectionData)1 Root_meta_data_TextData (org.finos.legend.pure.generated.Root_meta_data_TextData)1 InstanceValue (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue)1