protected Boolean run(
      final String executionCourseCode, final String groupPropertiesCode, final String[] selected)
      throws FenixServiceException {

    if (selected == null) {
      return Boolean.TRUE;
    }

    final Grouping groupProperties = FenixFramework.getDomainObject(groupPropertiesCode);
    if (groupProperties == null) {
      throw new ExistingServiceException();
    }

    final List<ExecutionCourse> executionCourses = groupProperties.getExecutionCourses();
    StringBuilder sbStudentNumbers = new StringBuilder("");
    sbStudentNumbers.setLength(0);
    // studentCodes list has +1 entry if "select all" was selected
    int totalStudentsProcessed = 0;

    for (final String number : selected) {
      if (number.equals("Todos os Alunos")) {
      } else {
        Registration registration = FenixFramework.getDomainObject(number);
        if (!studentHasSomeAttendsInGrouping(registration, groupProperties)) {
          final Attends attends = findAttends(registration, executionCourses);
          if (attends != null) {
            if (sbStudentNumbers.length() != 0) {
              sbStudentNumbers.append(", " + registration.getNumber().toString());
            } else {
              sbStudentNumbers.append(registration.getNumber().toString());
            }
            totalStudentsProcessed++;
            groupProperties.addAttends(attends);
          }
        }
      }
    }

    if (totalStudentsProcessed > 0) {
      List<ExecutionCourse> ecs = groupProperties.getExecutionCourses();
      for (ExecutionCourse ec : ecs) {
        GroupsAndShiftsManagementLog.createLog(
            ec,
            Bundle.MESSAGING,
            "log.executionCourse.groupAndShifts.grouping.attends.added",
            Integer.toString(totalStudentsProcessed),
            sbStudentNumbers.toString(),
            groupProperties.getName(),
            ec.getNome(),
            ec.getDegreePresentationString());
      }
    }

    return Boolean.TRUE;
  }
  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);
  }
  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;
  }
 public static boolean studentHasSomeAttendsInGrouping(
     final Registration registration, final Grouping groupProperties) {
   for (final Attends attends : groupProperties.getAttendsSet()) {
     final Registration otherRegistration = attends.getRegistration();
     if (registration == otherRegistration) {
       return true;
     }
   }
   return false;
 }
示例#5
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;
  }
示例#6
0
  private static void informStudents(
      final StudentGroup studentGroup, final Registration registration, final Grouping grouping) {

    final StringBuilder executionCourseNames = new StringBuilder();
    for (final ExecutionCourse executionCourse : grouping.getExecutionCourses()) {
      if (executionCourseNames.length() > 0) {
        executionCourseNames.append(", ");
      }
      executionCourseNames.append(executionCourse.getNome());
    }
  }
  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;
  }
 private static List getAllStudentGroups(Grouping groupProperties) {
   List result = new ArrayList();
   List studentGroups = groupProperties.getStudentGroups();
   result.addAll(studentGroups);
   return result;
 }