Search in sources :

Example 31 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class GroupAdministrationHelper method getGroupForm.

/**
 * Construct a group form for the group with the specified key.
 *
 * @param key
 * @param entityEnum
 * @return
 */
public GroupForm getGroupForm(String key) {
    log.debug("Initializing group form for group key " + key);
    // find the current version of this group entity
    IEntityGroup group = GroupService.findGroup(key);
    // update the group form with the existing group's main information
    GroupForm form = new GroupForm();
    form.setKey(key);
    form.setName(group.getName());
    form.setDescription(group.getDescription());
    form.setCreatorId(group.getCreatorID());
    form.setType(groupListHelper.getEntityType(group).toString());
    // add child groups to our group form bean
    for (IGroupMember child : group.getChildren()) {
        JsonEntityBean childBean = groupListHelper.getEntity(child);
        form.addMember(childBean);
    }
    return form;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Example 32 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class GroupAdministrationHelper method createGroup.

/**
 * Create a new group under the specified parent. The new group will automatically be added to
 * the parent group.
 *
 * @param groupForm form object representing the new group
 * @param parent parent group for this new group
 * @param creator the uPortal user creating the new group
 */
public void createGroup(GroupForm groupForm, JsonEntityBean parent, IPerson creator) {
    if (!canCreateMemberGroup(creator, parent.getId())) {
        throw new RuntimeAuthorizationException(creator, IPermission.CREATE_GROUP_ACTIVITY, groupForm.getKey());
    }
    if (log.isDebugEnabled()) {
        log.debug("Creating new group for group form [" + groupForm.toString() + "] and parent [" + parent.toString() + "]");
    }
    // get the entity type of the parent group
    EntityEnum type = EntityEnum.getEntityEnum(groupForm.getType());
    // create a new group with the parent's entity type
    IEntityGroup group = GroupService.newGroup(type.getClazz());
    // find the current version of this group entity
    group.setCreatorID(creator.getUserName());
    group.setName(groupForm.getName());
    group.setDescription(groupForm.getDescription());
    // to the group
    for (JsonEntityBean child : groupForm.getMembers()) {
        EntityEnum childType = EntityEnum.getEntityEnum(child.getEntityTypeAsString());
        if (childType.isGroup()) {
            IEntityGroup member = GroupService.findGroup(child.getId());
            group.addChild(member);
        } else {
            IGroupMember member = GroupService.getGroupMember(child.getId(), type.getClazz());
            group.addChild(member);
        }
    }
    // save the group, updating both its basic information and group membership
    group.update();
    // add this group to the membership list for the specified parent
    IEntityGroup parentGroup = GroupService.findGroup(parent.getId());
    parentGroup.addChild(group);
    parentGroup.updateMembers();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Example 33 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class GroupListHelperImplTest method testGetEntityTypePortlet.

@Test
public void testGetEntityTypePortlet() {
    GroupListHelperImpl helper = new GroupListHelperImpl();
    IGroupMember mocked = manuallyMockGroupMember(IPortletDefinition.class);
    EntityEnum ee = helper.getEntityType(mocked);
    assertEquals("portlet", ee.toString());
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) GroupListHelperImpl(org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl) Test(org.junit.Test)

Example 34 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class ApiGroupsService method getGroupsForMember.

// Internal search, thus case sensitive.
@Override
public Set<Entity> getGroupsForMember(String memberName) {
    Set<Entity> groups = new HashSet<Entity>();
    if (StringUtils.isNotEmpty(memberName)) {
        EntityIdentifier[] identifiers = GroupService.searchForEntities(memberName, GroupService.SearchMethod.DISCRETE, EntityEnum.PERSON.getClazz());
        for (EntityIdentifier entityIdentifier : identifiers) {
            if (entityIdentifier.getType().equals(EntityEnum.PERSON.getClazz())) {
                IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
                if (memberName.equalsIgnoreCase(groupMember.getKey())) {
                    Iterator it = GroupService.findParentGroups(groupMember);
                    while (it.hasNext()) {
                        IEntityGroup g = (IEntityGroup) it.next();
                        Entity e = EntityFactory.createEntity(g, EntityEnum.getEntityEnum(g.getLeafType(), true));
                        groups.add(e);
                    }
                    return groups;
                }
            }
        }
    }
    return groups;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) Iterator(java.util.Iterator) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 35 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class ApiGroupsService method getMembersForGroup.

@Override
public Set<Entity> getMembersForGroup(String groupName) {
    Set<Entity> members = new HashSet<Entity>();
    if (StringUtils.isNotEmpty(groupName)) {
        EntityIdentifier[] identifiers = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, EntityEnum.GROUP.getClazz());
        for (EntityIdentifier entityIdentifier : identifiers) {
            if (entityIdentifier.getType().equals(IEntityGroup.class)) {
                IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
                if (groupMember.getLeafType().equals(IPerson.class)) {
                    String groupMemberName = EntityService.instance().lookupEntityName(EntityEnum.GROUP, groupMember.getKey());
                    if (groupName.equalsIgnoreCase(groupMemberName)) {
                        for (IGroupMember gm : groupMember.asGroup().getDescendants()) {
                            if (!gm.isGroup()) {
                                EntityIdentifier ident = gm.getUnderlyingEntityIdentifier();
                                Entity member = findMember(ident.getKey(), true);
                                members.add(member);
                            }
                        }
                        return members;
                    }
                }
            }
        }
    }
    return members;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Aggregations

IGroupMember (org.apereo.portal.groups.IGroupMember)52 IEntityGroup (org.apereo.portal.groups.IEntityGroup)29 HashSet (java.util.HashSet)17 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)14 ArrayList (java.util.ArrayList)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)12 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)10 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 IPermission (org.apereo.portal.security.IPermission)8 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)7 GroupsException (org.apereo.portal.groups.GroupsException)6 HashMap (java.util.HashMap)4 IEntity (org.apereo.portal.groups.IEntity)4 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)4 IPerson (org.apereo.portal.security.IPerson)4 Element (net.sf.ehcache.Element)3 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)3 AuthorizationServiceFacade (org.apereo.portal.services.AuthorizationServiceFacade)3 GcGetMembers (edu.internet2.middleware.grouperClient.api.GcGetMembers)2 WsGetMembersResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults)2