diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-common')
7 files changed, 176 insertions, 171 deletions
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<String, Object> 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<String, Object> 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); diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java index c7edfb81..24ea203f 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/ProfileController.java @@ -75,6 +75,17 @@ public class ProfileController extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ProfileController.class); + private static final String PROFILE_ID = "profile_id"; + private static final String PROFILEID = "profileId"; + private static final String STATE_LIST = "stateList"; + private static final String COUNTRIES = "countries"; + private static final String TIME_ZONES = "timeZones"; + private static final String AVAILABLE_ROLES= "availableRoles"; + private static final String PROFILE = "profile"; + private static final String PROFILE_CONTAINER = "ProfileController.save"; + private static final String UTF8 = "UTF-8"; + private static final String APPLICATION_JSON = "application / json"; + @Autowired private UserProfileService service; @@ -83,8 +94,6 @@ public class ProfileController extends RestrictedBaseController { @Autowired private RoleService roleService; - - private String viewName; @RequestMapping(value = { "/profile" }, method = RequestMethod.GET) public ModelAndView profile(HttpServletRequest request) throws IOException { @@ -98,25 +107,25 @@ public class ProfileController extends RestrictedBaseController { profile = UserUtils.getUserSession(request); profileId = profile.getId(); } else { - profileId = Long.parseLong(request.getParameter("profile_id")); + profileId = Long.parseLong(request.getParameter(PROFILE_ID)); profile = userService.getUser(String.valueOf(profileId)); } try { - model.put("stateList", mapper.writeValueAsString(getStates())); - model.put("countries", mapper.writeValueAsString(getCountries())); - model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); - model.put("profile", mapper.writeValueAsString(profile)); - model.put("profileId", mapper.writeValueAsString(profileId)); + model.put(STATE_LIST, mapper.writeValueAsString(getStates())); + model.put(COUNTRIES, mapper.writeValueAsString(getCountries())); + model.put(TIME_ZONES, mapper.writeValueAsString(getTimeZones())); + model.put(AVAILABLE_ROLES, mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); + model.put(PROFILE, mapper.writeValueAsString(profile)); + model.put(PROFILEID, mapper.writeValueAsString(profileId)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "profile: failed to write JSON", e); } - return new ModelAndView("profile", "model", model); + return new ModelAndView(PROFILE, "model", model); } @RequestMapping(value = { "/self_profile" }, method = RequestMethod.GET) - public ModelAndView selfProfile(HttpServletRequest request) throws Exception{ + public ModelAndView selfProfile(HttpServletRequest request) { Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -124,16 +133,16 @@ public class ProfileController extends RestrictedBaseController { User user = UserUtils.getUserSession(request); User profile = UserUtils.getUserSession(request); try { - model.put("stateList", mapper.writeValueAsString(getStates())); - model.put("countries", mapper.writeValueAsString(getCountries())); - model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); - model.put("profile", mapper.writeValueAsString(profile)); - model.put("profileId", mapper.writeValueAsString(profileId)); + model.put(STATE_LIST, mapper.writeValueAsString(getStates())); + model.put(COUNTRIES, mapper.writeValueAsString(getCountries())); + model.put(TIME_ZONES, mapper.writeValueAsString(getTimeZones())); + model.put(AVAILABLE_ROLES, mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); + model.put(PROFILE, mapper.writeValueAsString(profile)); + model.put(PROFILEID, mapper.writeValueAsString(profileId)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "self_profile: failed to write JSON", e); } - return new ModelAndView("profile", "model", model); + return new ModelAndView(PROFILE, "model", model); } @RequestMapping(value = { "/get_self_profile" }, method = RequestMethod.GET) @@ -145,12 +154,12 @@ public class ProfileController extends RestrictedBaseController { Long profileId = null; User profile = UserUtils.getUserSession(request); try { - model.put("stateList", mapper.writeValueAsString(getStates())); - model.put("countries", mapper.writeValueAsString(getCountries())); - model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); - model.put("profile", mapper.writeValueAsString(profile)); - model.put("profileId", mapper.writeValueAsString(profileId)); + model.put(STATE_LIST, mapper.writeValueAsString(getStates())); + model.put(COUNTRIES, mapper.writeValueAsString(getCountries())); + model.put(TIME_ZONES, mapper.writeValueAsString(getTimeZones())); + model.put(AVAILABLE_ROLES, mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); + model.put(PROFILE, mapper.writeValueAsString(profile)); + model.put(PROFILEID, mapper.writeValueAsString(profileId)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -172,15 +181,15 @@ public class ProfileController extends RestrictedBaseController { profile = UserUtils.getUserSession(request); profileId = profile.getId(); } else { - profileId = Long.parseLong(request.getParameter("profile_id")); + profileId = Long.parseLong(request.getParameter(PROFILE_ID)); profile = userService.getUser(String.valueOf(profileId)); } - model.put("stateList", mapper.writeValueAsString(getStates())); - model.put("countries", mapper.writeValueAsString(getCountries())); - model.put("timeZones", mapper.writeValueAsString(getTimeZones())); - model.put("availableRoles", mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); - model.put("profile", mapper.writeValueAsString(profile)); - model.put("profileId", mapper.writeValueAsString(profileId)); + model.put(STATE_LIST, mapper.writeValueAsString(getStates())); + model.put(COUNTRIES, mapper.writeValueAsString(getCountries())); + model.put(TIME_ZONES, mapper.writeValueAsString(getTimeZones())); + model.put(AVAILABLE_ROLES, mapper.writeValueAsString(getAvailableRoles(user.getOrgUserId()))); + model.put(PROFILE, mapper.writeValueAsString(profile)); + model.put(PROFILEID, mapper.writeValueAsString(profileId)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -192,41 +201,41 @@ public class ProfileController extends RestrictedBaseController { @RequestMapping(value = { "/profile/saveProfile" }, method = RequestMethod.POST) public ModelAndView saveProfile(HttpServletRequest request, HttpServletResponse response) { - logger.info(EELFLoggerDelegate.debugLogger, "ProfileController.save"); + logger.info(EELFLoggerDelegate.debugLogger, PROFILE_CONTAINER); try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - User user = mapper.readValue(root.get("profile").toString(), User.class); + User user = mapper.readValue(root.get(PROFILE).toString(), User.class); String selectedCountry = mapper.readValue(root.get("selectedCountry").toString(), String.class); String selectedState = mapper.readValue(root.get("selectedState").toString(), String.class); String selectedTimeZone = mapper.readValue(root.get("selectedTimeZone").toString(), String.class); - Long profileId = Long.parseLong(request.getParameter("profile_id")); + Long profileId = Long.parseLong(request.getParameter(PROFILE_ID)); - User domainUser = (User) userService.getUser(String.valueOf(profileId)); + User domainUser = userService.getUser(String.valueOf(profileId)); user.setPseudoRoles(domainUser.getPseudoRoles()); user.setUserApps(domainUser.getUserApps()); - if (!selectedCountry.equals("")) { + if (!selectedCountry.isEmpty()) { user.setCountry(selectedCountry); } - if (!selectedState.equals("")) { + if (!selectedState.isEmpty()) { user.setState(selectedState); } - if (!selectedTimeZone.equals("")) { + if (!selectedTimeZone.isEmpty()) { user.setTimeZoneId(Long.parseLong(selectedTimeZone)); } service.saveUser(user); logger.info(EELFLoggerDelegate.auditLogger, "Save profile for user {}", profileId); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); + response.setCharacterEncoding(UTF8); + response.setContentType(APPLICATION_JSON); PrintWriter out = response.getWriter(); out.write("" + profileId); return null; } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "saveProfile failed", e); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); try { PrintWriter out = response.getWriter(); out.write("An error occurred in the saveProfile ()"); @@ -240,7 +249,7 @@ public class ProfileController extends RestrictedBaseController { @RequestMapping(value = { "/profile/removeRole" }, method = RequestMethod.POST) public ModelAndView removeRole(HttpServletRequest request, HttpServletResponse response) throws IOException { - logger.info(EELFLoggerDelegate.debugLogger, "ProfileController.save"); + logger.info(EELFLoggerDelegate.debugLogger, PROFILE_CONTAINER); try { ObjectMapper mapper = new ObjectMapper(); @@ -248,7 +257,7 @@ public class ProfileController extends RestrictedBaseController { JsonNode root = mapper.readTree(request.getReader()); Role role = mapper.readValue(root.get("role").toString(), Role.class); - String profileId = request.getParameter("profile_id"); + String profileId = request.getParameter(PROFILE_ID); User domainUser = userService.getUser(profileId); @@ -262,14 +271,14 @@ public class ProfileController extends RestrictedBaseController { } logger.info(EELFLoggerDelegate.auditLogger, "Remove role " + role.getId() + " from user " + profileId); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + response.setContentType(APPLICATION_JSON); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); Map<String, Object> model = new HashMap<>(); - model.put("profile", mapper.writeValueAsString(domainUser)); + model.put(PROFILE, mapper.writeValueAsString(domainUser)); JSONObject j = new JSONObject(mapper.writeValueAsString(domainUser)); out.write(j.toString()); @@ -277,7 +286,7 @@ public class ProfileController extends RestrictedBaseController { return null; } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "removeRole failed", e); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred in the removeRole ()"); return null; @@ -287,14 +296,14 @@ public class ProfileController extends RestrictedBaseController { @RequestMapping(value = { "/profile/addNewRole" }, method = RequestMethod.POST) public ModelAndView addNewRole(HttpServletRequest request, HttpServletResponse response) throws IOException { - logger.info(EELFLoggerDelegate.debugLogger, "ProfileController.save" ); + logger.info(EELFLoggerDelegate.debugLogger, PROFILE_CONTAINER ); try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); Role role = mapper.readValue(root.get("role").toString(), Role.class); - String profileId = request.getParameter("profile_id"); + String profileId = request.getParameter(PROFILE_ID); User domainUser = userService.getUser(profileId); domainUser.addRole(role); service.saveUser(domainUser); @@ -305,13 +314,13 @@ public class ProfileController extends RestrictedBaseController { } logger.info(EELFLoggerDelegate.auditLogger, "Add new role " + role.getName() + " to user " + profileId); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + response.setContentType(APPLICATION_JSON); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); Map<String, Object> model = new HashMap<>(); - model.put("profile", mapper.writeValueAsString(domainUser)); + model.put(PROFILE, mapper.writeValueAsString(domainUser)); JSONObject j = new JSONObject(mapper.writeValueAsString(domainUser)); out.write(j.toString()); @@ -319,8 +328,8 @@ public class ProfileController extends RestrictedBaseController { return null; } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "addNewRole 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 addNewRole ()"); return null; @@ -328,16 +337,6 @@ public class ProfileController extends RestrictedBaseController { } - @Override - public String getViewName() { - return viewName; - } - - @Override - public void setViewName(String viewName) { - this.viewName = viewName; - } - @SuppressWarnings("rawtypes") public List getStates() { return AppUtils.getLookupList("FN_LU_STATE", "STATE_CD", "STATE", null, "STATE_CD"); @@ -358,4 +357,13 @@ public class ProfileController extends RestrictedBaseController { return roleService.getAvailableRoles(requestedLoginId); } + @Override + public String getViewName() { + return viewName; + } + + @Override + public void setViewName(String viewName) { + this.viewName = viewName; + } }
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java index 52dedd46..d555ba46 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/RoleController.java @@ -84,8 +84,6 @@ public class RoleController extends RestrictedBaseController { @Autowired private RoleService roleService; - private String viewName; - @RequestMapping(value = { "/role" }, method = RequestMethod.GET) public ModelAndView role(HttpServletRequest request) throws IOException { Map<String, Object> model = new HashMap<>(); @@ -133,6 +131,14 @@ public class RoleController extends RestrictedBaseController { } + private void trowIfUserRoleExist(String roleName, String userId) throws IOException, SecurityException + { + List<Role> roles = roleService.getAvailableRoles(userId); + for (Role existRole : roles) + if (existRole.getName().equalsIgnoreCase(roleName)) + throw new SecurityException("role already exists: " + existRole.getName()); + } + /** * Creates a new role or updates an existing role. * @@ -167,11 +173,8 @@ public class RoleController extends RestrictedBaseController { domainRole.setPriority(role.getPriority()); } else { doAuditLog("saveRole: creating new role", role.getName()); - // check for existing role of same name - List<Role> roles = roleService.getAvailableRoles(user.getOrgUserId()); - for (Role existRole : roles) - if (existRole.getName().equalsIgnoreCase(role.getName())) - throw new Exception("role already exists: " + existRole.getName()); + + trowIfUserRoleExist(role.getName(),user.getOrgUserId()); domainRole = new Role(); domainRole.setName(role.getName()); @@ -371,13 +374,12 @@ public class RoleController extends RestrictedBaseController { } @Override - public String getViewName() { - return viewName; - } - - @Override - public void setViewName(String viewName) { - this.viewName = viewName; - } - + public String getViewName() { + return viewName; + } + + @Override + public void setViewName(String viewName) { + this.viewName = viewName; + } } diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java index 681702bf..04c1f2bc 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/UsageListController.java @@ -65,6 +65,31 @@ public class UsageListController extends RestrictedBaseController { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UsageListController.class); + private void addUsers2jsonArray(JSONArray ja,HashMap activeUsers,String httpSessionId) + { + List<UserRowBean> rows = UsageUtils.getActiveUsers(activeUsers); + for (UserRowBean userRowBean : rows) + ja.put(userRowBean2json(userRowBean,httpSessionId)); + } + + private JSONObject userRowBean2json(UserRowBean userRowBean,String httpSessionId) + { + JSONObject jo = new JSONObject(); + jo.put("id", userRowBean.getId()); + jo.put("lastName", userRowBean.getLastName()); + jo.put("email", userRowBean.getEmail()); + jo.put("lastAccess", userRowBean.getLastAccess()); + jo.put("remaining", userRowBean.getRemaining()); + jo.put("sessionId", userRowBean.getSessionId()); + if (!httpSessionId.equals(userRowBean.getSessionId())) { + jo.put("delete", "yes"); + } else { + jo.put("delete", "no"); + } + + return jo; + } + @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(value = { "/usage_list" }, method = RequestMethod.GET) public ModelAndView usageList(HttpServletRequest request) { @@ -76,24 +101,10 @@ public class UsageListController extends RestrictedBaseController { activeUsers.put(httpSession.getId(), httpSession); httpSession.getServletContext().setAttribute("activeUsers", activeUsers); } - List<UserRowBean> rows = UsageUtils.getActiveUsers(activeUsers); + JSONArray ja = new JSONArray(); try { - for (UserRowBean userRowBean : rows) { - JSONObject jo = new JSONObject(); - jo.put("id", userRowBean.getId()); - jo.put("lastName", userRowBean.getLastName()); - jo.put("email", userRowBean.getEmail()); - jo.put("lastAccess", userRowBean.getLastAccess()); - jo.put("remaining", userRowBean.getRemaining()); - jo.put("sessionId", userRowBean.getSessionId()); - if (!(httpSession.getId().equals(userRowBean.getSessionId()))) { - jo.put("delete", "yes"); - } else { - jo.put("delete", "no"); - } - ja.put(jo); - } + addUsers2jsonArray(ja,activeUsers,httpSession.getId()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "usageList failed", e); } @@ -113,24 +124,9 @@ public class UsageListController extends RestrictedBaseController { activeUsers.put(httpSession.getId(), httpSession); httpSession.getServletContext().setAttribute("activeUsers", activeUsers); } - List<UserRowBean> rows = UsageUtils.getActiveUsers(activeUsers); JSONArray ja = new JSONArray(); try { - for (UserRowBean userRowBean : rows) { - JSONObject jo = new JSONObject(); - jo.put("id", userRowBean.getId()); - jo.put("lastName", userRowBean.getLastName()); - jo.put("email", userRowBean.getEmail()); - jo.put("lastAccess", userRowBean.getLastAccess()); - jo.put("remaining", userRowBean.getRemaining()); - jo.put("sessionId", userRowBean.getSessionId()); - if (!(httpSession.getId().equals(userRowBean.getSessionId()))) { - jo.put("delete", "yes"); - } else { - jo.put("delete", "no"); - } - ja.put(jo); - } + addUsers2jsonArray(ja,activeUsers,httpSession.getId()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "getUsageList failed", e); } @@ -154,24 +150,9 @@ public class UsageListController extends RestrictedBaseController { UsageUtils.getActiveUsersAfterDelete(activeUsers, data); HttpSession httpSession = request.getSession(); - List<UserRowBean> rows = UsageUtils.getActiveUsers(activeUsers); JSONArray ja = new JSONArray(); try { - for (UserRowBean userRowBean : rows) { - JSONObject jo = new JSONObject(); - jo.put("id", userRowBean.getId()); - jo.put("lastName", userRowBean.getLastName()); - jo.put("email", userRowBean.getEmail()); - jo.put("lastAccess", userRowBean.getLastAccess()); - jo.put("remaining", userRowBean.getRemaining()); - jo.put("sessionId", userRowBean.getSessionId()); - if (!(httpSession.getId().equals(userRowBean.getSessionId()))) { - jo.put("delete", "yes"); - } else { - jo.put("delete", "no"); - } - ja.put(jo); - } + addUsers2jsonArray(ja,activeUsers,httpSession.getId()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "removeSession failed", e); } diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java index ba90f46f..600deeb3 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastController.java @@ -37,7 +37,9 @@ */ package org.onap.portalapp.controller.sample; +import java.io.IOException; import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; @@ -67,6 +69,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class BroadcastController extends RestrictedBaseController { private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(BroadcastController.class); + + private static final String BROADCAST_MESSAGE = "broadcastMessage"; + private static final String BROADCAST_SITIES = "broadcastSites"; + private static final String UTF8 = "UTF-8"; @Autowired private BroadcastService broadcastService; @@ -77,8 +83,8 @@ public class BroadcastController extends RestrictedBaseController { ObjectMapper mapper = new ObjectMapper(); try { - model.put("broadcastMessage", mapper.writeValueAsString(broadcastService.getBroadcastMessage(request))); - model.put("broadcastSites", mapper.writeValueAsString(referenceData(request).get("broadcastSites"))); + model.put(BROADCAST_MESSAGE, mapper.writeValueAsString(broadcastService.getBroadcastMessage(request))); + model.put(BROADCAST_SITIES, mapper.writeValueAsString(referenceData(request).get(BROADCAST_SITIES))); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "broadcast() failed", e); } @@ -92,8 +98,8 @@ public class BroadcastController extends RestrictedBaseController { try { - model.put("broadcastMessage", mapper.writeValueAsString(broadcastService.getBroadcastMessage(request))); - model.put("broadcastSites", mapper.writeValueAsString(referenceData(request).get("broadcastSites"))); + model.put(BROADCAST_MESSAGE, mapper.writeValueAsString(broadcastService.getBroadcastMessage(request))); + model.put(BROADCAST_SITIES, mapper.writeValueAsString(referenceData(request).get(BROADCAST_SITIES))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -109,7 +115,7 @@ public class BroadcastController extends RestrictedBaseController { Map lookupData = new HashMap(); if ("true".equals(SystemProperties.getProperty(SystemProperties.CLUSTERED))) { - lookupData.put("broadcastSites", AppUtils.getLookupList("fn_lu_broadcast_site", "broadcast_site_cd", + lookupData.put(BROADCAST_SITIES, AppUtils.getLookupList("fn_lu_broadcast_site", "broadcast_site_cd", "broadcast_site_descr", "", "broadcast_site_descr")); } @@ -117,21 +123,21 @@ public class BroadcastController extends RestrictedBaseController { } @RequestMapping(value = { "/broadcast/save" }, method = RequestMethod.POST) - public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws Exception { + public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws IOException { try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - BroadcastMessage broadcastMessage = mapper.readValue(root.get("broadcastMessage").toString(), + BroadcastMessage broadcastMessage = mapper.readValue(root.get(BROADCAST_MESSAGE).toString(), BroadcastMessage.class); broadcastService.saveBroadcastMessage(broadcastMessage); - 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(broadcastMessage); @@ -141,8 +147,8 @@ public class BroadcastController extends RestrictedBaseController { return null; } catch (Exception e) { - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred while saving the BroadcastMessage in the save () mapping-/broadcast/save "); logger.error(EELFLoggerDelegate.errorLogger, "save() failed", e); diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java index 8b740d0b..c9c666fb 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/BroadcastListController.java @@ -37,6 +37,7 @@ */ package org.onap.portalapp.controller.sample; +import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; @@ -65,6 +66,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class BroadcastListController extends RestrictedBaseController { private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(BroadcastListController.class); + private static final String UTF8 = "UTF-8"; + @Autowired private BroadcastService broadcastService; @@ -78,7 +81,7 @@ public class BroadcastListController extends RestrictedBaseController { @RequestMapping(value = { "/get_broadcast_list" }, method = RequestMethod.GET) public void getBroadcast(HttpServletRequest request, HttpServletResponse response) { - Map<String, Object> model = new HashMap<String, Object>(); + Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); try { model.put("model", broadcastService.getBcModel(request)); @@ -94,7 +97,7 @@ public class BroadcastListController extends RestrictedBaseController { } @RequestMapping(value = { "/broadcast_list/remove" }, method = RequestMethod.POST) - public ModelAndView remove(HttpServletRequest request, HttpServletResponse response) throws Exception { + public ModelAndView remove(HttpServletRequest request, HttpServletResponse response) throws IOException { try { @@ -106,9 +109,9 @@ public class BroadcastListController extends RestrictedBaseController { broadcastService.removeBroadcastMessage(broadcastMessage); - 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(broadcastMessage); @@ -118,8 +121,8 @@ public class BroadcastListController extends RestrictedBaseController { return null; } catch (Exception e) { - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred while removing the BroadcastMessage in the remove ()"); logger.error(EELFLoggerDelegate.errorLogger, "remove() failed", e); @@ -129,7 +132,7 @@ public class BroadcastListController extends RestrictedBaseController { } @RequestMapping(value = { "/broadcast_list/toggleActive" }, method = RequestMethod.POST) - public ModelAndView toggleActive(HttpServletRequest request, HttpServletResponse response) throws Exception { + public ModelAndView toggleActive(HttpServletRequest request, HttpServletResponse response) throws IOException { try { @@ -141,9 +144,9 @@ public class BroadcastListController extends RestrictedBaseController { broadcastService.saveBroadcastMessage(broadcastMessage); - 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(broadcastMessage); @@ -153,8 +156,8 @@ public class BroadcastListController extends RestrictedBaseController { return null; } catch (Exception e) { - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF8); + request.setCharacterEncoding(UTF8); PrintWriter out = response.getWriter(); out.write("An error occurred while saving the BroadcastMessage in the toggleActive () "); logger.error(EELFLoggerDelegate.errorLogger, "toggleActive() failed", e); diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/CamundaCockpitController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/CamundaCockpitController.java index c43b4acc..4c32b964 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/CamundaCockpitController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/sample/CamundaCockpitController.java @@ -59,20 +59,22 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/") -public class CamundaCockpitController extends RestrictedBaseController { +public class CamundaCockpitController extends RestrictedBaseController { + + private static final String CAMUNDA_COCKPIT_LINK = "camunda_cockpit_link"; @SuppressWarnings("rawtypes") @RequestMapping(value = {"/get_camunda_cockpit_link" }, method = RequestMethod.GET, produces = "application/json") @ResponseBody public Map getCamundaCockpitLink(HttpServletRequest request,HttpServletResponse response) { - Map<String,String> map = new HashMap<String,String>(); + Map<String,String> map = new HashMap<>(); String camundaCockpitUrl = ""; String camundaCockpitlinkDefined = "false"; - if (SystemProperties.containsProperty("camunda_cockpit_link")){ - camundaCockpitUrl = SystemProperties.getProperty("camunda_cockpit_link"); + if (SystemProperties.containsProperty(CAMUNDA_COCKPIT_LINK)){ + camundaCockpitUrl = SystemProperties.getProperty(CAMUNDA_COCKPIT_LINK); camundaCockpitlinkDefined = "true"; }; map.put("link_defined", camundaCockpitlinkDefined); - map.put("camunda_cockpit_link", camundaCockpitUrl); + map.put(CAMUNDA_COCKPIT_LINK, camundaCockpitUrl); return map; }; } |