X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FOscA1Client.java;h=c596bd59202180cc059ef574cdce34197265ba9c;hb=189d22ac70cefa9d533d930bc728020a3e55ea11;hp=0efe14d9f9db5f5d9bf533f279eeb0cbff8646c5;hpb=1a842614f22343c7c19686e27021c022ede2a6ca;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java index 0efe14d9..c596bd59 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 Nordix Foundation + * Copyright (C) 2020 Nordix Foundation * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +21,15 @@ package org.oransc.policyagent.clients; import java.lang.invoke.MethodHandles; -import java.util.ArrayList; import java.util.List; -import org.json.JSONArray; -import org.json.JSONException; + import org.json.JSONObject; import org.oransc.policyagent.configuration.RicConfig; import org.oransc.policyagent.repository.Policy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.util.UriComponentsBuilder; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -123,12 +122,12 @@ public class OscA1Client implements A1Client { private Flux getPolicyTypeIds() { return restClient.get(POLICY_TYPES) // - .flatMapMany(this::parseJsonArrayOfString); + .flatMapMany(JsonHelper::parseJsonArrayOfString); } private Flux getPolicyIdentitiesByType(String typeId) { return restClient.get(POLICY_IDS_URI.buildAndExpand(typeId).toUriString()) // - .flatMapMany(this::parseJsonArrayOfString); + .flatMapMany(JsonHelper::parseJsonArrayOfString); } private Mono getCreateSchema(String policyTypeResponse, String policyTypeId) { @@ -138,7 +137,7 @@ public class OscA1Client implements A1Client { schemaObj.put(TITLE, policyTypeId); return Mono.just(schemaObj.toString()); } catch (Exception e) { - logger.error("Unexcpected response for policy type: {}", policyTypeResponse, e); + logger.error("Unexpected response for policy type: {}, exception: {}", policyTypeResponse, e.toString()); return Mono.error(e); } } @@ -152,18 +151,4 @@ public class OscA1Client implements A1Client { return getPolicyIdentitiesByType(typeId) // .flatMap(policyId -> deletePolicyById(typeId, policyId)); } - - private Flux parseJsonArrayOfString(String inputString) { - try { - List 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 Flux.fromIterable(arrayList); - } catch (JSONException ex) { // invalid json - return Flux.error(ex); - } - } }