@Atomic
public static InfoSiteStudentsWithoutGroup run(final String groupPropertiesCode, final String username)
throws FenixServiceException {
check(RolePredicates.STUDENT_PREDICATE);
final InfoSiteStudentsWithoutGroup infoSiteStudentsWithoutGroup = new InfoSiteStudentsWithoutGroup();
final Grouping grouping = FenixFramework.getDomainObject(groupPropertiesCode);
if (grouping == null) {
throw new ExistingServiceException();
}
final Collection allStudentsGroups = grouping.getStudentGroupsSet();
final Integer groupNumber = grouping.findMaxGroupNumber() + 1;
infoSiteStudentsWithoutGroup.setGroupNumber(groupNumber);
infoSiteStudentsWithoutGroup.setInfoGrouping(InfoGrouping.newInfoFromDomain(grouping));
final Collection<Attends> attends = grouping.getAttendsSet();
Registration userStudent = null;
for (Object element : attends) {
final Attends attend = (Attends) element;
final Registration registration = attend.getRegistration();
final Person person = registration.getPerson();
if (person.getUser().getUsername().equals(username)) {
userStudent = registration;
break;
}
}
final InfoStudent infoStudent = getInfoStudentFromStudent(userStudent);
infoSiteStudentsWithoutGroup.setInfoUserStudent(infoStudent);
if (grouping.getEnrolmentPolicy().equals(new EnrolmentGroupPolicyType(2))) {
return infoSiteStudentsWithoutGroup;
}
final Set<Attends> attendsWithOutGroupsSet = new HashSet<Attends>(attends);
for (final Iterator iterator = allStudentsGroups.iterator(); iterator.hasNext();) {
final StudentGroup studentGroup = (StudentGroup) iterator.next();
final Collection allStudentGroupsAttends = studentGroup.getAttendsSet();
for (final Iterator iterator2 = allStudentGroupsAttends.iterator(); iterator2.hasNext();) {
final Attends studentGroupAttend = (Attends) iterator2.next();
attendsWithOutGroupsSet.remove(studentGroupAttend);
}
}
final List<InfoStudent> infoStudentList = new ArrayList<InfoStudent>(attendsWithOutGroupsSet.size());
for (Object element : attendsWithOutGroupsSet) {
final Attends attend = (Attends) element;
final Registration registration = attend.getRegistration();
if (!registration.equals(userStudent)) {
final InfoStudent infoStudent2 = getInfoStudentFromStudent(registration);
infoStudentList.add(infoStudent2);
}
}
infoSiteStudentsWithoutGroup.setInfoStudentList(infoStudentList);
return infoSiteStudentsWithoutGroup;
}