+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ String uri = POLICY_STATUS_URI.buildAndExpand(policy.type().name(), policy.id()).toUriString();
+ return restClient.get(uri);
+
+ }
+
+ private Flux<String> getPolicyTypeIds() {
+ return restClient.get(POLICY_TYPES) //
+ .flatMapMany(JsonHelper::parseJsonArrayOfString);
+ }
+
+ private Flux<String> getPolicyIdentitiesByType(String typeId) {
+ return restClient.get(POLICY_IDS_URI.buildAndExpand(typeId).toUriString()) //
+ .flatMapMany(JsonHelper::parseJsonArrayOfString);
+ }
+
+ private Mono<String> getCreateSchema(String policyTypeResponse, String policyTypeId) {
+ try {
+ JSONObject obj = new JSONObject(policyTypeResponse);
+ JSONObject schemaObj = obj.getJSONObject(CREATE_SCHEMA);
+ schemaObj.put(TITLE, policyTypeId);
+ return Mono.just(schemaObj.toString());
+ } catch (Exception e) {
+ String exceptionString = e.toString();
+ logger.error("Unexpected response for policy type: {}, exception: {}", policyTypeResponse, exceptionString);
+ return Mono.error(e);
+ }
+ }
+
+ private Mono<String> deletePolicyById(String typeId, String policyId) {
+ String uri = POLICY_URI.buildAndExpand(typeId, policyId).toUriString();
+ return restClient.delete(uri);
+ }
+
+ private Flux<String> deletePoliciesForType(String typeId) {
+ return getPolicyIdentitiesByType(typeId) //
+ .flatMap(policyId -> deletePolicyById(typeId, policyId));
+ }