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);
}
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);
}
}
}
Aggregations