Search in sources :

Example 51 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup 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 52 with IEntityGroup

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

the class GroupAdministrationHelper method deleteGroup.

/**
 * Delete a group from the group store
 *
 * @param key key of the group to be deleted
 * @param user performing the delete operation
 */
public void deleteGroup(String key, IPerson deleter) {
    if (!canDeleteGroup(deleter, key)) {
        throw new RuntimeAuthorizationException(deleter, IPermission.DELETE_GROUP_ACTIVITY, key);
    }
    log.info("Deleting group with key " + key);
    // find the current version of this group entity
    IEntityGroup group = GroupService.findGroup(key);
    // groups
    for (IEntityGroup parent : group.getParentGroups()) {
        parent.removeChild(group);
        parent.updateMembers();
    }
    // delete the group
    group.delete();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException)

Example 53 with IEntityGroup

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

the class GroupAdministrationHelper method updateGroupDetails.

/**
 * Update the title and description of an existing group in the group store.
 *
 * @param groupForm Form representing the new group configuration
 * @param updater Updating user
 */
public void updateGroupDetails(GroupForm groupForm, IPerson updater) {
    if (!canEditGroup(updater, groupForm.getKey())) {
        throw new RuntimeAuthorizationException(updater, IPermission.EDIT_GROUP_ACTIVITY, groupForm.getKey());
    }
    if (log.isDebugEnabled()) {
        log.debug("Updating group for group form [" + groupForm.toString() + "]");
    }
    // find the current version of this group entity
    IEntityGroup group = GroupService.findGroup(groupForm.getKey());
    group.setName(groupForm.getName());
    group.setDescription(groupForm.getDescription());
    // save the group, updating both its basic information and group
    // membership
    group.update();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException)

Example 54 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup 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 55 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup 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)

Aggregations

IEntityGroup (org.apereo.portal.groups.IEntityGroup)77 IGroupMember (org.apereo.portal.groups.IGroupMember)29 ArrayList (java.util.ArrayList)21 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)16 EntityIdentifier (org.apereo.portal.EntityIdentifier)14 HashSet (java.util.HashSet)11 HashMap (java.util.HashMap)10 LinkedList (java.util.LinkedList)9 GroupsException (org.apereo.portal.groups.GroupsException)9 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)9 IPermission (org.apereo.portal.security.IPermission)9 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)8 List (java.util.List)7 CompositeName (javax.naming.CompositeName)7 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 IPerson (org.apereo.portal.security.IPerson)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 DateTime (org.joda.time.DateTime)7