@Override public void dropRolesForUser(String sessID, String user, Set<UserRole> roles) throws RemoteException, SessionExpiredException, SQLException, SecurityException { checkAdmin(sessID); // Check if any of the roles given are already assigned, and if so remove them from the // roles to register. Set<UserRole> assignedRoles = getRolesForUser(sessID, user); if (assignedRoles.containsAll(roles)) { return; } else if (assignedRoles.size() > 0) { roles.removeAll(assignedRoles); } // register the remaining roles. TableSchema raTable = MedSavantDatabase.UserRoleAssignmentTableSchema; for (UserRole role : roles) { DeleteQuery dq = new DeleteQuery(raTable.getTableName()); dq.addCondition( BinaryCondition.equalTo( raTable.getDBColumn( MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_USERNAME), user)); dq.addCondition( BinaryCondition.equalTo( raTable.getDBColumn( MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_ROLE_ID), role.getRoleId())); ConnectionController.executeUpdate(sessID, dq.toString()); } }
@Override public UserRole getRoleByName(String sessID, String roleName) throws RemoteException, SessionExpiredException, SQLException { String thisDatabase = SessionManager.getInstance().getDatabaseForSession(sessID); TableSchema roleTable = MedSavantDatabase.UserRoleTableSchema; SelectQuery sq = new SelectQuery(); sq.addFromTable(roleTable.getTable()); sq.addAllColumns(); sq.addCondition( BinaryCondition.equalTo( roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ROLENAME), roleName)); ResultSet rs = null; try { rs = ConnectionController.executeQuery(sessID, sq.toString()); if (rs.next()) { int roleId = rs.getInt(1); String name = rs.getString(2); String roleDescription = rs.getString(3); return new UserRole(roleId, name, roleDescription, thisDatabase); } return null; } finally { if (rs != null) { rs.close(); } } }
private Set<UserRole> getRolesForUser(String sessID, String user) throws RemoteException, SQLException, SessionExpiredException { String database = SessionManager.getInstance().getDatabaseForSession(sessID); TableSchema roleTable = MedSavantDatabase.UserRoleTableSchema; TableSchema roleATable = MedSavantDatabase.UserRoleAssignmentTableSchema; SelectQuery sq = new SelectQuery(); sq.addColumns( roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ID), roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ROLENAME), roleTable.getDBColumn( MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ROLE_DESCRIPTION)); Condition joinCondition = BinaryCondition.equalTo( roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ID), roleATable.getDBColumn( MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_ROLE_ID)); sq.addJoin( SelectQuery.JoinType.INNER, roleTable.getTable(), roleATable.getTable(), joinCondition); sq.addCondition( BinaryCondition.equalTo( roleATable.getDBColumn( MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_USERNAME), user)); ResultSet rs = null; try { rs = ConnectionController.executeQuery(sessID, sq.toString()); Set<UserRole> roleSet = new HashSet<UserRole>(); while (rs.next()) { int roleId = rs.getInt(1); String roleName = rs.getString(2); String roleDescription = rs.getString(3); roleSet.add(new UserRole(roleId, roleName, roleDescription, database)); } return roleSet; } finally { if (rs != null) { rs.close(); } } }
private void applyFilters(SelectQuery query) { if (this.filters != null && this.filters.length > 0) { ComboCondition comboCondition = new ComboCondition(ComboCondition.Op.AND); if (filters.length > 0) { for (int i = 0; i < filters.length; i++) { Filter filter = filters[i]; FilterType filterType = filter.getFilterType(); DbColumn filterColumn = new DbColumn(dbTable, filter.getField(), "", null, null); if (filterType.equals(FilterType.EQ)) { comboCondition.addCondition(BinaryCondition.equalTo(filterColumn, filter.getValue())); } else if (filterType.equals(FilterType.GT)) { comboCondition.addCondition( BinaryCondition.greaterThan(filterColumn, filter.getValue(), false)); } else if (filterType.equals(FilterType.LT)) { comboCondition.addCondition( BinaryCondition.lessThan(filterColumn, filter.getValue(), false)); } else if (filterType.equals(FilterType.GTE)) { comboCondition.addCondition( BinaryCondition.greaterThan(filterColumn, filter.getValue(), true)); } else if (filterType.equals(FilterType.LTE)) { comboCondition.addCondition( BinaryCondition.lessThan(filterColumn, filter.getValue(), true)); } else if (filterType.equals(FilterType.NEQ)) { comboCondition.addCondition( BinaryCondition.notEqualTo(filterColumn, filter.getValue())); } else if (filterType.equals(FilterType.IN)) { ComboCondition comboConditionOR = new ComboCondition(ComboCondition.Op.OR); String[] condicion = filter.getValue().toString().split(","); for (int z = 0; z < condicion.length; z++) { comboConditionOR.addCondition(BinaryCondition.equalTo(filterColumn, condicion[z])); } comboCondition.addCondition(comboConditionOR); } else { throw new UnsupportedOperationException( "Currently, the filter operation " + filterType + " is not supported"); } } } query.addCondition(comboCondition); } }