Skip to content

Commit

Permalink
Validator: fix UNIQUE mixed case INTERLIS.UUIDOID (claeis/ilivalidato…
Browse files Browse the repository at this point in the history
  • Loading branch information
claeis committed Apr 18, 2023
1 parent 9360464 commit c5d8eaf
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ideas/open issues

iox-ili 1.21.18 (SNAPSHOT)
-----------------------------
- Validator: fix UNIQUE mixed case INTERLIS.UUIDOID (ilivalidator#371)
- Iox2wkb/RingCollector: fix issues with duplicate coordinates (ili2db#510)
- Iox2wkb/RingCollector: fix issue with inner boundary with arcs continued by outer boundary with straights (ili2db#510)

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/ch/interlis/iox_j/validator/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,10 @@ public Value getValueFromObjectPath(IomObject parentObject,IomObject iomObjStart
}else {
String attrValue = iomObj.getattrvalue(currentAttrName);
if (attrValue != null) {
if (attrValue.equals("true")) {
if(attrRef.getAttr().isDomainIliUuid()) {
Type aliasedType = ((TypeAlias) type).getAliasing().getType();
return new Value(aliasedType, normalizeUUID(attrValue));
}else if (attrValue.equals("true")) {
return new Value(true);
} else if (attrValue.equals("false")) {
return new Value(false);
Expand Down Expand Up @@ -2030,6 +2033,12 @@ public Value getValueFromObjectPath(IomObject parentObject,IomObject iomObjStart
}
return Value.createUndefined();
}
public static String normalizeUUID(String attrValue) {
if(attrValue==null) {
return null;
}
return attrValue.toLowerCase();
}
private boolean isBackward(Viewable srcObjClass, RoleDef role) {
AssociationDef assoc=(AssociationDef) role.getContainer();
if(assoc.isLightweight()) {
Expand Down
9 changes: 8 additions & 1 deletion src/test/data/validator/UniqueConstraints23.ili
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ MODEL UniqueConstraints23
attr04 : TEXT*10;
UNIQUE WHERE INTERLIS.inEnumRange(attr01, attr02, attr03) : attr04;
END ClassN3;

CLASS ClassL =
attr1 : INTERLIS.UUIDOID;
attr2 : TEXT*10;
UNIQUE attr1;
END ClassL;


END Topic;

Expand Down Expand Up @@ -309,7 +316,7 @@ MODEL UniqueConstraints23
k1 -- {0..2} ClassK;
UNIQUE i1->attrI;
END assocIK;

END EmbeddedUnique;

TOPIC LinkObjUnique=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class UniqueConstraints23Test {
private final static String CLASSM=TOPIC+".ClassM";
private final static String CLASSN=TOPIC+".ClassN";
private final static String CLASSN3=TOPIC+".ClassN3";
private final static String CLASSL=TOPIC+".ClassL";
private final static String CLASSO=TOPIC+".ClassO";
private final static String CLASSO2=TOPIC+".ClassO2";
private final static String CLASSP=TOPIC+".ClassP";
Expand Down Expand Up @@ -465,6 +466,80 @@ public void uniqueAttrValueAttr1Different_Ok(){
// Asserts.
assertTrue(logger.getErrs().size()==0);
}
@Test
public void uniqueAttrValueUuidDifferent_Ok(){
// Set object.
Iom_jObject obj1=new Iom_jObject(CLASSL,OID1);
obj1.setattrvalue("attr1", "960a3aed-ff1a-41ba-b177-34480efb2a6d");
obj1.setattrvalue("attr2", "15");
Iom_jObject obj2=new Iom_jObject(CLASSL,OID2);
obj2.setattrvalue("attr1", "9d16a51e-15fd-40c6-9a50-ac715c75a2a0");
obj2.setattrvalue("attr2", "20");
// Create and run validator.
ValidationConfig modelConfig=new ValidationConfig();
LogCollector logger=new LogCollector();
LogEventFactory errFactory=new LogEventFactory();
Settings settings=new Settings();
Validator validator=new Validator(td, modelConfig,logger,errFactory,settings);
validator.validate(new StartTransferEvent());
validator.validate(new StartBasketEvent(TOPIC,BID));
validator.validate(new ObjectEvent(obj1));
validator.validate(new ObjectEvent(obj2));
validator.validate(new EndBasketEvent());
validator.validate(new EndTransferEvent());
// Asserts.
assertTrue(logger.getErrs().size()==0);
}
@Test
public void uniqueAttrValueUuidSame_Fail(){
// Set object.
Iom_jObject obj1=new Iom_jObject(CLASSL,OID1);
obj1.setattrvalue("attr1", "960a3aed-ff1a-41ba-b177-34480efb2a6d");
obj1.setattrvalue("attr2", "15");
Iom_jObject obj2=new Iom_jObject(CLASSL,OID2);
obj2.setattrvalue("attr1", "960a3aed-ff1a-41ba-b177-34480efb2a6d");
obj2.setattrvalue("attr2", "20");
// Create and run validator.
ValidationConfig modelConfig=new ValidationConfig();
LogCollector logger=new LogCollector();
LogEventFactory errFactory=new LogEventFactory();
Settings settings=new Settings();
Validator validator=new Validator(td, modelConfig,logger,errFactory,settings);
validator.validate(new StartTransferEvent());
validator.validate(new StartBasketEvent(TOPIC,BID));
validator.validate(new ObjectEvent(obj1));
validator.validate(new ObjectEvent(obj2));
validator.validate(new EndBasketEvent());
validator.validate(new EndTransferEvent());
// Asserts.
assertEquals(1,logger.getErrs().size());
assertEquals("Unique constraint UniqueConstraints23.Topic.ClassL.Constraint1 is violated! Values 960a3aed-ff1a-41ba-b177-34480efb2a6d already exist in Object: o1", logger.getErrs().get(0).getEventMsg());
}
@Test
public void uniqueAttrValueUuidSameDifferentCase_Fail(){
// Set object.
Iom_jObject obj1=new Iom_jObject(CLASSL,OID1);
obj1.setattrvalue("attr1", "960A3aed-ff1a-41ba-b177-34480efb2a6d");
obj1.setattrvalue("attr2", "15");
Iom_jObject obj2=new Iom_jObject(CLASSL,OID2);
obj2.setattrvalue("attr1", "960a3aed-ff1a-41ba-b177-34480efb2a6d");
obj2.setattrvalue("attr2", "20");
// Create and run validator.
ValidationConfig modelConfig=new ValidationConfig();
LogCollector logger=new LogCollector();
LogEventFactory errFactory=new LogEventFactory();
Settings settings=new Settings();
Validator validator=new Validator(td, modelConfig,logger,errFactory,settings);
validator.validate(new StartTransferEvent());
validator.validate(new StartBasketEvent(TOPIC,BID));
validator.validate(new ObjectEvent(obj1));
validator.validate(new ObjectEvent(obj2));
validator.validate(new EndBasketEvent());
validator.validate(new EndTransferEvent());
// Asserts.
assertEquals(1,logger.getErrs().size());
assertEquals("Unique constraint UniqueConstraints23.Topic.ClassL.Constraint1 is violated! Values 960a3aed-ff1a-41ba-b177-34480efb2a6d already exist in Object: o1", logger.getErrs().get(0).getEventMsg());
}

// Es wird getestet ob ein Fehler ausgegeben wird, wenn Text Unique und Nummer Unique separat sind und nicht identisch ist.
@Test
Expand Down

0 comments on commit c5d8eaf

Please sign in to comment.