Example #1
0
  /**
   * Checks if person belongs to curricular course. The unit path format should be:
   * IST{.<SubUnitAcronym>}.<DegreeAcronym>.<CurricularCourseAcronym>
   *
   * <p>Accepted roles: STUDENT
   *
   * @param person
   * @param groupCheckQuery
   * @return
   * @throws NonExistingServiceException
   * @throws ExcepcaoPersistencia
   */
  private static Boolean checkCurricularCourseGroup(Person person, GroupCheckQuery groupCheckQuery)
      throws NonExistingServiceException {
    final String[] unitAcronyms = groupCheckQuery.unitFullPath.split("\\.");

    if (!groupCheckQuery.roleType.equals("STUDENT")) {
      throw new NonExistingServiceException();
    }

    for (final DegreeCurricularPlan degreeCurricularPlan :
        getDegree(unitAcronyms).getActiveDegreeCurricularPlans()) {

      final CurricularCourse curricularCourse =
          degreeCurricularPlan.getCurricularCourseByAcronym(unitAcronyms[4]);

      if (curricularCourse != null) {
        List<Enrolment> enrolments =
            curricularCourse.getEnrolmentsByExecutionPeriod(
                getExecutionPeriod(groupCheckQuery.year, groupCheckQuery.semester));
        for (Enrolment enrolment : enrolments) {
          if (enrolment.getStudentCurricularPlan().getRegistration().getPerson().equals(person)) {
            return true;
          }
        }
      }
    }

    return false;
  }