Extend version consistency check
@@ -30,6 +30,8 @@ import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+
/**
* Checks if {@code jcr:baseVersion} reference properties resolve to a node.
*/
@@ -59,11 +61,18 @@ public class ReferenceCheck extends AsyncNodeStateProcessor {
NodeState version = getNodeByUUID(ref, resolvedPath);
if (version == null) {
result = new BrokenReference(path, ref, resolvedPath.get());
+ } else if (!isReferenceable(version, ref)) {
+ result = new ReferenceTargetInvalid(path, ref, resolvedPath.get(), version.getString(JCR_UUID));
}
}
return Optional.ofNullable(result);
}
+ private boolean isReferenceable(@NotNull NodeState node,
+ @NotNull String uuid) {
+ return uuid.equals(node.getString(JCR_UUID));
+ }
+
private final class BrokenReference implements Result {
private final Path path;
@@ -93,4 +102,39 @@ public class ReferenceCheck extends AsyncNodeStateProcessor {
return json.toString();
}
}
+
+ private final class ReferenceTargetInvalid implements Result {
+
+ private final Path path;
+
+ private final String reference;
+
+ private final String resolvedPath;
+
+ private final String targetUUID;
+
+ public ReferenceTargetInvalid(@NotNull Path path,
+ @NotNull String reference,
+ @NotNull String resolvedPath,
+ @Nullable String targetUUID) {
+ this.path = path;
+ this.reference = reference;
+ this.resolvedPath = resolvedPath;
+ this.targetUUID = targetUUID;
+ }
+
+ @Override
+ public String toJson() {
+ JsopBuilder json = new JsopBuilder();
+ json.object();
+ json.key("type").value("referenceTargetInvalid");
+ json.key("path").value(new Path(path, propertyName).toString());
+ json.key("uuid").value(reference);
+ json.key("targetUuid").value(targetUUID);
+ json.key("resolved").value(resolvedPath);
+ json.key("revision").value(headRevision.toString());
+ json.endObject();
+ return json.toString();
+ }
+ }
}
