public static void upsertRole(DbConn cnx, RRoleDto dto) { if (dto.getId() != null) { cnx.runUpdate("role_update_all_by_id", dto.getName(), dto.getDescription(), dto.getId()); // Permissions cnx.runUpdate("perm_delete_for_role", dto.getId()); for (String i : dto.getPermissions()) { cnx.runUpdate("perm_insert", i, dto.getId()); } } else { RRole.create(cnx, dto.getName(), dto.getDescription(), dto.getPermissions().toArray(new String[dto.getPermissions().size()])); } }
private static RRoleDto mapRole(ResultSet rs, int colShift) { try { RRoleDto tmp = new RRoleDto(); tmp.setId(rs.getInt(1 + colShift)); tmp.setName(rs.getString(2 + colShift)); tmp.setDescription(rs.getString(3 + colShift)); return tmp; } catch (SQLException e) { throw new JqmAdminApiInternalException(e); } }
@Override int doWork() { jqmlogger.info("# Roles defined"); try (DbConn cnx = Helpers.getNewDbSession()) { for (RRoleDto role : MetaService.getRoles(cnx)) { jqmlogger.info("{} - {}", role.getName(), role.getDescription()); } } return 0; } }
for (RRoleDto dto : res) ids.add(dto.getId()); if (dto.getId().equals(role_id)) dto.addPermission(permName);
public static void syncRoles(DbConn cnx, List<RRoleDto> dtos) { for (RRoleDto existing : getRoles(cnx)) { boolean foundInNewSet = false; for (RRoleDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteRole(cnx, existing.getId(), false); } } for (RRoleDto dto : dtos) { upsertRole(cnx, dto); } }
for (RRoleDto dto : res) ids.add(dto.getId()); if (dto.getId().equals(role_id)) dto.addPermission(permName);
public static void syncRoles(DbConn cnx, List<RRoleDto> dtos) { for (RRoleDto existing : getRoles(cnx)) { boolean foundInNewSet = false; for (RRoleDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteRole(cnx, existing.getId(), false); } } for (RRoleDto dto : dtos) { upsertRole(cnx, dto); } }
public static void upsertRole(DbConn cnx, RRoleDto dto) { if (dto.getId() != null) { cnx.runUpdate("role_update_all_by_id", dto.getName(), dto.getDescription(), dto.getId()); // Permissions cnx.runUpdate("perm_delete_for_role", dto.getId()); for (String i : dto.getPermissions()) { cnx.runUpdate("perm_insert", i, dto.getId()); } } else { RRole.create(cnx, dto.getName(), dto.getDescription(), dto.getPermissions().toArray(new String[dto.getPermissions().size()])); } }
private static RRoleDto mapRole(ResultSet rs, int colShift) { try { RRoleDto tmp = new RRoleDto(); tmp.setId(rs.getInt(1 + colShift)); tmp.setName(rs.getString(2 + colShift)); tmp.setDescription(rs.getString(3 + colShift)); return tmp; } catch (SQLException e) { throw new JqmAdminApiInternalException(e); } }