Skip to content

Commit 1b7b1cb

Browse files
committed
Show correct error message in NodeKindViolation for blank nodes
1 parent 9969fd9 commit 1b7b1cb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

core/esmf-aspect-model-validator/src/main/java/org/eclipse/esmf/aspectmodel/shacl/violation/NodeKindViolation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public String violationSpecificMessage() {
4848
return String.format( "Property %s on %s is %s, but it must be %s.",
4949
propertyName(), context.element().isAnon() ? "the element" : elementName(),
5050
nodeKindString.apply( actualNodeKind ), nodeKindString.apply( allowedNodeKind ) );
51+
} else if ( context.parentProperty().isPresent() ) {
52+
return String.format( "Property %s on %s is %s, but it must be %s.",
53+
parentPropertyName(), parentElementName(), nodeKindString.apply( actualNodeKind ), nodeKindString.apply( allowedNodeKind ) );
5154
}
5255
return context.element().isAnon() ?
5356
String.format( "The element is %s, but it must be %s.",

core/esmf-aspect-model-validator/src/main/java/org/eclipse/esmf/aspectmodel/shacl/violation/Violation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,20 @@ default String elementName() {
175175
.orElse( "anonymous element" );
176176
}
177177

178+
default String parentElementName() {
179+
return context().parentElement().map( Resource::getURI )
180+
.map( this::shortUri )
181+
.orElse( "anonymous element" );
182+
}
183+
178184
default String propertyName() {
179185
return context().property().map( Resource::getURI ).map( this::shortUri ).orElse( elementName() );
180186
}
181187

188+
default String parentPropertyName() {
189+
return context().parentProperty().map( Resource::getURI ).map( this::shortUri ).orElse( propertyName() );
190+
}
191+
182192
default String value( final Property property ) {
183193
return shortUri( property.getURI() );
184194
}

0 commit comments

Comments
 (0)