From 736ee9bee7970acd8c3411d8a867e0080de16655 Mon Sep 17 00:00:00 2001 From: Edyta Krukowska Date: Wed, 2 Dec 2020 15:16:11 +0100 Subject: Improve code quality - fix sonars Issue-ID: SDC-3394 Signed-off-by: Edyta Krukowska Change-Id: Ifb65fb90d5111aa78bcd330d8d569af904f957d4 --- .../java/org/onap/sdc/api/IDistributionClient.java | 2 +- .../java/org/onap/sdc/http/SdcConnectorClient.java | 30 ++++++++++++---------- .../java/org/onap/sdc/impl/ArtifactInfoImpl.java | 4 +-- .../main/java/org/onap/sdc/impl/Configuration.java | 4 --- .../impl/DistributionClientDownloadResultImpl.java | 2 +- .../sdc/impl/JsonContainerResourceInstance.java | 4 +-- .../org/onap/sdc/impl/NotificationDataImpl.java | 4 +-- .../main/java/org/onap/sdc/utils/GeneralUtils.java | 19 +++++++------- .../org/onap/sdc/utils/heat/HeatParameter.java | 10 ++++---- 9 files changed, 38 insertions(+), 41 deletions(-) diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java index ce17318..fe37dc1 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/api/IDistributionClient.java @@ -198,7 +198,7 @@ public interface IDistributionClient { /** * This method parses artifact of type VF_MODULES_METADATA payload data * .
- * Method is deprecated due to VF Module changes. Only backward + * @deprecated Method is deprecated due to VF Module changes. Only backward * compatibility is supported.
* * @param artifactPayload diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java b/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java index 36044c7..7aac780 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/http/SdcConnectorClient.java @@ -76,7 +76,7 @@ public class SdcConnectorClient { } public Either, IDistributionClientResult> getValidArtifactTypesList() { - Pair getServersResponsePair = performAsdcServerRequest(AsdcUrls.GET_VALID_ARTIFACT_TYPES); + Pair getServersResponsePair = performAsdcServerRequest(); HttpAsdcResponse getArtifactTypeResponse = getServersResponsePair.getFirst(); Either, IDistributionClientResult> response; @@ -104,11 +104,11 @@ public class SdcConnectorClient { } } - private Pair performAsdcServerRequest(final String url) { + private Pair performAsdcServerRequest() { String requestId = generateRequestId(); Map requestHeaders = addHeadersToHttpRequest(requestId); - log.debug("about to perform getServerList. requestId= {} url= {}", requestId, url); - return httpClient.getRequest(url, requestHeaders, false); + log.debug("about to perform getServerList. requestId= {} url= {}", requestId, AsdcUrls.GET_VALID_ARTIFACT_TYPES); + return httpClient.getRequest(AsdcUrls.GET_VALID_ARTIFACT_TYPES, requestHeaders, false); } public Either registerAsdcTopics(ApiCredential credential) { @@ -123,7 +123,7 @@ public class SdcConnectorClient { String jsonRequest = gson.toJson(registrationRequest); StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON); - log.debug("about to perform registerAsdcTopics. requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_TOPIC_REGISTRATION); + log.debug("about to perform registerAsdcTopics. requestId= {} url= {}", requestId, AsdcUrls.POST_FOR_TOPIC_REGISTRATION); Pair registerResponsePair = httpClient.postRequest(AsdcUrls.POST_FOR_TOPIC_REGISTRATION, body, requestHeaders, false); HttpAsdcResponse registerResponse = registerResponsePair.getFirst(); int status = registerResponse.getStatus(); @@ -137,7 +137,7 @@ public class SdcConnectorClient { } handeAsdcConnectionClose(registerResponsePair); - log.debug("registerAsdcTopics response= " + status + ". requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_TOPIC_REGISTRATION); + log.debug("registerAsdcTopics response= {}. requestId= {} url= {}", status, requestId, AsdcUrls.POST_FOR_TOPIC_REGISTRATION); return response; } @@ -158,7 +158,7 @@ public class SdcConnectorClient { String jsonRequest = gson.toJson(registrationRequest); StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON); - log.debug("about to perform unregisterTopics. requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_UNREGISTER); + log.debug("about to perform unregisterTopics. requestId= {} url= {}", requestId, AsdcUrls.POST_FOR_UNREGISTER); Pair unRegisterResponsePair = httpClient.postRequest(AsdcUrls.POST_FOR_UNREGISTER, body, requestHeaders, false); HttpAsdcResponse unRegisterResponse = unRegisterResponsePair.getFirst(); int status = unRegisterResponse.getStatus(); @@ -171,7 +171,7 @@ public class SdcConnectorClient { handeAsdcConnectionClose(unRegisterResponsePair); - log.debug("unregisterTopics response = " + status + ". requestId= " + requestId + " url= " + AsdcUrls.POST_FOR_UNREGISTER); + log.debug("unregisterTopics response = {}. requestId= {} url= {}", status, requestId, AsdcUrls.POST_FOR_UNREGISTER); return response; @@ -221,7 +221,7 @@ public class SdcConnectorClient { private Either, IDistributionClientResult> handleParsingError(Exception e) { Either, IDistributionClientResult> result; - log.error("failed to parse response from ASDC. error: " + e.getMessage()); + log.error("failed to parse response from ASDC. error: ", e); IDistributionClientResult response = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to parse response from ASDC"); result = Either.right(response); return result; @@ -248,7 +248,7 @@ public class SdcConnectorClient { return Either.left(registrationResponse); } catch (UnsupportedOperationException | IOException e) { - log.error("failed to pars response from ASDC. error: " + e.getMessage()); + log.error("failed to parse response from ASDC. error: ", e); DistributionClientResultImpl response = new DistributionClientResultImpl(DistributionActionResultEnum.GENERAL_ERROR, "failed to parse response from ASDC"); return Either.right(response); } @@ -281,12 +281,13 @@ public class SdcConnectorClient { } else if (status == HttpStatus.SC_GATEWAY_TIMEOUT) { errorResponse = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_SERVER_TIMEOUT, "ASDC server problem"); } - log.error("status from ASDC is " + registerResponse); + log.error("status from ASDC is {}", registerResponse); log.error(errorResponse.toString()); try { String errorString = IOUtils.toString(registerResponse.getMessage().getContent()); - log.debug("error from ASDC is: " + errorString); + log.debug("error from ASDC is: {}", errorString); } catch (UnsupportedOperationException | IOException e) { + log.error("During error handling another exception occurred: ", e); } return errorResponse; @@ -308,12 +309,13 @@ public class SdcConnectorClient { } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) { errorResponse = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, "ASDC server problem"); } - log.error("status from ASDC is " + registerResponse); + log.error("status from ASDC is {}", registerResponse); log.error(errorResponse.toString()); try { String errorString = IOUtils.toString(registerResponse.getMessage().getContent()); - log.debug("error from ASDC is: " + errorString); + log.debug("error from ASDC is: {}", errorString); } catch (UnsupportedOperationException | IOException e) { + log.error("During error handling another exception occurred: ", e); } return errorResponse; diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java index c59ba3f..72e6535 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/ArtifactInfoImpl.java @@ -71,7 +71,7 @@ class ArtifactInfoImpl implements IArtifactInfo { } public static List convertToArtifactInfoImpl(List list) { - List ret = new ArrayList(); + List ret = new ArrayList<>(); if (list != null) { for (IArtifactInfo artifactInfo : list) { ret.add(new ArtifactInfoImpl(artifactInfo)); @@ -172,7 +172,7 @@ class ArtifactInfoImpl implements IArtifactInfo { } public List getRelatedArtifacts() { - List temp = new ArrayList(); + List temp = new ArrayList<>(); if (relatedArtifactsInfo != null) { temp.addAll(relatedArtifactsInfo); } diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java index 67071e9..1196d7a 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/Configuration.java @@ -130,10 +130,6 @@ public class Configuration implements IConfiguration { return keyStorePassword; } - public String getComsumerID() { - return comsumerID; - } - public void setComsumerID(String comsumerID) { this.comsumerID = comsumerID; } diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java index ae2b893..624ee84 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientDownloadResultImpl.java @@ -64,7 +64,7 @@ public class DistributionClientDownloadResultImpl extends DistributionClientResu @Override public String getArtifactFilename() { //Fix of bug 292443 in TDP - if (artifactName == null || !artifactName.matches("attachment;\\s*filename=\".*?\"")) { + if (artifactName == null || !artifactName.matches("attachment;\\s*filename=\"[^\"]*+\"")) { return artifactName; } String fileName = "filename=\""; diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java index eeaf235..eda14d4 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/JsonContainerResourceInstance.java @@ -55,7 +55,7 @@ class JsonContainerResourceInstance implements IResourceInstance { } public static List convertToJsonContainer(List resources) { - List buildResources = new ArrayList(); + List buildResources = new ArrayList<>(); if (resources != null) { for (IResourceInstance resourceInstance : resources) { buildResources.add(new JsonContainerResourceInstance(resourceInstance)); @@ -111,7 +111,7 @@ class JsonContainerResourceInstance implements IResourceInstance { @Override public List getArtifacts() { - List temp = new ArrayList(); + List temp = new ArrayList<>(); if (artifacts != null) { temp.addAll(artifacts); } diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java index 925b79b..1be0fa6 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/NotificationDataImpl.java @@ -105,7 +105,7 @@ class NotificationDataImpl implements INotificationData { @Override public List getResources() { - List ret = new ArrayList(); + List ret = new ArrayList<>(); if (resources != null) { ret.addAll(resources); } @@ -127,7 +127,7 @@ class NotificationDataImpl implements INotificationData { @Override public List getServiceArtifacts() { - List temp = new ArrayList(); + List temp = new ArrayList<>(); if (serviceArtifacts != null) { temp.addAll(serviceArtifacts); } diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java index d550b74..ff5d201 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/GeneralUtils.java @@ -21,22 +21,21 @@ package org.onap.sdc.utils; -import com.google.common.base.Charsets; import com.google.common.hash.Hashing; +import fj.data.Either; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.impl.DistributionClientResultImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.net.InetAddress; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.regex.Pattern; -import org.onap.sdc.api.results.IDistributionClientResult; -import org.onap.sdc.impl.DistributionClientResultImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import fj.data.Either; - public class GeneralUtils { private static final Logger LOGGER = LoggerFactory.getLogger(GeneralUtils.class.getName()); private static final int STRING_LENGTH_DIVIDER = 4; @@ -45,7 +44,7 @@ public class GeneralUtils { } public static String calculateMD5(String data) { - String calculatedMd5 = Hashing.md5().hashString(data, Charsets.UTF_8).toString(); + String calculatedMd5 = Hashing.md5().hashString(data, StandardCharsets.UTF_8).toString(); // encode base-64 result byte[] encodeBase64 = Base64.getEncoder().encode(calculatedMd5.getBytes()); return new String(encodeBase64); @@ -61,7 +60,7 @@ public class GeneralUtils { boolean isEncoded = false; try { // If no exception is caught, then it is possibly a base64 encoded string - byte[] data = Base64.getDecoder().decode(str); + Base64.getDecoder().decode(str); // checks if the string was properly padded to the isEncoded = ((str.length() % STRING_LENGTH_DIVIDER == 0) && (Pattern.matches("\\A[a-zA-Z0-9/+]+={1,2}\\z", str))); diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java index 731e3e9..479387d 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java @@ -30,7 +30,7 @@ public class HeatParameter { private String description; //This is in order to workaround "default" field in HeatParameterEntry, since default is Java keyword //YAML constructor will lowercase it during parsing - private String Default; + private String defaultValue; private String hidden = "false"; //defaultParameters value according to OpenStack spec private List constraints; @@ -76,11 +76,11 @@ public class HeatParameter { } public String getDefault() { - return Default; + return defaultValue; } public void setDefault(String default1) { - Default = default1; + defaultValue = default1; } @@ -198,8 +198,8 @@ public class HeatParameter { if (label != null) { sb.append("label:" + label + ", "); } - if (Default != null) { - sb.append("default:" + Default + ", "); + if (defaultValue != null) { + sb.append("default:" + defaultValue + ", "); } if (hidden != null) { sb.append("hidden:" + hidden + ", "); -- cgit 1.2.3-korg