public Role getRoleByName(String name) { try { return (Role) DB.exec((db) -> { RoleManager mgr = new RoleManager(db); return mgr.getRoleByName(name); }); } catch (Exception e) { getApp().getLog().error(e); return null; } } }
@Override public Stream getAll(int offset, int limit, Map<String, Boolean> orders) throws Exception { List<Role> list = (List<Role>) DB.exec(db -> { RoleManager mgr = new RoleManager(db); return mgr.getAll(offset,limit,orders); }); return list.stream(); }
@Override public int getItemCount() throws Exception { return (int) DB.exec(db -> { RoleManager mgr = new RoleManager(db); return mgr.getItemCount(); }); }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmrole <role>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role r = rm.getRoleByName(args[1]); if (r != null) db.session().delete(r); db.commit(); cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found"); } catch (Exception e) { cli.println (e.getMessage()); } } }
public List<Role> getRoles() { try { return DB.exec(db-> { RoleManager mgr = new RoleManager(db); return mgr.getAll(); }); } catch (Exception e) { getApp().getLog().error(e); return null; } } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmrole <role>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role r = rm.getRoleByName(args[1]); if (r != null) db.session().delete(r); db.commit(); cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found"); } catch (Exception e) { cli.println (e.getMessage()); } } }
public List<Role> getRoles() { try { return (List<Role>) DB.exec((db) -> { RoleManager mgr = new RoleManager(db); return mgr.getAll(); }); } catch (Exception e) { getApp().getLog().error(e); return null; } }
return; RoleManager rm = new RoleManager(db); Role[] rr = null; if (line.hasOption('r')) { int i=0; for (String s : roles) { Role r = rm.getRoleByName(s); if (r == null) { cli.println ("Role '" + s + "' does not exist - aborting");
@Override public void exec(CLIContext cli, String[] args) throws Exception { try (DB db = new DB()) { db.open(); RoleManager rm = new RoleManager(db); for (Role r : rm.getAll()) { cli.println (r.getName() + " " + r.getPermissions()); } } catch (Exception e) { cli.println (e.getMessage()); } } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length < 2) { cli.println("Usage: addpermission <role> <permission 1> <permission 2> ... <permission n>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role role = null; if (rm.getRoleByName(args[1]) == null) { role = new Role(args[1]); Set<Permission> perms = role.getPermissions(); for (int i = 2; i < args.length; i++) perms.add(Permission.valueOf(args[i])); db.save(role); } db.commit(); cli.println (role != null ? "Role created " + role.getName() : " Role already exists"); } catch (Exception e) { cli.println (e.getMessage()); } } }
return; RoleManager rm = new RoleManager(db); Role[] rr = null; if (line.hasOption('r')) { int i=0; for (String s : roles) { Role r = rm.getRoleByName(s); if (r == null) { cli.println ("Role '" + s + "' does not exist - aborting");
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length < 2) { cli.println("Usage: addrole <role> <permission 1> <permission 2> ... <permission n>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role role = null; if (rm.getRoleByName(args[1]) == null) { role = new Role(args[1]); Set<Permission> perms = role.getPermissions(); for (int i = 2; i < args.length; i++) perms.add(Permission.valueOf(args[i])); db.save(role); } db.commit(); cli.println (role != null ? "Role created " + role.getName() : " Role already exists"); } catch (Exception e) { cli.println (e.getMessage()); } } }