Search in sources :

Example 6 with Operation

use of io.crnk.operations.Operation in project crnk-framework by crnk-project.

the class OperationsCall method add.

public void add(HttpMethod method, Object object) {
    Operation operation = new Operation();
    Resource resource = toResource(object);
    operation.setOp(method.toString());
    operation.setPath(computePath(method, resource));
    if (method == HttpMethod.POST || method == HttpMethod.PATCH) {
        operation.setValue(resource);
    }
    QueuedOperation queuedOperation = new QueuedOperation();
    queuedOperation.operation = operation;
    queuedOperations.add(queuedOperation);
}
Also used : Resource(io.crnk.core.engine.document.Resource) Operation(io.crnk.operations.Operation)

Example 7 with Operation

use of io.crnk.operations.Operation in project crnk-framework by crnk-project.

the class OperationsRequestProcessor method process.

@Override
public void process(HttpRequestContext context) throws IOException {
    if (context.accepts(JSONPATCH_CONTENT_TYPE)) {
        try {
            ObjectMapper mapper = moduleContext.getObjectMapper();
            List<Operation> operations = Arrays.asList(mapper.readValue(context.getRequestBody(), Operation[].class));
            List<OperationResponse> responses = operationsModule.apply(operations);
            String responseJson = mapper.writeValueAsString(responses);
            context.setContentType(JSONPATCH_CONTENT_TYPE);
            context.setResponse(200, responseJson);
        } catch (Exception e) {
            LOGGER.error("failed to execute operations", e);
            context.setResponse(500, (byte[]) null);
        }
    }
}
Also used : Operation(io.crnk.operations.Operation) OperationResponse(io.crnk.operations.OperationResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Aggregations

Operation (io.crnk.operations.Operation)7 Resource (io.crnk.core.engine.document.Resource)3 OperationResponse (io.crnk.operations.OperationResponse)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GraphUtils (io.crnk.operations.internal.GraphUtils)2 OrderedOperation (io.crnk.operations.server.order.OrderedOperation)2 IOException (java.io.IOException)2 HttpAdapter (io.crnk.client.http.HttpAdapter)1 HttpAdapterRequest (io.crnk.client.http.HttpAdapterRequest)1 HttpAdapterResponse (io.crnk.client.http.HttpAdapterResponse)1 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)1 Response (io.crnk.core.engine.dispatcher.Response)1 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)1 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 InternalServerErrorException (io.crnk.core.exception.InternalServerErrorException)1 RepositoryMethodParameterProvider (io.crnk.legacy.internal.RepositoryMethodParameterProvider)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1