use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement in project legend-engine by finos.
the class DataParseTreeWalker method visitDataElement.
private DataElement visitDataElement(DataParserGrammar.DataElementContext ctx) {
DataElement dataElement = new DataElement();
dataElement.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
dataElement._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
dataElement.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
dataElement.stereotypes = ctx.stereotypes() == null ? Lists.mutable.empty() : this.visitStereotypes(ctx.stereotypes());
dataElement.taggedValues = ctx.taggedValues() == null ? Lists.mutable.empty() : this.visitTaggedValues(ctx.taggedValues());
dataElement.data = HelperEmbeddedDataGrammarParser.parseEmbeddedData(ctx.embeddedData(), walkerSourceInformation, extensions);
return dataElement;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement in project legend-engine by finos.
the class PackageableElementFirstPassBuilder method visit.
@Override
public PackageableElement visit(DataElement dataElement) {
final Root_meta_data_DataElement compiled = new Root_meta_data_DataElement_Impl(dataElement.name);
GenericType mappingGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(this.context.pureModel.getType("meta::data::DataElement"));
org.finos.legend.pure.m3.coreinstance.Package pack = this.context.pureModel.getOrCreatePackage(dataElement._package);
compiled._name(dataElement.name)._package(pack)._classifierGenericType(mappingGenericType)._stereotypes(ListIterate.collect(dataElement.stereotypes, s -> context.resolveStereotype(s.profile, s.value, s.profileSourceInformation, s.sourceInformation)))._taggedValues(ListIterate.collect(dataElement.taggedValues, t -> new Root_meta_pure_metamodel_extension_TaggedValue_Impl("")._tag(context.resolveTag(t.tag.profile, t.tag.value, t.tag.profileSourceInformation, t.tag.sourceInformation))._value(t.value)));
pack._childrenAdd(compiled);
return compiled;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.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.engine.protocol.pure.v1.model.packageableElement.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.engine.protocol.pure.v1.model.packageableElement.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