API enhancements: simplified operation import invoke with EdmEnabledODataClient

This commit is contained in:
Francesco Chicchiriccò 2014-05-19 13:23:42 +02:00
parent 946356fb0f
commit 4a1d5ab343
18 changed files with 504 additions and 33 deletions

View File

@ -1269,9 +1269,15 @@ public class V4Services extends AbstractServices {
assert "Microsoft.Test.OData.Services.ODataWCFService.Address".equals(entity.getType());
assert entity.getProperty("address").getValue().isComplex();
final ResWrap<AtomPropertyImpl> result = new ResWrap<AtomPropertyImpl>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ "Microsoft.Test.OData.Services.ODataWCFService.Address"),
null,
(AtomPropertyImpl) entity.getProperty("address"));
return xml.createResponse(
null,
xml.writeProperty(acceptType, entity.getProperty("address")),
xml.writeProperty(acceptType, result),
null,
acceptType);
} catch (Exception e) {

View File

@ -153,6 +153,67 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
functionImports(ODataPubFormat.JSON_FULL_METADATA);
}
@Test
public void edmEnabledFunctionImports() throws EdmPrimitiveTypeException {
// GetDefaultColor
final ODataInvokeRequest<ODataProperty> defaultColorReq = edmClient.getInvokeRequestFactory().
getFunctionImportInvokeRequest("GetDefaultColor");
final ODataProperty defaultColor = defaultColorReq.execute().getBody();
assertNotNull(defaultColor);
assertTrue(defaultColor.hasEnumValue());
assertEquals("Red", defaultColor.getEnumValue().getValue());
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Color", defaultColor.getEnumValue().getTypeName());
// GetPerson2
final ODataPrimitiveValue city =
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("London");
final ODataInvokeRequest<ODataEntity> person2Req = edmClient.getInvokeRequestFactory().
getFunctionImportInvokeRequest(
"GetPerson2", Collections.<String, ODataValue>singletonMap("city", city));
final ODataEntity person2 = person2Req.execute().getBody();
assertNotNull(person2);
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", person2.getTypeName().toString());
assertEquals(1, person2.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
// GetPerson
final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
address.add(client.getObjectFactory().newPrimitiveProperty("Street",
client.getObjectFactory().newPrimitiveValueBuilder().buildString("1 Microsoft Way")));
address.add(client.getObjectFactory().newPrimitiveProperty("City",
client.getObjectFactory().newPrimitiveValueBuilder().buildString("London")));
address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
client.getObjectFactory().newPrimitiveValueBuilder().buildString("98052")));
final ODataInvokeRequest<ODataEntity> personReq = edmClient.getInvokeRequestFactory().
getFunctionImportInvokeRequest(
"GetPerson", Collections.<String, ODataValue>singletonMap("address", address));
final ODataEntity person = personReq.execute().getBody();
assertNotNull(person);
assertEquals(person2, person);
// GetAllProducts
final ODataInvokeRequest<ODataEntitySet> productsReq = edmClient.getInvokeRequestFactory().
getFunctionImportInvokeRequest("GetAllProducts");
final ODataEntitySet products = productsReq.execute().getBody();
assertNotNull(products);
assertEquals(5, products.getCount());
// GetProductsByAccessLevel
final ODataEnumValue accessLevel = getClient().getObjectFactory().
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "None");
final ODataInvokeRequest<ODataProperty> prodByALReq = edmClient.getInvokeRequestFactory().
getFunctionImportInvokeRequest(
"GetProductsByAccessLevel",
Collections.<String, ODataValue>singletonMap("accessLevel", accessLevel));
final ODataProperty prodByAL = prodByALReq.execute().getBody();
assertNotNull(prodByAL);
assertTrue(prodByAL.hasCollectionValue());
assertEquals(5, prodByAL.getCollectionValue().size());
assertTrue(prodByAL.getCollectionValue().asJavaCollection().contains("Car"));
}
private void actionImports(final ODataPubFormat format) {
final Edm edm = getEdm();
final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
@ -204,6 +265,34 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
actionImports(ODataPubFormat.JSON_FULL_METADATA);
}
@Test
public void edmEnabledActionImports() {
// Discount
final ODataPrimitiveValue percentage = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(22);
final ODataInvokeRequest<ODataNoContent> discountReq = edmClient.getInvokeRequestFactory().
getActionImportInvokeRequest(
"Discount", Collections.<String, ODataValue>singletonMap("percentage", percentage));
final ODataNoContent discount = discountReq.execute().getBody();
assertNotNull(discount);
// ResetBossAddress
final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
address.add(client.getObjectFactory().newPrimitiveProperty("Street",
client.getObjectFactory().newPrimitiveValueBuilder().buildString("Via Le Mani Dal Naso, 123")));
address.add(client.getObjectFactory().newPrimitiveProperty("City",
client.getObjectFactory().newPrimitiveValueBuilder().buildString("Tollo")));
address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
client.getObjectFactory().newPrimitiveValueBuilder().buildString("66010")));
final ODataInvokeRequest<ODataProperty> resetBossAddressReq = edmClient.getInvokeRequestFactory().
getActionImportInvokeRequest(
"ResetBossAddress", Collections.<String, ODataValue>singletonMap("address", address));
final ODataProperty resetBossAddress = resetBossAddressReq.execute().getBody();
assertNotNull(resetBossAddress);
assertEquals(address.getTypeName(), resetBossAddress.getComplexValue().getTypeName());
}
private void bossEmails(final ODataPubFormat format) {
final Edm edm = getEdm();
final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();

View File

@ -19,6 +19,8 @@
package org.apache.olingo.client.api;
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
import org.apache.olingo.commons.api.edm.Edm;
/**
@ -47,4 +49,9 @@ public interface CommonEdmEnabledODataClient<UT extends CommonUpdateType> extend
* @return Edm
*/
Edm getCachedEdm();
CommonURIBuilder<?> getURIBuilder();
@Override
EdmEnabledInvokeRequestFactory getInvokeRequestFactory();
}

View File

@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.api.communication.request.invoke;
import java.util.Map;
import org.apache.olingo.commons.api.domain.ODataInvokeResult;
import org.apache.olingo.commons.api.domain.ODataValue;
public interface EdmEnabledInvokeRequestFactory extends InvokeRequestFactory {
/**
* Gets an invoke request instance for the first function import with the given name (no overloading supported).
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param functionImportName operation to be invoked
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
String functionImportName);
/**
* Gets an invoke request instance for the first function import with the given name (no overloading supported).
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param functionImportName operation to be invoked
* @param parameters parameters to pass to operation import invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
String functionImportName, Map<String, ODataValue> parameters);
/**
* Gets an invoke request instance for the action import with the given name.
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param actionImportName operation to be invoked
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
String actionImportName);
/**
* Gets an invoke request instance for the action import with the given name.
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param actionImportName operation to be invoked
* @param parameters parameters to pass to operation import invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
String actionImportName, Map<String, ODataValue> parameters);
}

View File

@ -36,7 +36,7 @@ public interface InvokeRequestFactory extends Serializable {
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param uri URI that identifies the function import
* @param operation operation to be invoked
* @return new ODataInvokeRequest instance.
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(URI uri, EdmOperation operation);
@ -46,8 +46,8 @@ public interface InvokeRequestFactory extends Serializable {
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param uri URI that identifies the function import
* @param operation operation to be invoked
* @param parameters parameters to pass to function import invocation
* @return new ODataInvokeRequest instance.
* @param parameters parameters to pass to operation invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ODataInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(
URI uri, EdmOperation operation, Map<String, ODataValue> parameters);

View File

@ -20,7 +20,15 @@ package org.apache.olingo.client.api.v3;
import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory;
import org.apache.olingo.client.api.uri.v3.URIBuilder;
public interface EdmEnabledODataClient extends CommonEdmEnabledODataClient<UpdateType>, ODataClient {
@Override
URIBuilder getURIBuilder();
@Override
EdmEnabledInvokeRequestFactory getInvokeRequestFactory();
}

View File

@ -20,7 +20,14 @@ package org.apache.olingo.client.api.v4;
import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory;
import org.apache.olingo.client.api.uri.v4.URIBuilder;
public interface EdmEnabledODataClient extends CommonEdmEnabledODataClient<UpdateType>, ODataClient {
@Override
URIBuilder getURIBuilder();
@Override
EdmEnabledInvokeRequestFactory getInvokeRequestFactory();
}

View File

@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.core.communication.request.invoke.v3;
import java.util.Map;
import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
import org.apache.olingo.client.api.v3.EdmEnabledODataClient;
import org.apache.olingo.commons.api.domain.ODataInvokeResult;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.edm.EdmActionImport;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.EdmSchema;
public class EdmEnabledInvokeRequestFactoryImpl
extends InvokeRequestFactoryImpl implements EdmEnabledInvokeRequestFactory {
private static final long serialVersionUID = 5854571629835831697L;
private final EdmEnabledODataClient edmClient;
public EdmEnabledInvokeRequestFactoryImpl(final EdmEnabledODataClient client) {
super(client);
this.edmClient = client;
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
final String functionImportName) {
return getFunctionImportInvokeRequest(functionImportName, null);
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
final String functionImportName, final Map<String, ODataValue> parameters) {
EdmFunctionImport efi = null;
for (EdmSchema schema : edmClient.getCachedEdm().getSchemas()) {
final EdmEntityContainer container = schema.getEntityContainer();
if (container != null) {
efi = container.getFunctionImport(functionImportName);
}
}
if (efi == null) {
throw new IllegalArgumentException("Could not find FunctionImport for name " + functionImportName);
}
return getInvokeRequest(
edmClient.getURIBuilder().appendOperationCallSegment(functionImportName).build(),
efi.getUnboundFunctions().get(0),
parameters);
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
final String actionImportName) {
return getActionImportInvokeRequest(actionImportName, null);
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
final String actionImportName, final Map<String, ODataValue> parameters) {
EdmActionImport eai = null;
for (EdmSchema schema : edmClient.getCachedEdm().getSchemas()) {
final EdmEntityContainer container = schema.getEntityContainer();
if (container != null) {
eai = container.getActionImport(actionImportName);
}
}
if (eai == null) {
throw new IllegalArgumentException("Could not find ActionImport for name " + actionImportName);
}
return getInvokeRequest(
edmClient.getURIBuilder().appendOperationCallSegment(actionImportName).build(),
eai.getUnboundAction(),
parameters);
}
}

View File

@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.core.communication.request.invoke.v4;
import java.util.Map;
import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.commons.api.domain.ODataInvokeResult;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.edm.EdmActionImport;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.EdmSchema;
public class EdmEnabledInvokeRequestFactoryImpl
extends InvokeRequestFactoryImpl implements EdmEnabledInvokeRequestFactory {
private static final long serialVersionUID = 5854571629835831697L;
private final EdmEnabledODataClient edmClient;
public EdmEnabledInvokeRequestFactoryImpl(final EdmEnabledODataClient client) {
super(client);
this.edmClient = client;
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
final String functionImportName) {
return getFunctionImportInvokeRequest(functionImportName, null);
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
final String functionImportName, final Map<String, ODataValue> parameters) {
EdmFunctionImport efi = null;
for (EdmSchema schema : edmClient.getCachedEdm().getSchemas()) {
final EdmEntityContainer container = schema.getEntityContainer();
if (container != null) {
efi = container.getFunctionImport(functionImportName);
}
}
if (efi == null) {
throw new IllegalArgumentException("Could not find FunctionImport for name " + functionImportName);
}
return getInvokeRequest(
edmClient.getURIBuilder().appendOperationCallSegment(functionImportName).build(),
efi.getUnboundFunctions().get(0),
parameters);
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
final String actionImportName) {
return getActionImportInvokeRequest(actionImportName, null);
}
@Override
public <RES extends ODataInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
final String actionImportName, final Map<String, ODataValue> parameters) {
EdmActionImport eai = null;
for (EdmSchema schema : edmClient.getCachedEdm().getSchemas()) {
final EdmEntityContainer container = schema.getEntityContainer();
if (container != null) {
eai = container.getActionImport(actionImportName);
}
}
if (eai == null) {
throw new IllegalArgumentException("Could not find ActionImport for name " + actionImportName);
}
return getInvokeRequest(
edmClient.getURIBuilder().appendOperationCallSegment(actionImportName).build(),
eai.getUnboundAction(),
parameters);
}
}

View File

@ -86,5 +86,4 @@ public class ODataInvokeRequestImpl<T extends ODataInvokeResult> extends Abstrac
throw new IllegalArgumentException("While adding GET parameters", e);
}
}
}

View File

@ -53,9 +53,11 @@ import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
import org.apache.olingo.commons.api.edm.EdmElement;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmSchema;
@ -285,7 +287,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
return entitySet;
}
protected void odataNavigationLinks(final EdmStructuredType edmType,
protected void odataNavigationLinks(final EdmType edmType,
final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) {
for (Link link : linked.getNavigationLinks()) {
@ -294,8 +296,8 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
if (inlineEntity == null && inlineEntitySet == null) {
ODataLinkType linkType = null;
if (edmType != null) {
final EdmNavigationProperty navProp = edmType.getNavigationProperty(link.getTitle());
if (edmType instanceof EdmStructuredType) {
final EdmNavigationProperty navProp = ((EdmStructuredType) edmType).getNavigationProperty(link.getTitle());
if (navProp != null) {
linkType = navProp.isCollection()
? ODataLinkType.ENTITY_SET_NAVIGATION
@ -338,8 +340,8 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
* @param metadataETag metadata ETag
* @return Edm type information
*/
private EdmEntityType findEntityType(final ContextURL contextURL, final String metadataETag) {
EdmEntityType entityType = null;
private EdmType findType(final ContextURL contextURL, final String metadataETag) {
EdmType type = null;
if (client instanceof EdmEnabledODataClient && contextURL != null) {
final Edm edm = ((EdmEnabledODataClient) client).getEdm(metadataETag);
@ -348,30 +350,33 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
for (EdmSchema schema : edm.getSchemas()) {
final EdmEntityContainer container = schema.getEntityContainer();
EdmBindingTarget bindingTarget =
container.getEntitySet(contextURL.getEntitySetOrSingletonOrType());
EdmBindingTarget bindingTarget = container.getEntitySet(contextURL.getEntitySetOrSingletonOrType());
if (bindingTarget == null) {
bindingTarget = container.getSingleton(contextURL.getEntitySetOrSingletonOrType());
}
if (bindingTarget != null) {
if (contextURL.getNavOrPropertyPath() == null) {
entityType = bindingTarget.getEntityType();
type = bindingTarget.getEntityType();
} else {
final EdmNavigationProperty navProp = bindingTarget.getEntityType().
getNavigationProperty(contextURL.getNavOrPropertyPath());
entityType = navProp == null
type = navProp == null
? bindingTarget.getEntityType()
: navProp.getType();
}
}
}
if (type == null) {
type = new EdmTypeInfo.Builder().setEdm(edm).
setTypeExpression(contextURL.getEntitySetOrSingletonOrType()).build().getType();
}
} else {
entityType = edm.getEntityType(new FullQualifiedName(contextURL.getDerivedEntity()));
type = edm.getEntityType(new FullQualifiedName(contextURL.getDerivedEntity()));
}
}
return entityType;
return type;
}
@Override
@ -386,7 +391,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
final URI base = resource.getContextURL() == null
? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
final EdmEntityType edmType = findEntityType(resource.getContextURL(), resource.getMetadataETag());
final EdmType edmType = findType(resource.getContextURL(), resource.getMetadataETag());
FullQualifiedName typeName = null;
if (resource.getPayload().getType() == null) {
if (edmType != null) {
@ -434,8 +439,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
}
for (Property property : resource.getPayload().getProperties()) {
add(entity, getODataProperty(
new ResWrap<Property>(resource.getContextURL(), resource.getMetadataETag(), property)));
EdmType propertyType = null;
if (edmType instanceof EdmEntityType) {
final EdmElement edmProperty = ((EdmEntityType) edmType).getProperty(property.getName());
if (edmProperty != null) {
propertyType = edmProperty.getType();
}
}
add(entity, getODataProperty(propertyType, property));
}
return entity;
@ -445,14 +456,21 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
final String propertyName, final String propertyType) {
FullQualifiedName typeName = null;
final EdmType entityType = findEntityType(contextURL, metadataETag);
if (entityType instanceof EdmStructuredType) {
final EdmProperty edmProperty = ((EdmStructuredType) entityType).getStructuralProperty(propertyName);
final EdmType type = findType(contextURL, metadataETag);
if (type instanceof EdmStructuredType) {
final EdmProperty edmProperty = ((EdmStructuredType) type).getStructuralProperty(propertyName);
if (edmProperty != null) {
typeName = edmProperty.getType().getFullQualifiedName();
}
}
if (typeName == null && type != null) {
typeName = type.getFullQualifiedName();
}
return buildTypeInfo(typeName, propertyType);
}
protected EdmTypeInfo buildTypeInfo(final FullQualifiedName typeName, final String propertyType) {
EdmTypeInfo typeInfo = null;
if (typeName == null) {
if (propertyType != null) {
@ -468,6 +486,8 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
return typeInfo;
}
protected abstract CommonODataProperty getODataProperty(EdmType type, Property resource);
protected ODataValue getODataValue(final FullQualifiedName type,
final Valuable valuable, final ContextURL contextURL, final String metadataETag) {
@ -475,7 +495,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
if (valuable.getValue().isPrimitive()) {
value = client.getObjectFactory().newPrimitiveValueBuilder().
setText(valuable.getValue().asPrimitive().get()).
setType(type == null
setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
? null
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
} else if (valuable.getValue().isGeospatial()) {

View File

@ -34,6 +34,7 @@ import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.core.domain.v3.ODataPropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.op.ResourceFactory;
@ -98,6 +99,17 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
property.getPayload(), property.getContextURL(), property.getMetadataETag()));
}
@Override
protected ODataProperty getODataProperty(final EdmType type, final Property resource) {
final EdmTypeInfo typeInfo = buildTypeInfo(type == null ? null : type.getFullQualifiedName(), resource.getType());
return new ODataPropertyImpl(resource.getName(),
getODataValue(typeInfo == null
? null
: typeInfo.getFullQualifiedName(),
resource, null, null));
}
@Override
public ODataLinkCollection getLinkCollection(final LinkCollection linkCollection) {
final ODataLinkCollection collection = new ODataLinkCollection(linkCollection.getNext());

View File

@ -63,8 +63,8 @@ import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.ODataValuable;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.core.data.AnnotationImpl;
import org.apache.olingo.commons.core.data.EnumValueImpl;
@ -259,7 +259,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
@Override
protected void odataNavigationLinks(final EdmStructuredType edmType,
protected void odataNavigationLinks(final EdmType edmType,
final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) {
super.odataNavigationLinks(edmType, linked, odataLinked, metadataETag, base);
@ -286,13 +286,29 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
resource.getPayload().getName(), resource.getPayload().getType());
final ODataProperty property = new ODataPropertyImpl(resource.getPayload().getName(),
getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
getODataValue(typeInfo == null
? null
: typeInfo.getFullQualifiedName(),
resource.getPayload(), resource.getContextURL(), resource.getMetadataETag()));
odataAnnotations(resource.getPayload(), property);
return property;
}
@Override
protected ODataProperty getODataProperty(final EdmType type, final Property resource) {
final EdmTypeInfo typeInfo = buildTypeInfo(type == null ? null : type.getFullQualifiedName(), resource.getType());
final ODataProperty property = new ODataPropertyImpl(resource.getName(),
getODataValue(typeInfo == null
? null
: typeInfo.getFullQualifiedName(),
resource, null, null));
odataAnnotations(resource, property);
return property;
}
@Override
protected ODataValue getODataValue(final FullQualifiedName type,
final Valuable valuable, final ContextURL contextURL, final String metadataETag) {

View File

@ -18,15 +18,21 @@
*/
package org.apache.olingo.client.core.v3;
import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.uri.v3.URIBuilder;
import org.apache.olingo.client.api.v3.EdmEnabledODataClient;
import org.apache.olingo.client.core.communication.request.invoke.v3.EdmEnabledInvokeRequestFactoryImpl;
import org.apache.olingo.client.core.uri.v3.URIBuilderImpl;
import org.apache.olingo.commons.api.edm.Edm;
public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEnabledODataClient {
private final String serviceRoot;
private EdmEnabledInvokeRequestFactory edmEnabledInvokeRequestFactory;
private Edm edm;
public EdmEnabledODataClientImpl(final String serviceRoot) {
@ -57,4 +63,18 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEna
}
return this.edm;
}
@Override
public URIBuilder getURIBuilder() {
return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot);
}
@Override
public EdmEnabledInvokeRequestFactory getInvokeRequestFactory() {
if (edmEnabledInvokeRequestFactory == null) {
edmEnabledInvokeRequestFactory = new EdmEnabledInvokeRequestFactoryImpl(this);
}
return edmEnabledInvokeRequestFactory;
}
}

View File

@ -55,7 +55,7 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
private static final long serialVersionUID = -1655712193243609209L;
private final Configuration configuration = new ConfigurationImpl();
protected final Configuration configuration = new ConfigurationImpl();
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());

View File

@ -19,9 +19,13 @@
package org.apache.olingo.client.core.v4;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.communication.request.invoke.EdmEnabledInvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.uri.v4.URIBuilder;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.core.communication.request.invoke.v4.EdmEnabledInvokeRequestFactoryImpl;
import org.apache.olingo.client.core.uri.v4.URIBuilderImpl;
import org.apache.olingo.commons.api.edm.Edm;
public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEnabledODataClient {
@ -32,6 +36,8 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEna
private String metadataETag;
private EdmEnabledInvokeRequestFactory edmEnabledInvokeRequestFactory;
public EdmEnabledODataClientImpl(final String serviceRoot) {
super();
@ -64,4 +70,17 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEna
}
return this.edm;
}
@Override
public URIBuilder getURIBuilder() {
return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot);
}
@Override
public EdmEnabledInvokeRequestFactory getInvokeRequestFactory() {
if (edmEnabledInvokeRequestFactory == null) {
edmEnabledInvokeRequestFactory = new EdmEnabledInvokeRequestFactoryImpl(this);
}
return edmEnabledInvokeRequestFactory;
}
}

View File

@ -58,7 +58,7 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
private static final long serialVersionUID = -6653176125573631964L;
private final Configuration configuration = new ConfigurationImpl();
protected final Configuration configuration = new ConfigurationImpl();
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());