SolutionImportHandler implements IPlatformImportHandler { protected void importRoles( List<RoleExport> roles, Map<String, List<String>> roleToUserMap ) { if ( roles != null ) { IUserRoleDao roleDao = PentahoSystem.get( IUserRoleDao.class ); ITenant tenant = new Tenant( "/pentaho/" + TenantUtils.getDefaultTenant(), true ); IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = PentahoSystem.get( IRoleAuthorizationPolicyRoleBindingDao.class ); Set<String> existingRoles = new HashSet<>(); for ( RoleExport role : roles ) { getLogger().debug( Messages.getInstance().getString( "ROLE.importing", role.getRolename() ) ); try { List<String> users = roleToUserMap.get( role.getRolename() ); String[] userarray = users == null ? new String[] {} : users.toArray( new String[] {} ); IPentahoRole role1 = roleDao.createRole( tenant, role.getRolename(), null, userarray ); } catch ( AlreadyExistsException e ) { existingRoles.add( role.getRolename() ); getLogger().info( Messages.getInstance().getString( "ROLE.Already.Exists", role.getRolename() ) ); } try { if ( existingRoles.contains( role.getRolename() ) ) { if ( isOverwriteFile() ) { roleBindingDao.setRoleBindings( tenant, role.getRolename(), role.getPermissions() ); } } else { roleBindingDao.setRoleBindings( tenant, role.getRolename(), role.getPermissions() ); } } catch ( Exception e ) { getLogger().info( Messages.getInstance() .getString( "ERROR.SettingRolePermissions", role.getRolename() ), e ); } } } } SolutionImportHandler( List<IMimeType> mimeTypes ); ImportSession getImportSession(); Log getLogger(); @Override void importFile( IPlatformImportBundle bundle ); @Override List<IMimeType> getMimeTypes(); IPlatformImportBundle build( RepositoryFileImportBundle.Builder builder ); Response createSchedulerJob( SchedulerResource scheduler, JobScheduleRequest jobScheduleRequest ); boolean isOverwriteFile(); void setOverwriteFile( boolean overwriteFile );  }
@Test public void testImportRoles() throws Exception { String roleName = "ADMIN"; List<String> permissions = new ArrayList<String>(); RoleExport role = new RoleExport(); role.setRolename( roleName ); role.setPermission( permissions ); List<RoleExport> roles = new ArrayList<>(); roles.add( role ); Map<String, List<String>> roleToUserMap = new HashMap<>(); final List<String> adminUsers = new ArrayList<>(); adminUsers.add( "admin" ); adminUsers.add( "root" ); roleToUserMap.put( roleName, adminUsers ); String[] userStrings = adminUsers.toArray( new String[] {} ); importHandler.importRoles( roles, roleToUserMap ); Mockito.verify( userRoleDao ).createRole( Mockito.any( ITenant.class ), Mockito.eq( roleName ), Mockito.anyString(), Mockito.any( userStrings.getClass() ) ); Mockito.verify( roleAuthorizationPolicyRoleBindingDao ) .setRoleBindings( Mockito.any( ITenant.class ), Mockito.eq( roleName ), Mockito.eq( permissions ) ); }