@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 Attends findAttend(
      final ExecutionCourse executionCourse,
      final Integer studentNumber,
      final List<DomainException> exceptionList) {

    final List<Attends> activeAttends = new ArrayList<Attends>(2);
    for (final Attends attend : executionCourse.getAttends()) {
      if (attend.getRegistration().getNumber().equals(studentNumber)
          && (isActive(attend) || belongsToActiveExternalCycle(attend))) {
        activeAttends.add(attend);
      }
    }

    if (activeAttends.size() == 1) {
      return activeAttends.iterator().next();
    }

    if (activeAttends.isEmpty()) {
      exceptionList.add(
          new DomainException("errors.student.without.active.attends", studentNumber.toString()));
    } else {
      exceptionList.add(
          new DomainException(
              "errors.student.with.several.active.attends", studentNumber.toString()));
    }

    return null;
  }
 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;
 }
示例#6
0
 private static boolean belongsToActiveExternalCycle(final Attends attend) {
   if (attend.hasEnrolment()) {
     final CycleCurriculumGroup cycle = attend.getEnrolment().getParentCycleCurriculumGroup();
     if (cycle != null && cycle.isExternal()) {
       final Student student = attend.getRegistration().getStudent();
       return student.getActiveRegistrationFor(cycle.getDegreeCurricularPlanOfDegreeModule())
           != null;
     }
   }
   return false;
 }
示例#7
0
 private static boolean isActive(final Attends attends) {
   final RegistrationState state;
   if (attends.hasEnrolment()) {
     state =
         attends
             .getEnrolment()
             .getRegistration()
             .getLastRegistrationState(attends.getExecutionYear());
   } else {
     state = attends.getRegistration().getLastRegistrationState(attends.getExecutionYear());
   }
   return state != null && state.isActive();
 }
示例#8
0
  private static void writeMarks(
      final List<AttendsMark> marks,
      final ExecutionCourse executionCourse,
      final Evaluation evaluation)
      throws FenixServiceMultipleException {

    final List<DomainException> exceptionList = new ArrayList<DomainException>();

    for (final AttendsMark entry : marks) {

      final Attends attend = findAttend(executionCourse, entry.attendId);
      final String markValue = entry.mark;

      if (attend.hasEnrolment() && attend.getEnrolment().isImpossible()) {
        exceptionList.add(
            new DomainException(
                "errors.student.with.impossible.enrolment",
                attend.getRegistration().getStudent().getNumber().toString()));
      } else {
        final Mark mark = attend.getMarkByEvaluation(evaluation);

        if (isToDeleteMark(markValue)) {
          if (mark != null) {
            mark.delete();
          }
        } else {
          try {
            if (mark == null) {
              evaluation.addNewMark(attend, markValue);
            } else {
              mark.setMark(markValue);
            }
          } catch (InvalidMarkDomainException e) {
            exceptionList.add(e);
          }
        }
      }
    }

    if (!exceptionList.isEmpty()) {
      throw new FenixServiceMultipleException(exceptionList);
    }

    EvaluationManagementLog.createLog(
        executionCourse,
        "resources.MessagingResources",
        "log.executionCourse.evaluation.generic.edited.marks",
        evaluation.getPresentationName(),
        executionCourse.getName(),
        executionCourse.getDegreePresentationString());
  }