Search in sources :

Example 1 with OrderedOperation

use of io.crnk.operations.server.order.OrderedOperation in project crnk-framework by crnk-project.

the class OperationsModule method fetchUpToDateResponses.

protected void fetchUpToDateResponses(List<OrderedOperation> orderedOperations, OperationResponse[] responses) {
    RequestDispatcher requestDispatcher = moduleContext.getRequestDispatcher();
    // get current set of resources after all the updates have been applied
    for (OrderedOperation orderedOperation : orderedOperations) {
        Operation operation = orderedOperation.getOperation();
        OperationResponse operationResponse = responses[orderedOperation.getOrdinal()];
        boolean isPost = operation.getOp().equalsIgnoreCase(HttpMethod.POST.toString());
        boolean isPatch = operation.getOp().equalsIgnoreCase(HttpMethod.PATCH.toString());
        if (isPost || isPatch) {
            Resource resource = operationResponse.getSingleData().get();
            String path = resource.getType() + "/" + resource.getId();
            String method = HttpMethod.GET.toString();
            RepositoryMethodParameterProvider parameterProvider = null;
            Map<String, Set<String>> parameters = new HashMap<>();
            parameters.put("include", getLoadedRelationshipNames(resource));
            Response response = requestDispatcher.dispatchRequest(path, method, parameters, parameterProvider, null);
            copyDocument(operationResponse, response.getDocument());
            operationResponse.setIncluded(null);
        }
    }
}
Also used : Response(io.crnk.core.engine.dispatcher.Response) OperationResponse(io.crnk.operations.OperationResponse) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Resource(io.crnk.core.engine.document.Resource) OrderedOperation(io.crnk.operations.server.order.OrderedOperation) OrderedOperation(io.crnk.operations.server.order.OrderedOperation) Operation(io.crnk.operations.Operation) OperationResponse(io.crnk.operations.OperationResponse) RepositoryMethodParameterProvider(io.crnk.legacy.internal.RepositoryMethodParameterProvider) RequestDispatcher(io.crnk.core.engine.dispatcher.RequestDispatcher)

Example 2 with OrderedOperation

use of io.crnk.operations.server.order.OrderedOperation in project crnk-framework by crnk-project.

the class OperationsModule method executeOperations.

protected List<OperationResponse> executeOperations(List<OrderedOperation> orderedOperations) {
    OperationResponse[] responses = new OperationResponse[orderedOperations.size()];
    boolean successful = true;
    for (OrderedOperation orderedOperation : orderedOperations) {
        OperationResponse operationResponse = executeOperation(orderedOperation.getOperation());
        responses[orderedOperation.getOrdinal()] = operationResponse;
        int status = operationResponse.getStatus();
        if (status >= 400) {
            successful = false;
            break;
        }
    }
    if (orderedOperations.size() > 1 && successful) {
        fetchUpToDateResponses(orderedOperations, responses);
    }
    fillinIgnoredOperations(responses);
    return Arrays.asList(responses);
}
Also used : OrderedOperation(io.crnk.operations.server.order.OrderedOperation) OperationResponse(io.crnk.operations.OperationResponse)

Aggregations

OperationResponse (io.crnk.operations.OperationResponse)2 OrderedOperation (io.crnk.operations.server.order.OrderedOperation)2 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)1 Response (io.crnk.core.engine.dispatcher.Response)1 Resource (io.crnk.core.engine.document.Resource)1 RepositoryMethodParameterProvider (io.crnk.legacy.internal.RepositoryMethodParameterProvider)1 Operation (io.crnk.operations.Operation)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1