本文整理汇总了Java中org.apache.olingo.commons.api.data.Entity.addProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.addProperty方法的具体用法?Java Entity.addProperty怎么用?Java Entity.addProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.commons.api.data.Entity
的用法示例。
在下文中一共展示了Entity.addProperty方法的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);
}
}
示例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);
}
示例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;
}
示例4: 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, edmEntityType);
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!", HttpStatusCode.INTERNAL_SERVER_ERROR, e);
}
entities.add(newEntity);
return newEntity;
}
示例5: negativeDeltaEntityTest
import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test(expected = SerializerException.class)
public void negativeDeltaEntityTest() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta");
Delta delta = new Delta();
final Entity entity2 = data.readAll(edmEntitySet).getEntities().get(1);
List<Entity> addedEntity = new ArrayList<Entity>();
Entity changedEntity = new Entity();
changedEntity.addProperty(entity2.getProperty("PropertyString"));
addedEntity.add(changedEntity);
delta.getEntities().addAll(addedEntity);
ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta ,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build())
.build()).getContent();
}
示例6: 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));
}
示例7: expand
import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void expand() throws Exception {
final Entity relatedEntity1 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 1.5));
final Entity relatedEntity2 = new Entity().addProperty(new Property(null, "Related1", ValueType.PRIMITIVE, 2.75));
EntityCollection target = new EntityCollection();
target.getEntities().add(relatedEntity1);
target.getEntities().add(relatedEntity2);
Link link = new Link();
link.setTitle("NavigationProperty");
link.setInlineEntitySet(target);
Entity entity = new Entity();
entity.setId(null);
entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, (short) 1));
entity.getNavigationLinks().add(link);
EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(entity);
Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1,NavigationProperty(Related1))\","
+ "\"value\":[{\"@odata.id\":null,"
+ "\"[email protected]\":\"#Int16\",\"Property1\":1,"
+ "\"NavigationProperty\":["
+ "{\"@odata.id\":null,\"[email protected]\":\"#Double\",\"Related1\":1.5},"
+ "{\"@odata.id\":null,\"[email protected]\":\"#Double\",\"Related1\":2.75}]}]}",
serialize(serializer, metadata, null, entityCollection, "Property1,NavigationProperty(Related1)"));
}
示例8: consumeEntityProperties
import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node,
final Entity entity) throws DeserializerException {
List<String> propertyNames = edmEntityType.getPropertyNames();
for (String propertyName : propertyNames) {
JsonNode jsonNode = node.get(propertyName);
if (jsonNode != null) {
EdmProperty edmProperty = (EdmProperty) edmEntityType.getProperty(propertyName);
if (jsonNode.isNull() && !edmProperty.isNullable()) {
throw new DeserializerException("Property: " + propertyName + " must not be null.",
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName);
}
Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(),
jsonNode);
entity.addProperty(property);
node.remove(propertyName);
}
}
}
示例9: 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;
}
示例10: getAggregatedEntities
import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
/**
* Method recursively goes through aggregations, creates entities and adds
* fields to them. When entity has all fields from aggregations it adds to
* entities list. If groupBy has aggregation $count then property with
* {@link #countAlias} name will be added to entity with doc count from
* response aggregations.
*
* @param aggs
* response aggregations
* @param parent
* parent entity
* @param entityType
* entity type
* @return list of entities
*/
protected List<Entity> getAggregatedEntities(Map<String, Aggregation> aggs, Entity parent,
ElasticEdmEntityType entityType) {
List<Entity> entities = new ArrayList<>();
for (Entry<String, Terms> entry : collectTerms(aggs).entrySet()) {
for (Bucket bucket : entry.getValue().getBuckets()) {
Entity entity = new Entity();
if (parent != null) {
entity.getProperties().addAll(parent.getProperties());
}
Property property = createProperty(entry.getKey(), bucket.getKey(), entityType);
entity.addProperty(property);
Map<String, Aggregation> subAggs = bucket.getAggregations().asMap();
if (subAggs.isEmpty()) {
addAggsAndCountIfNeeded(aggs, bucket.getDocCount(), entity, entityType);
entities.add(entity);
} else {
List<Entity> subEntities = getAggregatedEntities(subAggs, entity, entityType);
if (subEntities.isEmpty()) {
addAggsAndCountIfNeeded(subAggs, bucket.getDocCount(), entity, entityType);
entities.add(entity);
} else {
entities.addAll(subEntities);
}
}
}
}
return entities;
}
示例11: entityCollectionSimple
import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void entityCollectionSimple() throws Exception {
Entity entity = new Entity();
entity.setId(null);
entity.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, 1.25F));
EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(entity);
Assert.assertEquals("{\"@odata.context\":\"$metadata#EntitySet(Property1)\","
+ "\"value\":[{\"@odata.id\":null,\"[email protected]\":\"#Single\",\"Property1\":1.25}]}",
serialize(serializer, metadata, null, entityCollection, null));
}
示例12: nullCollectionButInDataMap
import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void nullCollectionButInDataMap() 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, "CollPropertyEnumString", ValueType.COLLECTION_ENUM, null));
entity.addProperty(new Property(null, "PropertyDefString", ValueType.PRIMITIVE, "Test"));
entity.addProperty(new Property(null, "CollPropertyDefString", ValueType.COLLECTION_PRIMITIVE, null));
ComplexValue complexValue = new ComplexValue();
complexValue.getValue().add(entity.getProperty("PropertyEnumString"));
complexValue.getValue().add(entity.getProperty("CollPropertyEnumString"));
complexValue.getValue().add(entity.getProperty("PropertyDefString"));
complexValue.getValue().add(entity.getProperty("CollPropertyDefString"));
entity.addProperty(new Property(null, "PropertyCompMixedEnumDef", ValueType.COMPLEX, complexValue));
entity.addProperty(new Property(null, "CollPropertyCompMixedEnumDef", ValueType.COLLECTION_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("{\"@odata.context\":\"$metadata#ESMixEnumDefCollComp/$entity\","
+ "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ "\"PropertyEnumString\":\"String2,String3\","
+ "\"CollPropertyEnumString\":[],"
+ "\"PropertyDefString\":\"Test\","
+ "\"CollPropertyDefString\":[],"
+ "\"PropertyCompMixedEnumDef\":{\"PropertyEnumString\":\"String2,String3\","
+ "\"CollPropertyEnumString\":[],"
+ "\"PropertyDefString\":\"Test\",\"CollPropertyDefString\":[]},"
+ "\"CollPropertyCompMixedEnumDef\":[]}",
resultString);
}
示例13: 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);
}
示例14: selectInDelta
import org.apache.olingo.commons.api.data.Entity; //导入方法依赖的package包/类
@Test
public void selectInDelta() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESDelta");
final EdmEntityType entityType = edmEntitySet.getEntityType();
final UriHelper helper = odata.createUriHelper();
final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyString")));
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
final Entity entity2 = data.readAll(edmEntitySet).getEntities().get(1);
Delta delta = new Delta();
List<Entity> addedEntity = new ArrayList<Entity>();
Entity changedEntity = new Entity();
changedEntity.setId(entity2.getId());
changedEntity.addProperty(entity2.getProperty("PropertyString"));
changedEntity.addProperty(entity2.getProperty("PropertyInt16"));
addedEntity.add(entity);
addedEntity.add(changedEntity);
delta.getEntities().addAll(addedEntity);
InputStream stream = ser.entityCollection(metadata, edmEntitySet.getEntityType(), delta ,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, null, select))
.suffix(Suffix.ENTITY).build())
.select(select).build()).getContent();
String jsonString = IOUtils.toString(stream);
Assert.assertEquals("{"
+"\"@context\":\"$metadata#ESDelta(PropertyString)/$entity/$delta\","
+ "\"value\":[{\"@id\":\"ESDelta(32767)\",\"PropertyString\":\"Number:32767\"},"
+ "{\"@id\":\"ESDelta(-32768)\",\"PropertyString\":\"Number:-32768\"}]}",
jsonString);
}
示例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 = "{"
+ "\"@context\":\"$metadata#ESDelta/$delta\",\"value\":[{\"@id\":\"ESDelta(32767)\","
+ "\"PropertyInt16\":32767,\"PropertyString\":\"Number:32767\"},{\"@id\":\"ESDelta(100)\","
+ "\"PropertyInt16\":100,\"PropertyString\":\"Number:100\","
+ "\"[email protected]\":"
+ "{\"@id\":\"ESAllPrim(32767)\",\"PropertyInt16\":32767,\"PropertyString\":"
+ "\"First Resource - positive values\","
+ "\"PropertyBoolean\":true,\"PropertyByte\":255,\"PropertySByte\":127,\"PropertyInt32\":2147483647,"
+ "\"PropertyInt64\":9223372036854775807,\"PropertySingle\":1.79E20,\"PropertyDouble\":-1.79E19,"
+ "\"PropertyDecimal\":34,\"PropertyBinary\":\"ASNFZ4mrze8=\",\"PropertyDate\":\"2012-12-03\","
+ "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\",\"PropertyDuration\":\"PT6S\",\"PropertyGuid\":"
+ "\"01234567-89ab-cdef-0123-456789abcdef\",\"PropertyTimeOfDay\":\"03:26:05\"}}]"
+ "}";
Assert.assertNotNull(jsonString);
Assert.assertEquals(expectedResult, jsonString);
}