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