Exemplo n.º 1
0
  public Set<Entity> search(String entityType, String searchTerm) {

    Set<Entity> results = new HashSet<Entity>();
    EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    EntityIdentifier[] identifiers;
    Class identifierType;

    // if the entity type is a group, use the group service's findGroup method
    // to locate it
    if (entityEnum.isGroup()) {
      identifiers =
          GroupService.searchForGroups(searchTerm, GroupService.CONTAINS, entityEnum.getClazz());
      identifierType = IEntityGroup.class;
    }
    // otherwise use the getGroupMember method
    else {
      identifiers =
          GroupService.searchForEntities(searchTerm, GroupService.CONTAINS, 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;
  }
Exemplo n.º 2
0
  public Entity getEntity(String entityType, String entityId, boolean populateChildren) {

    // get the EntityEnum for the specified entity type
    EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);

    // if the entity type is a group, use the group service's findGroup method
    // 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) {
          @SuppressWarnings("unchecked")
          Iterator<IGroupMember> members = (Iterator<IGroupMember>) entityGroup.getMembers();
          entity = populateChildren(entity, members);
        }
        IAuthorizationPrincipal authP = getPrincipalForEntity(entity);
        Principal principal = new PrincipalImpl(authP.getKey(), authP.getPrincipalString());

        entity.setPrincipal(principal);
        return entity;
      }
    }

    // otherwise use the getGroupMember method
    else {
      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;
    }
  }