use of org.apache.jackrabbit.oak.remote.RemoteCommitException in project jackrabbit-oak by apache.
the class SetContentRemoteOperation method apply.
@Override
public void apply(Root root) throws RemoteCommitException {
logger.debug("performing 'set' operation on path={}, name={}", path, name);
Tree tree = root.getTree(path);
if (!tree.exists()) {
throw new RemoteCommitException("tree does not exist");
}
value.whenType(new SetPropertyHandler(binaries, root, tree, name));
}
use of org.apache.jackrabbit.oak.remote.RemoteCommitException in project jackrabbit-oak by apache.
the class AddContentRemoteOperation method apply.
@Override
public void apply(Root root) throws RemoteCommitException {
logger.debug("performing 'add' operation on path={}", path);
Tree tree = root.getTree(path);
if (tree.exists()) {
throw new RemoteCommitException("node already exists");
}
Tree parent = tree.getParent();
if (!parent.exists()) {
throw new RemoteCommitException("parent node does not exist");
}
parent.addChild(tree.getName());
}
use of org.apache.jackrabbit.oak.remote.RemoteCommitException in project jackrabbit-oak by apache.
the class PatchRevisionHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
RemoteSession session = (RemoteSession) request.getAttribute("session");
if (session == null) {
sendInternalServerError(response, "session not found");
return;
}
RemoteRevision base = readRevision(request, session);
if (base == null) {
sendGone(response, "revision not found");
return;
}
RemoteOperation operation;
try {
operation = parseOperations(session, new ObjectMapper().readTree(request.getInputStream()));
} catch (Exception e) {
operation = null;
}
if (operation == null) {
sendBadRequest(response, "unable to parse the list of operations");
return;
}
RemoteRevision revision;
try {
revision = session.commit(base, operation);
} catch (RemoteCommitException e) {
logger.warn("unable to perform the commit", e);
sendBadRequest(response, "commit failed");
return;
}
response.setStatus(HttpServletResponse.SC_CREATED);
response.setContentType("application/json");
ServletOutputStream stream = response.getOutputStream();
JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
renderResponse(generator, revision);
generator.flush();
stream.close();
}
use of org.apache.jackrabbit.oak.remote.RemoteCommitException in project jackrabbit-oak by apache.
the class CopyContentRemoteOperation method apply.
@Override
public void apply(Root root) throws RemoteCommitException {
logger.debug("performing 'copy' operation on source={}, target={}", source, target);
Tree sourceTree = root.getTree(source);
if (!sourceTree.exists()) {
throw new RemoteCommitException("source tree does not exist");
}
Tree targetTree = root.getTree(target);
if (targetTree.exists()) {
throw new RemoteCommitException("target tree already exists");
}
Tree targetParentTree = targetTree.getParent();
if (!targetParentTree.exists()) {
throw new RemoteCommitException("parent of target tree does not exist");
}
copy(sourceTree, targetParentTree, targetTree.getName());
}
use of org.apache.jackrabbit.oak.remote.RemoteCommitException in project jackrabbit-oak by apache.
the class ContentRemoteSession method commit.
@Override
public ContentRemoteRevision commit(RemoteRevision revision, RemoteOperation operation) throws RemoteCommitException {
ContentRemoteRevision contentRemoteRevision = null;
if (revision instanceof ContentRemoteRevision) {
contentRemoteRevision = (ContentRemoteRevision) revision;
}
if (contentRemoteRevision == null) {
throw new IllegalArgumentException("invalid revision");
}
ContentRemoteOperation contentRemoteOperation = null;
if (operation instanceof ContentRemoteOperation) {
contentRemoteOperation = (ContentRemoteOperation) operation;
}
if (contentRemoteOperation == null) {
throw new IllegalArgumentException("invalid operation");
}
Root root = contentRemoteRevision.getRoot();
if (root == null) {
throw new IllegalStateException("unable to locate the root");
}
contentRemoteOperation.apply(root);
try {
root.commit();
} catch (CommitFailedException e) {
throw new RemoteCommitException("unable to apply the changes", e);
}
return new ContentRemoteRevision(contentRemoteRevisions.put(contentSession.getAuthInfo(), root), root);
}
Aggregations