@Atomic
  public static void run(Department department, String[] add, String[] remove) {
    check(RolePredicates.DEPARTMENT_ADMINISTRATIVE_OFFICE_PREDICATE);
    List<Person> toAdd = materializePersons(add);
    List<Person> toRemove = materializePersons(remove);
    List<Person> finalList = new ArrayList<Person>();

    Role bolonhaRole = Role.getRoleByRoleType(RoleType.BOLONHA_MANAGER);

    Group group = department.getCompetenceCourseMembersGroup();
    if (group == null) {
      group = new FixedSetGroup();
    }

    for (Person person : group.getElements()) {

      if (!toRemove.contains(person)) {
        finalList.add(person);
        addBolonhaRole(person, bolonhaRole);
      } else if (person.hasRole(RoleType.BOLONHA_MANAGER)
          && !belongsToOtherGroupsWithSameRole(department, person)) {
        person.removeRoleByType(RoleType.BOLONHA_MANAGER);
      }
    }

    for (Person person : toAdd) {
      if (!finalList.contains(person)) {
        finalList.add(person);
        addBolonhaRole(person, bolonhaRole);
      }
    }

    department.setCompetenceCourseMembersGroup(new FixedSetGroup(finalList));
  }
Example #2
0
  private void fillParticipant(
      String guiderRole,
      final PhdIndividualProgramProcess process,
      PhdParticipant phdParticipant,
      HSSFRow row) {
    String processNumber = process.getProcessNumber();
    String studentNumber =
        process.getStudent() != null ? process.getStudent().getNumber().toString() : "";
    String studentName = process.getPerson().getName();

    String participantName = phdParticipant.getName();
    String institution = phdParticipant.getWorkLocation();

    addCellValue(row, onNullEmptyString(processNumber), 0);
    addCellValue(row, onNullEmptyString(studentNumber), 1);
    addCellValue(row, onNullEmptyString(studentName), 2);
    addCellValue(row, onNullEmptyString(participantName), 3);
    addCellValue(row, onNullEmptyString(guiderRole), 4);
    addCellValue(row, onNullEmptyString(institution), 5);

    if (!phdParticipant.isTeacher()) {
      addCellValue(row, onNullEmptyString(null), 6);
      addCellValue(row, onNullEmptyString(null), 7);
      addCellValue(row, onNullEmptyString(null), 8);
    } else {
      InternalPhdParticipant internalPhdParticipant = (InternalPhdParticipant) phdParticipant;
      Teacher teacher = internalPhdParticipant.getTeacher();

      addCellValue(row, onNullEmptyString(teacher.getTeacherId()), 6);
      Department department = internalPhdParticipant.getDepartment();

      addCellValue(row, onNullEmptyString(department != null ? department.getCode() : ""), 7);
      addCellValue(row, onNullEmptyString(department != null ? department.getName() : ""), 8);
    }
  }
 private List<SelectItem> readAllowedDepartmentUnits() {
   final List<SelectItem> result = new ArrayList<SelectItem>();
   for (final Department department : Bennu.getInstance().getDepartmentsSet()) {
     if (department.getCompetenceCourseMembersGroup() != null
         && department.getCompetenceCourseMembersGroup().isMember(getUserView())) {
       DepartmentUnit departmentUnit = department.getDepartmentUnit();
       result.add(new SelectItem(departmentUnit.getExternalId(), departmentUnit.getName()));
     }
   }
   Collections.sort(result, new BeanComparator("label"));
   if (result.size() == 1) {
     Department personDepartment = getPersonDepartment();
     if (personDepartment != null
         && !result
             .get(0)
             .getValue()
             .equals(personDepartment.getDepartmentUnit().getExternalId())) {
       result.add(
           0,
           new SelectItem(
               personDepartment.getDepartmentUnit().getExternalId(), personDepartment.getName()));
     }
   }
   return result;
 }
 public ActionForward selectYear(
     ActionMapping mapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response) {
   YearSelection yearSelection = getYearSelection(request);
   DegreeCurricularPlan dcp = getDegreeCurricularPlan(request);
   List<TutorshipIntentionSelector> selector = new ArrayList<TutorshipIntentionSelector>();
   for (Department department : dcp.getDegree().getDepartmentsSet()) {
     for (Teacher teacher : department.getAllTeachers(yearSelection.getExecutionYear())) {
       selector.add(
           new TutorshipIntentionSelector(
               teacher, department, dcp, yearSelection.getExecutionYear()));
     }
   }
   RenderUtils.invalidateViewState();
   request.setAttribute("yearSelection", yearSelection);
   request.setAttribute("selector", selector);
   return mapping.findForward("manage");
 }
  private static boolean belongsToOtherGroupsWithSameRole(
      Department departmentWhoAsks, Person person) {
    Collection<Department> departments = Bennu.getInstance().getDepartmentsSet();
    for (Department department : departments) {
      if (department != departmentWhoAsks) {
        Group group = department.getCompetenceCourseMembersGroup();
        if (group != null && group.isMember(person)) {
          return true;
        }
      }
    }

    for (Degree degree : Degree.readBolonhaDegrees()) {
      for (DegreeCurricularPlan dcp : degree.getDegreeCurricularPlans()) {
        Group group = dcp.getCurricularPlanMembersGroup();
        if (group != null && group.isMember(person)) {
          return true;
        }
      }
    }

    return false;
  }
  @Service
  public static List run(Integer departmentId, Integer executionYearId)
      throws FenixServiceException {

    // Execution Year
    ExecutionYear executionYear = null;
    if (executionYearId != null) {
      executionYear = rootDomainObject.readExecutionYearByOID(executionYearId);
    }
    // Departement
    Department department = rootDomainObject.readDepartmentByOID(departmentId);
    List teachers = department.getAllCurrentTeachers();
    Iterator iter = teachers.iterator();

    List<Professorship> professorships = new ArrayList<Professorship>();
    List<Professorship> responsibleFors = new ArrayList<Professorship>();
    while (iter.hasNext()) {
      Teacher teacher = (Teacher) iter.next();
      List<Professorship> teacherProfessorships = null;
      if (executionYear == null) {
        teacherProfessorships = teacher.getProfessorships();
      } else {
        teacherProfessorships = teacher.getProfessorships(executionYear);
      }
      if (teacherProfessorships != null) {
        professorships.addAll(teacherProfessorships);
      }

      List<Professorship> teacherResponsibleFors = null;
      if (executionYear == null) {
        teacherResponsibleFors = teacher.responsibleFors();
      } else {
        teacherResponsibleFors = new ArrayList<Professorship>();
        for (final Professorship professorship : teacher.responsibleFors()) {
          if (professorship.getExecutionCourse().isLecturedIn(executionYear)) {
            teacherResponsibleFors.add(professorship);
          }
        }
      }
      if (teacherResponsibleFors != null) {
        responsibleFors.addAll(teacherResponsibleFors);
      }
    }

    List detailedProfessorships = getDetailedProfessorships(professorships, responsibleFors);

    Collections.sort(
        detailedProfessorships,
        new Comparator() {

          @Override
          public int compare(Object o1, Object o2) {

            DetailedProfessorship detailedProfessorship1 = (DetailedProfessorship) o1;
            DetailedProfessorship detailedProfessorship2 = (DetailedProfessorship) o2;
            int result =
                detailedProfessorship1
                        .getInfoProfessorship()
                        .getInfoExecutionCourse()
                        .getIdInternal()
                        .intValue()
                    - detailedProfessorship2
                        .getInfoProfessorship()
                        .getInfoExecutionCourse()
                        .getIdInternal()
                        .intValue();
            if (result == 0
                && (detailedProfessorship1.getResponsibleFor().booleanValue()
                    || detailedProfessorship2.getResponsibleFor().booleanValue())) {
              if (detailedProfessorship1.getResponsibleFor().booleanValue()) {
                return -1;
              }
              if (detailedProfessorship2.getResponsibleFor().booleanValue()) {
                return 1;
              }
            }

            return result;
          }
        });

    List result = new ArrayList();
    iter = detailedProfessorships.iterator();
    List<DetailedProfessorship> temp = new ArrayList<DetailedProfessorship>();
    while (iter.hasNext()) {
      DetailedProfessorship detailedProfessorship = (DetailedProfessorship) iter.next();
      if (temp.isEmpty()
          || temp.get(temp.size() - 1)
              .getInfoProfessorship()
              .getInfoExecutionCourse()
              .equals(detailedProfessorship.getInfoProfessorship().getInfoExecutionCourse())) {
        temp.add(detailedProfessorship);
      } else {
        result.add(temp);
        temp = new ArrayList<DetailedProfessorship>();
        temp.add(detailedProfessorship);
      }
    }
    if (!temp.isEmpty()) {
      result.add(temp);
    }
    return result;
  }