Skip to content

Commit 83a4949

Browse files
committed
fix for #211
1 parent ded8684 commit 83a4949

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/n10s/validation/ValidationProcedures.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public Stream<ValidationResult> shaclValidateTxForTrigger(
2727
@Name("createdRelationships") Object createdRelationships,
2828
@Name("assignedLabels") Object assignedLabels, @Name("removedLabels") Object removedLabels,
2929
@Name("assignedNodeProperties") Object assignedNodeProperties,
30-
@Name("removedNodeProperties") Object removedNodeProperties) {
30+
@Name("removedNodeProperties") Object removedNodeProperties,
31+
@Name("deletedRelationships") Object deletedRelationships,
32+
@Name("deletedNodes") Object deletedNodes) {
3133

3234
//we may want to add additional params to this method like the max duration of the validation?
3335

@@ -39,6 +41,8 @@ public Stream<ValidationResult> shaclValidateTxForTrigger(
3941
params.put("removedLabels", removedLabels);
4042
params.put("assignedNodeProperties", assignedNodeProperties);
4143
params.put("removedNodeProperties", removedNodeProperties);
44+
params.put("deletedRelationships", deletedRelationships);
45+
params.put("deletedNodes", deletedNodes);
4246

4347
Result validationResults = tx.execute(MAP_APOC_TRIGGER_PARAMS_TO_VALIDATION, params);
4448

@@ -136,21 +140,20 @@ public Stream<ValidationResult> validateSetFromCompiled(
136140
.flatMap(x -> tx.execute(x, vc.getAllParams()).stream()).map(ValidationResult::new);
137141

138142
}
139-
140-
// TODO: need to add deleted labels and deleted nodes (basically everything but relationship properties)
141-
// TODO: rethink which ones are needed <--
143+
142144
private static final String MAP_APOC_TRIGGER_PARAMS_TO_VALIDATION =
143145
"UNWIND reduce(nodes = [], x IN keys($removedLabels) | nodes + $removedLabels[x]) AS rln "
144146
+ " MATCH (rln)<--(x) WITH collect(DISTINCT x) AS sn "
145147
//the direction makes it valid for both direct and inverse
146-
+ " UNWIND sn + $createdNodes + [x IN $createdRelationships | startNode(x)] + [x IN $createdRelationships | endNode(x)] +"
148+
+ " UNWIND sn + $createdNodes + [x IN $createdRelationships | startNode(x)] + [x IN $createdRelationships | endNode(x)] + " +
149+
" [x IN $deletedRelationships | startNode(x)] + [x IN $deletedRelationships | endNode(x)] +"
147150
//end node is also for inverse rels
148151
+ " reduce( nodes = [] , x IN keys($assignedLabels) | nodes + $assignedLabels[x]) + "
149152
+ " reduce( nodes = [] , x IN keys($assignedNodeProperties) | nodes + "
150153
+ " [ item IN $assignedNodeProperties[x] | item.node] ) +"
151154
+ " reduce( nodes = [] , x IN keys($removedNodeProperties) | nodes + "
152155
+ " [ item IN $removedNodeProperties[x] | item.node] ) AS nd "
153-
+ " WITH collect( DISTINCT nd) AS touchedNodes\n"
156+
+ " WITH apoc.coll.subtract(collect( DISTINCT nd), $deletedNodes) AS touchedNodes\n"
154157
+ "CALL n10s.validation.shacl.validateSet(touchedNodes) YIELD focusNode, nodeType, shapeId, propertyShape, offendingValue, resultPath, severity, resultMessage\n"
155158
+ "RETURN {focusNode: focusNode, nodeType: nodeType, shapeId: shapeId, propertyShape: propertyShape, offendingValue: offendingValue, resultPath:resultPath, severity:severity, resultMessage:resultMessage } AS validationResult ";
156159

0 commit comments

Comments
 (0)