Search in sources :

Example 1 with DataElement

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;
}
Also used : DataElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement)

Example 2 with 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;
}
Also used : Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) PackageableElementVisitor(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) QualifiedProperty(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty) Mapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping) ListIterate(org.eclipse.collections.impl.utility.ListIterate) DataElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement) FastList(org.eclipse.collections.impl.list.mutable.FastList) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) UserDefinedFunctionHandler(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.UserDefinedFunctionHandler) org.finos.legend.pure.generated(org.finos.legend.pure.generated) List(java.util.List) PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain) PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) Lists(org.eclipse.collections.impl.factory.Lists) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) ListIterable(org.eclipse.collections.api.list.ListIterable) SectionIndex(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex) TypeAndMultiplicity(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.inference.TypeAndMultiplicity) PackageableRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)

Example 3 with DataElement

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());
}
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 4 with DataElement

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());
}
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 5 with DataElement

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

PackageableElement (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement)4 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)3 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)3 Root_meta_data_DataElement (org.finos.legend.pure.generated.Root_meta_data_DataElement)3 Test (org.junit.Test)3 DataElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement)2 List (java.util.List)1 ListIterable (org.eclipse.collections.api.list.ListIterable)1 Lists (org.eclipse.collections.impl.factory.Lists)1 FastList (org.eclipse.collections.impl.list.mutable.FastList)1 ListIterate (org.eclipse.collections.impl.utility.ListIterate)1 UserDefinedFunctionHandler (org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.UserDefinedFunctionHandler)1 TypeAndMultiplicity (org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.inference.TypeAndMultiplicity)1 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)1 PackageableElementVisitor (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor)1 PackageableConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection)1 org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain)1 Class (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class)1 Mapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping)1 PackageableRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime)1