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