use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class EntityService method getEntity.
public Entity getEntity(String entityType, String entityId, boolean populateChildren) {
// get the EntityEnum for the specified entity type
if (StringUtils.isBlank(entityType) && StringUtils.isBlank(entityId)) {
return null;
}
final EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
if (entityEnum == null) {
throw new RuntimeException("EntityEnum instance not found for specified type: " + entityType);
}
// to locate it
if (entityEnum.isGroup()) {
// attempt to find the entity
IEntityGroup entityGroup = GroupService.findGroup(entityId);
if (entityGroup == null) {
return null;
} else {
Entity entity = EntityFactory.createEntity(entityGroup, entityEnum);
if (populateChildren) {
Iterator<IGroupMember> members = entityGroup.getChildren().iterator();
entity = populateChildren(entity, members);
}
IAuthorizationPrincipal authP = getPrincipalForEntity(entity);
Principal principal = new PrincipalImpl(authP.getKey(), authP.getPrincipalString());
entity.setPrincipal(principal);
return entity;
}
} else // otherwise use the getGroupMember method
{
IGroupMember groupMember = GroupService.getGroupMember(entityId, entityEnum.getClazz());
if (groupMember == null || groupMember instanceof IEntityGroup) {
return null;
}
Entity entity = EntityFactory.createEntity(groupMember, entityEnum);
// the group member interface doesn't include the entity name, so
// we'll need to look that up manually
entity.setName(lookupEntityName(entity));
if (EntityEnum.GROUP.toString().equals(entity.getEntityType()) || EntityEnum.PERSON.toString().equals(entity.getEntityType())) {
IAuthorizationPrincipal authP = getPrincipalForEntity(entity);
Principal principal = new PrincipalImpl(authP.getKey(), authP.getPrincipalString());
entity.setPrincipal(principal);
}
return entity;
}
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class EntityService method search.
// External search, thus case insensitive.
public Set<Entity> search(String entityType, String searchTerm) {
if (StringUtils.isBlank(entityType) && StringUtils.isBlank(searchTerm)) {
return null;
}
final Set<Entity> results = new HashSet<>();
final EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
if (entityEnum == null) {
throw new RuntimeException("EntityEnum instance not found for specified type: " + entityType);
}
// if the entity type is a group, use the group service's findGroup method
// to locate it
EntityIdentifier[] identifiers;
Class<?> identifierType;
if (entityEnum.isGroup()) {
identifiers = GroupService.searchForGroups(searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz());
identifierType = IEntityGroup.class;
} else // otherwise use the getGroupMember method
{
identifiers = GroupService.searchForEntities(searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz());
identifierType = entityEnum.getClazz();
}
for (EntityIdentifier entityIdentifier : identifiers) {
if (entityIdentifier.getType().equals(identifierType)) {
IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
Entity entity = getEntity(groupMember);
results.add(entity);
}
}
return results;
}
use of org.apereo.portal.portlets.groupselector.EntityEnum 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.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class GroupListHelperImplTest method testGetEntityTypeCategory.
@Test
public void testGetEntityTypeCategory() {
GroupListHelperImpl helper = new GroupListHelperImpl();
MockedGroupMemberEntityGroup mocked = new MockedGroupMemberEntityGroup(IPortletDefinition.class);
EntityEnum ee = helper.getEntityType(mocked);
assertEquals("category", ee.toString());
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class PermissionAssignmentMapController method placeInHierarchy.
private void placeInHierarchy(Assignment a, List<Assignment> hierarchy, String owner, String activity, String target) {
// Assertions.
if (a == null) {
String msg = "Argument 'a' [Assignment] cannot be null";
throw new IllegalArgumentException(msg);
}
if (hierarchy == null) {
String msg = "Argument 'hierarchy' cannot be null";
throw new IllegalArgumentException(msg);
}
// is already in the hierarchy somewhere...
for (Assignment root : hierarchy) {
Assignment duplicate = root.findDecendentOrSelfIfExists(a.getPrincipal());
if (duplicate != null) {
return;
}
}
// To proceed, we need to know about the containing
// groups (if any) for this principal...
IGroupMember member = null;
EntityEnum entityEnum = a.getPrincipal().getEntityType();
if (entityEnum.isGroup()) {
member = GroupService.findGroup(a.getPrincipal().getId());
} else {
member = GroupService.getGroupMember(a.getPrincipal().getId(), entityEnum.getClazz());
}
AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
Iterator<?> it = GroupService.getCompositeGroupService().findParentGroups(member);
if (it.hasNext()) {
// This member must be nested within its parent(s)...
while (it.hasNext()) {
IEntityGroup group = (IEntityGroup) it.next();
EntityEnum beanType = EntityEnum.getEntityEnum(group.getLeafType(), true);
JsonEntityBean bean = new JsonEntityBean(group, beanType);
Assignment parent = null;
for (Assignment root : hierarchy) {
parent = root.findDecendentOrSelfIfExists(bean);
if (parent != null) {
// We found one...
parent.addChild(a);
break;
}
}
if (parent == null) {
// We weren't able to integrate this node into the existing
// hierarchy; we have to dig deeper, until we either (1)
// find a match, or (2) reach a root; type is INHERIT,
// unless (by chance) there's something specified in an
// entry on grantOrDenyMap.
IAuthorizationPrincipal principal = authService.newPrincipal(group);
Assignment.Type assignmentType = getAssignmentType(principal, owner, activity, target);
parent = new Assignment(principal.getPrincipalString(), bean, assignmentType);
parent.addChild(a);
placeInHierarchy(parent, hierarchy, owner, activity, target);
}
}
} else {
// This member is a root...
hierarchy.add(a);
}
}
Aggregations