Search in sources :

Example 1 with Association

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association in project legend-sdlc by finos.

the class TestProtocolToEntityConverter method testToEntityIfPossible.

@Test
public void testToEntityIfPossible() {
    PermissiveClassToEntityConverter converter = new PermissiveClassToEntityConverter();
    Class cls = new Class();
    cls.superTypes = Collections.singletonList("meta::pure::metamodel::type::Any");
    cls.name = "EmptyClass";
    cls._package = "model::test";
    Optional<Entity> entity = converter.toEntityIfPossible(cls);
    Assert.assertTrue(entity.isPresent());
    assertEntityEqualsClass(cls, entity.get());
    Optional<Entity> notAClass = converter.toEntityIfPossible(new Association());
    Assert.assertFalse(notAClass.isPresent());
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Association(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association) Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) Test(org.junit.Test)

Example 2 with Association

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association in project legend-engine by finos.

the class TestDomainCompilationFromGrammar method testClassWithBusinessTemporalMilesoning.

@Test
public void testClassWithBusinessTemporalMilesoning() {
    Pair<PureModelContextData, PureModel> modelWithInput = test("Class apps::Employee \n" + "{ \n" + "  name: String[1]; \n" + "  firm: apps::Firm[1]; \n" + "}\n\n" + "Class <<meta::pure::profiles::temporal.businesstemporal>> apps::Firm \n" + "{ \n" + "  name: String[1]; \n" + "} \n" + "Association apps::Employee_Firm \n" + "{ \n" + "  worksFor: apps::Firm[*]; \n" + "  employs: apps::Employee[*]; \n" + "} \n");
    PureModel model = modelWithInput.getTwo();
    Type clazz = model.getType("apps::Employee", SourceInformation.getUnknownSourceInformation());
    Root_meta_pure_metamodel_type_Class_Impl<?> type = (Root_meta_pure_metamodel_type_Class_Impl<?>) clazz;
    org.eclipse.collections.api.block.function.Function<Class, RichIterable<? extends org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property>> originalMilestonedPropertiesGetter = org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.ClassAccessor::_originalMilestonedProperties;
    RichIterable<? extends Property> firmProperty = originalMilestonedPropertiesGetter.valueOf(type).select(p -> p.getName().equals("firm"));
    Assert.assertTrue("Missing firm property in _originalMilestonedProperties", firmProperty.size() == 1);
    RichIterable<? extends org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property> worksForProperty = originalMilestonedPropertiesGetter.valueOf(type).select(p -> p.getName().equals("worksFor"));
    Assert.assertTrue("Missing worksFor property in _originalMilestonedProperties", worksForProperty.size() == 1);
    Association association = model.getAssociation("apps::Employee_Firm", SourceInformation.getUnknownSourceInformation());
    RichIterable<? extends org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property> worksForPropertyFromAssoc = association._originalMilestonedProperties().select(p -> p.getName().equals("worksFor"));
    Assert.assertTrue("Missing worksFor property in _originalMilestonedProperties for association", worksForPropertyFromAssoc.size() == 1);
}
Also used : Association(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association) Property(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) RichIterable(org.eclipse.collections.api.RichIterable) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) Class(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Root_meta_pure_metamodel_type_Class_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_Class_Impl) Test(org.junit.Test)

Example 3 with Association

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association in project legend-engine by finos.

the class RelationalCompilerExtension method getExtraAssociationMappingProcessors.

@Override
public List<Function3<AssociationMapping, Mapping, CompileContext, AssociationImplementation>> getExtraAssociationMappingProcessors() {
    return Collections.singletonList((associationMapping, parentMapping, context) -> {
        if (associationMapping instanceof RelationalAssociationMapping) {
            RelationalAssociationMapping relationalAssociationImplementation = (RelationalAssociationMapping) associationMapping;
            RelationalAssociationImplementation base = new Root_meta_relational_mapping_RelationalAssociationImplementation_Impl("");
            final org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association pureAssociation = context.resolveAssociation(relationalAssociationImplementation.association, associationMapping.sourceInformation);
            MutableList<EmbeddedRelationalInstanceSetImplementation> embeddedRelationalPropertyMappings = Lists.mutable.empty();
            MutableList<Store> stores = ListIterate.collect(relationalAssociationImplementation.stores, context::resolveStore);
            // NOTE: we set the association before processing the property mappings, so we can resolve the correct property in the association
            // in the case where the user does not provide the class name of where the association property comes from
            base._association(pureAssociation);
            RichIterable<org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.PropertyMapping> rpm = ListIterate.collect(relationalAssociationImplementation.propertyMappings, propertyMapping -> HelperRelationalBuilder.processAbstractRelationalPropertyMapping(propertyMapping, context, base, null, embeddedRelationalPropertyMappings, HelperMappingBuilder.getAllEnumerationMappings(parentMapping), Maps.mutable.empty()));
            base._stores(stores)._propertyMappings(rpm)._parent(parentMapping);
            parentMapping._classMappingsAddAll(embeddedRelationalPropertyMappings);
            return base;
        }
        return null;
    });
}
Also used : RelationalAssociationImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.RelationalAssociationImplementation) Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) EmbeddedRelationalInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.relational.mapping.EmbeddedRelationalInstanceSetImplementation) RelationalAssociationMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.RelationalAssociationMapping)

Example 4 with Association

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association in project legend-engine by finos.

the class XStoreAssociationMappingParseTreeWalker method visitXStorePropertyMapping.

private XStorePropertyMapping visitXStorePropertyMapping(XStoreAssociationMappingParserGrammar.XStorePropertyMappingContext ctx, String association) {
    XStorePropertyMapping xStorePropertyMapping = new XStorePropertyMapping();
    xStorePropertyMapping.property = new PropertyPointer();
    xStorePropertyMapping.property._class = association;
    xStorePropertyMapping.property.property = PureGrammarParserUtility.fromQualifiedName(ctx.qualifiedName().packagePath() == null ? Collections.emptyList() : ctx.qualifiedName().packagePath().identifier(), ctx.qualifiedName().identifier());
    xStorePropertyMapping.property.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx.qualifiedName());
    xStorePropertyMapping.source = ctx.sourceAndTargetMappingId() == null ? "" : ctx.sourceAndTargetMappingId().sourceId().getText();
    xStorePropertyMapping.target = ctx.sourceAndTargetMappingId() == null ? "" : ctx.sourceAndTargetMappingId().targetId().getText();
    xStorePropertyMapping.crossExpression = visitLambda(ctx.combinedExpression());
    xStorePropertyMapping.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    return xStorePropertyMapping;
}
Also used : XStorePropertyMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.xStore.XStorePropertyMapping) PropertyPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.PropertyPointer)

Example 5 with Association

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association in project legend-engine by finos.

the class DomainParseTreeWalker method visitAssociation.

// ----------------------------------------------- ASSOCIATION -----------------------------------------------
private Association visitAssociation(DomainParserGrammar.AssociationContext ctx) {
    Association assoc = new Association();
    assoc._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
    assoc.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
    assoc.stereotypes = ctx.stereotypes() == null ? Lists.mutable.empty() : this.visitStereotypes(ctx.stereotypes());
    assoc.taggedValues = ctx.taggedValues() == null ? Lists.mutable.empty() : this.visitTaggedValues(ctx.taggedValues());
    assoc.properties = ctx.associationBody().properties().property() == null ? new ArrayList<>() : ListIterate.collect(ctx.associationBody().properties().property(), this::visitSimpleProperty);
    assoc.qualifiedProperties = ctx.associationBody().properties().qualifiedProperty() == null ? new ArrayList<>() : ListIterate.collect(ctx.associationBody().properties().qualifiedProperty(), this::visitDerivedProperty);
    assoc.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    return assoc;
}
Also used : Association(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.Test)5 RichIterable (org.eclipse.collections.api.RichIterable)4 Lists (org.eclipse.collections.impl.factory.Lists)4 ListIterate (org.eclipse.collections.impl.utility.ListIterate)4 Class (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class)4 MutableList (org.eclipse.collections.api.list.MutableList)3 FastList (org.eclipse.collections.impl.list.mutable.FastList)3 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)3 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)3 SetImplementation (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.SetImplementation)3 Property (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property)3 Class (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class)3 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)3 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)3 List (java.util.List)2 Optional (java.util.Optional)2 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)2 PackageableElementVisitor (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElementVisitor)2 PackageableConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection)2 DataElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.data.DataElement)2