@Override public void createContent() throws Exception { this.session = PentahoSessionHolder.getSession(); this.repository = PentahoSystem.get(IUnifiedRepository.class, session); final RepositoryFile BIRTfile = (RepositoryFile) parameterProviders.get("path").getParameter("file"); final String ExecBIRTFilePath = "../webapps/birt/" + BIRTfile.getId() + ".rptdocument"; /* * Get BIRT report design from repository */ final File ExecBIRTFile = new File(ExecBIRTFilePath); if (!ExecBIRTFile.exists()) { final FileOutputStream fos = new FileOutputStream(ExecBIRTFilePath); try { final SimpleRepositoryFileData data = repository.getDataForRead(BIRTfile.getId(), SimpleRepositoryFileData.class); final InputStream inputStream = data.getInputStream(); final byte[] buffer = new byte[0x1000]; int bytesRead = inputStream.read(buffer); while (bytesRead >= 0) { fos.write(buffer, 0, bytesRead); bytesRead = inputStream.read(buffer); } } catch (final Exception e) { Logger.error(getClass().getName(), e.getMessage()); } finally { fos.close(); } } /* * Redirect to BIRT Viewer */ try { // Get informations about user context final IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class); String roles = ""; final ListIterator<String> li = service.getRolesForUser(null, session.getName()).listIterator(); while (li.hasNext()) { roles = roles + li.next().toString() + ","; } // Redirect final HttpServletResponse response = (HttpServletResponse) this.parameterProviders.get("path").getParameter("httpresponse"); response.sendRedirect( "/birt/frameset?__document=" + BIRTfile.getId() + ".rptdocument&__showtitle=false&username="******"&userroles=" + roles + "&reportname=" + BIRTfile.getTitle()); } catch (final Exception e) { Logger.error(getClass().getName(), e.getMessage()); } }
@Test public void testGetSystemRoles() throws Exception { IUserRoleListService mockService = mock(IUserRoleListService.class); when(mockService.getSystemRoles()).thenReturn(Arrays.asList("foo", "bar")); CachingUserRoleListServiceDecorator decorator = new CachingUserRoleListServiceDecorator(mockService); List<String> allRoles = decorator.getSystemRoles(); assertArrayEquals("does not match", new String[] {"foo", "bar"}, allRoles.toArray()); // second call should be from cache allRoles = decorator.getSystemRoles(); assertArrayEquals("does not match", new String[] {"foo", "bar"}, allRoles.toArray()); verify(mockService, times(1)).getSystemRoles(); }
protected List<String> getNewRoles() { List<String> origRoles = userRoleListService.getAllRoles(); List<String> newRoles1 = new ArrayList<String>(origRoles); for (String extraRole : extraRoles) { if (!origRoles.contains(extraRole)) { newRoles1.add(extraRole); } } if (logger.isDebugEnabled()) { logger.debug( String.format("original roles: %s, new roles: %s", origRoles, newRoles1)); // $NON-NLS-1$ } return newRoles1; }
@Before public void setup() { service1 = mock(IUserRoleListService.class); service2 = mock(IUserRoleListService.class); mockTenant = mock(ITenant.class); String joe = "joe"; String ceo = "ceo"; when(service1.getAllRoles()).thenReturn(Arrays.asList("ceo", "admin")); when(service1.getAllRoles(mockTenant)).thenReturn(Arrays.asList("ceo", "admin")); when(service1.getAllUsers()).thenReturn(Arrays.asList("joe", "suzy")); when(service1.getAllUsers(mockTenant)).thenReturn(Arrays.asList("joe", "suzy")); when(service1.getRolesForUser(mockTenant, joe)).thenReturn(Arrays.asList("admin")); when(service1.getSystemRoles()).thenReturn(Arrays.asList("authenticated", "anonymous")); when(service1.getUsersInRole(mockTenant, ceo)).thenReturn(Arrays.asList("suzy")); when(service2.getAllRoles()).thenReturn(Arrays.asList("extraRole1", "admin")); when(service2.getAllRoles(mockTenant)).thenReturn(Arrays.asList("extraRole1", "admin")); when(service2.getAllUsers()).thenReturn(Arrays.asList("user1", "suzy")); when(service2.getAllUsers(mockTenant)).thenReturn(Arrays.asList("user1", "suzy")); when(service2.getRolesForUser(mockTenant, joe)).thenReturn(Arrays.asList("admin", "rockstar")); when(service2.getSystemRoles()).thenReturn(Arrays.asList("serveradmin", "anonymous")); when(service2.getUsersInRole(mockTenant, ceo)).thenReturn(Arrays.asList("ted", "suzy")); compositeService = new CompositeUserRoleListService(Arrays.asList(service1, service2)); }
@Override public List<String> getAllUsers() { return userRoleListService.getAllUsers(); }
@Override public List<String> getSystemRoles() { return userRoleListService.getSystemRoles(); }
@Override public List<String> getRolesForUser(ITenant tenant, String username) { return userRoleListService.getRolesForUser(tenant, username); }
@Override public List<String> getUsersInRole(ITenant tenant, String role) { return userRoleListService.getUsersInRole(tenant, role); }
@Override public List<String> getAllRoles(ITenant tenant) { return userRoleListService.getAllRoles(tenant); }