Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve object for paths ending in association #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/java/ch/interlis/iox_j/validator/AttributeArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PP: Sollte auch einfacher gehen.

Suggested change
if (oid == null ? otherOid != null : !oid.equals(otherOid)) {
if (!Objects.equals(oid, otherOid)) return false;

PP: Könnte auch gleich für die Refoid so gemacht werden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects.equals gibt es leider erst ab Java 7 😞

return false;
}

// compare ref
String refoid=thisObj.getobjectrefoid();
String otherRefoid=otherObj.getobjectrefoid();
Expand Down
24 changes: 4 additions & 20 deletions src/main/java/ch/interlis/iox_j/validator/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<IomObject> objects = new ArrayList<IomObject>();
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);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/data/validator/AssociationPath.ili
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 26 additions & 0 deletions src/test/data/validator/AssociationPath.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS"
xmlns:geom="http://www.interlis.ch/geometry/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ModelA="http://www.interlis.ch/xtf/2.4/ModelA">
<ili:headersection>
<ili:models>
<ili:model>ModelA</ili:model>
</ili:models>
<ili:sender>ili2gpkg-5.0.1-447c03f22b8f346a44ada86c553d10110872fd40</ili:sender>
</ili:headersection>
<ili:datasection>
<ModelA:TopicA ili:bid="basket_1">
<ModelA:ClassB1 ili:tid="obj_b1">
<ModelA:Code>abc</ModelA:Code>
</ModelA:ClassB1>
<ModelA:ClassB1 ili:tid="obj_b2">
<ModelA:Code>xyz</ModelA:Code>
</ModelA:ClassB1>
<ModelA:ClassA1 ili:tid="obj_a1">
<ModelA:AssocB ili:ref="obj_b2"></ModelA:AssocB>
<ModelA:Attr>true</ModelA:Attr>
</ModelA:ClassA1>
</ModelA:TopicA>
</ili:datasection>
</ili:transfer>
32 changes: 32 additions & 0 deletions src/test/java/ch/interlis/iox_j/validator/AssociationPathTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down