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;
}
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());
}
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());
}
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));
}
Aggregations