/** * Get an EntityEnum for a String type representation. * * @param type * @return */ public static EntityEnum getEntityEnum(String type) { if (PORTLET.toString().equalsIgnoreCase(type)) { return PORTLET; } else if (CATEGORY.toString().equalsIgnoreCase(type)) { return CATEGORY; } else if (PERSON.toString().equalsIgnoreCase(type)) { return PERSON; } else if (GROUP.toString().equalsIgnoreCase(type)) { return GROUP; } return null; }
public String getEntityTypeAsString() { return entityType.toString().toUpperCase(); }
/** * Compute a hash based on type and ID to uniquely identify this bean. This method helps avoid * the unlikely case where a group and person in the same principal list have the same ID. * * <p>Periods are replaced to avoid issues in JSP EL and form names can't contain spaces. Also * SpEL parsing of form field names fails with characters such as dash or parenthesis (which * PAGS groups can have) and likely other characters so they are also replaced with underscores. * * @return EntityType + "_" + ID */ public String getTypeAndIdHash() { assert (entityType != null); assert (id != null); String idStr = id.replaceAll("\\W", "__"); return entityType.toString().toLowerCase() + "_" + idStr; }
@Override public Set<String> getEntityTypesForGroupType(String groupType) { // add the group type itself to the allowed list Set<String> set = new HashSet<String>(); set.add(groupType); /* * If the supplied type is a person group, add the person entity type. * If the supplied type is a category, add the channel type. Otherwise, * throw an exception. * * This method will require an update if more entity types are added * in the future. */ EntityEnum type = EntityEnum.getEntityEnum(groupType); if (EntityEnum.GROUP.equals(type)) { set.add(EntityEnum.PERSON.toString()); } else if (EntityEnum.CATEGORY.equals(type)) { set.add(EntityEnum.PORTLET.toString()); } else { throw new IllegalArgumentException( "Unable to determine a root entity for group type '" + groupType + "'"); } return set; }
@Override public Entity getGroup(String groupId, boolean populateChildren) { return EntityService.instance() .getEntity(EntityEnum.GROUP.toString(), groupId, populateChildren); }
public static Entity createEntity(IGroupMember member, EntityEnum entityType) { if (member == null) { return null; } Entity entity = new EntityImpl(); entity.setEntityType(entityType.toString()); entity.setId(member.getKey()); setPrincipal(entity); return entity; }
public IAuthorizationPrincipal getPrincipalForEntity(Entity entity) { // attempt to determine the entity type class for this principal if (entity == null) { return null; } Class entityType; if (entity.getEntityType().equals(EntityEnum.GROUP.toString())) { entityType = IEntityGroup.class; } else { entityType = EntityEnum.getEntityEnum(entity.getEntityType()).getClazz(); } // construct an authorization principal for this JsonEntityBean AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance(); IAuthorizationPrincipal p = authService.newPrincipal(entity.getId(), entityType); return p; }
public Entity getEntity(IGroupMember member) { if (member == null) { return null; } // get the type of this member entity EntityEnum entityEnum = getEntityType(member); // construct a new entity bean for this entity Entity entity; if (entityEnum.isGroup()) { entity = EntityFactory.createEntity((IEntityGroup) member, entityEnum); } else { entity = EntityFactory.createEntity(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.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; }
public static Entity createEntity(IEntityGroup group, EntityEnum entityType) { if (group == null) { return null; } Entity entity = new EntityImpl(); entity.setEntityType(entityType.toString()); entity.setId(group.getKey()); entity.setName(group.getName()); entity.setCreatorId(group.getCreatorID()); entity.setDescription(group.getDescription()); setPrincipal(entity); return entity; }
/** * 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; }