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;
}
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();
}
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());
}
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;
}
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;
}
Aggregations