@SuppressWarnings("unchecked") @Test public void updateDashboardTest() throws Exception { DBDashboard dashboard = new DBDashboard(); dashboard.setName(uttestdashbaord1); dashboard.setId(1L); dashboard.setOwner(uttestuser); RDBMS db = Mockito.mock(RDBMS.class); when(db.query(Matchers.anyString(),Matchers.eq(ImmutableMap.of("name", uttestdashbaord1)), Matchers.eq(-1),Matchers.any(DBDashboardMapper.class))) .thenReturn(Lists.<DBDashboard>newArrayList(dashboard)); when(db.update(Mockito.anyString(), Matchers.anyMap())) .thenReturn(1); DashboardService dashboardService = new DashboardService(); BaseDBService<?> ds=(BaseDBService<?>)ReflectFieldUtil.getField(dashboardService, "dashboardService"); BaseDBService<?> rs=(BaseDBService<?>)ReflectFieldUtil.getField(dashboardService, "rightGroupService"); ReflectFieldUtil.setField(BaseDBService.class,ds, "db", db); ReflectFieldUtil.setField(BaseDBService.class,rs, "db", db); String newConfig = "testConfig"; long id = dashboardService.updateDashboard(uttestdashbaord1, "newName", newConfig); Assert.assertTrue(id == 1); }
@PreAuthorize("hasAuthority(#dashboardName+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") public int updateDashboard(String dashboardName, String displayname, String newConfig) { checkNotNull(dashboardName); DBDashboard dashboardCondition = new DBDashboard(); dashboardCondition.setName(dashboardName); List<DBDashboard> list = dashboardService.get(dashboardCondition); checkState(list.get(0) != null, "[%s] dashboard is not exists.", dashboardName); dashboardCondition.setId(list.get(0).getId()); if(newConfig!=null){ dashboardCondition.setConfig(newConfig); } if(displayname!=null){ dashboardCondition.setDisplayName(displayname); } int response = dashboardService.updateById(dashboardCondition); return response; }
DashboardService { @PreAuthorize("hasAuthority(#dashboardName+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") public int updateDashboard(String dashboardName, String displayname, String newConfig) { checkNotNull(dashboardName); DBDashboard dashboardCondition = new DBDashboard(); dashboardCondition.setName(dashboardName); List<DBDashboard> list = dashboardService.get(dashboardCondition); checkState(list.get(0) != null, "[%s] dashboard is not exists.", dashboardName); dashboardCondition.setId(list.get(0).getId()); if(newConfig!=null){ dashboardCondition.setConfig(newConfig); } if(displayname!=null){ dashboardCondition.setDisplayName(displayname); } int response = dashboardService.updateById(dashboardCondition); return response; } }
DashboardService { @PreAuthorize("hasAuthority(#dashboardName+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") public int updateDashboard(String dashboardName, String displayname, String newConfig) { checkNotNull(dashboardName); DBDashboard dashboardCondition = new DBDashboard(); dashboardCondition.setName(dashboardName); List<DBDashboard> list = dashboardService.get(dashboardCondition); checkState(list.get(0) != null, "[%s] dashboard is not exists.", dashboardName); dashboardCondition.setId(list.get(0).getId()); if(newConfig!=null){ dashboardCondition.setConfig(newConfig); } if(displayname!=null){ dashboardCondition.setDisplayName(displayname); } int response = dashboardService.updateById(dashboardCondition); return response; } DashboardService(); }
DashboardService { @PreAuthorize("hasAuthority(#dashboardName+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") public int updateDashboard(String dashboardName, String displayname, String newConfig) { checkNotNull(dashboardName); DBDashboard dashboardCondition = new DBDashboard(); dashboardCondition.setName(dashboardName); List<DBDashboard> list = dashboardService.get(dashboardCondition); checkState(list.get(0) != null, "[%s] dashboard is not exists.", dashboardName); dashboardCondition.setId(list.get(0).getId()); if(newConfig!=null){ dashboardCondition.setConfig(newConfig); } if(displayname!=null){ dashboardCondition.setDisplayName(displayname); } int response = dashboardService.updateById(dashboardCondition); return response; } DashboardService(); String getManagePermission(String dashboardName); String getViewPermission(String dashboardName); @PreAuthorize("hasAuthority('ADD_DASHBOARD')") long addDashboard(DBDashboard dashboard); @PreAuthorize("hasAnyAuthority(#dashboardName+'_MANAGE','SYS_MANAGE_DASHBOARD')") int deleteDashboard(String dashboardName); @PreFilter("hasAuthority(filterObject+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") int deleteDashboards(List<String> dashboardNames); @PreAuthorize("hasAuthority(#dashboardName+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") int updateDashboard(String dashboardName, String displayname, String newConfig); @PreAuthorize("hasAnyAuthority(#dashboardName+'_MANAGE',#dashboardName+'_VIEW','SYS_MANAGE_DASHBOARD','SYS_VIEW_DASHBOARD')") DBDashboard getDashboardByName(String dashboardName); List<String> getAllDashboardsForOwner(String userName); @PreFilter("hasAuthority(filterObject+'_MANAGE') or hasAuthority(filterObject+'_VIEW') or hasAuthority('SYS_MANAGE_DASHBOARD') or hasAuthority('SYS_VIEW_DASHBOARD')") List<DBDashboard> getDashboardByNames(List<String> names); @PostFilter("hasAuthority(filterObject.name+'_MANAGE') or hasAuthority(filterObject.name+'_VIEW') or hasAuthority('SYS_MANAGE_DASHBOARD') or hasAuthority('SYS_VIEW_DASHBOARD')") List<DBDashboard> getUserViewedDashboard(); @PostFilter("hasAuthority(filterObject.name+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") List<DBDashboard> getAllUserManagedDashboard(); }
DashboardService { @PreAuthorize("hasAuthority(#dashboardName+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") public int updateDashboard(String dashboardName, String displayname, String newConfig) { checkNotNull(dashboardName); DBDashboard dashboardCondition = new DBDashboard(); dashboardCondition.setName(dashboardName); List<DBDashboard> list = dashboardService.get(dashboardCondition); checkState(list.get(0) != null, "[%s] dashboard is not exists.", dashboardName); dashboardCondition.setId(list.get(0).getId()); if(newConfig!=null){ dashboardCondition.setConfig(newConfig); } if(displayname!=null){ dashboardCondition.setDisplayName(displayname); } int response = dashboardService.updateById(dashboardCondition); return response; } DashboardService(); String getManagePermission(String dashboardName); String getViewPermission(String dashboardName); @PreAuthorize("hasAuthority('ADD_DASHBOARD')") long addDashboard(DBDashboard dashboard); @PreAuthorize("hasAnyAuthority(#dashboardName+'_MANAGE','SYS_MANAGE_DASHBOARD')") int deleteDashboard(String dashboardName); @PreFilter("hasAuthority(filterObject+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") int deleteDashboards(List<String> dashboardNames); @PreAuthorize("hasAuthority(#dashboardName+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") int updateDashboard(String dashboardName, String displayname, String newConfig); @PreAuthorize("hasAnyAuthority(#dashboardName+'_MANAGE',#dashboardName+'_VIEW','SYS_MANAGE_DASHBOARD','SYS_VIEW_DASHBOARD')") DBDashboard getDashboardByName(String dashboardName); List<String> getAllDashboardsForOwner(String userName); @PreFilter("hasAuthority(filterObject+'_MANAGE') or hasAuthority(filterObject+'_VIEW') or hasAuthority('SYS_MANAGE_DASHBOARD') or hasAuthority('SYS_VIEW_DASHBOARD')") List<DBDashboard> getDashboardByNames(List<String> names); @PostFilter("hasAuthority(filterObject.name+'_MANAGE') or hasAuthority(filterObject.name+'_VIEW') or hasAuthority('SYS_MANAGE_DASHBOARD') or hasAuthority('SYS_VIEW_DASHBOARD')") List<DBDashboard> getUserViewedDashboard(); @PostFilter("hasAuthority(filterObject.name+'_MANAGE') or hasAuthority('SYS_MANAGE_DASHBOARD')") List<DBDashboard> getAllUserManagedDashboard();  }