diff options
Diffstat (limited to 'ResmanagementService')
8 files changed, 28 insertions, 35 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); diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java index 1f7c8a1..13a3ca6 100644 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java @@ -24,7 +24,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; import org.junit.Test; -import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; import mockit.Mock; import mockit.MockUp; @@ -299,7 +298,7 @@ public class JsonUtilTest { jsonObj.put("a", "1"); jsonObj.put("b", "2"); String parentKey = ""; - String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); + String result = JsonUtil.getStrValueByParentJson(jsonObj, parentKey, key); String expectedResult = "1"; assertEquals(expectedResult, result); } @@ -318,7 +317,7 @@ public class JsonUtilTest { return new JSONObject(); } }; - String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); + String result = JsonUtil.getStrValueByParentJson(jsonObj, parentKey, key); String expectedResult = null; assertEquals(expectedResult, result); } @@ -330,7 +329,7 @@ public class JsonUtilTest { jsonObj.put("a", "1"); jsonObj.put("b", "2"); String parentKey = "b"; - String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); + String result = JsonUtil.getStrValueByParentJson(jsonObj, parentKey, key); String expectedResult = null; assertEquals(expectedResult, result); } diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java index a62e61e..159bdcf 100644 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java @@ -57,7 +57,7 @@ public class ResponseUtilTest { int httpStatusCode = -1; int retCode1 = -1; String msg1 = "123"; - JSONObject result = ResponseUtil.genHttpResponse(null, httpStatusCode, retCode1, msg1); + JSONObject result = ResponseUtil.genHttpResponse(httpStatusCode, retCode1, msg1); JSONObject expectedResult = new JSONObject(); expectedResult.put("msg", "123"); assertEquals(result.toString(), expectedResult.toString()); @@ -73,7 +73,7 @@ public class ResponseUtilTest { map.put("a", -1); map.put("b", 1); String msg1 = "123"; - JSONObject result = ResponseUtil.genHttpResponse(null, codeMap, msg1, map); + JSONObject result = ResponseUtil.genHttpResponse(codeMap, msg1, map); JSONObject expectedResult = new JSONObject(); expectedResult.put("msg", "123"); expectedResult.put("a", "-1"); |