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


Java Entity.setId方法代码示例

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


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

示例1: parse

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Override
public InstanceData<EdmEntityType, Entity> parse(SearchResponse response,
        ElasticEdmEntitySet entitySet) throws ODataApplicationException {
    ElasticEdmEntityType entityType = entitySet.getEntityType();
    Iterator<SearchHit> hits = response.getHits().iterator();
    if (hits.hasNext()) {
        SearchHit firstHit = hits.next();
        Map<String, Object> source = firstHit.getSource();

        Entity entity = new Entity();
        entity.setId(ProcessorUtils.createId(entityType.getName(), firstHit.getId()));
        entity.addProperty(
                createProperty(ElasticConstants.ID_FIELD_NAME, firstHit.getId(), entityType));

        for (Map.Entry<String, Object> entry : source.entrySet()) {
            ElasticEdmProperty edmProperty = entityType.findPropertyByEField(entry.getKey());
            entity.addProperty(
                    createProperty(edmProperty.getName(), entry.getValue(), entityType));
        }
        return new InstanceData<>(entityType, entity);
    } else {
        throw new ODataApplicationException("No data found", HttpStatus.SC_NOT_FOUND,
                Locale.ROOT);
    }
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:26,代码来源:EntityParser.java

示例2: parse

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Override
public InstanceData<EdmEntityType, AbstractEntityCollection> parse(SearchResponse response,
        ElasticEdmEntitySet entitySet) {
    ElasticEdmEntityType entityType = entitySet.getEntityType();
    EntityCollection entities = new EntityCollection();
    for (SearchHit hit : response.getHits()) {
        Map<String, Object> source = hit.getSource();

        Entity entity = new Entity();
        entity.setId(ProcessorUtils.createId(entityType.getName(), hit.getId()));
        entity.addProperty(
                createProperty(ElasticConstants.ID_FIELD_NAME, hit.getId(), entityType));

        for (Map.Entry<String, Object> entry : source.entrySet()) {
            ElasticEdmProperty edmProperty = entityType.findPropertyByEField(entry.getKey());
            entity.addProperty(
                    createProperty(edmProperty.getName(), entry.getValue(), entityType));
        }
        entities.getEntities().add(entity);
    }
    if (isCount()) {
        entities.setCount((int) response.getHits().getTotalHits());
    }
    return new InstanceData<>(entityType, entities);
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:26,代码来源:EntityCollectionParser.java

示例3: create

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
public Entity create(final EdmEntitySet edmEntitySet) throws DataProviderException {
  final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
  EntityCollection entitySet = readAll(edmEntitySet);
  final List<Entity> entities = entitySet.getEntities();
  final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntitySet.getEntityType());
  Entity newEntity = new Entity();
  newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
  for (final String keyName : edmEntityType.getKeyPredicateNames()) {
    newEntity.addProperty(DataCreator.createPrimitive(keyName, newKey.get(keyName)));
  }

  createProperties(edmEntityType, newEntity.getProperties());
  try {
    newEntity
        .setId(URI.create(odata.createUriHelper().buildCanonicalURL(edmEntitySet, newEntity)));
  } catch (final SerializerException e) {
    throw new DataProviderException("Unable to set entity ID!", e);
  }
  entities.add(newEntity);

  return newEntity;
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:23,代码来源:DataProvider.java

示例4: createEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private Entity createEntity(EdmEntityType edmEntityType, Entity entity, List<Entity> entityList) {
  
  // the ID of the newly created entity is generated automatically
  int newId = 1;
  while (entityIdExists(newId, entityList)) {
    newId++;
  }

  Property idProperty = entity.getProperty("ID");
  if (idProperty != null) {
    idProperty.setValue(ValueType.PRIMITIVE, Integer.valueOf(newId));
  } else {
    // as of OData v4 spec, the key property can be omitted from the POST request body
    entity.getProperties().add(new Property(null, "ID", ValueType.PRIMITIVE, newId));
  }
  entity.setId(createId(entity, "ID"));
  entityList.add(entity);

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

示例5: entityCollectionWithComplexProperty

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void entityCollectionWithComplexProperty() throws Exception {
  Entity entity = new Entity();
  entity.setId(null);
  entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1L));
  ComplexValue complexValue = new ComplexValue();
  complexValue.getValue().add(new Property(null, "Inner1", ValueType.PRIMITIVE,
      BigDecimal.TEN.scaleByPowerOfTen(-5)));
  Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  time.clear();
  time.set(Calendar.HOUR_OF_DAY, 13);
  time.set(Calendar.SECOND, 59);
  time.set(Calendar.MILLISECOND, 999);
  complexValue.getValue().add(new Property("Edm.TimeOfDay", "Inner2", ValueType.PRIMITIVE, time));
  entity.addProperty(new Property("Namespace.ComplexType", "Property2", ValueType.COMPLEX, complexValue));
  EntityCollection entityCollection = new EntityCollection();
  entityCollection.getEntities().add(entity);
  Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,Property2)\","
      + "\"value\":[{\"@odata.id\":null,"
      + "\"[email protected]\":\"#Int64\",\"Property1\":1,"
      + "\"Property2\":{\"@odata.type\":\"#Namespace.ComplexType\","
      + "\"[email protected]\":\"#Decimal\",\"Inner1\":0.00010,"
      + "\"[email protected]\":\"#TimeOfDay\",\"Inner2\":\"13:00:59.999\"}}]}",
      serialize(serializer, metadata, null, entityCollection, null));
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:26,代码来源:EdmAssistedJsonSerializerTest.java

示例6: createProduct

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private Entity createProduct(EdmEntityType edmEntityType, Entity entity) {

    // the ID of the newly created product entity is generated automatically
    int newId = 1;
    while (productIdExists(newId)) {
      newId++;
    }

    Property idProperty = entity.getProperty("ID");
    if (idProperty != null) {
      idProperty.setValue(ValueType.PRIMITIVE, Integer.valueOf(newId));
    } else {
      // as of OData v4 spec, the key property can be omitted from the POST request body
      entity.getProperties().add(new Property(null, "ID", ValueType.PRIMITIVE, newId));
    }
    entity.setId(createId("Products", newId));
    this.productList.add(entity);

    return entity;

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

示例7: createEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Override
public void createEntity(DataRequest request, Entity entity, EntityResponse response)
        throws ODataApplicationException {
    EdmEntitySet edmEntitySet = request.getEntitySet();
    String baseURL = request.getODataRequest().getRawBaseUri();
    try {
        Entity created = createEntityInTable(edmEntitySet.getEntityType(), entity);
        entity.setId(new URI(ODataUtils.buildLocation(baseURL, created, edmEntitySet.getName(),
                                                      edmEntitySet.getEntityType())));
        response.writeCreatedEntity(edmEntitySet, created);
    } catch (ODataServiceFault | SerializerException | URISyntaxException | EdmPrimitiveTypeException e) {
        response.writeNotModified();
        String error = "Error occurred while creating entity. :" + e.getMessage();
        throw new ODataApplicationException(error, 500, Locale.ENGLISH);
    }
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:17,代码来源:ODataAdapter.java

示例8: cloneEntityCollection

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private List<Entity> cloneEntityCollection(final List<Entity> entities) {
  final List<Entity> clonedEntities = new ArrayList<Entity>();
  
  for(final Entity entity : entities) {
    final Entity clonedEntity = new Entity();
    
    clonedEntity.setId(entity.getId());
    for(final Property property : entity.getProperties()) {
      clonedEntity.addProperty(new Property(property.getType(), 
                                            property.getName(), 
                                            property.getValueType(), 
                                            property.getValue()));
    }
     
    clonedEntities.add(clonedEntity);
  }
  
  return clonedEntities;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:20,代码来源:Storage.java

示例9: 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

示例10: nullComplexValueButInDataMapAndNullCollectionsNotInDataMap

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void nullComplexValueButInDataMapAndNullCollectionsNotInDataMap() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp");
  Entity entity = new Entity();
  entity.setId(URI.create("id"));
  entity.addProperty(new Property(null, "PropertyEnumString", ValueType.ENUM, 6));
  entity.addProperty(new Property(null, "PropertyDefString", ValueType.PRIMITIVE, "Test"));
  entity.addProperty(new Property(null, "PropertyCompMixedEnumDef", ValueType.COMPLEX, null));
  final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
      EntitySerializerOptions.with()
          .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
          .build()).getContent());
  Assert.assertEquals("{\"@context\":\"$metadata#ESMixEnumDefCollComp/$entity\","
      + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\","
      + "\"PropertyEnumString\":\"String2,String3\","
      + "\"CollPropertyEnumString\":[],"
      + "\"PropertyDefString\":\"Test\","
      + "\"CollPropertyDefString\":[],"
      + "\"PropertyCompMixedEnumDef\":null,"
      + "\"CollPropertyCompMixedEnumDef\":[]}",
      resultString);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:23,代码来源:ODataJsonSerializerv01Test.java

示例11: toEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private static Entity toEntity(
    EdmEntitySet entitySet, String entityId, Map<String, Object> source) {

  Entity entity = new Entity();
  entity.setId(URI.create(entitySet.getName() + "('" + entityId + "')"));

  Property property = new Property(null, "_id", ValueType.PRIMITIVE, entityId);
  entity.addProperty(property);

  addProperties(entitySet.getEntityType(), source, entity.getProperties());
  return entity;
}
 
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:13,代码来源:EntityRepository.java

示例12: readAll

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
public EntityCollection readAll(EdmEntitySet edmEntitySet) throws SQLException {
    Statement statement = connection.createStatement();

    ResultSet rs = statement.executeQuery("SELECT id, model FROM Cars ORDER BY id");
    EntityCollection entityCollection = new EntityCollection();

    while (rs.next()) {
        Entity entity = new Entity().addProperty(createPrimitive("Id", rs.getInt(1))).addProperty(createPrimitive("Model", rs.getString(2)));
        entity.setId(createId("Cars", rs.getInt(1)));
        entityCollection.getEntities().add(entity);
    }

    return entityCollection;
}
 
开发者ID:sbcd90,项目名称:olingo-jersey,代码行数:15,代码来源:DummyDataProvider.java

示例13: createEntityId

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void createEntityId(final Edm edm, final OData odata, final String entitySetName,
    final EntityCollection entities) {
  if (entitySetName == null) {
    throw new IllegalArgumentException("The entitySetName can not be null.");
  }

  if (entities == null) {
    throw new IllegalArgumentException("The entities can not be null.");
  }

  final EdmEntitySet entitySet = edm.getEntityContainer().getEntitySet(entitySetName);

  if (entitySet == null) {
    throw new NullPointerException(
        "Can not find the entity set name \"" + entitySetName + "\" in the entity data model.");
  }

  final UriHelper helper = odata.createUriHelper();

  for (Entity entity : entities.getEntities()) {
    try {
      entity.setId(URI.create(helper.buildCanonicalURL(entitySet, entity)));
    } catch (final SerializerException e) {
      entity.setId(URI.create("id"));
    }
  }
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:28,代码来源:DataCreator.java

示例14: readNavigationEntities

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
public List<Entity> readNavigationEntities(EdmEntitySet entitySet) {
  
  EntityCollection entityCollection = data.get(entitySet.getName());
  List<Entity> entities = new ArrayList<Entity>();
  Entity otherEntity = entitySet.getName() == "ESAllPrim" ? data.get("ESDelta").getEntities().get(0) :
    data.get("ESAllPrim").getEntities().get(0);
  EntityCollection ec1=new EntityCollection();
  Entity entity1 = new Entity();
  entity1.setId(entityCollection.getEntities().get(0).getId());//added navigation
  entity1.addProperty(entityCollection.getEntities().get(0).getProperty(edm.getEntityContainer()
      .getEntitySet(entitySet.getName()).getEntityType().getPropertyNames().get(0)));
  Link link = new Link();
  Entity entity2 = new Entity();
  entity2.setId(otherEntity.getId());
  ec1.getEntities().add(entity2);
  link.setInlineEntitySet(ec1);
  link.setTitle("NavPropertyETAllPrimMany");
  entity1.getNavigationLinks().add(link);
  
  Entity entity3 = new Entity();
  EntityCollection ec2=new EntityCollection();
  entity3.setId(entityCollection.getEntities().get(0).getId());//added navigation
  DeletedEntity delentity = new DeletedEntity();
  delentity.setId(otherEntity.getId());
  delentity.setReason(Reason.deleted);
  ec2.getEntities().add(delentity);
  Link delLink = new Link();
  delLink.setInlineEntitySet(ec2);
  delLink.setTitle("NavPropertyETAllPrimMany");
  entity3.getNavigationLinks().add(delLink);
  entities.add(otherEntity);
  entities.add(entity1);
  entities.add(entity3);
  return entities;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:36,代码来源:DataProvider.java

示例15: navigationEntityInDeltaEntity

import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void navigationEntityInDeltaEntity() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta");
  Delta delta = new Delta();
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
  final Entity entity2 = data.readAll(edmEntitySet).getEntities().get(3);
  final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(
      ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
  List<Entity> addedEntity = new ArrayList<Entity>();
  Entity changedEntity = new Entity();
  changedEntity.setId(entity.getId());
  changedEntity.addProperty(entity.getProperty("PropertyString"));
  addedEntity.add(entity);
  addedEntity.add(entity2);
  delta.getEntities().addAll(addedEntity);
   InputStream stream = ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta ,
      EntityCollectionSerializerOptions.with()
      .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).expand(expand)
      .build()).getContent();
     String jsonString = IOUtils.toString(stream);
     final String expectedResult = "{"         
         +  "\"@odata.context\":\"$metadata#ESDelta/$delta\",\"value\":"
         + "[{\"@odata.id\":\"ESDelta(32767)\",\"PropertyInt16\":32767,\"PropertyString\":"
         + "\"Number:32767\"},{\"@odata.id\":\"ESDelta(100)\",\"PropertyInt16\":100,"
         + "\"PropertyString\":\"Number:100\"}]"
         + "}";
     Assert.assertNotNull(jsonString);
     Assert.assertEquals(expectedResult, jsonString);
   }
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:30,代码来源:JsonDeltaSerializerTest.java


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