Esempio n. 1
0
  public void changeGroup(String groupId) throws Exception {
    OrganizationService service = WCMCoreUtils.getService(OrganizationService.class);
    UIBreadcumbs uiBreadcumb = getChild(UIBreadcumbs.class);
    uiBreadcumb.setPath(getPath(null, groupId));

    UITree tree = getChild(UITree.class);
    Collection<?> sibblingGroup;

    if (groupId == null) {
      sibblingGroup = service.getGroupHandler().findGroups(null);
      tree.setSibbling((List) sibblingGroup);
      tree.setChildren(null);
      tree.setSelected(null);
      selectGroup_ = null;
      return;
    }

    selectGroup_ = service.getGroupHandler().findGroupById(groupId);
    String parentGroupId = null;
    if (selectGroup_ != null) parentGroupId = selectGroup_.getParentId();
    Group parentGroup = null;
    if (parentGroupId != null) parentGroup = service.getGroupHandler().findGroupById(parentGroupId);

    Collection childrenGroup = service.getGroupHandler().findGroups(selectGroup_);
    sibblingGroup = service.getGroupHandler().findGroups(parentGroup);

    tree.setSibbling((List) sibblingGroup);
    tree.setChildren((List) childrenGroup);
    tree.setSelected(selectGroup_);
    tree.setParentSelected(parentGroup);
  }
  /**
   * Reset tree into the current selected group.
   *
   * @param groupId
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  private void changeGroup(String groupId) throws Exception {
    OrganizationService service = getApplicationComponent(OrganizationService.class);
    UIBreadcumbs uiBreadcumb = getChild(UIBreadcumbs.class);
    uiBreadcumb.setPath(getPath(null, groupId));

    UITree tree = getChild(UIFilterableTree.class);
    Collection<?> sibblingGroup;

    if (groupId == null) {
      sibblingGroup = service.getGroupHandler().findGroups(null);
      tree.setSibbling((List) sibblingGroup);
      tree.setChildren(null);
      tree.setSelected(null);
      selectGroup_ = null;
      return;
    }

    selectGroup_ = service.getGroupHandler().findGroupById(groupId);
    String parentGroupId = null;
    if (selectGroup_ != null) parentGroupId = selectGroup_.getParentId();
    Group parentGroup = null;
    if (parentGroupId != null) parentGroup = service.getGroupHandler().findGroupById(parentGroupId);

    Collection childrenGroup = service.getGroupHandler().findGroups(selectGroup_);
    sibblingGroup = service.getGroupHandler().findGroups(parentGroup);

    tree.setSibbling((List) sibblingGroup);
    tree.setChildren((List) childrenGroup);
    tree.setSelected(selectGroup_);
    tree.setParentSelected(parentGroup);
  }
 /**
  * Get path of the group in tree.
  *
  * @param list
  * @param id
  * @return
  * @throws Exception
  */
 private List<LocalPath> getPath(List<LocalPath> list, String id) throws Exception {
   if (list == null) list = new ArrayList<LocalPath>(5);
   if (id == null) return list;
   OrganizationService service = getApplicationComponent(OrganizationService.class);
   Group group = service.getGroupHandler().findGroupById(id);
   if (group == null) return list;
   list.add(0, new LocalPath(group.getId(), group.getGroupName()));
   getPath(list, group.getParentId());
   return list;
 }
  public void linkMembership(User user, Group g, MembershipType mt, boolean broadcast)
      throws Exception {
    if (log.isTraceEnabled()) {
      Tools.logMethodIn(
          log,
          LogLevel.TRACE,
          "linkMembership",
          new Object[] {"user", user, "group", g, "membershipType", mt, "broadcast", broadcast});
    }

    orgService.flush();

    if (user == null) {
      throw new InvalidNameException("Can not create membership record because user is null");
    }
    if (orgService.getUserHandler().findUserByName(user.getUserName()) == null) {
      throw new InvalidNameException(
          "Can not create membership record because user "
              + user.getUserName()
              + " does not exist.");
    }

    if (g == null) {
      throw new InvalidNameException(
          "Can not create membership record for " + user.getUserName() + " because group is null");
    }
    // Check group exist
    Group g1 = this.orgService.getGroupHandler().findGroupById(g.getId());
    if (g1 == null) {
      throw new InvalidNameException(
          "Can not create membership record for "
              + user.getUserName()
              + " because group "
              + g.getGroupName()
              + " is not exist");
    }

    if (mt == null) {
      throw new InvalidNameException(
          "Can not create membership record for "
              + user.getUserName()
              + " because membership type is null");
    }

    if (orgService.getMembershipTypeHandler().findMembershipType(mt.getName()) == null) {
      throw new InvalidNameException("MembershipType doesn't exist: " + mt.getName());
    }

    String plGroupName = getPLIDMGroupName(g.getGroupName());

    String groupId =
        getIdentitySession()
            .getPersistenceManager()
            .createGroupKey(
                plGroupName, orgService.getConfiguration().getGroupType(g.getParentId()));

    if (isCreateMembership(mt.getName(), g.getId())) {
      if (getIdentitySession().getRoleManager().getRoleType(mt.getName()) == null) {
        getIdentitySession().getRoleManager().createRoleType(mt.getName());
      }

      if (getIdentitySession()
          .getRoleManager()
          .hasRole(user.getUserName(), groupId, mt.getName())) {
        return;
      }
    }

    if (isAssociationMapped() && getAssociationMapping().equals(mt.getName())) {
      getIdentitySession()
          .getRelationshipManager()
          .associateUserByKeys(groupId, user.getUserName());
    }

    MembershipImpl membership = new MembershipImpl();
    membership.setMembershipType(mt.getName());
    membership.setUserName(user.getUserName());
    membership.setGroupId(g.getId());

    if (broadcast) {
      preSave(membership, true);
    }

    if (isCreateMembership(mt.getName(), g.getId())) {
      getIdentitySession().getRoleManager().createRole(mt.getName(), user.getUserName(), groupId);
    }

    if (broadcast) {
      postSave(membership, true);
    }
  }