Swap String concatenation with StringBuilder 53/32453/1
authorMunir Ahmad <munir.ahmad@bell.ca>
Wed, 21 Feb 2018 21:44:58 +0000 (16:44 -0500)
committerMunir Ahmad <munir.ahmad@bell.ca>
Wed, 21 Feb 2018 21:46:08 +0000 (16:46 -0500)
Change-Id: I5c43d3267e5f75623bcc837e27c57a6ad6aa8877
Issue-ID: SO-437
Signed-off-by: Munir Ahmad <munir.ahmad@bell.ca>
adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImpl.java
adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/impl/SDNCRestClient.java
adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/sdncrest/SDNCConnector.java
adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java

index acc6d72..d7be686 100644 (file)
@@ -886,7 +886,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
     public Map <String, Object> validateStackParams (Map <String, Object> inputParams,
                                                      HeatTemplate heatTemplate) throws IllegalArgumentException {
         // Check that required parameters have been supplied for this template type
-        String missingParams = null;
+        StringBuilder missingParams = null;
         List <String> paramList = new ArrayList <> ();
 
         // TODO: Enhance DB to support defaults for Heat Template parameters
@@ -894,9 +894,9 @@ public class MsoHeatUtils extends MsoCommonUtils {
         for (HeatTemplateParam parm : heatTemplate.getParameters ()) {
             if (parm.isRequired () && !inputParams.containsKey (parm.getParamName ())) {
                 if (missingParams == null) {
-                    missingParams = parm.getParamName ();
+                    missingParams = new StringBuilder(parm.getParamName());
                 } else {
-                    missingParams += "," + parm.getParamName ();
+                    missingParams.append("," + parm.getParamName());
                 }
             }
             paramList.add (parm.getParamName ());
index 2c04ae9..f050882 100644 (file)
@@ -1985,16 +1985,16 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                String outputTempl = "  subnet_id_%subnetId%:\n" + "    description: Openstack subnet identifier\n"
                                + "    value: {get_resource: subnet_%subnetId%}\n";
 
-               String curR;
+               StringBuilder curR;
                String curO;
                StringBuilder resourcesBuf = new StringBuilder ();
                StringBuilder outputsBuf = new StringBuilder ();
                for (Subnet subnet : subnets) {
 
                        // build template for each subnet
-                       curR = resourceTempl;
+                       curR = new StringBuilder(resourceTempl);
                        if (subnet.getSubnetId () != null) {
-                               curR = curR.replace ("%subnetId%", subnet.getSubnetId ());
+                               curR = new StringBuilder(curR.toString().replace("%subnetId%", subnet.getSubnetId()));
                        } else {
                                String error = "Missing Required AAI SubnetId for subnet in HEAT Template";
                                LOGGER.error (MessageEnum.RA_MISSING_PARAM, error, "Openstack", "", MsoLogger.ErrorCode.DataError, "Missing Required AAI ID  for subnet in HEAT Template");
@@ -2002,13 +2002,13 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                        }
 
                        if (subnet.getSubnetName () != null) {
-                               curR = curR.replace ("%name%", subnet.getSubnetName ());
+                               curR = new StringBuilder(curR.toString().replace("%name%", subnet.getSubnetName()));
                        } else {
-                               curR = curR.replace ("%name%", subnet.getSubnetId ());
+                               curR = new StringBuilder(curR.toString().replace("%name%", subnet.getSubnetId()));
                        }
 
                        if (subnet.getCidr () != null) {
-                               curR = curR.replace ("%cidr%", subnet.getCidr ());
+                               curR = new StringBuilder(curR.toString().replace("%cidr%", subnet.getCidr()));
                        } else {
                                String error = "Missing Required cidr for subnet in HEAT Template";
                                LOGGER.error (MessageEnum.RA_MISSING_PARAM, error, "Openstack", "", MsoLogger.ErrorCode.DataError, "Missing Required cidr for subnet in HEAT Template");
@@ -2016,23 +2016,23 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                        }
 
                        if (subnet.getIpVersion () != null) {
-                               curR = curR + "      ip_version: " + subnet.getIpVersion () + "\n";
+                               curR.append("      ip_version: " + subnet.getIpVersion() + "\n");
                        }
                        if (subnet.getEnableDHCP () != null) {
-                               curR = curR + "      enable_dhcp: " +  Boolean.toString (subnet.getEnableDHCP ()) + "\n";
+                               curR.append("      enable_dhcp: ").append(Boolean.toString(subnet.getEnableDHCP())).append("\n");
                        }
                        if (subnet.getGatewayIp () != null && !subnet.getGatewayIp ().isEmpty() ) {
-                               curR = curR + "      gateway_ip: " + subnet.getGatewayIp () + "\n";
+                               curR.append("      gateway_ip: " + subnet.getGatewayIp() + "\n");
                        }
 
                        if (subnet.getAllocationPools() != null) {
-                               curR = curR + "      allocation_pools:\n";
+                               curR.append("      allocation_pools:\n");
                                for (Pool pool : subnet.getAllocationPools())
                                {
                                        if (!isNullOrEmpty(pool.getStart()) && !isNullOrEmpty(pool.getEnd()))
                                        {
-                                               curR = curR + "       - start: " + pool.getStart () + "\n";
-                                               curR = curR + "         end: " + pool.getEnd () + "\n";
+                                               curR.append("       - start: " + pool.getStart() + "\n");
+                                               curR.append("         end: " + pool.getEnd() + "\n");
                                        }
                                }
                        }
index 97f30be..45d5944 100644 (file)
@@ -197,7 +197,7 @@ public class SDNCRestClient implements Runnable {
                        //default
                        sdncResp.setRespCode(HttpURLConnection.HTTP_INTERNAL_ERROR);
                        String respMsg = "Error processing request to SDNC. ";
-                       String sdncErrMsg = "";
+                       StringBuilder sdncErrMsg = new StringBuilder();
 
                        if (e instanceof java.net.SocketTimeoutException )
                        {
@@ -229,7 +229,7 @@ public class SDNCRestClient implements Runnable {
                                                                String eType = null;
                                                                try {
                                                                        eType = xpath.evaluate("error-type", error);
-                                                                       sdncErrMsg = ". SDNC Returned-[error-type:" + eType;
+                                                                       sdncErrMsg = new StringBuilder(". SDNC Returned-[error-type:" + eType);
                                                                } catch (Exception e3) {
                                                                    msoLogger.error (MessageEnum.RA_EVALUATE_XPATH_ERROR, "error-type", error.toString(), "SDNC", "", MsoLogger.ErrorCode.DataError, "Exception while evaluate xpath", e3);
                                                                }
@@ -237,7 +237,7 @@ public class SDNCRestClient implements Runnable {
                                                                String eTag = null;
                                                                try {
                                                                        eTag = xpath.evaluate( "error-tag", error);
-                                                                       sdncErrMsg = sdncErrMsg + ", error-tag:" + eTag;
+                                                                       sdncErrMsg.append(", error-tag:").append(eTag);
                                                                } catch (Exception e3) {
                                                                        msoLogger.error (MessageEnum.RA_EVALUATE_XPATH_ERROR, "error-tag", error.toString(), "SDNC", "", MsoLogger.ErrorCode.DataError, "Exception while evaluate xpath", e3);
                                                                }
@@ -245,7 +245,7 @@ public class SDNCRestClient implements Runnable {
                                                                String eMsg = null;
                                                                try {
                                                                        eMsg = xpath.evaluate("error-message", error);
-                                                                       sdncErrMsg = sdncErrMsg + ", error-message:" + eMsg + "]";
+                                                                       sdncErrMsg.append(", error-message:").append(eMsg).append("]");
                                                                } catch (Exception e3) {
                                                                        msoLogger.error (MessageEnum.RA_EVALUATE_XPATH_ERROR, "error-message", error.toString(), "SDNC", "", MsoLogger.ErrorCode.DataError, "Exception while evaluate xpath", e3);
                                                                }
index 262d23b..be0466a 100644 (file)
@@ -257,7 +257,7 @@ public abstract class SDNCConnector {
                //   </error>
                // </errors>
 
-               String output = null;
+               StringBuilder output = null;
 
                try {
                        XPathFactory xpathFactory = XPathFactory.newInstance();
@@ -306,9 +306,9 @@ public abstract class SDNCConnector {
 
                                if (!info.isEmpty()) {
                                        if (output == null) {
-                                               output = "[" + info + "]";
+                                               output = new StringBuilder("[" + info + "]");
                                        } else {
-                                               output += " [" + info + "]";
+                                               output.append(" [").append(info).append("]");
                                        }
                                }
                        }
@@ -317,6 +317,6 @@ public abstract class SDNCConnector {
                                MsoLogger.ErrorCode.DataError, "Exception while analyzing errors", e);
                }
 
-               return output;
+               return output.toString();
        }
 }
index 7fe09be..a292c76 100644 (file)
@@ -1170,7 +1170,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
             }
 
             // Check that required parameters have been supplied
-            String missingParams = null;
+            StringBuilder missingParams = null;
             List <String> paramList = new ArrayList <> ();
 
             // New for 1510 - consult the PARAM_ALIAS field to see if we've been
@@ -1264,9 +1264,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
                     } else {
                         LOGGER.debug ("adding to missing parameters list: " + parm.getParamName ());
                         if (missingParams == null) {
-                            missingParams = parm.getParamName ();
+                            missingParams = new StringBuilder(parm.getParamName());
                         } else {
-                            missingParams += "," + parm.getParamName ();
+                            missingParams.append("," + parm.getParamName());
                         }
                     }
                 }
@@ -1276,7 +1276,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
                 if (checkRequiredParameters) {
                     // Problem - missing one or more required parameters
                     String error = "Create VFModule: Missing Required inputs: " + missingParams;
-                    LOGGER.error (MessageEnum.RA_MISSING_PARAM, missingParams, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create VFModule: Missing Required inputs");
+                    LOGGER.error (MessageEnum.RA_MISSING_PARAM, missingParams.toString(), "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create VFModule: Missing Required inputs");
                     LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, error);
                     throw new VnfException (error, MsoExceptionCategory.USERDATA);
                 } else {
@@ -1871,7 +1871,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
             }
 
             // Check that required parameters have been supplied
-            String missingParams = null;
+            StringBuilder missingParams = null;
             List <String> paramList = new ArrayList <> ();
 
             // New for 1510 - consult the PARAM_ALIAS field to see if we've been
@@ -2009,9 +2009,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
                     else {
                         LOGGER.debug ("adding to missing parameters list: " + parm.getParamName ());
                         if (missingParams == null) {
-                            missingParams = parm.getParamName ();
+                            missingParams = new StringBuilder(parm.getParamName());
                         } else {
-                            missingParams += "," + parm.getParamName ();
+                            missingParams.append("," + parm.getParamName());
                         }
                     }
                 }
@@ -2021,7 +2021,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
                 // Problem - missing one or more required parameters
                 if (checkRequiredParameters) {
                 String error = "Update VNF: Missing Required inputs: " + missingParams;
-                LOGGER.error (MessageEnum.RA_MISSING_PARAM, missingParams, "OpenStack", "", MsoLogger.ErrorCode.DataError, error);
+                LOGGER.error (MessageEnum.RA_MISSING_PARAM, missingParams.toString(), "OpenStack", "", MsoLogger.ErrorCode.DataError, error);
                     LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, error);
                 throw new VnfException (error, MsoExceptionCategory.USERDATA);
                 } else {