Search in sources :

Example 1 with RemoteOperation

use of org.apache.jackrabbit.oak.remote.RemoteOperation in project jackrabbit-oak by apache.

the class ContentRemoteSession method createAggregateOperation.

@Override
public ContentRemoteOperation createAggregateOperation(final List<RemoteOperation> operations) {
    if (operations == null) {
        throw new IllegalArgumentException("operations not provided");
    }
    List<ContentRemoteOperation> contentRemoteOperations = new ArrayList<ContentRemoteOperation>();
    for (RemoteOperation operation : operations) {
        if (operation == null) {
            throw new IllegalArgumentException("operation not provided");
        }
        ContentRemoteOperation contentRemoteOperation = null;
        if (operation instanceof ContentRemoteOperation) {
            contentRemoteOperation = (ContentRemoteOperation) operation;
        }
        if (contentRemoteOperation == null) {
            throw new IllegalArgumentException("invalid operation");
        }
        contentRemoteOperations.add(contentRemoteOperation);
    }
    return new AggregateContentRemoteOperation(contentRemoteOperations);
}
Also used : RemoteOperation(org.apache.jackrabbit.oak.remote.RemoteOperation) ArrayList(java.util.ArrayList)

Example 2 with RemoteOperation

use of org.apache.jackrabbit.oak.remote.RemoteOperation 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)

Aggregations

RemoteOperation (org.apache.jackrabbit.oak.remote.RemoteOperation)2 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 ArrayList (java.util.ArrayList)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 RemoteCommitException (org.apache.jackrabbit.oak.remote.RemoteCommitException)1 RemoteRevision (org.apache.jackrabbit.oak.remote.RemoteRevision)1 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)1