@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;
  }
Exemple #2
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;
  }
Exemple #3
0
 private static Attends findAttend(final ExecutionCourse executionCourse, final String attendId) {
   for (final Attends attend : executionCourse.getAttends()) {
     if (attend.getExternalId().equals(attendId)) {
       return attend;
     }
   }
   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;
 }
  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;
  }
Exemple #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;
 }
  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;
  }
Exemple #8
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();
 }
Exemple #9
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());
  }
Exemple #10
0
  private static List<AttendsMark> convertMarks(
      final ExecutionCourse executionCourse, final List<StudentMark> marks)
      throws FenixServiceMultipleException {

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

    for (final StudentMark studentMark : marks) {
      final Attends attend = findAttend(executionCourse, studentMark.studentNumber, exceptionList);
      if (attend != null) {
        result.add(new AttendsMark(attend.getExternalId(), studentMark.mark));
      }
    }

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

    return result;
  }
Exemple #11
0
 private static void addMark(
     List<AttendsMark> result,
     StudentMark studentMark,
     Attends attend,
     List<DomainException> exceptionList) {
   if (studentMark.mark.length() - studentMark.mark.indexOf('.') - 1 > 2) {
     exceptionList.add(
         new DomainException("error.mark.more.than.two.decimals", studentMark.studentNumber));
   } else {
     result.add(new AttendsMark(attend.getExternalId(), studentMark.mark));
   }
 }
Exemple #12
0
  protected Set<Teacher> getTeachers(List<ExecutionSemester> executionSemesters) {
    Set<Teacher> teachers = new HashSet<Teacher>();
    ExecutionYear previousExecutionYear =
        executionSemester.getExecutionYear().getPreviousExecutionYear();
    for (final DegreeCurricularPlan degreeCurricularPlan : degree.getDegreeCurricularPlansSet()) {
      for (final CurricularCourse course : degreeCurricularPlan.getCurricularCourses()) {
        for (final ExecutionCourse executionCourse : course.getAssociatedExecutionCourses()) {
          if (executionSemesters.contains(executionCourse.getExecutionPeriod())) {
            for (Professorship professorhip : executionCourse.getProfessorshipsSet()) {
              if (professorhip
                  .getPerson()
                  .getTeacher()
                  .isActiveOrHasAuthorizationForSemester(executionCourse.getExecutionPeriod())) {
                teachers.add(professorhip.getPerson().getTeacher());
              }
            }
          }
          if (previousExecutionYear.equals(
              executionCourse.getExecutionPeriod().getExecutionYear())) {
            if (executionCourse.isDissertation()) {
              for (Attends attends : executionCourse.getAttends()) {
                if (attends.hasEnrolment() && attends.getEnrolment().getThesis() != null) {
                  for (ThesisEvaluationParticipant thesisEvaluationParticipant :
                      attends.getEnrolment().getThesis().getOrientation()) {
                    if (thesisEvaluationParticipant.getPerson().getTeacher() != null
                        && thesisEvaluationParticipant
                            .getPerson()
                            .getTeacher()
                            .isActiveOrHasAuthorizationForSemester(
                                executionCourse.getExecutionPeriod())) {
                      teachers.add(thesisEvaluationParticipant.getPerson().getTeacher());
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    PhdProgram phdProgram = degree.getPhdProgram();
    if (phdProgram != null) {
      for (PhdIndividualProgramProcess phdIndividualProgramProcess :
          phdProgram.getIndividualProgramProcesses()) {
        for (ExecutionSemester executionSemester : executionSemesters) {
          if (phdIndividualProgramProcess.isActive(
              executionSemester.getAcademicInterval().toInterval())) {
            for (PhdParticipant phdParticipant : phdIndividualProgramProcess.getParticipants()) {
              if (phdParticipant instanceof InternalPhdParticipant) {
                InternalPhdParticipant internalPhdParticipant =
                    (InternalPhdParticipant) phdParticipant;
                if (internalPhdParticipant.isGuidingOrAssistantGuiding()
                    && internalPhdParticipant.getPerson().getTeacher() != null
                    && internalPhdParticipant
                        .getPerson()
                        .getTeacher()
                        .isActiveOrHasAuthorizationForSemester(executionSemester)) {
                  teachers.add(internalPhdParticipant.getPerson().getTeacher());
                }
              }
            }
          }
        }
      }
    }
    return teachers;
  }
Exemple #13
0
  private String getTeachersAndTeachingHours(CurricularCourse course, boolean responsibleTeacher) {
    Map<Teacher, Double> responsiblesMap = new HashMap<Teacher, Double>();
    List<ExecutionSemester> executionSemesters = getSelectedExecutionSemesters();
    for (final ExecutionCourse executionCourse : course.getAssociatedExecutionCourses()) {
      if (executionSemesters.contains(executionCourse.getExecutionPeriod())) {
        for (Professorship professorhip : executionCourse.getProfessorshipsSet()) {
          if (professorhip.isResponsibleFor() == responsibleTeacher
              && professorhip
                  .getPerson()
                  .getTeacher()
                  .isActiveOrHasAuthorizationForSemester(executionCourse.getExecutionPeriod())) {
            Double hours = responsiblesMap.get(professorhip.getTeacher());
            if (hours == null) {
              hours = 0.0;
            }
            hours = hours + getHours(professorhip);
            responsiblesMap.put(professorhip.getTeacher(), hours);
          }
        }
      }
    }
    int counter = 1000;
    List<String> responsibles = new ArrayList<String>();
    for (Teacher teacher : responsiblesMap.keySet()) {
      String responsible =
          teacher.getPerson().getName() + " (" + responsiblesMap.get(teacher) + ")";
      counter -= JSONObject.escape(responsible + ", ").getBytes().length;
      responsibles.add(responsible);
    }

    if (!responsibleTeacher && course.isDissertation()) {
      Set<Teacher> teachers = new HashSet<Teacher>();
      for (ExecutionCourse executionCourse : course.getAssociatedExecutionCoursesSet()) {
        if (executionCourse
            .getExecutionPeriod()
            .getExecutionYear()
            .equals(executionSemester.getExecutionYear().getPreviousExecutionYear())) {
          for (Attends attends : executionCourse.getAttends()) {
            if (attends.hasEnrolment() && attends.getEnrolment().getThesis() != null) {
              for (ThesisEvaluationParticipant thesisEvaluationParticipant :
                  attends.getEnrolment().getThesis().getOrientation()) {
                if (thesisEvaluationParticipant.getPerson().getTeacher() != null
                    && thesisEvaluationParticipant
                        .getPerson()
                        .getTeacher()
                        .isActiveOrHasAuthorizationForSemester(
                            executionCourse.getExecutionPeriod())) {
                  teachers.add(thesisEvaluationParticipant.getPerson().getTeacher());
                }
              }
            }
          }
        }
      }
      for (Teacher teacher : teachers) {
        String responsible = teacher.getPerson().getName() + " (0.0)";
        if (counter - JSONObject.escape(responsible).getBytes().length < 0) {
          break;
        }
        if (!responsiblesMap.containsKey(teacher)) {
          counter -= JSONObject.escape(responsible + ", ").getBytes().length;
          responsibles.add(responsible);
        }
      }
    }

    return StringUtils.join(responsibles, ", ");
  }