Search in sources :

Example 1 with EnumValueMapping

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping in project legend-pure by finos.

the class TestEnumerationMapping method testValidComplexEnumToEnumMapping.

@Test
public void testValidComplexEnumToEnumMapping() {
    this.runtime.createInMemorySource("model.pure", "###Pure\n" + "\n" + "Enum my::SourceEnum\n" + "{\n" + "   A, B, C\n" + "}\n" + "\n" + "Enum my::TargetEnum\n" + "{\n" + "   X, Y\n" + "}\n" + "\n" + "###Mapping\n" + "import my::*;\n" + "\n" + "Mapping my::TestMapping\n" + "(\n" + "   TargetEnum : EnumerationMapping\n" + "   {\n" + "      X : SourceEnum.A,\n" + "      Y : [SourceEnum.B, my::SourceEnum.C]\n" + "   }\n" + ")");
    this.runtime.compile();
    org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping mapping = (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) this.runtime.getCoreInstance("my::TestMapping");
    EnumerationMapping enumerationMapping = mapping._enumerationMappings().getFirst();
    Assert.assertEquals("my::TargetEnum", PackageableElement.getUserPathForPackageableElement(enumerationMapping._enumeration()));
    ImmutableList<EnumValueMapping> enumValueMappings = (ImmutableList<EnumValueMapping>) enumerationMapping._enumValueMappings();
    Assert.assertEquals(2, enumValueMappings.size());
    EnumValueMapping enumValueMapping1 = enumValueMappings.get(0);
    Assert.assertEquals("X", enumValueMapping1._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances1 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValuesCoreInstance();
    Assert.assertEquals(1, sourceValuesCoreInstances1.size());
    Assert.assertTrue(sourceValuesCoreInstances1.get(0) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances1.get(0))._enumeration()));
    ImmutableList<CoreInstance> sourceValues1 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValues();
    Assert.assertEquals(1, sourceValues1.size());
    Assert.assertTrue(sourceValues1.get(0) instanceof Enum);
    Assert.assertEquals("A", ((Enum) sourceValues1.get(0))._name());
    EnumValueMapping enumValueMapping2 = enumValueMappings.get(1);
    Assert.assertEquals("Y", enumValueMapping2._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances2 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValuesCoreInstance();
    Assert.assertEquals(2, sourceValuesCoreInstances2.size());
    Assert.assertTrue(sourceValuesCoreInstances2.get(0) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances2.get(0))._enumeration()));
    Assert.assertTrue(sourceValuesCoreInstances2.get(1) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances2.get(1))._enumeration()));
    ImmutableList<CoreInstance> sourceValues2 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValues();
    Assert.assertEquals(2, sourceValues2.size());
    Assert.assertTrue(sourceValues2.get(0) instanceof Enum);
    Assert.assertEquals("B", ((Enum) sourceValues2.get(0))._name());
    Assert.assertTrue(sourceValues2.get(1) instanceof Enum);
    Assert.assertEquals("C", ((Enum) sourceValues2.get(1))._name());
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) EnumStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.EnumStub) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) ImmutableList(org.eclipse.collections.api.list.ImmutableList) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) IntegerCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance) Test(org.junit.Test)

Example 2 with EnumValueMapping

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping in project legend-pure by finos.

the class TestEnumerationMapping method testValidSimpleEnumToEnumMapping.

@Test
public void testValidSimpleEnumToEnumMapping() {
    this.runtime.createInMemorySource("model.pure", "###Pure\n" + "\n" + "Enum my::SourceEnum\n" + "{\n" + "   A, B\n" + "}\n" + "\n" + "Enum my::TargetEnum\n" + "{\n" + "   X, Y\n" + "}\n" + "\n" + "###Mapping\n" + "import my::*;\n" + "\n" + "Mapping my::TestMapping\n" + "(\n" + "   TargetEnum : EnumerationMapping\n" + "   {\n" + "      X : SourceEnum.A,\n" + "      Y : my::SourceEnum.B\n" + "   }\n" + ")");
    this.runtime.compile();
    org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping mapping = (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) this.runtime.getCoreInstance("my::TestMapping");
    EnumerationMapping enumerationMapping = mapping._enumerationMappings().getFirst();
    Assert.assertEquals("my::TargetEnum", PackageableElement.getUserPathForPackageableElement(enumerationMapping._enumeration()));
    ImmutableList<EnumValueMapping> enumValueMappings = (ImmutableList<EnumValueMapping>) enumerationMapping._enumValueMappings();
    Assert.assertEquals(2, enumValueMappings.size());
    EnumValueMapping enumValueMapping1 = enumValueMappings.get(0);
    Assert.assertEquals("X", enumValueMapping1._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances1 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValuesCoreInstance();
    Assert.assertEquals(1, sourceValuesCoreInstances1.size());
    Assert.assertTrue(sourceValuesCoreInstances1.get(0) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances1.get(0))._enumeration()));
    ImmutableList<CoreInstance> sourceValues1 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValues();
    Assert.assertEquals(1, sourceValues1.size());
    Assert.assertTrue(sourceValues1.get(0) instanceof Enum);
    Assert.assertEquals("A", ((Enum) sourceValues1.get(0))._name());
    EnumValueMapping enumValueMapping2 = enumValueMappings.get(1);
    Assert.assertEquals("Y", enumValueMapping2._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances2 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValuesCoreInstance();
    Assert.assertEquals(1, sourceValuesCoreInstances2.size());
    Assert.assertTrue(sourceValuesCoreInstances2.get(0) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances2.get(0))._enumeration()));
    ImmutableList<CoreInstance> sourceValues2 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValues();
    Assert.assertEquals(1, sourceValues2.size());
    Assert.assertTrue(sourceValues2.get(0) instanceof Enum);
    Assert.assertEquals("B", ((Enum) sourceValues2.get(0))._name());
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) EnumStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.EnumStub) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) ImmutableList(org.eclipse.collections.api.list.ImmutableList) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) IntegerCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance) Test(org.junit.Test)

Example 3 with EnumValueMapping

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping in project legend-pure by finos.

the class EnumerationMappingUnbind method run.

@Override
public void run(EnumerationMapping enumerationMapping, MatcherState state, Matcher matcher, ModelRepository modelRepository, Context context) throws PureCompilationException {
    ProcessorSupport processorSupport = state.getProcessorSupport();
    MutableList<? extends CoreInstance> enumerations = Lists.mutable.with(enumerationMapping._enumerationCoreInstance()).withAll(EnumerationMappingProcessor.collectSourceEnumerationCoreInstances(enumerationMapping));
    Shared.cleanUpReferenceUsages(enumerations, enumerationMapping, processorSupport);
    Shared.cleanImportStubs(enumerations, processorSupport);
    for (EnumValueMapping enumValueMapping : (RichIterable<? extends EnumValueMapping>) enumerationMapping._enumValueMappings()) {
        Shared.cleanEnumStubs(Lists.mutable.with(enumValueMapping._enumCoreInstance()).withAll(EnumerationMappingProcessor.collectSourceEnumCoreInstances(enumValueMapping)), processorSupport);
    }
}
Also used : RichIterable(org.eclipse.collections.api.RichIterable) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping)

Example 4 with EnumValueMapping

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping in project legend-engine by finos.

the class HelperMappingBuilder method processEnumMapping.

public static org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping<Object> processEnumMapping(EnumerationMapping em, Mapping pureMapping, CompileContext context) {
    // validate there is no mixed protocol format for source value
    List<Object> sourceValues = em.enumValueMappings.stream().flatMap(enumValueMapping -> enumValueMapping.sourceValues.stream()).collect(Collectors.toList());
    if (sourceValues.stream().anyMatch(sourceValue -> !(sourceValue instanceof EnumValueMappingSourceValue)) && sourceValues.stream().anyMatch(sourceValue -> sourceValue instanceof EnumValueMappingSourceValue)) {
        throw new EngineException("Mixed formats for enum value mapping source values", em.sourceInformation, EngineErrorType.COMPILATION);
    }
    // process enum value mappings
    String id = getEnumerationMappingId(em);
    return new Root_meta_pure_mapping_EnumerationMapping_Impl<>(id, SourceInformationHelper.toM3SourceInformation(em.sourceInformation), null)._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::mapping::EnumerationMapping"))._typeArguments(FastList.newListWith(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::metamodel::type::Any")))))._name(id)._parent(pureMapping)._enumeration(context.resolveEnumeration(em.enumeration, em.sourceInformation))._enumValueMappings(ListIterate.collect(em.enumValueMappings, v -> new Root_meta_pure_mapping_EnumValueMapping_Impl(null, SourceInformationHelper.toM3SourceInformation(em.sourceInformation), null)._enum(context.resolveEnumValue(em.enumeration, v.enumValue))._sourceValues(convertSourceValues(em, v.sourceValues, context))));
}
Also used : AggregationFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregationFunctionSpecification) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) PurePropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.PurePropertyMapping) XStoreAssociationImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.xStore.XStoreAssociationImplementation) SetIterable(org.eclipse.collections.api.set.SetIterable) Generalization(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Generalization) MutableList(org.eclipse.collections.api.list.MutableList) MutableSet(org.eclipse.collections.api.set.MutableSet) Handlers(org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.Handlers) PropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyMapping) RichIterable(org.eclipse.collections.api.RichIterable) Variable(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) EnumValueMappingEnumSourceValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumValueMappingEnumSourceValue) Root_meta_pure_metamodel_function_LambdaFunction_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_LambdaFunction_Impl) Map(java.util.Map) InstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.InstanceSetImplementation) Multiplicity(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Multiplicity) AssociationImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.AssociationImplementation) EnumerationMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumerationMapping) MappingClass(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.MappingClass) GroupByFunctionSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.GroupByFunctionSpecification) Root_meta_pure_mapping_SubstituteStore_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_SubstituteStore_Impl) MappingTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest) Root_meta_pure_metamodel_function_property_Property_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_function_property_Property_Impl) LocalMappingPropertyInfo(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.LocalMappingPropertyInfo) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) Root_meta_pure_mapping_xStore_XStoreAssociationImplementation_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_xStore_XStoreAssociationImplementation_Impl) Collectors(java.util.stream.Collectors) Root_meta_pure_mapping_MappingClass_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_MappingClass_Impl) Objects(java.util.Objects) Root_meta_pure_mapping_aggregationAware_AggregationFunctionSpecification_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_AggregationFunctionSpecification_Impl) List(java.util.List) ClassMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.ClassMapping) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) Procedure2(org.eclipse.collections.api.block.procedure.Procedure2) 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) Optional(java.util.Optional) InputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData) EnumValueMappingStringSourceValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumValueMappingStringSourceValue) VariableExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) PropertyMappingsImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMappingsImplementation) AggregateSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.aggregationAware.AggregateSpecification) Root_meta_pure_mapping_EnumValueMapping_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_EnumValueMapping_Impl) MappingInclude(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.MappingInclude) AssociationMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.AssociationMapping) XStoreAssociationMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.xStore.XStoreAssociationMapping) EnumValueMappingIntegerSourceValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumValueMappingIntegerSourceValue) Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1_(org.finos.legend.pure.generated.platform_pure_corefunctions_meta.Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1_) FastList(org.eclipse.collections.impl.list.mutable.FastList) EnumValueMappingSourceValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumValueMappingSourceValue) HelperModelBuilder.getElementFullPath(org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperModelBuilder.getElementFullPath) ObjectInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.ObjectInputData) Root_meta_pure_mapping_EnumerationMapping_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_EnumerationMapping_Impl) AggregateFunction(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateFunction) GroupByFunction(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.GroupByFunction) Root_meta_pure_metamodel_relationship_Generalization_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_relationship_Generalization_Impl) Root_meta_pure_mapping_MappingInclude_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_MappingInclude_Impl) Root_meta_pure_metamodel_type_generics_GenericType_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl) PackageableElement(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation) Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation) LambdaFunction(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction) Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) Root_meta_pure_mapping_aggregationAware_GroupByFunctionSpecification_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_GroupByFunctionSpecification_Impl) AggregateSetImplementationContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateSetImplementationContainer) Sets(org.eclipse.collections.impl.factory.Sets) Root_meta_pure_mapping_aggregationAware_AggregateSetImplementationContainer_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_aggregationAware_AggregateSetImplementationContainer_Impl) ImmutableSet(org.eclipse.collections.api.set.ImmutableSet) Root_meta_pure_metamodel_type_generics_GenericType_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Root_meta_pure_mapping_EnumValueMapping_Impl(org.finos.legend.pure.generated.Root_meta_pure_mapping_EnumValueMapping_Impl) EnumValueMappingSourceValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.EnumValueMappingSourceValue)

Example 5 with EnumValueMapping

use of org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping in project legend-pure by finos.

the class TestEnumerationMapping method testValidHybridEnumToEnumMapping.

@Test
public void testValidHybridEnumToEnumMapping() {
    this.runtime.createInMemorySource("model.pure", "###Pure\n" + "\n" + "Enum my::SourceEnum1\n" + "{\n" + "   A, B, C\n" + "}\n" + "\n" + "Enum my::SourceEnum2\n" + "{\n" + "   P, Q, R\n" + "}\n" + "\n" + "Enum my::TargetEnum\n" + "{\n" + "   U, V, W, X, Y, Z\n" + "}\n" + "\n" + "###Mapping\n" + "import my::*;\n" + "\n" + "Mapping my::TestMapping\n" + "(\n" + "   TargetEnum : EnumerationMapping enumsATargetEnum\n" + "   {\n" + "      U : my::SourceEnum1.A,\n" + "      V : my::SourceEnum1.A,\n" + "      W : [my::SourceEnum1.A, my::SourceEnum1.B],\n" + "      X : [my::SourceEnum1.A, my::SourceEnum1.B, my::SourceEnum1.C],\n" + "      Y : [my::SourceEnum1.A, my::SourceEnum1.B, my::SourceEnum1.C],\n" + "      Z : my::SourceEnum1.C\n" + "   }\n" + "   TargetEnum : EnumerationMapping enumsBTargetEnum\n" + "   {\n" + "      U : my::SourceEnum2.P,\n" + "      V : my::SourceEnum2.P\n," + "      W : [my::SourceEnum2.P, my::SourceEnum2. Q,my::SourceEnum2.R]\n" + "   }\n" + "   TargetEnum : EnumerationMapping integersTargetEnum2\n" + "   {\n" + "      X : [4,5,6],\n" + "      Y : 3\n" + "   }\n" + "   TargetEnum : EnumerationMapping stringsTargetEnum2\n" + "   {\n" + "      Y : ['One','Two','Three'],\n" + "      Z : 'A'\n" + "   }\n" + ")");
    this.runtime.compile();
    org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping mapping = (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) this.runtime.getCoreInstance("my::TestMapping");
    EnumerationMapping enumerationMapping = mapping._enumerationMappings().detect(detectByEnumerationMappingName("enumsATargetEnum"));
    Assert.assertEquals("my::TargetEnum", PackageableElement.getUserPathForPackageableElement(enumerationMapping._enumeration()));
    ImmutableList<EnumValueMapping> enumValueMappings = (ImmutableList<EnumValueMapping>) enumerationMapping._enumValueMappings();
    Assert.assertEquals(6, enumValueMappings.size());
    EnumValueMapping enumValueMapping1 = enumValueMappings.get(0);
    Assert.assertEquals("U", enumValueMapping1._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances1 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValuesCoreInstance();
    Assert.assertEquals(1, sourceValuesCoreInstances1.size());
    Assert.assertTrue(sourceValuesCoreInstances1.get(0) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum1", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances1.get(0))._enumeration()));
    ImmutableList<CoreInstance> sourceValues1 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValues();
    Assert.assertEquals(1, sourceValues1.size());
    Assert.assertTrue(sourceValues1.get(0) instanceof Enum);
    Assert.assertEquals("A", ((Enum) sourceValues1.get(0))._name());
    enumValueMappings = (ImmutableList<EnumValueMapping>) mapping._enumerationMappings().detect(detectByEnumerationMappingName("enumsBTargetEnum"))._enumValueMappings();
    EnumValueMapping enumValueMapping2 = enumValueMappings.get(1);
    Assert.assertEquals("V", enumValueMapping2._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances2 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValuesCoreInstance();
    Assert.assertEquals(1, sourceValuesCoreInstances2.size());
    Assert.assertTrue(sourceValuesCoreInstances2.get(0) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum2", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances2.get(0))._enumeration()));
    ImmutableList<CoreInstance> sourceValues2 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValues();
    Assert.assertEquals(1, sourceValues2.size());
    Assert.assertTrue(sourceValues2.get(0) instanceof Enum);
    Assert.assertEquals("P", ((Enum) sourceValues2.get(0))._name());
    EnumValueMapping enumValueMapping3 = enumValueMappings.get(2);
    Assert.assertEquals("W", enumValueMapping3._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances3 = (ImmutableList<CoreInstance>) enumValueMapping3._sourceValuesCoreInstance();
    Assert.assertEquals(3, sourceValuesCoreInstances3.size());
    Assert.assertTrue(sourceValuesCoreInstances3.get(0) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum2", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances3.get(0))._enumeration()));
    Assert.assertTrue(sourceValuesCoreInstances3.get(1) instanceof EnumStub);
    Assert.assertEquals("my::SourceEnum2", PackageableElement.getUserPathForPackageableElement(((EnumStub) sourceValuesCoreInstances3.get(1))._enumeration()));
    ImmutableList<CoreInstance> sourceValues3 = (ImmutableList<CoreInstance>) enumValueMapping3._sourceValues();
    Assert.assertEquals(3, sourceValues3.size());
    Assert.assertTrue(sourceValues3.get(0) instanceof Enum);
    Assert.assertEquals("P", ((Enum) sourceValues3.get(0))._name());
    Assert.assertTrue(sourceValues3.get(1) instanceof Enum);
    Assert.assertEquals("Q", ((Enum) sourceValues3.get(1))._name());
    Assert.assertTrue(sourceValues3.get(2) instanceof Enum);
    Assert.assertEquals("R", ((Enum) sourceValues3.get(2))._name());
    enumValueMappings = (ImmutableList<EnumValueMapping>) mapping._enumerationMappings().detect(detectByEnumerationMappingName("integersTargetEnum2"))._enumValueMappings();
    enumValueMapping1 = enumValueMappings.get(0);
    Assert.assertEquals("X", enumValueMapping1._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances4 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValuesCoreInstance();
    Assert.assertEquals(3, sourceValuesCoreInstances4.size());
    Assert.assertTrue(sourceValuesCoreInstances4.get(0) instanceof IntegerCoreInstance);
    MutableList<? extends Object> sourceValues4 = enumValueMapping1._sourceValues().toList();
    Assert.assertEquals(3, sourceValues4.size());
    Assert.assertEquals(4L, sourceValues4.get(0));
    Assert.assertEquals(5L, sourceValues4.get(1));
    Assert.assertEquals(6L, sourceValues4.get(2));
    enumValueMapping2 = enumValueMappings.get(1);
    Assert.assertEquals("Y", enumValueMapping2._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances5 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValuesCoreInstance();
    Assert.assertEquals(1, sourceValuesCoreInstances5.size());
    Assert.assertTrue(sourceValuesCoreInstances4.get(0) instanceof IntegerCoreInstance);
    MutableList<? extends Object> sourceValues5 = enumValueMapping2._sourceValues().toList();
    Assert.assertEquals(1, sourceValues5.size());
    Assert.assertEquals(3L, sourceValues5.get(0));
    enumValueMappings = (ImmutableList<EnumValueMapping>) mapping._enumerationMappings().detect(detectByEnumerationMappingName("stringsTargetEnum2"))._enumValueMappings();
    enumValueMapping1 = enumValueMappings.get(0);
    Assert.assertEquals("Y", enumValueMapping1._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances6 = (ImmutableList<CoreInstance>) enumValueMapping1._sourceValuesCoreInstance();
    Assert.assertEquals(3, sourceValuesCoreInstances6.size());
    Assert.assertTrue(sourceValuesCoreInstances4.get(0) instanceof IntegerCoreInstance);
    MutableList<? extends Object> sourceValues6 = enumValueMapping1._sourceValues().toList();
    Assert.assertEquals(3, sourceValues6.size());
    Assert.assertEquals("One", sourceValues6.get(0));
    Assert.assertEquals("Two", sourceValues6.get(1));
    Assert.assertEquals("Three", sourceValues6.get(2));
    enumValueMapping2 = enumValueMappings.get(1);
    Assert.assertEquals("Z", enumValueMapping2._enum()._name());
    ImmutableList<CoreInstance> sourceValuesCoreInstances7 = (ImmutableList<CoreInstance>) enumValueMapping2._sourceValuesCoreInstance();
    Assert.assertEquals(1, sourceValuesCoreInstances7.size());
    Assert.assertTrue(sourceValuesCoreInstances4.get(0) instanceof IntegerCoreInstance);
    MutableList<? extends Object> sourceValues7 = enumValueMapping2._sourceValues().toList();
    Assert.assertEquals(1, sourceValues7.size());
    Assert.assertEquals("A", sourceValues7.get(0));
}
Also used : Enum(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum) EnumStub(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.EnumStub) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) ImmutableList(org.eclipse.collections.api.list.ImmutableList) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping) EnumerationMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping) IntegerCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance) EnumValueMapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) IntegerCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance) Test(org.junit.Test)

Aggregations

EnumValueMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumValueMapping)4 ImmutableList (org.eclipse.collections.api.list.ImmutableList)3 EnumerationMapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.EnumerationMapping)3 EnumStub (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.EnumStub)3 Enum (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enum)3 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)3 IntegerCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.IntegerCoreInstance)3 Test (org.junit.Test)3 RichIterable (org.eclipse.collections.api.RichIterable)2 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Procedure2 (org.eclipse.collections.api.block.procedure.Procedure2)1 MutableList (org.eclipse.collections.api.list.MutableList)1 ImmutableSet (org.eclipse.collections.api.set.ImmutableSet)1 MutableSet (org.eclipse.collections.api.set.MutableSet)1 SetIterable (org.eclipse.collections.api.set.SetIterable)1 Lists (org.eclipse.collections.impl.factory.Lists)1