Search in sources :

Example 1 with RemoteCommitException

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));
}
Also used : RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) Tree(org.apache.jackrabbit.oak.api.Tree)

Example 2 with RemoteCommitException

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());
}
Also used : RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) Tree(org.apache.jackrabbit.oak.api.Tree)

Example 3 with RemoteCommitException

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();
}
Also used : RemoteOperation(org.apache.jackrabbit.oak.remote.RemoteOperation) ServletOutputStream(javax.servlet.ServletOutputStream) RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) IOException(java.io.IOException)

Example 4 with RemoteCommitException

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());
}
Also used : RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) Tree(org.apache.jackrabbit.oak.api.Tree)

Example 5 with RemoteCommitException

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);
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) PathUtils.denotesRoot(org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot) RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Aggregations

RemoteCommitException (org.apache.jackrabbit.oak.remote.RemoteCommitException)7 Tree (org.apache.jackrabbit.oak.api.Tree)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 Root (org.apache.jackrabbit.oak.api.Root)1 PathUtils.denotesRoot (org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot)1 RemoteOperation (org.apache.jackrabbit.oak.remote.RemoteOperation)1 RemoteRevision (org.apache.jackrabbit.oak.remote.RemoteRevision)1 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)1