diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-common')
2 files changed, 35 insertions, 30 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java index 34ad676e..9809b78a 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/CacheAdminController.java @@ -37,6 +37,8 @@ */ package org.onap.portalapp.controller.core; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; @@ -71,6 +73,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; public class CacheAdminController extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CacheAdminController.class); + private static final String CACHE_NAME = "cacheName"; + private static final String APPLICATION_JSON = "application/json"; private JCSAdminBean jcsAdminBean = new JCSAdminBean(); @@ -94,9 +98,9 @@ public class CacheAdminController extends RestrictedBaseController { @RequestMapping(value = { "/jcs_admin/clearRegion" }, method = RequestMethod.GET) public void clearRegion(HttpServletRequest request, HttpServletResponse response) throws IOException { - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); clearCacheRegion(cacheName); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(getRegions().toString()); } @@ -104,7 +108,7 @@ public class CacheAdminController extends RestrictedBaseController { @RequestMapping(value = { "/jcs_admin/clearAll" }, method = RequestMethod.GET) public void clearAll(HttpServletResponse response) throws IOException { clearAllRegions(); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(getRegions().toString()); } @@ -112,16 +116,16 @@ public class CacheAdminController extends RestrictedBaseController { @RequestMapping(value = { "/jcs_admin/clearItem" }, method = RequestMethod.GET) public void clearItem(HttpServletRequest request, HttpServletResponse response) throws IOException { String keyName = request.getParameter("keyName"); - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); clearCacheRegionItem(cacheName, keyName); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(getRegions().toString()); } @RequestMapping(value = { "/jcs_admin/showItemDetails" }, method = RequestMethod.GET) public void showItemDetails(HttpServletRequest request, HttpServletResponse response) throws IOException { - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); String keyName = request.getParameter("keyName"); String details = null; try { @@ -131,20 +135,20 @@ public class CacheAdminController extends RestrictedBaseController { logger.error(EELFLoggerDelegate.errorLogger, "showItemDetails failed for cache name " + cacheName, e); } JSONObject j = new JSONObject(details); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(j.toString()); } @RequestMapping(value = { "/jcs_admin/showRegionDetails" }, method = RequestMethod.GET) public void showRegionDetails(HttpServletRequest request, HttpServletResponse response) { - String cacheName = request.getParameter("cacheName"); + String cacheName = request.getParameter(CACHE_NAME); ObjectMapper mapper = new ObjectMapper(); try { String details = getRegionStats(cacheName); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(details)); JSONObject j = new JSONObject(msg); - response.setContentType("application/json"); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write(j.toString()); } catch (Exception e) { @@ -163,9 +167,9 @@ public class CacheAdminController extends RestrictedBaseController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); for (CacheRegionInfo cri : regions) { - if (cri.getCache().getCacheName() != null && !cri.getCache().getCacheName().equals("[object Object]")) { + if (cri.getCache().getCacheName() != null && !"[object Object]".equals(cri.getCache().getCacheName())) { JSONObject jo = new JSONObject(); - jo.put("cacheName", cri.getCache().getCacheName()); + jo.put(CACHE_NAME, cri.getCache().getCacheName()); jo.put("size", cri.getCache().getSize()); jo.put("byteCount", cri.getByteCount()); jo.put("status", cri.getStatus()); @@ -187,11 +191,10 @@ public class CacheAdminController extends RestrictedBaseController { private String getRegionStats(String cacheName) throws CacheException { JCS cache = JCS.getInstance(cacheName); - String stats = cache.getStats(); - return stats; + return cache.getStats(); } - private String getItemDetails(String cacheName, String keyName) throws Exception { + private String getItemDetails(String cacheName, String keyName) throws CacheException,JsonProcessingException { JCS cache = JCS.getInstance(cacheName); ICacheElement element = cache.getCacheElement(keyName); diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FnMenuController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FnMenuController.java index e4c862fd..8f49b640 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FnMenuController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FnMenuController.java @@ -74,35 +74,35 @@ public class FnMenuController extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnMenuController.class); + private static final String UTF8 = "UTF-8"; + @Autowired FnMenuService service; @Autowired FunctionalMenuListService functionalMenuListService; - private String viewName; - @RequestMapping(value = { "/admin_fn_menu/get_parent_list" }, method = RequestMethod.GET) - public void getParentList(HttpServletRequest request, HttpServletResponse response) throws Exception { + public void getParentList(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException { ObjectMapper mapper = new ObjectMapper(); try { response.getWriter().write(mapper.writeValueAsString(service.getParentList())); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getParentListFailed", e); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred in the getParentList () "); } } @RequestMapping(value = { "/admin_fn_menu/get_function_cd_list" }, method = RequestMethod.GET) - public void getFunctionCDList(HttpServletRequest request, HttpServletResponse response) throws Exception { + public void getFunctionCDList(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException { ObjectMapper mapper = new ObjectMapper(); try { response.getWriter().write(mapper.writeValueAsString(functionalMenuListService.getFunctionCDList(request))); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getFunctionCDList", e); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred in the getFunctionCDList ()"); } @@ -153,7 +153,8 @@ public class FnMenuController extends RestrictedBaseController { } @RequestMapping(value = { "/admin_fn_menu/updateFnMenu" }, method = RequestMethod.POST) - public ModelAndView updateFnMenu(HttpServletRequest request, HttpServletResponse response) throws Exception { + public ModelAndView updateFnMenu(HttpServletRequest request, HttpServletResponse response) + throws java.io.IOException, java.io.UnsupportedEncodingException { try { ObjectMapper mapper = new ObjectMapper(); @@ -166,9 +167,9 @@ public class FnMenuController extends RestrictedBaseController { request.getSession().removeAttribute(SystemProperties.LEFT_MENU_CHILDREND); request.getSession().removeAttribute(SystemProperties.LEFT_MENU_PARENT); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(service.getMenuItem(fnMenuItem.getId())); @@ -179,8 +180,8 @@ public class FnMenuController extends RestrictedBaseController { } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "updateFnMenu failed", e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred in the updateFnMenu () "); } @@ -189,7 +190,8 @@ public class FnMenuController extends RestrictedBaseController { } @RequestMapping(value = { "/admin_fn_menu/removeMenuItem" }, method = RequestMethod.POST) - public ModelAndView removeFnMenu(HttpServletRequest request, HttpServletResponse response) throws Exception { + public ModelAndView removeFnMenu(HttpServletRequest request, HttpServletResponse response) + throws java.io.IOException, java.io.UnsupportedEncodingException { try { ObjectMapper mapper = new ObjectMapper(); @@ -198,9 +200,9 @@ public class FnMenuController extends RestrictedBaseController { Menu fnMenuItem = mapper.readValue(root.get("fnMenuItem").toString(), Menu.class); Menu fnMenuItemRow = service.getMenuItemRow(fnMenuItem.getId()); service.removeMenuItem(fnMenuItemRow); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(service.getMenuItem(fnMenuItem.getId())); out.write(responseString); @@ -209,8 +211,8 @@ public class FnMenuController extends RestrictedBaseController { } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "removeFnMenu failed", e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred in the removeFnMenu ()"); } |