use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class JsonEntityBeanTest method testEqualsEntityTypeNullSource.
@Test
public void testEqualsEntityTypeNullSource() {
EntityEnum ee = null;
JsonEntityBean jeb1 = buildNullBean();
jeb1.setChildrenInitialized(true);
jeb1.setCreatorId("");
jeb1.setDescription("");
jeb1.setEntityType(ee);
JsonEntityBean jeb2 = buildNullBean();
jeb2.setChildrenInitialized(true);
jeb2.setCreatorId("");
jeb2.setDescription("");
jeb2.setEntityType(EntityEnum.PORTLET);
assertFalse(jeb1.equals(jeb2));
}
use of org.apereo.portal.portlets.groupselector.EntityEnum 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.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class GroupListHelperImpl method getEntity.
/*
* (non-Javadoc)
* @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getEntity(java.lang.String, java.lang.String, boolean)
*/
@Override
public JsonEntityBean getEntity(String entityType, String entityId, boolean populateChildren) {
// get the EntityEnum for the specified entity type
EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
if (entityEnum == null) {
throw new IllegalArgumentException(String.format("Parameter entityType has an unknown value of [%s]", entityType));
}
// to locate it
if (entityEnum.isGroup()) {
// attempt to find the entity
IEntityGroup entity = GroupService.findGroup(entityId);
if (entity == null) {
return null;
} else {
JsonEntityBean jsonBean = new JsonEntityBean(entity, entityEnum);
if (populateChildren) {
Iterator<IGroupMember> members = entity.getChildren().iterator();
jsonBean = populateChildren(jsonBean, members);
}
if (jsonBean.getEntityType().isGroup() || EntityEnum.PERSON.equals(jsonBean.getEntityType())) {
IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean);
jsonBean.setPrincipalString(principal.getPrincipalString());
}
return jsonBean;
}
} else // otherwise use the getGroupMember method
{
IGroupMember entity = GroupService.getGroupMember(entityId, entityEnum.getClazz());
if (entity == null || entity instanceof IEntityGroup) {
return null;
}
JsonEntityBean jsonBean = new JsonEntityBean(entity, entityEnum);
// the group member interface doesn't include the entity name, so
// we'll need to look that up manually
jsonBean.setName(lookupEntityName(jsonBean));
if (EntityEnum.GROUP.equals(jsonBean.getEntityType()) || EntityEnum.PERSON.equals(jsonBean.getEntityType())) {
IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean);
jsonBean.setPrincipalString(principal.getPrincipalString());
}
return jsonBean;
}
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class GroupListHelperImpl method getEntity.
/*
* (non-Javadoc)
* @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getEntity(org.apereo.portal.groups.IGroupMember)
*/
@Override
public JsonEntityBean getEntity(IGroupMember member) {
// get the type of this member entity
EntityEnum entityEnum = getEntityType(member);
// construct a new entity bean for this entity
JsonEntityBean entity;
if (entityEnum.isGroup()) {
entity = new JsonEntityBean((IEntityGroup) member, entityEnum);
} else {
entity = new JsonEntityBean(member, entityEnum);
}
// if the name hasn't been set yet, look up the entity name
if (entity.getName() == null) {
entity.setName(lookupEntityName(entity));
}
if (EntityEnum.GROUP.equals(entity.getEntityType()) || EntityEnum.PERSON.equals(entity.getEntityType())) {
IAuthorizationPrincipal principal = getPrincipalForEntity(entity);
entity.setPrincipalString(principal.getPrincipalString());
}
return entity;
}
Aggregations