@Test public void getDashboardConfig() throws Exception { String ipAddress = "ipAddress"; String userId = "ann-acm"; String dashboardConfig = "TEST"; AcmUser user = new AcmUser(); user.setUserId(userId); DashboardDto returned = new DashboardDto(); returned.setUserId(userId); returned.setDashboardConfig(dashboardConfig); Dashboard ret = new Dashboard(); ret.setDashboardOwner(user); ret.setDashboardConfig(dashboardConfig); List<String> retList = new ArrayList<>(); retList.add(DashboardConstants.DASHBOARD_MODULE_NAME); mockHttpSession.setAttribute("acm_ip_address", ipAddress); Map<String, Object> prop = new HashMap<>(); prop.put("key", "value"); expect(mockDashboardPropertyReader.getModuleNameList()).andReturn(retList); expect(mockDashboardService.getDashboardConfigForUserAndModuleName(user, DashboardConstants.DASHBOARD_MODULE_NAME)).andReturn(ret); expect(mockDashboardService.getUserByUserId(userId)).andReturn(user); expect(mockDashboardService.prepareDashboardDto(ret, false, DashboardConstants.DASHBOARD_MODULE_NAME)).andReturn(returned); expect(mockAuthentication.getName()).andReturn("ann-acm").atLeastOnce(); replayAll(); MvcResult result = mockMvc.perform( get("/api/v1/plugin/dashboard/get") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .session(mockHttpSession) .principal(mockAuthentication)) .andReturn(); verifyAll(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertTrue(result.getResponse().getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)); String json = result.getResponse().getContentAsString(); log.info("results: " + json); DashboardDto fromJson = new ObjectMapper().readValue(json, DashboardDto.class); assertNotNull(fromJson); assertEquals(returned.getDashboardConfig(), fromJson.getDashboardConfig()); }
@RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public DashboardDto getDashboardConfig( @RequestParam(value = "moduleName", required = false, defaultValue = "DASHBOARD") String moduleName, Authentication authentication) throws AcmDashboardException, AcmObjectNotFoundException { String userId = authentication.getName(); log.info("Finding dashboard configuration for user: [{}]", userId); AcmUser owner = dashboardService.getUserByUserId(userId); if (owner == null) { throw new AcmObjectNotFoundException("user", null, "Object not found", null); } Dashboard retval = null; DashboardDto dashboardDto; boolean inserted = false; try { List<String> modules = dashboardPropertyReader.getModuleNameList(); if (!modules.contains(moduleName.trim())) { throw new AcmDashboardException("Module name:" + moduleName + " does not exist"); } retval = dashboardService.getDashboardConfigForUserAndModuleName(owner, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } catch (AcmObjectNotFoundException e) { if (dashboardPropertyReader.getModuleNameList().contains(moduleName)) { if (retval == null) { retval = dashboardService.createDefaultModuleDashboard(owner, moduleName); inserted = true; getEventPublisher().publishDashboardEvent(retval, authentication, true, true); } log.info("Module dashboard config for user [{}] and module [{}] is inserted into the DB", userId, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } else { log.warn("Module dashboard config for user: [{}] and module: [{}] NOT inserted into the DB, the moduleName does NOT exists", userId, moduleName, moduleName, e); throw e; } } catch (Exception e1) { log.error("Exception occurred while raising an event or while reading values from fetched DB dashboard ", e1); throw new AcmDashboardException("Get dashboard exception", e1); } }
GetDashboardConfigAPIController { @RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public DashboardDto getDashboardConfig( @RequestParam(value = "moduleName", required = false, defaultValue = "DASHBOARD") String moduleName, Authentication authentication) throws AcmDashboardException, AcmObjectNotFoundException { String userId = authentication.getName(); log.info("Finding dashboard configuration for user: [{}]", userId); AcmUser owner = dashboardService.getUserByUserId(userId); if (owner == null) { throw new AcmObjectNotFoundException("user", null, "Object not found", null); } Dashboard retval = null; DashboardDto dashboardDto; boolean inserted = false; try { List<String> modules = dashboardPropertyReader.getModuleNameList(); if (!modules.contains(moduleName.trim())) { throw new AcmDashboardException("Module name:" + moduleName + " does not exist"); } retval = dashboardService.getDashboardConfigForUserAndModuleName(owner, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } catch (AcmObjectNotFoundException e) { if (dashboardPropertyReader.getModuleNameList().contains(moduleName)) { if (retval == null) { retval = dashboardService.createDefaultModuleDashboard(owner, moduleName); inserted = true; getEventPublisher().publishDashboardEvent(retval, authentication, true, true); } log.info("Module dashboard config for user [{}] and module [{}] is inserted into the DB", userId, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } else { log.warn("Module dashboard config for user: [{}] and module: [{}] NOT inserted into the DB, the moduleName does NOT exists", userId, moduleName, moduleName, e); throw e; } } catch (Exception e1) { log.error("Exception occurred while raising an event or while reading values from fetched DB dashboard ", e1); throw new AcmDashboardException("Get dashboard exception", e1); } } }
GetDashboardConfigAPIController { @RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public DashboardDto getDashboardConfig( @RequestParam(value = "moduleName", required = false, defaultValue = "DASHBOARD") String moduleName, Authentication authentication) throws AcmDashboardException, AcmObjectNotFoundException { String userId = authentication.getName(); log.info("Finding dashboard configuration for user: [{}]", userId); AcmUser owner = dashboardService.getUserByUserId(userId); if (owner == null) { throw new AcmObjectNotFoundException("user", null, "Object not found", null); } Dashboard retval = null; DashboardDto dashboardDto; boolean inserted = false; try { List<String> modules = dashboardPropertyReader.getModuleNameList(); if (!modules.contains(moduleName.trim())) { throw new AcmDashboardException("Module name:" + moduleName + " does not exist"); } retval = dashboardService.getDashboardConfigForUserAndModuleName(owner, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } catch (AcmObjectNotFoundException e) { if (dashboardPropertyReader.getModuleNameList().contains(moduleName)) { if (retval == null) { retval = dashboardService.createDefaultModuleDashboard(owner, moduleName); inserted = true; getEventPublisher().publishDashboardEvent(retval, authentication, true, true); } log.info("Module dashboard config for user [{}] and module [{}] is inserted into the DB", userId, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } else { log.warn("Module dashboard config for user: [{}] and module: [{}] NOT inserted into the DB, the moduleName does NOT exists", userId, moduleName, moduleName, e); throw e; } } catch (Exception e1) { log.error("Exception occurred while raising an event or while reading values from fetched DB dashboard ", e1); throw new AcmDashboardException("Get dashboard exception", e1); } }  }
GetDashboardConfigAPIController { @RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public DashboardDto getDashboardConfig( @RequestParam(value = "moduleName", required = false, defaultValue = "DASHBOARD") String moduleName, Authentication authentication) throws AcmDashboardException, AcmObjectNotFoundException { String userId = authentication.getName(); log.info("Finding dashboard configuration for user: [{}]", userId); AcmUser owner = dashboardService.getUserByUserId(userId); if (owner == null) { throw new AcmObjectNotFoundException("user", null, "Object not found", null); } Dashboard retval = null; DashboardDto dashboardDto; boolean inserted = false; try { List<String> modules = dashboardPropertyReader.getModuleNameList(); if (!modules.contains(moduleName.trim())) { throw new AcmDashboardException("Module name:" + moduleName + " does not exist"); } retval = dashboardService.getDashboardConfigForUserAndModuleName(owner, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } catch (AcmObjectNotFoundException e) { if (dashboardPropertyReader.getModuleNameList().contains(moduleName)) { if (retval == null) { retval = dashboardService.createDefaultModuleDashboard(owner, moduleName); inserted = true; getEventPublisher().publishDashboardEvent(retval, authentication, true, true); } log.info("Module dashboard config for user [{}] and module [{}] is inserted into the DB", userId, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } else { log.warn("Module dashboard config for user: [{}] and module: [{}] NOT inserted into the DB, the moduleName does NOT exists", userId, moduleName, moduleName, e); throw e; } } catch (Exception e1) { log.error("Exception occurred while raising an event or while reading values from fetched DB dashboard ", e1); throw new AcmDashboardException("Get dashboard exception", e1); } }  @RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody DashboardDto getDashboardConfig(
            @RequestParam(value = "moduleName", required = false, defaultValue = "DASHBOARD") String moduleName,
            Authentication authentication); DashboardEventPublisher getEventPublisher(); void setEventPublisher(DashboardEventPublisher eventPublisher); DashboardPropertyReader getDashboardPropertyReader(); void setDashboardPropertyReader(DashboardPropertyReader dashboardPropertyReader); DashboardService getDashboardService(); void setDashboardService(DashboardService dashboardService); }
GetDashboardConfigAPIController { @RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public DashboardDto getDashboardConfig( @RequestParam(value = "moduleName", required = false, defaultValue = "DASHBOARD") String moduleName, Authentication authentication) throws AcmDashboardException, AcmObjectNotFoundException { String userId = authentication.getName(); log.info("Finding dashboard configuration for user: [{}]", userId); AcmUser owner = dashboardService.getUserByUserId(userId); if (owner == null) { throw new AcmObjectNotFoundException("user", null, "Object not found", null); } Dashboard retval = null; DashboardDto dashboardDto; boolean inserted = false; try { List<String> modules = dashboardPropertyReader.getModuleNameList(); if (!modules.contains(moduleName.trim())) { throw new AcmDashboardException("Module name:" + moduleName + " does not exist"); } retval = dashboardService.getDashboardConfigForUserAndModuleName(owner, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } catch (AcmObjectNotFoundException e) { if (dashboardPropertyReader.getModuleNameList().contains(moduleName)) { if (retval == null) { retval = dashboardService.createDefaultModuleDashboard(owner, moduleName); inserted = true; getEventPublisher().publishDashboardEvent(retval, authentication, true, true); } log.info("Module dashboard config for user [{}] and module [{}] is inserted into the DB", userId, moduleName); dashboardDto = dashboardService.prepareDashboardDto(retval, inserted, moduleName); return dashboardDto; } else { log.warn("Module dashboard config for user: [{}] and module: [{}] NOT inserted into the DB, the moduleName does NOT exists", userId, moduleName, moduleName, e); throw e; } } catch (Exception e1) { log.error("Exception occurred while raising an event or while reading values from fetched DB dashboard ", e1); throw new AcmDashboardException("Get dashboard exception", e1); } }  @RequestMapping(value = "/get", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody DashboardDto getDashboardConfig(
            @RequestParam(value = "moduleName", required = false, defaultValue = "DASHBOARD") String moduleName,
            Authentication authentication); DashboardEventPublisher getEventPublisher(); void setEventPublisher(DashboardEventPublisher eventPublisher); DashboardPropertyReader getDashboardPropertyReader(); void setDashboardPropertyReader(DashboardPropertyReader dashboardPropertyReader); DashboardService getDashboardService(); void setDashboardService(DashboardService dashboardService);  }