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