@Service
  public static InfoSiteStudentsAndGroups run(Integer groupingId) throws FenixServiceException {
    InfoSiteStudentsAndGroups infoSiteStudentsAndGroups = new InfoSiteStudentsAndGroups();

    Grouping grouping = rootDomainObject.readGroupingByOID(groupingId);

    if (grouping == null) {
      throw new ExistingServiceException();
    }

    List infoSiteStudentsAndGroupsList = new ArrayList();
    List studentGroups = getAllStudentGroups(grouping);
    Iterator iterStudentGroups = studentGroups.iterator();
    while (iterStudentGroups.hasNext()) {

      List studentGroupAttendList = new ArrayList();
      StudentGroup studentGroup = (StudentGroup) iterStudentGroups.next();

      studentGroupAttendList = studentGroup.getAttends();

      Iterator iterStudentGroupAttendList = studentGroupAttendList.iterator();
      InfoSiteStudentInformation infoSiteStudentInformation = null;
      InfoSiteStudentAndGroup infoSiteStudentAndGroup = null;
      Attends attend = null;

      while (iterStudentGroupAttendList.hasNext()) {
        infoSiteStudentInformation = new InfoSiteStudentInformation();
        infoSiteStudentAndGroup = new InfoSiteStudentAndGroup();

        attend = (Attends) iterStudentGroupAttendList.next();

        infoSiteStudentAndGroup.setInfoStudentGroup(
            InfoStudentGroup.newInfoFromDomain(studentGroup));

        infoSiteStudentInformation.setNumber(attend.getRegistration().getNumber());

        infoSiteStudentInformation.setName(attend.getRegistration().getPerson().getName());

        infoSiteStudentInformation.setUsername(
            (attend.getRegistration().getPerson().getUsername()));

        infoSiteStudentInformation.setEmail(attend.getRegistration().getPerson().getEmail());

        infoSiteStudentInformation.setPersonID(
            attend.getRegistration().getPerson().getIdInternal());

        infoSiteStudentAndGroup.setInfoSiteStudentInformation(infoSiteStudentInformation);

        infoSiteStudentsAndGroupsList.add(infoSiteStudentAndGroup);
      }
    }

    Collections.sort(
        infoSiteStudentsAndGroupsList, new BeanComparator("infoStudentGroup.groupNumber"));

    infoSiteStudentsAndGroups.setInfoSiteStudentsAndGroupsList(infoSiteStudentsAndGroupsList);
    infoSiteStudentsAndGroups.setInfoGrouping(InfoGrouping.newInfoFromDomain(grouping));

    return infoSiteStudentsAndGroups;
  }
  protected Boolean run(
      String executionCourseID,
      String studentGroupID,
      String groupPropertiesID,
      List studentUsernames)
      throws FenixServiceException {

    final StudentGroup studentGroup = FenixFramework.getDomainObject(studentGroupID);
    if (studentGroup == null) {
      throw new InvalidArgumentsServiceException();
    }

    final Grouping grouping = studentGroup.getGrouping();
    final IGroupEnrolmentStrategyFactory enrolmentGroupPolicyStrategyFactory =
        GroupEnrolmentStrategyFactory.getInstance();
    final IGroupEnrolmentStrategy strategy =
        enrolmentGroupPolicyStrategyFactory.getGroupEnrolmentStrategyInstance(grouping);

    if (!strategy.checkStudentsUserNamesInGrouping(studentUsernames, grouping)) {
      throw new InvalidArgumentsServiceException();
    }

    StringBuilder sbStudentNumbers = new StringBuilder("");
    sbStudentNumbers.setLength(0);
    for (final String studentUsername : (List<String>) studentUsernames) {
      Attends attend = grouping.getStudentAttend(studentUsername);
      if (attend != null) {
        if (sbStudentNumbers.length() != 0) {
          sbStudentNumbers.append(", " + attend.getRegistration().getNumber().toString());
        } else {
          sbStudentNumbers.append(attend.getRegistration().getNumber().toString());
        }
        attend.removeStudentGroups(studentGroup);
      }
    }

    // no students means no log entry -- list may contain invalid values, so
    // its size cannot be used to test
    if (sbStudentNumbers.length() != 0) {
      List<ExecutionCourse> ecs = grouping.getExecutionCourses();
      for (ExecutionCourse ec : ecs) {
        GroupsAndShiftsManagementLog.createLog(
            ec,
            "resources.MessagingResources",
            "log.executionCourse.groupAndShifts.grouping.group.element.removed",
            Integer.toString(studentUsernames.size()),
            sbStudentNumbers.toString(),
            studentGroup.getGroupNumber().toString(),
            grouping.getName(),
            ec.getNome(),
            ec.getDegreePresentationString());
      }
    }
    return true;
  }
  protected Boolean run(String objectCode, String groupingCode) throws FenixServiceException {
    Grouping grouping = FenixFramework.getDomainObject(groupingCode);

    if (grouping == null) {
      throw new ExistingServiceException();
    }

    List attendsElements = new ArrayList();
    attendsElements.addAll(grouping.getAttends());
    Iterator iterator = attendsElements.iterator();
    StringBuilder sbStudentNumbers = new StringBuilder("");
    sbStudentNumbers.setLength(0);

    while (iterator.hasNext()) {
      Attends attend = (Attends) iterator.next();
      if (sbStudentNumbers.length() != 0) {
        sbStudentNumbers.append(", " + attend.getRegistration().getNumber().toString());
      } else {
        sbStudentNumbers.append(attend.getRegistration().getNumber().toString());
      }

      boolean found = false;
      Iterator iterStudentsGroups = grouping.getStudentGroupsSet().iterator();
      while (iterStudentsGroups.hasNext() && !found) {

        StudentGroup studentGroup = (StudentGroup) iterStudentsGroups.next();

        if (studentGroup != null) {
          studentGroup.removeAttends(attend);
          found = true;
        }
      }
      grouping.removeAttends(attend);
    }

    // no students means no log entry -- list may contain invalid values, so
    // its size cannot be used to test
    if (sbStudentNumbers.length() != 0) {
      List<ExecutionCourse> ecs = grouping.getExecutionCourses();
      for (ExecutionCourse ec : ecs) {
        GroupsAndShiftsManagementLog.createLog(
            ec,
            "resources.MessagingResources",
            "log.executionCourse.groupAndShifts.grouping.memberSet.removed",
            Integer.toString(attendsElements.size()),
            sbStudentNumbers.toString(),
            grouping.getName(),
            ec.getNome(),
            ec.getDegreePresentationString());
      }
    }

    return true;
  }
示例#4
0
  private static void checkIfStudentIsNotEnrolledInOtherGroups(
      final List<StudentGroup> studentGroups,
      final StudentGroup studentGroupEnrolled,
      final Attends studentAttend)
      throws InvalidSituationServiceException {

    for (final StudentGroup studentGroup : studentGroups) {
      if (studentGroup != studentGroupEnrolled
          && studentGroup.getAttends().contains(studentAttend)) {
        throw new InvalidSituationServiceException();
      }
    }
  }
  public Integer run(
      Integer executionCourseCode,
      Integer studentGroupCode,
      Integer groupPropertiesCode,
      String shiftCodeString)
      throws FenixServiceException {
    Grouping groupProperties = rootDomainObject.readGroupingByOID(groupPropertiesCode);

    if (groupProperties == null) {
      throw new ExistingServiceException();
    }

    StudentGroup studentGroup = rootDomainObject.readStudentGroupByOID(studentGroupCode);

    if (studentGroup == null) {
      throw new InvalidSituationServiceException();
    }

    Integer shiftCode = null;
    if (shiftCodeString != null && shiftCodeString.length() > 0) {
      shiftCode = new Integer(shiftCodeString);
    }

    if (studentGroup.getShift() != null && shiftCode == null) {
      throw new InvalidArgumentsServiceException();
    }

    if (studentGroup.getShift() == null) {
      if (shiftCode != null) {
        throw new InvalidArgumentsServiceException();
      }
    } else {
      if (studentGroup.getShift().getIdInternal().intValue() != shiftCode.intValue()) {
        throw new InvalidArgumentsServiceException();
      }
    }

    if (studentGroup.getShift() != null && groupProperties.getShiftType() != null) {
      return Integer.valueOf(1);
    }

    if (studentGroup.getShift() != null && groupProperties.getShiftType() == null) {
      return Integer.valueOf(2);
    }

    if (studentGroup.getShift() == null && groupProperties.getShiftType() != null) {
      return Integer.valueOf(3);
    }

    if (studentGroup.getShift() == null && groupProperties.getShiftType() == null) {
      return Integer.valueOf(4);
    }

    return Integer.valueOf(5);
  }
示例#6
0
  @Checked("RolePredicates.STUDENT_PREDICATE")
  @Service
  public static Boolean run(Integer studentGroupCode, String username)
      throws FenixServiceException {

    final StudentGroup studentGroup = rootDomainObject.readStudentGroupByOID(studentGroupCode);
    if (studentGroup == null) {
      throw new InvalidArgumentsServiceException();
    }
    final Registration registration = Registration.readByUsername(username);
    if (registration == null) {
      throw new InvalidArgumentsServiceException();
    }

    final Grouping grouping = studentGroup.getGrouping();
    final Attends studentAttend = grouping.getStudentAttend(registration);
    if (studentAttend == null) {
      throw new NotAuthorizedException();
    }
    if (studentGroup.getAttends().contains(studentAttend)) {
      throw new InvalidSituationServiceException();
    }

    final IGroupEnrolmentStrategyFactory enrolmentGroupPolicyStrategyFactory =
        GroupEnrolmentStrategyFactory.getInstance();
    final IGroupEnrolmentStrategy strategy =
        enrolmentGroupPolicyStrategyFactory.getGroupEnrolmentStrategyInstance(grouping);

    boolean result = strategy.checkPossibleToEnrolInExistingGroup(grouping, studentGroup);
    if (!result) {
      throw new InvalidArgumentsServiceException();
    }

    checkIfStudentIsNotEnrolledInOtherGroups(
        grouping.getStudentGroups(), studentGroup, studentAttend);

    studentGroup.addAttends(studentAttend);

    informStudents(studentGroup, registration, grouping);

    return Boolean.TRUE;
  }