From 20c3adbd42446e088a44469f57123778286e0b97 Mon Sep 17 00:00:00 2001 From: burdziak Date: Mon, 18 Mar 2019 13:33:40 +0100 Subject: Solve sonar issues Change-Id: I5da7e2eebd496086d72bb6a96b229e34ac8a004e Issue-ID: PORTAL-523 Signed-off-by: burdziak --- .../controller/core/PostSearchController.java | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'ecomp-sdk/epsdk-app-common/src') diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/PostSearchController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/PostSearchController.java index d5137c2c..a8c3a5d6 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/PostSearchController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/PostSearchController.java @@ -78,6 +78,9 @@ public class PostSearchController extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PostSearchController.class); + private static final String POST_SEARCH_BEAN = "postSearchBean"; + private static final String UTF8 = "UTF-8"; + @SuppressWarnings("rawtypes") private static List sortByList = null; @@ -91,13 +94,13 @@ public class PostSearchController extends RestrictedBaseController { private ProfileService profileService; @RequestMapping(value = { "/post_search" }, method = RequestMethod.GET) - public ModelAndView welcome(@ModelAttribute("postSearchBean") PostSearchBean postSearchBean) { + public ModelAndView welcome(@ModelAttribute(POST_SEARCH_BEAN) PostSearchBean postSearchBean) { Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); try { - postSearchBean = new PostSearchBean(); - model.put("profileList", mapper.writeValueAsString(postSearchBean.getSearchResult())); - model.put("postSearchBean", mapper.writeValueAsString(postSearchBean)); + PostSearchBean postSearchBeanLocal = new PostSearchBean(); + model.put("profileList", mapper.writeValueAsString(postSearchBeanLocal.getSearchResult())); + model.put(POST_SEARCH_BEAN, mapper.writeValueAsString(postSearchBeanLocal)); model.put("existingUsers", mapper.writeValueAsString(getExistingUsers())); model.put("sortByList", mapper.writeValueAsString(getSortByList())); } catch (Exception ex) { @@ -109,13 +112,13 @@ public class PostSearchController extends RestrictedBaseController { @RequestMapping(value = { "/post_search_sample" }, method = RequestMethod.GET) public void getPostSearchProfile(HttpServletResponse response, - @ModelAttribute("postSearchBean") PostSearchBean postSearchBean) { + @ModelAttribute(POST_SEARCH_BEAN) PostSearchBean postSearchBean) { Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); try { - postSearchBean = new PostSearchBean(); - model.put("profileList", mapper.writeValueAsString(postSearchBean.getSearchResult())); - model.put("postSearchBean", mapper.writeValueAsString(postSearchBean)); + PostSearchBean postSearchBeanLocal = new PostSearchBean(); + model.put("profileList", mapper.writeValueAsString(postSearchBeanLocal.getSearchResult())); + model.put(POST_SEARCH_BEAN, mapper.writeValueAsString(postSearchBeanLocal)); model.put("existingUsers", mapper.writeValueAsString(getExistingUsers())); model.put("sortByList", mapper.writeValueAsString(getSortByList())); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); @@ -152,14 +155,14 @@ public class PostSearchController extends RestrictedBaseController { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - PostSearchBean postSearchBean = mapper.readValue(root.get("postSearchBean").toString(), + PostSearchBean postSearchBean = mapper.readValue(root.get(POST_SEARCH_BEAN).toString(), PostSearchBean.class); postSearchBean.setSearchResult(loadSearchResultData(request, postSearchBean)); - 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(postSearchBean); @@ -201,7 +204,7 @@ public class PostSearchController extends RestrictedBaseController { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); JsonNode root = mapper.readTree(request.getReader()); - PostSearchBean postSearch = mapper.readValue(root.get("postSearchBean").toString(), PostSearchBean.class); + PostSearchBean postSearch = mapper.readValue(root.get(POST_SEARCH_BEAN).toString(), PostSearchBean.class); String errorMsg = "{}"; try { postSearchService.process(request, postSearch); @@ -212,9 +215,9 @@ public class PostSearchController extends RestrictedBaseController { "Exception occurred while performing PostSearchController.process. Details:", e); } logger.info(EELFLoggerDelegate.auditLogger, "Import new user from webphone "); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); String postSearchString = mapper.writeValueAsString(postSearch); -- cgit 1.2.3-korg