Ejemplo n.º 1
0
 public ExecutionCourseSender(ExecutionCourse executionCourse) {
   super();
   setCourse(Objects.requireNonNull(executionCourse));
   setFromAddress(Sender.getNoreplyMail());
   addReplyTos(new ExecutionCourseReplyTo());
   addReplyTos(new CurrentUserReplyTo());
   setMembers(TeacherGroup.get(executionCourse));
   final String labelECTeachers =
       BundleUtil.getString(
           Bundle.SITE,
           "label.org.fenixedu.academic.domain.accessControl.ExecutionCourseTeachersGroupWithName",
           new String[] {executionCourse.getNome()});
   final String labelECStudents =
       BundleUtil.getString(
           Bundle.SITE,
           "label.org.fenixedu.academic.domain.accessControl.ExecutionCourseStudentsGroupWithName",
           new String[] {executionCourse.getNome()});
   final String labelECResponsibleTeachers =
       BundleUtil.getString(
           Bundle.SITE,
           "label.org.fenixedu.academic.domain.accessControl.ExecutionCourseResponsibleTeachersGroupWithName",
           new String[] {executionCourse.getNome()});
   // fixed recipients
   addRecipients(new Recipient(labelECTeachers, TeacherGroup.get(executionCourse)));
   addRecipients(new Recipient(labelECStudents, StudentGroup.get(executionCourse)));
   addRecipients(
       new Recipient(
           labelECResponsibleTeachers,
           TeacherResponsibleOfExecutionCourseGroup.get(executionCourse)));
   setFromName(createFromName());
 }
Ejemplo n.º 2
0
  /**
   * Checks if person belongs to deparment on a specified execution year. The unit path format
   * should be: IST.<DepartmentAcronym>
   *
   * <p>Accepted roles: STUDENT, TEACHER and EMPLOYEE
   *
   * @param person
   * @param groupCheckQuery
   * @return
   * @throws ExcepcaoPersistencia
   * @throws FenixServiceException
   */
  private static Boolean checkDepartmentGroup(Person person, GroupCheckQuery groupCheckQuery)
      throws NonExistingServiceException {

    final String[] unitAcronyms = groupCheckQuery.unitFullPath.split("\\.");
    if (!groupCheckQuery.roleType.equals("TEACHER")
        && !groupCheckQuery.roleType.equals("STUDENT")
        && !groupCheckQuery.roleType.equals("EMPLOYEE")) {
      throw new NonExistingServiceException();
    }

    if (groupCheckQuery.roleType.equals("TEACHER")) {
      return TeacherGroup.get(getDepartment(unitAcronyms), getExecutionYear(groupCheckQuery.year))
          .isMember(person.getUser());
    } else if (groupCheckQuery.roleType.equals("EMPLOYEE")) {
      if (person != null && person.getEmployee() != null) {
        final Department lastDepartmentWorkingPlace =
            person
                .getEmployee()
                .getLastDepartmentWorkingPlace(
                    getExecutionYear(groupCheckQuery.year).getBeginDateYearMonthDay(),
                    getExecutionYear(groupCheckQuery.year).getEndDateYearMonthDay());
        return (lastDepartmentWorkingPlace != null
            && lastDepartmentWorkingPlace.equals(getDepartment(unitAcronyms)));
      }
      return false;
    } else {
      if (person != null && person.getStudent() != null) {
        for (final Registration registration : person.getStudent().getRegistrationsSet()) {
          for (final Enrolment enrolment :
              registration
                  .getLastStudentCurricularPlan()
                  .getEnrolmentsByExecutionYear(getExecutionYear(groupCheckQuery.year))) {
            if (enrolment.getCurricularCourse().getCompetenceCourse() != null) {
              final CompetenceCourse competenceCourse =
                  enrolment.getCurricularCourse().getCompetenceCourse();
              if (competenceCourse.getDepartmentsSet().contains(getDepartment(unitAcronyms))) {
                return true;
              }

              if (competenceCourse.hasDepartmentUnit()
                  && competenceCourse.getDepartmentUnit().getDepartment()
                      == getDepartment(unitAcronyms)) {
                return true;
              }
            }
          }
        }
      }
      return false;
    }
  }
Ejemplo n.º 3
0
  /**
   * Checks if person belongs to degree. The unit path format should be: IST.<DegreeAcronym>
   *
   * <p>Accepted roles: TEACHER and STUDENT
   *
   * @param person
   * @param groupCheckQuery
   * @return
   * @throws ExcepcaoPersistencia
   * @throws FenixServiceException
   */
  private static Boolean checkDegreeGroup(Person person, GroupCheckQuery groupCheckQuery)
      throws NonExistingServiceException {
    String[] unitAcronyms = groupCheckQuery.unitFullPath.split("\\.");

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

    Degree degree = getDegree(unitAcronyms);

    Group group;
    if (groupCheckQuery.roleType.equals("STUDENT")) {
      group = StudentGroup.get(degree, null);
    } else {
      group = TeacherGroup.get(degree);
    }

    return group.isMember(person.getUser());
  }
Ejemplo n.º 4
0
  /**
   * Checks if person belongs to curricular course. The unit path format should be:
   * IST{.<SubUnitAcronym>}.<DegreeAcronym>.<CurricularCourseAcronym>
   *
   * <p>Accepted roles: STUDENT and TEACHER
   *
   * @param person
   * @param groupCheckQuery
   * @return
   * @throws NonExistingServiceException
   * @throws ExcepcaoPersistencia
   */
  private static Boolean checkExecutionCourseGroup(Person person, GroupCheckQuery groupCheckQuery)
      throws NonExistingServiceException {
    String[] unitAcronyms = groupCheckQuery.unitFullPath.split("\\.");

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

    Degree degree = getDegree(unitAcronyms);
    for (DegreeCurricularPlan degreeCurricularPlan : degree.getActiveDegreeCurricularPlans()) {

      ExecutionSemester executionSemester =
          getExecutionPeriod(groupCheckQuery.year, groupCheckQuery.semester);

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

      if (curricularCourse != null) {
        List<ExecutionCourse> executionCourses =
            curricularCourse.getExecutionCoursesByExecutionPeriod(executionSemester);

        for (ExecutionCourse executionCourse : executionCourses) {
          Group group;

          if (groupCheckQuery.roleType.equals("TEACHER")) {
            group = TeacherGroup.get(executionCourse);
          } else {
            group = StudentGroup.get(executionCourse);
          }

          if (group.isMember(person.getUser())) {
            return true;
          }
        }
      }
    }

    return false;
  }