コード例 #1
0
ファイル: EntityService.java プロジェクト: cl4r1ty2/uPortal
  public Entity getEntity(IGroupMember member) {

    // 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;
  }
コード例 #2
0
  private void processDefaultHolder(
      Entity entity, AnnotationMetadata<DefaultHolder> defaultHolder) {

    Query query = ContextUtil.getEntityFactory().buildQuery(entity.getEntityType());
    for (String filter : defaultHolder.getAnnotation().filters()) {
      query.addCriterion(
          new Path(filter),
          Condition.EQ,
          ContextUtil.getMRS()
              .getPropertyMetadata(entity.getEntityType(), filter)
              .getValue(entity));
    }
    List<Entity> existingEntities = ContextUtil.getDRS().findByQuery(query);
    PropertyMetadata propertyMetadata =
        ContextUtil.getMRS()
            .getPropertyMetadata(entity.getEntityType(), defaultHolder.getField().getName());
    boolean currentValue = (Boolean) propertyMetadata.getValue(entity);

    if (existingEntities.size() > 1 && currentValue) {
      for (Entity existingEntity : existingEntities) {
        if (!existingEntity.equals(entity) && (Boolean) propertyMetadata.getValue(existingEntity)) {
          propertyMetadata.setValue(existingEntity, false);
          sessionFactory.getCurrentSession().saveOrUpdate(existingEntity);
        }
      }
    } else if (existingEntities.size() == 1 && !currentValue) {
      propertyMetadata.setValue(entity, true);
      sessionFactory.getCurrentSession().saveOrUpdate(entity);
    }
  }
コード例 #3
0
ファイル: EntityService.java プロジェクト: cl4r1ty2/uPortal
  public IAuthorizationPrincipal getPrincipalForEntity(Entity entity) {

    // attempt to determine the entity type class for this principal
    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
    AuthorizationService authService = AuthorizationService.instance();
    IAuthorizationPrincipal p = authService.newPrincipal(entity.getId(), entityType);
    return p;
  }
コード例 #4
0
ファイル: EntityService.java プロジェクト: cl4r1ty2/uPortal
  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;
    }
  }
コード例 #5
0
ファイル: EntityService.java プロジェクト: cl4r1ty2/uPortal
 /**
  * Convenience method that looks up the name of the given group member. Used for person types.
  *
  * @param entity Entity to look up
  * @return groupMember's name or null if there's an error
  */
 public String lookupEntityName(Entity entity) {
   EntityEnum entityEnum = EntityEnum.getEntityEnum(entity.getEntityType());
   return lookupEntityName(entityEnum, entity.getId());
 }