Skip to content

Commit

Permalink
OAK-10104: Extend version consistency check
Browse files Browse the repository at this point in the history
  • Loading branch information
mreutegg committed Feb 6, 2023
1 parent 57e608c commit eec640a
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
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.
*/
Expand Down Expand Up @@ -59,11 +61,18 @@ protected Optional<Result> runTask(@NotNull Path path,
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;
Expand Down Expand Up @@ -93,4 +102,39 @@ public String toJson() {
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();
}
}
}

0 comments on commit eec640a

Please sign in to comment.