Ejemplo n.º 1
0
  private SupportRequestBean userInfoContextAppend(
      HttpServletRequest request, final StringBuilder exceptionInfo) {

    exceptionInfo.append("[UserLoggedIn] ");

    SupportRequestBean requestBean;
    String user;
    User userView = Authenticate.getUser();
    if (userView != null) {
      user = userView.getUsername();
      requestBean = SupportRequestBean.generateExceptionBean(userView.getPerson());
      MenuFunctionality selectedFunctionality =
          BennuPortalDispatcher.getSelectedFunctionality(request);
      if (selectedFunctionality != null) {
        requestBean.setSelectedFunctionality(selectedFunctionality);
      }
      setUserName(user);
      Set<RoleType> roles = new HashSet<RoleType>();
      for (Role role : userView.getPerson().getPersonRolesSet()) {
        roles.add(role.getRoleType());
      }
      setUserRoles(roles);
    } else {
      user = "******";
      requestBean = SupportRequestBean.generateExceptionBean(null);
    }
    exceptionInfo.append(user + "\n");
    return requestBean;
  }
  @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));
  }