本文整理汇总了Java中org.apache.olingo.commons.api.edm.EdmEntityType类的典型用法代码示例。如果您正苦于以下问题:Java EdmEntityType类的具体用法?Java EdmEntityType怎么用?Java EdmEntityType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdmEntityType类属于org.apache.olingo.commons.api.edm包,在下文中一共展示了EdmEntityType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的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.edm.EdmEntityType; //导入依赖的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);
}
示例3: parse
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的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);
}
示例4: create
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的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;
}
示例5: handleDeleteSingleNavigationProperties
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的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);
}
}
}
示例6: getContextUrl
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
private static ContextURL getContextUrl(final EdmEntitySet entitySet,
final EdmEntityType entityType,
final boolean isSingleEntity)
throws ODataLibraryException
{
ContextURL.Builder builder = ContextURL.with();
builder = (entitySet == null)
? isSingleEntity
? builder.type(entityType)
: builder.asCollection().type(entityType)
: builder.entitySet(entitySet);
builder = builder.suffix((isSingleEntity && (entitySet != null))
? ContextURL.Suffix.ENTITY
: null);
return builder.build();
}
示例7: createEntity
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
private Entity createEntity(EdmEntitySet edmEntitySet, EdmEntityType edmEntityType, Entity entity,
List<Entity> entityList, final String rawServiceUri) throws ODataApplicationException {
// 1.) Create the entity
final Entity newEntity = new Entity();
newEntity.setType(entity.getType());
// Create the new key of the entity
int newId = 1;
while (entityIdExists(newId, entityList)) {
newId++;
}
// Add all provided properties
newEntity.getProperties().addAll(entity.getProperties());
// Add the key property
newEntity.getProperties().add(new Property(null, "ID", ValueType.PRIMITIVE, newId));
newEntity.setId(createId(newEntity, "ID"));
// --> Implement Deep Insert handling here <--
entityList.add(newEntity);
return newEntity;
}
示例8: serializeEntity
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
private SerializerResult serializeEntity(final ODataRequest request, final Entity entity,
final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
final ContentType requestedFormat,
final ExpandOption expand, final SelectOption select, final boolean isContNav)
throws ODataLibraryException {
ContextURL contextUrl = isODataMetadataNone(requestedFormat) ? null :
getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, true, expand, null,isContNav);
return odata.createSerializer(requestedFormat, request.getHeaders(HttpHeader.ODATA_VERSION)).entity(
serviceMetadata,
edmEntityType,
entity,
EntitySerializerOptions.with()
.contextURL(contextUrl)
.expand(expand).select(select)
.build());
}
示例9: writeReadEntitySet
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
public void writeReadEntitySet(EdmEntityType entityType, EntityCollection entitySet)
throws SerializerException {
assert (!isClosed());
if (entitySet == null) {
writeNotFound(true);
return;
}
if (ContentTypeHelper.isODataMetadataFull(this.responseContentType)) {
buildOperations(entityType, entitySet);
}
// write the whole collection to response
this.response.setContent(this.serializer.entityCollection(metadata, entityType, entitySet, this.options)
.getContent());
writeOK(responseContentType);
close();
}
示例10: recordWithEntityTypeAndPropValues
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
@Test
public void recordWithEntityTypeAndPropValues() {
CsdlRecord csdlRecord = new CsdlRecord();
csdlRecord.setType("ns.et");
Edm mock = mock(Edm.class);
when(mock.getEntityType(new FullQualifiedName("ns", "et"))).thenReturn(mock(EdmEntityType.class));
List<CsdlPropertyValue> propertyValues = new ArrayList<CsdlPropertyValue>();
propertyValues.add(new CsdlPropertyValue());
csdlRecord.setPropertyValues(propertyValues);
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
csdlRecord.setAnnotations(csdlAnnotations);
EdmExpression record = AbstractEdmExpression.getExpression(mock, csdlRecord);
EdmDynamicExpression dynExp = assertDynamic(record);
EdmRecord asRecord = dynExp.asRecord();
assertNotNull(asRecord.getPropertyValues());
assertEquals(1, asRecord.getPropertyValues().size());
assertNotNull(asRecord.getType());
assertTrue(asRecord.getType() instanceof EdmEntityType);
assertNotNull(asRecord.getAnnotations());
assertEquals(1, asRecord.getAnnotations().size());
}
示例11: findEntity
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
public static Entity findEntity(EdmEntityType edmEntityType, EntityCollection entitySet,
List<UriParameter> keyParams) {
List<Entity> entityList = entitySet.getEntities();
// loop over all entities in order to find that one that matches
// all keys in request e.g. contacts(ContactID=1, CompanyID=1)
for (Entity entity : entityList) {
boolean foundEntity = entityMatchesAllKeys(edmEntityType, entity, keyParams);
if (foundEntity) {
return entity;
}
}
return null;
}
示例12: updateEntity
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType requestFormat, ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
// 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();
// 2. update the data in backend
// 2.1. retrieve the payload from the PUT request for the entity to be updated
InputStream requestInputStream = request.getBody();
ODataDeserializer deserializer = odata.createDeserializer(requestFormat);
DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType);
Entity requestEntity = result.getEntity();
// 2.2 do the modification in backend
List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates();
// Note that this updateEntity()-method is invoked for both PUT or PATCH operations
HttpMethod httpMethod = request.getMethod();
storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod);
//3. configure the response object
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
示例13: aliasForPropertyInComplexPropertyTwoLevels
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
@Test
public void aliasForPropertyInComplexPropertyTwoLevels() {
CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/comp2/Id").setAlias("alias");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
EdmProperty compMock = mock(EdmProperty.class);
EdmComplexType compTypeMock = mock(EdmComplexType.class);
EdmProperty comp2Mock = mock(EdmProperty.class);
EdmComplexType comp2TypeMock = mock(EdmComplexType.class);
when(comp2TypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
when(comp2Mock.getType()).thenReturn(comp2TypeMock);
when(compTypeMock.getStructuralProperty("comp2")).thenReturn(comp2Mock);
when(compMock.getType()).thenReturn(compTypeMock);
when(etMock.getStructuralProperty("comp")).thenReturn(compMock);
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
EdmProperty property = ref.getProperty();
assertNotNull(property);
assertTrue(property == keyPropertyMock);
}
示例14: createProduct
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的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;
}
示例15: writeEntitySet
import org.apache.olingo.commons.api.edm.EdmEntityType; //导入依赖的package包/类
protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
final Delta entitySet, final EntityCollectionSerializerOptions options,
final JsonGenerator json) throws IOException,
SerializerException {
json.writeStartArray();
for (final Entity entity : entitySet.getEntities()) {
writeAddedUpdatedEntity(metadata, entityType, entity, options.getExpand(),
options.getSelect(), options.getContextURL(), false, options.getContextURL()
.getEntitySetOrSingletonOrType(), json);
}
for (final DeletedEntity deletedEntity : entitySet.getDeletedEntities()) {
writeDeletedEntity(deletedEntity, options, json);
}
for (final DeltaLink addedLink : entitySet.getAddedLinks()) {
writeLink(addedLink, options, json, true);
}
for (final DeltaLink deletedLink : entitySet.getDeletedLinks()) {
writeLink(deletedLink, options, json, false);
}
json.writeEndArray();
}