From 2b5939fdb03a7f72a32cd9bf579e8f4f02c33311 Mon Sep 17 00:00:00 2001 From: Dominic Burger Date: Wed, 2 Oct 2024 10:03:03 +0200 Subject: [PATCH] Resolve object for paths ending in association --- .../iox_j/validator/AttributeArray.java | 11 +++++-- .../interlis/iox_j/validator/Validator.java | 24 +++----------- src/test/data/validator/AssociationPath.ili | 25 +++++++++++++++ src/test/data/validator/AssociationPath.xtf | 26 +++++++++++++++ .../iox_j/validator/AssociationPathTest.java | 32 +++++++++++++++++++ .../validator/UniqueConstraints10Test.java | 2 +- 6 files changed, 96 insertions(+), 24 deletions(-) create mode 100644 src/test/data/validator/AssociationPath.ili create mode 100644 src/test/data/validator/AssociationPath.xtf create mode 100644 src/test/java/ch/interlis/iox_j/validator/AssociationPathTest.java diff --git a/src/main/java/ch/interlis/iox_j/validator/AttributeArray.java b/src/main/java/ch/interlis/iox_j/validator/AttributeArray.java index 1179177c..d810e64f 100644 --- a/src/main/java/ch/interlis/iox_j/validator/AttributeArray.java +++ b/src/main/java/ch/interlis/iox_j/validator/AttributeArray.java @@ -85,13 +85,18 @@ public boolean equals(Object obj) { } private boolean equalsIomObj(IomObject thisObj, IomObject otherObj) { - // ignore oid, because only structEles that should never have an oid - // compare class/assoc/coord/... if(!thisObj.getobjecttag().equals(otherObj.getobjecttag())){ return false; } - + + // referenced objects can have oid + String oid = thisObj.getobjectoid(); + String otherOid = otherObj.getobjectoid(); + if (oid == null ? otherOid != null : !oid.equals(otherOid)) { + return false; + } + // compare ref String refoid=thisObj.getobjectrefoid(); String otherRefoid=otherObj.getobjectrefoid(); diff --git a/src/main/java/ch/interlis/iox_j/validator/Validator.java b/src/main/java/ch/interlis/iox_j/validator/Validator.java index 58172e2e..5356af07 100644 --- a/src/main/java/ch/interlis/iox_j/validator/Validator.java +++ b/src/main/java/ch/interlis/iox_j/validator/Validator.java @@ -2099,26 +2099,10 @@ public Value getValueFromObjectPath(IomObject parentObject,IomObject iomObjStart continue; } } - if (k != lastPathIndex) { - IomObject targetObj = getReferencedObject(role, targetOid); - if (targetObj != null) { - nextCurrentObjects.add(targetObj); - } - }else { - List objects = new ArrayList(); - IomObject targetRefObj = getReferencedObject(role, targetOid); - if (targetRefObj != null) { - if (role instanceof RoleDef) { - return Value.createOidValue(targetRefObj.getobjectoid()); - } else { - objects.add(targetRefObj); - nextCurrentObjects.addAll(objects); - } - - } else if (roleDefValue != null) { - objects.add(roleDefValue); - nextCurrentObjects.addAll(objects); - } + + IomObject targetObj = getReferencedObject(role, targetOid); + if (targetObj != null) { + nextCurrentObjects.add(targetObj); } } } diff --git a/src/test/data/validator/AssociationPath.ili b/src/test/data/validator/AssociationPath.ili new file mode 100644 index 00000000..13479038 --- /dev/null +++ b/src/test/data/validator/AssociationPath.ili @@ -0,0 +1,25 @@ +INTERLIS 2.4; + +MODEL ModelA (en) AT "http://www.interlis.ch/ili2c/tests/" VERSION "2024-10-01" = + TOPIC TopicA = + CLASS ClassA1 = + Attr : BOOLEAN; + END ClassA1; + + CLASS ClassB1 = + Code: TEXT*10; + END ClassB1; + + ASSOCIATION Assoc1 = + AssocA -- {0..*} ClassA1; + AssocB -<> {1} ClassB1; + END Assoc1; + + CONSTRAINTS OF ClassA1 = + MANDATORY CONSTRAINT IsOfClassAShouldFail : INTERLIS.isOfClass(THIS->AssocB, >ClassA1); + MANDATORY CONSTRAINT IsOfClassB : INTERLIS.isOfClass(THIS->AssocB, >ClassB1); + + MANDATORY CONSTRAINT CodeLength : INTERLIS.len(THIS->AssocB->Code) >= 3; + END; + END TopicA; +END ModelA. diff --git a/src/test/data/validator/AssociationPath.xtf b/src/test/data/validator/AssociationPath.xtf new file mode 100644 index 00000000..05a3ccbc --- /dev/null +++ b/src/test/data/validator/AssociationPath.xtf @@ -0,0 +1,26 @@ + + + + + ModelA + + ili2gpkg-5.0.1-447c03f22b8f346a44ada86c553d10110872fd40 + + + + + abc + + + xyz + + + + true + + + + diff --git a/src/test/java/ch/interlis/iox_j/validator/AssociationPathTest.java b/src/test/java/ch/interlis/iox_j/validator/AssociationPathTest.java new file mode 100644 index 00000000..d0434fd5 --- /dev/null +++ b/src/test/java/ch/interlis/iox_j/validator/AssociationPathTest.java @@ -0,0 +1,32 @@ +package ch.interlis.iox_j.validator; + +import ch.interlis.ili2c.metamodel.TransferDescription; +import ch.interlis.iox.IoxException; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; + +public class AssociationPathTest { + private static final String TEST_DIR = "src/test/data/validator"; + private static final String ILI_FILE = TEST_DIR + "/AssociationPath.ili"; + private static final String XTF_FILE = TEST_DIR + "/AssociationPath.xtf"; + + private TransferDescription td; + + @Before + public void setUp() { + td = ValidatorTestHelper.compileIliFile(ILI_FILE); + } + + @Test + public void testAssociationPath() throws IoxException { + File xtfFile = new File(XTF_FILE); + LogCollector logger = ValidatorTestHelper.validateObjectsFromXtf24(td, xtfFile); + + assertEquals(1, logger.getErrs().size()); + assertEquals("Mandatory Constraint ModelA.TopicA.ClassA1.IsOfClassAShouldFail is not true.", logger.getErrs().get(0).getEventMsg()); + } +} diff --git a/src/test/java/ch/interlis/iox_j/validator/UniqueConstraints10Test.java b/src/test/java/ch/interlis/iox_j/validator/UniqueConstraints10Test.java index 9e5de974..24c9beee 100644 --- a/src/test/java/ch/interlis/iox_j/validator/UniqueConstraints10Test.java +++ b/src/test/java/ch/interlis/iox_j/validator/UniqueConstraints10Test.java @@ -205,7 +205,7 @@ public void ref_Fail(){ validator.validate(new EndTransferEvent()); // Asserts. assertEquals(1,logger.getErrs().size()); - assertEquals("Unique constraint UniqueConstraints10.Topic.TableB.Constraint1 is violated! Values o1 already exist in Object: o3",logger.getErrs().get(0).getEventMsg()); + assertEquals("Unique constraint UniqueConstraints10.Topic.TableB.Constraint1 is violated! Values UniqueConstraints10.Topic.TableA oid o1 {} already exist in Object: o3",logger.getErrs().get(0).getEventMsg()); } @Test public void ref_Ok(){