当前位置: 首页>>代码示例>>Java>>正文


Java Entity.getId方法代码示例

本文整理汇总了Java中org.apache.olingo.commons.api.data.Entity.getId方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getId方法的具体用法?Java Entity.getId怎么用?Java Entity.getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.olingo.commons.api.data.Entity的用法示例。


在下文中一共展示了Entity.getId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeAddedUpdatedEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
public void writeAddedUpdatedEntity(final ServiceMetadata metadata, final EdmEntityType entityType,
    final Entity entity, final ExpandOption expand, final SelectOption select, final ContextURL url,
    final boolean onlyReference, String name, final JsonGenerator json)
    throws IOException, SerializerException {
  json.writeStartObject();
  if (entity.getId() != null && url != null) {
    name = url.getEntitySetOrSingletonOrType();
    String entityId = entity.getId().toString();
    if (!entityId.contains(name)) {
      String entityName = entityId.substring(0, entityId.indexOf("("));
      if (!entityName.equals(name)) {
        json.writeStringField(Constants.AT + Constants.CONTEXT, Constants.HASH + entityName
            + Constants.ENTITY);
      }
    }
  }
  json.writeStringField(Constants.AT + Constants.ATOM_ATTR_ID, getEntityId(entity, entityType, name));
  writeProperties(metadata, entityType, entity.getProperties(), select, json);
  writeNavigationProperties(metadata, entityType, entity, expand, name, json);
  json.writeEndObject();

}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:23,代码来源:JsonDeltaSerializerWithNavigations.java

示例2: getEntityId

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  try {
    if (entity != null) {
      if (entity.getId() == null) {
        if (entityType == null || entityType.getKeyPredicateNames() == null
            || name == null) {
          throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
        } else {
          final UriHelper uriHelper = new UriHelperImpl();
          entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
          return entity.getId().toASCIIString();
        }
      } else {
        return entity.getId().toASCIIString();
      }
    }
    return null;
  } catch (Exception e) {
    throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:29,代码来源:JsonDeltaSerializerWithNavigations.java

示例3: writeAddedUpdatedEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
public void writeAddedUpdatedEntity(final ServiceMetadata metadata, final EdmEntityType entityType,
    final Entity entity, final ExpandOption expand, final SelectOption select, final ContextURL url,
    final boolean onlyReference, String name, final JsonGenerator json)
    throws IOException, SerializerException {
  json.writeStartObject();
  if (entity.getId() != null && url != null) {
    String entityId = entity.getId().toString();
    name = url.getEntitySetOrSingletonOrType();
    if (!entityId.contains(name)) {
      String entityName = entityId.substring(0, entityId.indexOf("("));
      if (!entityName.equals(name)) {
        json.writeStringField(Constants.JSON_CONTEXT, HASH + entityName + ENTITY);
      }
    }
  }
  json.writeStringField(Constants.JSON_ID, getEntityId(entity, entityType, name));
  writeProperties(metadata, entityType, entity.getProperties(), select, json);
  json.writeEndObject();

}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:21,代码来源:JsonDeltaSerializer.java

示例4: getEntityId

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  try {
    if (entity != null) {
      if (entity.getId() == null) {
        if (entityType == null || entityType.getKeyPredicateNames() == null
            || name == null) {
          throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
        } else {
          final UriHelper uriHelper = new UriHelperImpl();
          entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
          return entity.getId().toASCIIString();
        }
      } else {
        return entity.getId().toASCIIString();
      }
    } 
    return null;
  } catch (Exception e) {
    throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:29,代码来源:JsonDeltaSerializer.java

示例5: getEntityId

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @param entityType 
 * @param name 
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  if(entity != null && entity.getId() == null) {
    if(entityType == null || entityType.getKeyPredicateNames() == null 
        || name == null) {
      throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
    }else{
      final UriHelper uriHelper = new UriHelperImpl(); 
      entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
    }
  }
  return entity.getId().toASCIIString();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:ODataJsonSerializer.java

示例6: writeDeletedEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void writeDeletedEntity(Entity deletedEntity,
    JsonGenerator json) throws IOException, SerializerException {
  if (deletedEntity.getId() == null) {
    throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
  }
  json.writeStartObject();
  if (isODataMetadataFull) {

    json.writeStringField(Constants.AT + Constants.CONTEXT, Constants.HASH + deletedEntity.getId().toASCIIString()
        + Constants.DELETEDENTITY);
  }
  if (((DeletedEntity) deletedEntity).getReason() == null) {
    throw new SerializerException("DeletedEntity reason is null.",
        SerializerException.MessageKeys.MISSING_DELTA_PROPERTY, Constants.REASON);
  }
  json.writeFieldName(Constants.AT + Constants.REMOVED);
  json.writeStartObject();
  json.writeStringField(Constants.ELEM_REASON,
      ((DeletedEntity) deletedEntity).getReason().name());
  List<Annotation> annotations = deletedEntity.getAnnotations();
  if (annotations != null && !annotations.isEmpty()) {
    for (Annotation annotation : annotations) {
      json.writeStringField(Constants.AT + annotation.getTerm(), annotation.getValue().toString());
    }
  }
  json.writeEndObject();
  List<Property> properties = deletedEntity.getProperties();
  if (properties != null && !properties.isEmpty()) {
    for (Property property : properties) {
      json.writeStringField(property.getName(), property.getValue().toString());
    }
  }
  json.writeStringField(Constants.AT + Constants.ATOM_ATTR_ID, deletedEntity.getId().toASCIIString());
  json.writeEndObject();

}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:37,代码来源:JsonDeltaSerializerWithNavigations.java

示例7: getEntityId

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
 * Get the ascii representation of the entity id
 * or thrown an {@link SerializerException} if id is <code>null</code>.
 *
 * @param entity the entity
 * @param entityType the entity Type
 * @param name the entity name
 * @return ascii representation of the entity id
 */
private String getEntityId(Entity entity, EdmEntityType entityType, String name) throws SerializerException {
  if(entity.getId() == null) {
    if((entity == null || entityType == null || entityType.getKeyPredicateNames() == null 
        || name == null)) {
      throw new SerializerException("Entity id is null.", SerializerException.MessageKeys.MISSING_ID);
    }else{
      final UriHelper uriHelper = new UriHelperImpl(); 
      entity.setId(URI.create(name + '(' + uriHelper.buildKeyPredicate(entityType, entity) + ')'));
    }
  }
  return entity.getId().toASCIIString();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:ODataXmlSerializer.java

示例8: doContainerSerialize

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
protected void doContainerSerialize(final ResWrap<Entity> container, final JsonGenerator jgen)
    throws IOException, EdmPrimitiveTypeException {

  final Entity entity = container.getPayload();

  jgen.writeStartObject();

  if (serverMode) {
    if (container.getContextURL() != null) {
      jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString());
    }
    if (container.getMetadataETag() != null) {
      jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag());
    }

    if (entity.getETag() != null) {
      jgen.writeStringField(Constants.JSON_ETAG, entity.getETag());
    }
  }

  if (entity.getType() != null && !isODataMetadataNone) {
    jgen.writeStringField(Constants.JSON_TYPE,
        new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external());
  }

  if (entity.getId() != null && !isODataMetadataNone) {
    jgen.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
  }

  for (Annotation annotation : entity.getAnnotations()) {
    valuable(jgen, annotation, "@" + annotation.getTerm());
  }

  for (Property property : entity.getProperties()) {
    valuable(jgen, property, property.getName());
  }

  if (serverMode && entity.getEditLink() != null && entity.getEditLink().getHref() != null) {
    jgen.writeStringField(Constants.JSON_EDIT_LINK, entity.getEditLink().getHref());

    if (entity.isMediaEntity()) {
      jgen.writeStringField(Constants.JSON_MEDIA_READ_LINK,
          entity.getEditLink().getHref() + "/$value");
    }
  }

  if (!isODataMetadataNone) {
    links(entity, jgen);
  }

  for (Link link : entity.getMediaEditLinks()) {
    if (link.getTitle() == null) {
      jgen.writeStringField(Constants.JSON_MEDIA_EDIT_LINK, link.getHref());
    }

    if (link.getInlineEntity() != null) {
      jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
    }
    if (link.getInlineEntitySet() != null) {
      jgen.writeArrayFieldStart(link.getTitle());
      for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
        jgen.writeObject(subEntry);
      }
      jgen.writeEndArray();
    }
  }

  if (serverMode) {
    for (Operation operation : entity.getOperations()) {
      final String anchor = operation.getMetadataAnchor();
      final int index = anchor.lastIndexOf('#');
      jgen.writeObjectFieldStart('#' + anchor.substring(index < 0 ? 0 : (index + 1)));
      jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle());
      jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
      jgen.writeEndObject();
    }
  }

  jgen.writeEndObject();
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:81,代码来源:JsonEntitySerializer.java


注:本文中的org.apache.olingo.commons.api.data.Entity.getId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。