registration = person.getStudentByType(DegreeType.BOLONHA_MASTER_DEGREE); } if (registration == null) {
    public static String updateIstUsername(Person person) {	String currentISTUsername = person.getIstUsername();	if (currentISTUsername == null && shouldHaveUID(person)) {	    String ist = "ist";	    String istUsername = null;	    Role mostImportantRole = getMostImportantRole(person.getPersonRoles());	    if (mostImportantRole.getRoleType() == RoleType.TEACHER) {		istUsername = ist + sumNumber(person.getTeacher().getTeacherNumber(), 10000);	    } else if (mostImportantRole.getRoleType() == RoleType.EMPLOYEE) {		istUsername = ist + sumNumber(person.getEmployee().getEmployeeNumber(), 20000);	    } else if (mostImportantRole.getRoleType() == RoleType.GRANT_OWNER		    && person.getGrantOwner() != null) {		istUsername = ist + sumNumber(person.getGrantOwner().getNumber(), 30000);	    } else if (mostImportantRole.getRoleType() == RoleType.STUDENT		    && person.getStudentByType(DegreeType.MASTER_DEGREE) != null) {		final Integer number = person.getStudentByType(DegreeType.MASTER_DEGREE).getNumber();		if (number < 10000) {// old master degree students		    istUsername = ist + sumNumber(number, 40000);		} else {// new master degree students		    istUsername = ist + sumNumber(number, 100000);		}	    } else if (mostImportantRole.getRoleType() == RoleType.STUDENT		    && person.getStudentByType(DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA) != null) {		istUsername = ist			+ sumNumber(person.getStudentByType(				DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA).getNumber(), 100000);	    } else if (mostImportantRole.getRoleType() == RoleType.STUDENT) {		Registration registration = person.getStudentByType(DegreeType.DEGREE);		if (registration == null) {		    registration = person.getStudentByType(DegreeType.BOLONHA_DEGREE);		}		if (registration == null) {		    registration = person.getStudentByType(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE);		}		if (registration != null) {		    final StudentType studentType = registration.getStudentKind().getStudentType();		    switch (studentType) {		    case EXTERNAL_STUDENT:		    case FOREIGN_STUDENT:			istUsername = ist + sumNumber(registration.getNumber(), 50000 - 100000);			// we subtract 100000 from the external/foreign student			// number to get his original legacy system number			break;		    default:			istUsername = ist + sumNumber(registration.getNumber(), 100000);			break;		    }		} else if (person.hasStudent() && person.getStudent().getNumber() < 10000) {		    istUsername = ist + sumNumber(person.getStudent().getNumber(), 60000);		}	    }	    if (StringUtils.isEmpty(istUsername)) {		throw new DomainException("error.setting.istUsername.not.authorized");	    }	    return istUsername;	}	return currentISTUsername;    }