X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dashboard%2Fwebapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fpolicyagentapi%2FPolicyAgentApiImpl.java;h=b41c30e3b2c2a57a41a9ce7cdd793f8686fbd130;hb=f2c4406acbb8c7ff00535acb1d4bccf067295976;hp=fe9c26cd1ce4dae7918b93f4d8b9bbe062bbfd8b;hpb=86b589317c67eb2350870c9c57c35eac3e9056f6;p=nonrtric.git diff --git a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/policyagentapi/PolicyAgentApiImpl.java b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/policyagentapi/PolicyAgentApiImpl.java index fe9c26cd..b41c30e3 100644 --- a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/policyagentapi/PolicyAgentApiImpl.java +++ b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/policyagentapi/PolicyAgentApiImpl.java @@ -28,10 +28,10 @@ import com.google.gson.reflect.TypeToken; import java.lang.invoke.MethodHandles; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Vector; import org.immutables.gson.Gson; import org.immutables.value.Value; @@ -55,19 +55,24 @@ import org.springframework.web.client.RestTemplate; public class PolicyAgentApiImpl implements PolicyAgentApi { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - RestTemplate restTemplate = new RestTemplate(); + RestTemplate restTemplate; private static com.google.gson.Gson gson = new GsonBuilder() // - .serializeNulls() // - .create(); // + .serializeNulls() // + .create(); // private final String urlPrefix; @Autowired public PolicyAgentApiImpl( - @org.springframework.beans.factory.annotation.Value("${policycontroller.url.prefix}") final String urlPrefix) { + @org.springframework.beans.factory.annotation.Value("${policycontroller.url.prefix}") final String urlPrefix) { + this(urlPrefix, new RestTemplate()); logger.debug("ctor prefix '{}'", urlPrefix); + } + + public PolicyAgentApiImpl(String urlPrefix, RestTemplate restTemplate) { this.urlPrefix = urlPrefix; + this.restTemplate = restTemplate; } private String baseUrl() { @@ -119,8 +124,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi { } try { - Type listType = new TypeToken>() { - }.getType(); + Type listType = new TypeToken>() {}.getType(); List rspParsed = gson.fromJson(rsp.getBody(), listType); PolicyInstances result = new PolicyInstances(); for (PolicyInfo p : rspParsed) { @@ -142,13 +146,13 @@ public class PolicyAgentApiImpl implements PolicyAgentApi { @Override public ResponseEntity putPolicy(String policyTypeIdString, String policyInstanceId, Object json, - String ric) { + String ric) { String url = baseUrl() + "/policy?type={type}&instance={instance}&ric={ric}&service={service}"; Map uriVariables = Map.of( // - "type", policyTypeIdString, // - "instance", policyInstanceId, // - "ric", ric, // - "service", "dashboard"); + "type", policyTypeIdString, // + "instance", policyInstanceId, // + "ric", ric, // + "service", "dashboard"); try { this.restTemplate.put(url, createJsonHttpEntity(json), uriVariables); @@ -174,7 +178,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi { @Value.Immutable @Gson.TypeAdapters interface RicInfo { - public String name(); + public String ricName(); public Collection nodeNames(); @@ -188,12 +192,11 @@ public class PolicyAgentApiImpl implements PolicyAgentApi { String rsp = this.restTemplate.getForObject(url, String.class, uriVariables); try { - Type listType = new TypeToken>() { - }.getType(); + Type listType = new TypeToken>() {}.getType(); List rspParsed = gson.fromJson(rsp, listType); - Collection result = new Vector<>(rspParsed.size()); + Collection result = new ArrayList<>(rspParsed.size()); for (RicInfo ric : rspParsed) { - result.add(ric.name()); + result.add(ric.ricName()); } return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK); } catch (Exception e) { @@ -204,7 +207,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi { private HttpEntity createJsonHttpEntity(Object content) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - return new HttpEntity(content, headers); + return new HttpEntity<>(content, headers); } }