Skip to content

Commit

Permalink
Ensure milestoned association property with duplicate class property…
Browse files Browse the repository at this point in the history
… name gets added to milestoned properties (#3228)

* Ensure milestoned association property with duplicate class property name gets added to milestoned properties

* Assert on content of both milestoned association properties
  • Loading branch information
jake-kim1 authored Nov 4, 2024
1 parent 0c3f637 commit 450b701
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private static void applyMilestoningPropertyTransformations(CompileContext conte
{
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property> propertiesUpdated = Lists.mutable.withAll(properties.select(p -> !originalProperties.contains(p))).withAll((Iterable) edgePointProperties);
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty> qualifiedPropertiesUpdated = Lists.mutable.withAll(qualifiedPropertiesGetter.valueOf(clazz)).withAll((Iterable) milestoningPropertyTransformations.flatCollect(t -> t.qualfiedPropertiesToAdd));
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property> originalMilestonedPropertiesUpdated = Lists.mutable.withAll(originalProperties.reject(p -> originalMilestonedProperties.anySatisfy(o -> o.getName().equals(p.getName()))));
MutableList<org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property> originalMilestonedPropertiesUpdated = Lists.mutable.withAll(originalProperties.reject(p -> originalMilestonedProperties.anySatisfy(o -> o.getName().equals(p.getName()) && o._owner().equals(p._owner()))));
propertiesSetter.accept(clazz, propertiesUpdated);
qualifiedPropertiesSetter.accept(clazz, qualifiedPropertiesUpdated);
originalPropertySetter.accept(clazz, originalMilestonedPropertiesUpdated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,78 @@ public void testClassWithBusinessTemporalMilesoning()
Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties for association", 1, worksForPropertyFromAssoc.size());
}

@Test
public void testClassesWithBusinessTemporalMilesoning()
{
Pair<PureModelContextData, PureModel> modelWithInput =
test("Class <<meta::pure::profiles::temporal.businesstemporal>> 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();
Class<?> typeEmployee = model.getClass("apps::Employee", SourceInformation.getUnknownSourceInformation());
RichIterable<? extends Property<?, ?>> firmProperty = typeEmployee._originalMilestonedProperties().select(p -> p.getName().equals("firm"));
Assert.assertEquals("Missing firm property in _originalMilestonedProperties", 1, firmProperty.size());
RichIterable<? extends Property<?, ?>> worksForProperty = typeEmployee._originalMilestonedProperties().select(p -> p.getName().equals("worksFor"));
Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties", 1, worksForProperty.size());

Class<?> typeFirm = model.getClass("apps::Firm", SourceInformation.getUnknownSourceInformation());
RichIterable<? extends Property<?, ?>> employsProperty = typeFirm._originalMilestonedProperties().select(p -> p.getName().equals("employs"));
Assert.assertEquals("Missing employs property in _originalMilestonedProperties", 1, employsProperty.size());

Association association = model.getAssociation("apps::Employee_Firm", SourceInformation.getUnknownSourceInformation());
RichIterable<? extends Property<? extends Object, ? extends Object>> originalMilestonedProperties = association._originalMilestonedProperties();
Assert.assertEquals("Expected 2 original milestoned properties, but found " + originalMilestonedProperties.size(), 2, originalMilestonedProperties.size());
RichIterable<? extends Property<?, ?>> worksForPropertyFromAssoc = originalMilestonedProperties.select(p -> p.getName().equals("worksFor"));
Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties for association", 1, worksForPropertyFromAssoc.size());
RichIterable<? extends Property<?, ?>> employsPropertyFromAssoc = originalMilestonedProperties.select(p -> p.getName().equals("employs"));
Assert.assertEquals("Missing employs property in _originalMilestonedProperties for association", 1, employsPropertyFromAssoc.size());
}

@Test
public void testClassesWithBusinessTemporalMilesoningWithDuplicatePropertyName()
{
Pair<PureModelContextData, PureModel> modelWithInput =
test("Class <<meta::pure::profiles::temporal.businesstemporal>> 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" +
" employs: apps::Employee[1]; \n" +
"} \n" +
"Association apps::Employee_Firm \n" +
"{ \n" +
" worksFor: apps::Firm[*]; \n" +
" employs: apps::Employee[*]; \n" +
"} \n");
PureModel model = modelWithInput.getTwo();
Class<?> type = model.getClass("apps::Employee", SourceInformation.getUnknownSourceInformation());
RichIterable<? extends Property<?, ?>> firmProperty = type._originalMilestonedProperties().select(p -> p.getName().equals("firm"));
Assert.assertEquals("Missing firm property in _originalMilestonedProperties", 1, firmProperty.size());
RichIterable<? extends Property<?, ?>> worksForProperty = type._originalMilestonedProperties().select(p -> p.getName().equals("worksFor"));
Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties", 1, worksForProperty.size());

Association association = model.getAssociation("apps::Employee_Firm", SourceInformation.getUnknownSourceInformation());
RichIterable<? extends Property<?, ?>> worksForPropertyFromAssoc = association._originalMilestonedProperties().select(p -> p.getName().equals("worksFor"));
Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties for association", 1, worksForPropertyFromAssoc.size());

RichIterable<? extends Property<?, ?>> employsPropertyFromAssoc = association._originalMilestonedProperties().select(p -> p.getName().equals("employs"));
Assert.assertEquals("Missing employs property in _originalMilestonedProperties for association", 1, employsPropertyFromAssoc.size());
}

public String getMilestoningModelWithDatePropagationAndInheritance()
{
return "###Pure\n" +
Expand Down

0 comments on commit 450b701

Please sign in to comment.