Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
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;
  }