summaryrefslogtreecommitdiffstats
path: root/ResmanagementService/service/src/main
diff options
context:
space:
mode:
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>2017-09-11 16:07:56 -0700
committerShashank Kumar Shankar <shashank.kumar.shankar@intel.com>2017-09-11 16:12:27 -0700
commitc5041675a30f1102daec55d08564b544b9a2071d (patch)
treef3305c621cd69793bbdbce2b891f2167cefaffe2 /ResmanagementService/service/src/main
parent89b20536425441a464d4832667abae80a6cd818f (diff)
Fix some Sonar issues in common util directory
This patch fixes some Sonar issues in common/util directory. Change-Id: I76ae980a3abb1d8a16d0197654cd9d759b13d597 Issue-Id: VFC-331 Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Diffstat (limited to 'ResmanagementService/service/src/main')
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java4
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java11
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java20
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java2
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java13
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java2
6 files changed, 23 insertions, 29 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java
index f6bf1ac..a033cbe 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java
@@ -128,7 +128,7 @@ public final class JsonUtil {
private static Object getJsonFieldObject(JSONObject jsonObj, String fieldName, int classType) {
try {
if(null != jsonObj && jsonObj.has(fieldName)) {
- Object result = new Object();
+ Object result;
switch(classType) {
case TYPE_STRING:
result = "null".equals(jsonObj.getString(fieldName)) ? "" : jsonObj.getString(fieldName);
@@ -244,7 +244,7 @@ public final class JsonUtil {
* @return
* @since VFC 1.0
*/
- public static String getStrValueByJson(JSONObject json, String parentKey, String key) {
+ public static String getStrValueByParentJson(JSONObject json, String parentKey, String key) {
if(parentKey.isEmpty()) {
return getStrValueByjson(json, key);
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java
index aa7c948..d783ea8 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java
@@ -63,6 +63,9 @@ public class RestfulUtil {
public static final String APPLICATION = "application/json";
+ public static final String NO_RESULT_EXCEPTION =
+ "org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result";
+
private static final Logger LOGGER = LoggerFactory.getLogger(RestfulUtil.class);
private static final Restful REST_CLIENT = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP);
@@ -277,7 +280,7 @@ public class RestfulUtil {
if(null == result || result.isEmpty()) {
LOGGER.error("result from url:" + url + " result:" + result);
throw new ServiceException(
- ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result"));
+ ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
JSONArray rsArray = null;
@@ -287,7 +290,7 @@ public class RestfulUtil {
} catch(JSONException e) {
LOGGER.error("getResources error:" + e);
throw new ServiceException(
- ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result"));
+ ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
return rsArray;
}
@@ -308,7 +311,7 @@ public class RestfulUtil {
if(null == result || result.isEmpty()) {
LOGGER.error("result from url:" + url + " result:" + result);
throw new ServiceException(
- ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result"));
+ ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
JSONArray rsArray = null;
@@ -325,7 +328,7 @@ public class RestfulUtil {
} catch(JSONException e) {
LOGGER.error("getResources error:" + e);
throw new ServiceException(
- ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result"));
+ ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
return rsArray;
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java
index c932669..d5da530 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java
@@ -83,11 +83,8 @@ public final class StringUtil {
public static boolean isInteger(String... strs) {
try {
for(String str : strs) {
- if(!StringUtils.isEmpty(str)) {
- int value = Integer.parseInt(str);
- if(value < 0) {
- return false;
- }
+ if(!StringUtils.isEmpty(str) && Integer.parseInt(str) < 0) {
+ return false;
}
}
} catch(NumberFormatException e) {
@@ -107,11 +104,8 @@ public final class StringUtil {
public static boolean isNumeric(String... strs) {
try {
for(String str : strs) {
- if(!StringUtils.isEmpty(str)) {
- float value = Float.parseFloat(str);
- if(value < 0) {
- return false;
- }
+ if(!StringUtils.isEmpty(str) && Float.parseFloat(str) < 0) {
+ return false;
}
}
} catch(NumberFormatException e) {
@@ -161,9 +155,9 @@ public final class StringUtil {
* @since VFC 1.0
*/
public static boolean compareZeroByInteger(String tatol, String used, String drTotal) {
- Integer ftotal = (int)0;
- Integer fused = (int)0;
- Integer fdrTotal = (int)0;
+ Integer ftotal = 0;
+ Integer fused = 0;
+ Integer fdrTotal = 0;
if(!StringUtils.isEmpty(tatol)) {
ftotal = Integer.valueOf(tatol);
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java
index e7f194d..ed0c675 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java
@@ -117,7 +117,7 @@ public final class RequestUtil {
*/
@SuppressWarnings("unchecked")
private static Map<String, String> getContextHeader(HttpServletRequest context) {
- Map<String, String> header = new HashMap<String, String>();
+ Map<String, String> header = new HashMap<>();
Enumeration<String> headerNames = context.getHeaderNames();
while(headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java
index 33f5325..13eb979 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java
@@ -50,7 +50,7 @@ public final class ResponseUtil {
* @since VFC 1.0
*/
public static JSONObject genHttpResponse(int retCode, String msg) {
- return genHttpResponse(null, createCodeMap(-1, retCode), msg, null);
+ return genHttpResponse(createCodeMap(-1, retCode), msg, null);
}
/**
@@ -66,14 +66,12 @@ public final class ResponseUtil {
* @since VFC 1.0
*/
public static JSONObject genHttpResponse(int retCode, String msg, Map<String, Object> map) {
- return genHttpResponse(null, createCodeMap(-1, retCode), msg, map);
+ return genHttpResponse(createCodeMap(-1, retCode), msg, map);
}
/**
* Roa request common return method <br/>
*
- * @param context
- * The http request context
* @param httpStatusCode
* The http response code
* @param retCode
@@ -83,22 +81,21 @@ public final class ResponseUtil {
* @return JSONObject The response for http request
* @since VFC 1.0
*/
- public static JSONObject genHttpResponse(HttpServletRequest context, int httpStatusCode, int retCode, String msg) {
- return genHttpResponse(context, createCodeMap(httpStatusCode, retCode), msg, null);
+ public static JSONObject genHttpResponse(int httpStatusCode, int retCode, String msg) {
+ return genHttpResponse(createCodeMap(httpStatusCode, retCode), msg, null);
}
/**
*
* Roa request common return method.<br>
*
- * @param context, The http request context
* @param codeMap
* @param msg, The message of request
* @param map, Other message of request
* @return
* @since VFC 1.0
*/
- public static JSONObject genHttpResponse(HttpServletRequest context, Map<String, Integer> codeMap, String msg,
+ public static JSONObject genHttpResponse(Map<String, Integer> codeMap, String msg,
Map<String, Object> map) {
JSONObject object = new JSONObject();
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java
index fcb94a6..fb00a2a 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java
@@ -54,7 +54,7 @@ public final class RoaResponseUtil {
* @since VFC 1.0
*/
public static <T> JSONObject get(List<T> list) {
- Map<String, Object> map = new HashMap<String, Object>(10);
+ Map<String, Object> map = new HashMap<>(10);
map.put(ParamConstant.PARAM_DATA, list);
LOGGER.info("function=get; msg=get map:{}", map.toString());
return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.QUERY_SUCESS_MSG, map);