/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for synchronous response. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @return batch response */ public BatchResponse commit() { return commit(false); }
public BatchRequest( final MediaType mediaType, final String address, final List<?> providers, final String jwt) { this.mediaType = mediaType; this.jwt = jwt; this.address = address; this.providers = providers; initBatchClientFactoryBean(); }
@Override public Map<String, String> batch(final BatchRequest batchRequest) { List<BatchRequestItem> batchRequestItems = new ArrayList<>(batchRequest.getItems()); Map<String, String> result = new LinkedHashMap<>(); try { List<BatchResponseItem> batchResponseItems = batchRequest.commit().getItems(); for (int i = 0; i < batchResponseItems.size(); i++) { String status = getStatus(batchResponseItems.get(i).getStatus()); if (batchRequestItems.get(i).getRequestURI().contains("/execute")) { result.put(StringUtils.substringAfterLast( StringUtils.substringBefore(batchRequestItems.get(i).getRequestURI(), "/execute"), "/"), status); } else { result.put(StringUtils.substringAfterLast( batchRequestItems.get(i).getRequestURI(), "/"), status); } } } catch (IOException e) { LOG.error("While processing Batch response", e); } return result; } }
/** * Initiates a new Batch request. * * The typical operation flow is: * <pre> * BatchRequest batchRequest = syncopeClient.batch(); * batchRequest.getService(UserService.class).create(...); * batchRequest.getService(UserService.class).update(...); * batchRequest.getService(GroupService.class).update(...); * batchRequest.getService(GroupService.class).delete(...); * ... * BatchResponse batchResponse = batchRequest().commit(); * List<BatchResponseItem> items = batchResponse.getItems() * </pre> * * @return empty Batch request */ public BatchRequest batch() { return new BatchRequest( mediaType, restClientFactory.getAddress(), restClientFactory.getProviders(), getJWT()); } }
BatchRequest batch = SyncopeConsoleSession.get().batch(); UserService batchUserService = batch.getService(UserService.class); GroupService batchGroupService = batch.getService(GroupService.class); AnyObjectService batchAnyObjectService = batch.getService(AnyObjectService.class); AnyService<?> batchAnyService = singleItem instanceof UserTO ? batchUserService ? batchGroupService : batchAnyObjectService; TaskService batchTaskService = batch.getService(TaskService.class); ReportService batchReportService = batch.getService(ReportService.class);
@Override public Map<String, String> batch(final BatchRequest batchRequest) { List<BatchRequestItem> batchRequestItems = new ArrayList<>(batchRequest.getItems()); Map<String, String> result = new LinkedHashMap<>(); try { List<BatchResponseItem> batchResponseItems = batchRequest.commit().getItems(); for (int i = 0; i < batchResponseItems.size(); i++) { String status = getStatus(batchResponseItems.get(i).getStatus()); if (batchRequestItems.get(i).getRequestURI().contains("/execute")) { result.put(StringUtils.substringAfterLast( StringUtils.substringBefore(batchRequestItems.get(i).getRequestURI(), "/execute"), "/"), status); } else { result.put(StringUtils.substringAfterLast( batchRequestItems.get(i).getRequestURI(), "/"), status); } } } catch (IOException e) { LOG.error("While processing Batch response", e); } return result; } }
/** * Initiates a new Batch request. * * The typical operation flow is: * <pre> * BatchRequest batchRequest = syncopeClient.batch(); * batchRequest.getService(UserService.class).create(...); * batchRequest.getService(UserService.class).update(...); * batchRequest.getService(GroupService.class).update(...); * batchRequest.getService(GroupService.class).delete(...); * ... * BatchResponse batchResponse = batchRequest().commit(); * List<BatchResponseItem> items = batchResponse.getItems() * </pre> * * @return empty Batch request */ public BatchRequest batch() { return new BatchRequest( mediaType, restClientFactory.getAddress(), restClientFactory.getProviders(), getJWT()); } }
public Map<String, String> batch(final BatchRequest batchRequest) { List<BatchRequestItem> batchRequestItems = new ArrayList<>(batchRequest.getItems()); Map<String, String> result = new LinkedHashMap<>(); try { List<BatchResponseItem> batchResponseItems = batchRequest.commit().getItems(); for (int i = 0; i < batchResponseItems.size(); i++) { String status = getStatus(batchResponseItems.get(i).getStatus()); if (batchRequestItems.get(i).getRequestURI().endsWith("/status")) { result.put(StringUtils.substringAfterLast( StringUtils.substringBefore(batchRequestItems.get(i).getRequestURI(), "/status"), "/"), status); } else { result.put(StringUtils.substringAfterLast( batchRequestItems.get(i).getRequestURI(), "/"), status); } } } catch (IOException e) { LOG.error("While processing Batch response", e); } return result; } }
/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for synchronous response. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @return batch response */ public BatchResponse commit() { return commit(false); }
public BatchRequest( final MediaType mediaType, final String address, final List<?> providers, final String jwt) { this.mediaType = mediaType; this.jwt = jwt; this.address = address; this.providers = providers; initBatchClientFactoryBean(); }
/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for a synchronous or asynchronous * response, depending on the {@code async} parameter. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @param async whether asynchronous Batch process is requested, or not * @return batch response */ public BatchResponse commit(final boolean async) { String boundary = "--batch_" + UUID.randomUUID().toString(); WebClient webClient = WebClient.create(bcfb.getAddress()).path("batch"). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))); if (async) { webClient.header(RESTHeaders.PREFER, Preference.RESPOND_ASYNC); } String body = BatchPayloadGenerator.generate(bcfb.getBatchRequestItems(), boundary); LOG.debug("Batch request body:\n{}", body); initBatchClientFactoryBean(); return new BatchResponse(boundary, jwt, webClient.post(body)); } }
/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for a synchronous or asynchronous * response, depending on the {@code async} parameter. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @param async whether asynchronous Batch process is requested, or not * @return batch response */ public BatchResponse commit(final boolean async) { String boundary = "--batch_" + UUID.randomUUID().toString(); WebClient webClient = WebClient.create(bcfb.getAddress()).path("batch"). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))); if (async) { webClient.header(RESTHeaders.PREFER, Preference.RESPOND_ASYNC); } String body = BatchPayloadGenerator.generate(bcfb.getBatchRequestItems(), boundary); LOG.debug("Batch request body:\n{}", body); initBatchClientFactoryBean(); return new BatchResponse(boundary, jwt, webClient.post(body)); } }