Search in sources :

Example 6 with OperationResponse

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

the class OperationsCall method getResponseObject.

public <T> T getResponseObject(int index, Class<T> clazz) {
    checkResponsesAvailable();
    OperationResponse response = responses.get(index);
    return fromResource(response, clazz);
}
Also used : OperationResponse(io.crnk.operations.OperationResponse)

Example 7 with OperationResponse

use of io.crnk.operations.OperationResponse 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

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