From 8924b4edb5cd7525d5334edd057efa9c0fcde9db Mon Sep 17 00:00:00 2001 From: "Kim, Jake" Date: Fri, 1 Nov 2024 12:31:02 -0400 Subject: [PATCH 1/2] Ensure milestoned association property with duplicate class property name gets added to milestoned properties --- .../compiler/toPureGraph/Milestoning.java | 2 +- .../TestDomainCompilationFromGrammar.java | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/Milestoning.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/Milestoning.java index 9f07df47e41..b15aa2ae6b5 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/Milestoning.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/Milestoning.java @@ -182,7 +182,7 @@ private static void applyMilestoningPropertyTransformations(CompileContext conte { MutableList propertiesUpdated = Lists.mutable.withAll(properties.select(p -> !originalProperties.contains(p))).withAll((Iterable) edgePointProperties); MutableList qualifiedPropertiesUpdated = Lists.mutable.withAll(qualifiedPropertiesGetter.valueOf(clazz)).withAll((Iterable) milestoningPropertyTransformations.flatCollect(t -> t.qualfiedPropertiesToAdd)); - MutableList originalMilestonedPropertiesUpdated = Lists.mutable.withAll(originalProperties.reject(p -> originalMilestonedProperties.anySatisfy(o -> o.getName().equals(p.getName())))); + MutableList 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); diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java index 62dbc621bf4..b7484ee63d8 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java @@ -2410,6 +2410,70 @@ public void testClassWithBusinessTemporalMilesoning() Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties for association", 1, worksForPropertyFromAssoc.size()); } + @Test + public void testClassesWithBusinessTemporalMilesoning() + { + Pair modelWithInput = + test("Class <> apps::Employee \n" + + "{ \n" + + " name: String[1]; \n" + + " firm: apps::Firm[1]; \n" + + "}\n\n" + + "Class <> 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 type = model.getClass("apps::Employee", SourceInformation.getUnknownSourceInformation()); + RichIterable> firmProperty = type._originalMilestonedProperties().select(p -> p.getName().equals("firm")); + Assert.assertEquals("Missing firm property in _originalMilestonedProperties", 1, firmProperty.size()); + RichIterable> 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> worksForPropertyFromAssoc = association._originalMilestonedProperties().select(p -> p.getName().equals("worksFor")); + Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties for association", 1, worksForPropertyFromAssoc.size()); + } + + @Test + public void testClassesWithBusinessTemporalMilesoningWithDuplicatePropertyName() + { + Pair modelWithInput = + test("Class <> apps::Employee \n" + + "{ \n" + + " name: String[1]; \n" + + " firm: apps::Firm[1]; \n" + + "}\n\n" + + "Class <> 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> firmProperty = type._originalMilestonedProperties().select(p -> p.getName().equals("firm")); + Assert.assertEquals("Missing firm property in _originalMilestonedProperties", 1, firmProperty.size()); + RichIterable> 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> worksForPropertyFromAssoc = association._originalMilestonedProperties().select(p -> p.getName().equals("worksFor")); + Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties for association", 1, worksForPropertyFromAssoc.size()); + + RichIterable> 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" + From 80c6d1030fe8ce9e7baceab37a512d9a88cfbc78 Mon Sep 17 00:00:00 2001 From: "Kim, Jake" Date: Fri, 1 Nov 2024 13:32:18 -0400 Subject: [PATCH 2/2] Assert on content of both milestoned association properties --- .../TestDomainCompilationFromGrammar.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java index b7484ee63d8..10d89844894 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/test/fromGrammar/TestDomainCompilationFromGrammar.java @@ -2429,15 +2429,23 @@ public void testClassesWithBusinessTemporalMilesoning() " employs: apps::Employee[*]; \n" + "} \n"); PureModel model = modelWithInput.getTwo(); - Class type = model.getClass("apps::Employee", SourceInformation.getUnknownSourceInformation()); - RichIterable> firmProperty = type._originalMilestonedProperties().select(p -> p.getName().equals("firm")); + Class typeEmployee = model.getClass("apps::Employee", SourceInformation.getUnknownSourceInformation()); + RichIterable> firmProperty = typeEmployee._originalMilestonedProperties().select(p -> p.getName().equals("firm")); Assert.assertEquals("Missing firm property in _originalMilestonedProperties", 1, firmProperty.size()); - RichIterable> worksForProperty = type._originalMilestonedProperties().select(p -> p.getName().equals("worksFor")); + RichIterable> 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> 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> worksForPropertyFromAssoc = association._originalMilestonedProperties().select(p -> p.getName().equals("worksFor")); + RichIterable> originalMilestonedProperties = association._originalMilestonedProperties(); + Assert.assertEquals("Expected 2 original milestoned properties, but found " + originalMilestonedProperties.size(), 2, originalMilestonedProperties.size()); + RichIterable> worksForPropertyFromAssoc = originalMilestonedProperties.select(p -> p.getName().equals("worksFor")); Assert.assertEquals("Missing worksFor property in _originalMilestonedProperties for association", 1, worksForPropertyFromAssoc.size()); + RichIterable> employsPropertyFromAssoc = originalMilestonedProperties.select(p -> p.getName().equals("employs")); + Assert.assertEquals("Missing employs property in _originalMilestonedProperties for association", 1, employsPropertyFromAssoc.size()); } @Test