本文整理汇总了Java中org.apache.olingo.commons.api.data.Entity类的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于org.apache.olingo.commons.api.data包,在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEndpointUri
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
@Override
public String createEndpointUri(final String scheme, final Map<String, String> options) throws URISyntaxException {
// set serviceUri on delegate component
Olingo4Component delegate = getCamelContext().getComponent(scheme, Olingo4Component.class);
Olingo4Configuration configuration = new Olingo4Configuration();
configuration.setServiceUri(this.serviceUri);
delegate.setConfiguration(configuration);
setAfterProducer( exchange -> {
if (!exchange.isFailed()) {
ClientEntity clientEntity = exchange.getIn().getBody(ClientEntity.class);
if (clientEntity != null) {
// convert client entity to JSON
final StringWriter writer = new StringWriter();
final Entity entity = odataClient.getBinder().getEntity(clientEntity);
final ODataSerializer serializer = odataClient.getSerializer(APPLICATION_JSON);
serializer.write(writer, entity);
exchange.getIn().setBody(writer.toString());
}
}
// TODO handle failure on missing resource 404
});
return super.createEndpointUri(scheme, options);
}
示例2: setFromEntity
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
protected void setFromEntity(Entity entity, boolean overrideWithNull) {
List<Property> sourceProperties = entity.getProperties();
if (proxy.properties == null || proxy.propertyAccessors == null) {
getProperties();
}
if (overrideWithNull) {
proxy.properties.forEach(prop -> {
if (!sourceProperties.contains(prop)) {
proxy.propertyAccessors.get(prop.getName()).set(this, null);
}
});
}
sourceProperties.forEach(prop -> proxy.propertyAccessors.get(prop.getName()).set(this, prop.getValue()));
// we need new values in the cache after the next call
proxy.properties = null;
}
示例3: test_JpaOlingoEntity_patch_updatesAllFieldsButID
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
@Test
public void test_JpaOlingoEntity_patch_updatesAllFieldsButID() {
// GIVEN
final String NEW_NAME = "NewName";
Entity entityToSet = new Entity().addProperty(new Property(null, NAME_FIELD, ValueType.PRIMITIVE, NEW_NAME))
.addProperty(new Property(null, ID_FIELD, ValueType.PRIMITIVE, "WRONG!!111"));
TestEntity SUT = new TestEntity();
// WHEN
SUT.patch(entityToSet);
// THEN
assertThat(SUT.getName()).isEqualTo(NEW_NAME);
assertThat(SUT.getID()).isEqualTo(ID_VALUE);
}
示例4: list
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
/**
* Reads multiple instances of an Entity Type.
*
* @param entitySet
* Entity Set to read from
* @param uriInfo
* contains filter, order by and paging arguments
* @return entities
* @throws ODataApplicationException
* if error occurred handling filter option
*/
public EntityCollection list(EdmEntitySet entitySet, UriInfo uriInfo)
throws ODataApplicationException {
SearchRequestBuilder searchRequest = elasticsearchTemplate.getClient()
.prepareSearch(toIndexName(entitySet))
.setTypes(toTypeName(entitySet))
.setQuery(toQueryBuilder(uriInfo.getFilterOption()));
configureSorting(uriInfo, searchRequest);
configurePaging(uriInfo, searchRequest);
SearchResponse response = searchRequest.execute().actionGet();
EntityCollection entityCollection = new EntityCollection();
List<Entity> entities = entityCollection.getEntities();
response.getHits().forEach(hit -> {
Entity entity = toEntity(entitySet, hit.getId(), hit.getSource());
entities.add(entity);
});
return entityCollection;
}
示例5: writeEntity
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
public static Entity writeEntity(RdfEdmProvider rdfEdmProvider, UriInfo uriInfo, Entity requestEntity)
throws OData2SparqlException, ODataApplicationException {
SparqlStatement sparqlStatement = null;
EdmEntitySet edmEntitySet = Util.getEdmEntitySet(uriInfo);
RdfEntityType entityType = rdfEdmProvider.getRdfEntityTypefromEdmEntitySet(edmEntitySet);
SparqlCreateUpdateDeleteBuilder sparqlCreateUpdateDeleteBuilder = new SparqlCreateUpdateDeleteBuilder(
rdfEdmProvider);
try {
sparqlStatement = sparqlCreateUpdateDeleteBuilder.generateInsertEntity(entityType, requestEntity);
} catch (Exception e) {
log.error(e.getMessage());
throw new OData2SparqlException(e.getMessage());
}
sparqlStatement.executeInsert(rdfEdmProvider);
return requestEntity;
}
示例6: updateEntity
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
public static void updateEntity(RdfEdmProvider rdfEdmProvider, UriInfo uriInfo, Entity requestEntity,
HttpMethod httpMethod) throws OData2SparqlException {
SparqlStatement sparqlStatement = null;
// 1. Retrieve the entity set which belongs to the requested entity
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
// Note: only in our example we can assume that the first segment is the EntitySet
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
//EdmEntityType edmEntityType = edmEntitySet.getEntityType();
RdfEntityType entityType = rdfEdmProvider.getRdfEntityTypefromEdmEntitySet(edmEntitySet);
List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
// Note that this updateEntity()-method is invoked for both PUT or PATCH operations
SparqlCreateUpdateDeleteBuilder sparqlCreateUpdateDeleteBuilder = new SparqlCreateUpdateDeleteBuilder(
rdfEdmProvider);
try {
sparqlStatement = sparqlCreateUpdateDeleteBuilder.generateUpdateEntity(entityType, keyPredicates,
requestEntity);
} catch (Exception e) {
log.error(e.getMessage());
throw new OData2SparqlException(e.getMessage());
}
sparqlStatement.executeDelete(rdfEdmProvider);
}
示例7: insertValuesReplace
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
private String insertValuesReplace(String group, RdfEntityType entityType, Entity entry) {
String insertReplace = group;
for (Property prop : entry.getProperties()) {
if (prop.getValue() != null) {
RdfProperty property = entityType.findProperty(prop.getName());
if (property.getIsKey()) {
insertReplace = insertReplace.replaceAll("\\?" + property.getVarName() + "\\b",
"<" + prop.getValue().toString() + ">");
} else {
insertReplace = insertReplace.replaceAll("\\?" + property.getVarName() + "\\b",
"\"" + prop.getValue().toString() + "\"");
}
}
}
//Replace any unmatched variables with UNDEF
insertReplace = insertReplace.replaceAll("\\?\\S+", "UNDEF");
return insertReplace;
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:19,代码来源:SparqlCreateUpdateDeleteBuilder.java
示例8: generateUpdatePropertyValues
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
private StringBuilder generateUpdatePropertyValues(RdfEntityType entityType, String entityKey, Entity entry) {
StringBuilder updatePropertyValues = new StringBuilder("VALUES( ?" + entityType.entityTypeName + "_p){");
StringBuilder properties = new StringBuilder();
boolean first = true;
for (Property prop : entry.getProperties()) {
if (prop.getValue() != null) {
if (!first) {
properties.append(" ;\n");
} else {
first = false;
}
RdfProperty property = entityType.findProperty(prop.getName());
if (property.getIsKey()) {
entityKey = prop.getValue().toString();
} else {
updatePropertyValues.append("(<" + property.propertyNode.getIRI() + ">) ");
}
}
}
return updatePropertyValues.append("}.");
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:22,代码来源:SparqlCreateUpdateDeleteBuilder.java
示例9: 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);
}
}
示例10: parse
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
@Override
public InstanceData<EdmEntityType, AbstractEntityCollection> parse(SearchResponse response,
ElasticEdmEntitySet entitySet) {
ElasticEdmEntityType entityType = entitySet.getEntityType();
Entity entity = new Entity();
Aggregations aggs = response.getAggregations();
if (aggs != null) {
aggs.asList().stream().filter(SingleValue.class::isInstance)
.map(SingleValue.class::cast)
.map(aggr -> createProperty(aggr.getName(), aggr.value(), entityType))
.forEach(entity::addProperty);
}
addCountIfNeeded(entity, response.getHits().getTotalHits());
EntityCollection entities = new EntityCollection();
entities.getEntities().add(entity);
return new InstanceData<>(entityType, entities);
}
示例11: subList
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
/**
* This is custom pagination, because Elasticsearch doesn't support this.
* Method to get sublist from parent list with top and skip parameter. We
* need to check whether top and skip are in parent list size or not, and
* then calculate from and to indexes.
*
* @param entities
* entities to paginate
* @return new sublist
*/
private List<Entity> subList(List<Entity> entities) {
if (entities.isEmpty()) {
return entities;
}
int top = pagination.getTop();
int skip = pagination.getSkip();
int fromIndex;
int toIndex;
int max = skip + top;
int actualSize = entities.size();
if (max <= actualSize) {
fromIndex = skip;
toIndex = top + skip;
} else {
fromIndex = skip > actualSize ? actualSize : skip;
toIndex = actualSize;
}
return entities.subList(fromIndex, toIndex);
}
示例12: 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);
}
示例13: deleteLinksTo
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
public void deleteLinksTo(final Entity to) throws DataProviderException {
for (final String entitySetName : data.keySet()) {
for (final Entity entity : data.get(entitySetName).getEntities()) {
for (Iterator<Link> linkIterator = entity.getNavigationLinks().iterator(); linkIterator
.hasNext();) {
final Link link = linkIterator.next();
if (to.equals(link.getInlineEntity())) {
linkIterator.remove();
} else if (link.getInlineEntitySet() != null) {
for (Iterator<Entity> iterator =
link.getInlineEntitySet().getEntities().iterator(); iterator.hasNext();) {
if (to.equals(iterator.next())) {
iterator.remove();
}
}
if (link.getInlineEntitySet().getEntities().isEmpty()) {
linkIterator.remove();
}
}
}
}
}
}
示例14: 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;
}
示例15: handleDeleteSingleNavigationProperties
import org.apache.olingo.commons.api.data.Entity; //导入依赖的package包/类
private void handleDeleteSingleNavigationProperties(final EdmEntitySet edmEntitySet,
final Entity entity, final Entity changedEntity) throws DataProviderException {
final EdmEntityType entityType = edmEntitySet.getEntityType();
final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();
for (final String navPropertyName : navigationPropertyNames) {
final Link navigationLink = changedEntity.getNavigationLink(navPropertyName);
final EdmNavigationProperty navigationProperty =
entityType.getNavigationProperty(navPropertyName);
if (!navigationProperty.isCollection() && navigationLink != null
&& navigationLink.getInlineEntity() == null) {
// Check if partner is available
if (navigationProperty.getPartner() != null
&& entity.getNavigationLink(navPropertyName) != null) {
Entity partnerEntity = entity.getNavigationLink(navPropertyName).getInlineEntity();
removeLink(navigationProperty.getPartner(), partnerEntity);
}
// Remove link
removeLink(navigationProperty, entity);
}
}
}