diff options
author | Jim Hahn <jrh3@att.com> | 2021-05-10 09:53:23 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-05-10 11:07:36 -0400 |
commit | 6372b62fcd8813d7d49fb279b933ffe2e4637048 (patch) | |
tree | 5d221f640ece91ce331f56d7bb6537a4393def3a /models-interactions/model-impl | |
parent | da708d64dc27f36ed5da733fca14ebfb4cc2832b (diff) |
Fix sonars in policy-models impls & simulators
Fixed:
- use "var"
Issue-ID: POLICY-3094
Change-Id: I65da54cae5a58966f21f981c6cea1259bfdf4239
Signed-off-by: Jim Hahn <jrh3@att.com>
simulators
Change-Id: I1144568485e62e0c72194caaf21ebf1ba88a6fef
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-impl')
10 files changed, 62 insertions, 68 deletions
diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java index 2648959bb..d638c9d3d 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,13 +95,13 @@ public class AaiCqResponse implements Serializable { public AaiCqResponse(String jsonString) { // Read JSON String and add all AaiObjects - JSONObject responseObj = new JSONObject(jsonString); - JSONArray resultsArray = new JSONArray(); + var responseObj = new JSONObject(jsonString); + var resultsArray = new JSONArray(); if (responseObj.has("results")) { resultsArray = (JSONArray) responseObj.get("results"); } - for (int i = 0; i < resultsArray.length(); i++) { - final JSONObject resultObject = resultsArray.getJSONObject(i); + for (var i = 0; i < resultsArray.length(); i++) { + final var resultObject = resultsArray.getJSONObject(i); extractVserver(resultObject); extractGenericVnf(resultObject); @@ -118,11 +118,11 @@ public class AaiCqResponse implements Serializable { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( + var json = new StreamSource( new StringReader(resultObject.getJSONObject("vserver").toString())); // Getting the vserver pojo again from the json - Vserver vserver = this.getAaiObject(json, Vserver.class); + var vserver = this.getAaiObject(json, Vserver.class); this.inventoryResponseItems.add(vserver); } } @@ -131,11 +131,11 @@ public class AaiCqResponse implements Serializable { if (resultObject.has(GENERIC_VNF)) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( + var json = new StreamSource( new StringReader(resultObject.getJSONObject(GENERIC_VNF).toString())); // Getting the generic vnf pojo again from the json - GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class); + var genericVnf = this.getAaiObject(json, GenericVnf.class); this.inventoryResponseItems.add(genericVnf); } @@ -146,11 +146,11 @@ public class AaiCqResponse implements Serializable { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( + var json = new StreamSource( new StringReader(resultObject.getJSONObject("service-instance").toString())); // Getting the employee pojo again from the json - ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class); + var serviceInstance = this.getAaiObject(json, ServiceInstance.class); this.inventoryResponseItems.add(serviceInstance); } @@ -160,11 +160,11 @@ public class AaiCqResponse implements Serializable { if (resultObject.has(VF_MODULE)) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( + var json = new StreamSource( new StringReader(resultObject.getJSONObject(VF_MODULE).toString())); // Getting the vf module pojo again from the json - VfModule vfModule = this.getAaiObject(json, VfModule.class); + var vfModule = this.getAaiObject(json, VfModule.class); this.inventoryResponseItems.add(vfModule); } @@ -174,11 +174,11 @@ public class AaiCqResponse implements Serializable { if (resultObject.has("cloud-region")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( + var json = new StreamSource( new StringReader(resultObject.getJSONObject("cloud-region").toString())); // Getting the cloud region pojo again from the json - CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class); + var cloudRegion = this.getAaiObject(json, CloudRegion.class); this.inventoryResponseItems.add(cloudRegion); } @@ -188,11 +188,11 @@ public class AaiCqResponse implements Serializable { if (resultObject.has("tenant")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( + var json = new StreamSource( new StringReader(resultObject.getJSONObject("tenant").toString())); // Getting the tenant pojo again from the json - Tenant tenant = this.getAaiObject(json, Tenant.class); + var tenant = this.getAaiObject(json, Tenant.class); this.inventoryResponseItems.add(tenant); } @@ -202,11 +202,11 @@ public class AaiCqResponse implements Serializable { if (resultObject.has("model-ver")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( + var json = new StreamSource( new StringReader(resultObject.getJSONObject("model-ver").toString())); // Getting the ModelVer pojo again from the json - ModelVer modelVer = this.getAaiObject(json, ModelVer.class); + var modelVer = this.getAaiObject(json, ModelVer.class); this.inventoryResponseItems.add(modelVer); } @@ -409,13 +409,13 @@ public class AaiCqResponse implements Serializable { GenericVnf genericVnf = null; // Get the vserver associated with the query - Vserver vserver = this.getVserver(); + var vserver = this.getVserver(); // Get the relationships of the vserver List<Relationship> relations = vserver.getRelationshipList().getRelationship(); // Find the relationship of the genericVNF - String genericVnfId = ""; + var genericVnfId = ""; List<RelationshipData> relationshipData = null; // Iterate through the list of relationships and get generic vnf @@ -457,13 +457,13 @@ public class AaiCqResponse implements Serializable { VfModule vfModule = null; // Get the vserver associated with the query - Vserver vserver = this.getVserver(); + var vserver = this.getVserver(); // Get the relationships of the vserver List<Relationship> relations = vserver.getRelationshipList().getRelationship(); // Find the relationship of VfModule - String vfModuleId = ""; + var vfModuleId = ""; List<RelationshipData> relationshipData = null; // Iterate through the list of relationships and get vf module @@ -554,7 +554,7 @@ public class AaiCqResponse implements Serializable { */ public Vserver getVserver() { Vserver vserver = null; - int index = 0; + var index = 0; while (this.inventoryResponseItems.get(index).getClass() != Vserver.class) { index = index + 1; } @@ -605,7 +605,7 @@ public class AaiCqResponse implements Serializable { */ public int getVfModuleCount(String custId, String invId, String verId) { List<VfModule> vfModuleList = this.getAllVfModules(); - int count = 0; + var count = 0; for (VfModule vfModule : vfModuleList) { if (vfModule.getModelCustomizationId() == null || vfModule.getModelInvariantId() == null || vfModule.getModelVersionId() == null) { diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java index 16ee887af..b2a410733 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java @@ -86,17 +86,17 @@ public final class AaiManager { if (getResponse == null) { return null; } else { - JSONObject responseObj = new JSONObject(getResponse); + var responseObj = new JSONObject(getResponse); JSONArray resultsArray; if (responseObj.has("result-data")) { resultsArray = (JSONArray) responseObj.get("result-data"); } else { return null; } - String resourceLink = resultsArray.getJSONObject(0).getString("resource-link"); - String start = resourceLink.replace(PREFIX, ""); - String query = "query/closed-loop"; - JSONObject payload = new JSONObject(); + var resourceLink = resultsArray.getJSONObject(0).getString("resource-link"); + var start = resourceLink.replace(PREFIX, ""); + var query = "query/closed-loop"; + var payload = new JSONObject(); payload.put("start", start); payload.put("query", query); return payload.toString(); @@ -119,7 +119,7 @@ public final class AaiManager { String urlGet = url + TENANT_URL; - String getResponse = getStringQuery(urlGet, username, password, requestId, vserver); + var getResponse = getStringQuery(urlGet, username, password, requestId, vserver); return createCustomQueryPayload(getResponse); } @@ -186,7 +186,7 @@ public final class AaiManager { String urlGet = url + key; - int attemptsLeft = 3; + var attemptsLeft = 3; while (attemptsLeft-- > 0) { NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", CommInfrastructure.REST, urlGet); @@ -255,7 +255,7 @@ public final class AaiManager { logger.error("Failed to encode the pnfName: {} using UTF-8", pnfName, e); return null; } - String responseGet = getStringQuery(urlGet, username, password, requestId, pnfName); + var responseGet = getStringQuery(urlGet, username, password, requestId, pnfName); if (responseGet == null) { logger.error("Null response from AAI for the url: {}.", urlGet); return null; diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java index 8a2c2cded..6a0e19a42 100644 --- a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -47,8 +47,8 @@ public class ResponseStatus implements Serializable { @Override public int hashCode() { - final int prime = 31; - int result = 1; + final var prime = 31; + var result = 1; result = prime * result + code; result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((value == null) ? 0 : value.hashCode()); diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/AppcLcmResponseCode.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/AppcLcmResponseCode.java index 9d36ff809..43697e9e8 100644 --- a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/AppcLcmResponseCode.java +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/AppcLcmResponseCode.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appclcm * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ @@ -59,7 +59,7 @@ public class AppcLcmResponseCode implements Serializable { * @return the string value equivalent of the APPC response code */ public static String toResponseValue(int code) { - StatusCodeEnum statusCodeEnum = StatusCodeEnum.fromStatusCode(code); + var statusCodeEnum = StatusCodeEnum.fromStatusCode(code); return (statusCodeEnum != null) ? statusCodeEnum.toString() : null; } } diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorGrpcClient.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorGrpcClient.java index 29fa687c0..ce0918d5e 100644 --- a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorGrpcClient.java +++ b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorGrpcClient.java @@ -54,13 +54,7 @@ public class CdsProcessorGrpcClient implements AutoCloseable { Preconditions.checkState(validationResult.getStatus().isValid(), "Error validating CDS server " + "properties: " + validationResult.getResult()); - StringBuilder bldr = new StringBuilder("gRPC://"); - bldr.append(props.getHost()); - bldr.append(":"); - bldr.append(props.getPort()); - bldr.append('/'); - - String url = bldr.toString(); + String url = "gRPC://" + props.getHost() + ":" + props.getPort() + "/"; this.channel = NettyChannelBuilder.forAddress(props.getHost(), props.getPort()) .intercept(new BasicAuthClientHeaderInterceptor(props)).usePlaintext().build(); diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorHandler.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorHandler.java index 660908bfa..bb7a038db 100644 --- a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorHandler.java +++ b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/client/CdsProcessorHandler.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 Bell Canada. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ package org.onap.policy.cds.client; import io.grpc.ManagedChannel; import io.grpc.stub.StreamObserver; import java.util.concurrent.CountDownLatch; -import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc; import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; @@ -47,13 +46,13 @@ public class CdsProcessorHandler { } CountDownLatch process(ExecutionServiceInput request, ManagedChannel channel) { - final ActionIdentifiers header = request.getActionIdentifiers(); + final var header = request.getActionIdentifiers(); LOGGER.info("Processing blueprint({}:{}) for action({})", header.getBlueprintVersion(), header.getBlueprintName(), header.getBlueprintVersion()); - final CountDownLatch finishLatch = new CountDownLatch(1); + final var finishLatch = new CountDownLatch(1); final BluePrintProcessingServiceStub asyncStub = BluePrintProcessingServiceGrpc.newStub(channel); - final StreamObserver<ExecutionServiceOutput> responseObserver = new StreamObserver<ExecutionServiceOutput>() { + final StreamObserver<ExecutionServiceOutput> responseObserver = new StreamObserver<>() { @Override public void onNext(ExecutionServiceOutput output) { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, url, output.toString()); diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java index 4f37e9592..a91548fca 100644 --- a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java +++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * rest * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -61,11 +61,11 @@ public class RestManager { */ public Pair<Integer, String> put(String url, String username, String password, Map<String, String> headers, String contentType, String body) { - HttpPut put = new HttpPut(url); + var put = new HttpPut(url); addHeaders(put, username, password, headers); put.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); put.setEntity(input); } catch (Exception e) { @@ -88,11 +88,11 @@ public class RestManager { */ public Pair<Integer, String> post(String url, String username, String password, Map<String, String> headers, String contentType, String body) { - HttpPost post = new HttpPost(url); + var post = new HttpPost(url); addHeaders(post, username, password, headers); post.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); post.setEntity(input); } catch (Exception e) { @@ -112,7 +112,7 @@ public class RestManager { * @return a Pair for the response status and the body */ public Pair<Integer, String> get(String url, String username, String password, Map<String, String> headers) { - HttpGet get = new HttpGet(url); + var get = new HttpGet(url); addHeaders(get, username, password, headers); return sendRequest(get); } @@ -131,12 +131,12 @@ public class RestManager { */ public Pair<Integer, String> delete(String url, String username, String password, Map<String, String> headers, String contentType, String body) { - HttpDeleteWithBody delete = new HttpDeleteWithBody(url); + var delete = new HttpDeleteWithBody(url); addHeaders(delete, username, password, headers); if (body != null && !body.isEmpty()) { delete.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); delete.setEntity(input); } catch (Exception e) { @@ -157,7 +157,7 @@ public class RestManager { * @return the response status code and the body */ public Pair<Integer, String> delete(String url, String username, String password, Map<String, String> headers) { - HttpDelete delete = new HttpDelete(url); + var delete = new HttpDelete(url); addHeaders(delete, username, password, headers); return sendRequest(delete); } @@ -174,12 +174,12 @@ public class RestManager { */ public Pair<Integer, String> patch(String url, String username, String password, Map<String, String> headers, String body) { - String contentType = "application/merge-patch+json"; - HttpPatch patch = new HttpPatch(url); + var contentType = "application/merge-patch+json"; + var patch = new HttpPatch(url); addHeaders(patch, username, password, headers); patch.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); patch.setEntity(input); } catch (Exception e) { @@ -204,7 +204,7 @@ public class RestManager { HttpClientBuilder.create().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()) { HttpResponse response = client.execute(request); if (response != null) { - String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + var returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); logger.debug("HTTP Response Status Code: {}", response.getStatusLine().getStatusCode()); logger.debug("HTTP Response Body:"); logger.debug(returnBody); diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java index 35a85d779..90864d42c 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java @@ -5,6 +5,7 @@ * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +60,7 @@ public class PciResponseCode implements Serializable { * @return the string value equivalent of the SDNR response code */ public static String toResponseValue(int code) { - StatusCodeEnum statusCodeEnum = StatusCodeEnum.fromStatusCode(code); + var statusCodeEnum = StatusCodeEnum.fromStatusCode(code); return (statusCodeEnum != null) ? statusCodeEnum.toString() : null; } } diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java index a5e4336da..90aea71ee 100644 --- a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java @@ -57,7 +57,7 @@ public final class Serialization { @Override public JsonElement serialize(PciRequest src, Type typeOfSrc, JsonSerializationContext context) { JsonElement requestJson = gsonPretty.toJsonTree(src, PciRequest.class); - JsonObject input = new JsonObject(); + var input = new JsonObject(); input.add("input", requestJson); return input; @@ -74,7 +74,7 @@ public final class Serialization { @Override public JsonElement serialize(PciResponse src, Type typeOfSrc, JsonSerializationContext context) { JsonElement responseJson = gsonPretty.toJsonTree(src, PciResponse.class); - JsonObject output = new JsonObject(); + var output = new JsonObject(); output.add("output", responseJson); return output; } diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponseWrapper.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponseWrapper.java index beb852864..b6eef29d2 100644 --- a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponseWrapper.java +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponseWrapper.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * so * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -70,7 +70,7 @@ public class SoResponseWrapper implements Serializable { @Override public int hashCode() { - final int prime = 31; + final var prime = 31; int result = super.hashCode(); result = prime * result + ((soResponse == null) ? 0 : soResponse.hashCode()); result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); |