+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ String uri = POLICY_STATUS_URI.buildAndExpand(policy.type().name(), policy.id()).toUriString();
+ return restClient.get(uri);
+
+ }
+
+ private Mono<List<String>> getPolicyIdentitiesById(String typeId) {
+ String uri = POLICY_IDS_URI.buildAndExpand(typeId).toUriString();
+ return restClient.get(uri) //
+ .flatMap(this::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) {
+ logger.error("Unexcpected response for policy type: {}", policyTypeResponse, e);
+ 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 getPolicyIdentitiesById(typeId) //
+ .flatMapMany(policyIds -> Flux.fromIterable(policyIds)) //
+ .flatMap(policyId -> deletePolicyById(typeId, policyId)); //
+ }
+
+ private Mono<List<String>> parseJsonArrayOfString(String inputString) {
+ try {
+ List<String> arrayList = new ArrayList<>();
+ JSONArray jsonArray = new JSONArray(inputString);
+ for (int i = 0; i < jsonArray.length(); i++) {
+ arrayList.add(jsonArray.getString(i));
+ }
+ logger.debug("A1 client: received list = {}", arrayList);
+ return Mono.just(arrayList);
+ } catch (JSONException ex) { // invalid json
+ return Mono.error(ex);
+ }
+ }