[OLINGO-377] Merge branch 'master' into OLINGO-377-FIT
This commit is contained in:
commit
c35725ce81
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.apache.olingo.fit.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
|
||||
|
@ -39,16 +44,11 @@ import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
|||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* This is the unit test class to check entity retrieve operations.
|
||||
*/
|
||||
|
@ -56,10 +56,10 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void withInlineEntity(final ODataClient client, final ODataFormat format) {
|
||||
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");
|
||||
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");
|
||||
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().
|
||||
getEntityRequest(uriBuilder.build());
|
||||
getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
||||
|
@ -91,15 +91,15 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
assertEquals(5, properties.size());
|
||||
|
||||
assertTrue(properties.get(0).getName().equals("CompanyID")
|
||||
|| properties.get(1).getName().equals("CompanyID")
|
||||
|| properties.get(2).getName().equals("CompanyID")
|
||||
|| properties.get(3).getName().equals("CompanyID")
|
||||
|| properties.get(4).getName().equals("CompanyID"));
|
||||
|| properties.get(1).getName().equals("CompanyID")
|
||||
|| properties.get(2).getName().equals("CompanyID")
|
||||
|| properties.get(3).getName().equals("CompanyID")
|
||||
|| properties.get(4).getName().equals("CompanyID"));
|
||||
assertTrue(properties.get(0).getValue().toString().equals("0")
|
||||
|| properties.get(1).getValue().toString().equals("0")
|
||||
|| properties.get(2).getValue().toString().equals("0")
|
||||
|| properties.get(3).getValue().toString().equals("0")
|
||||
|| properties.get(4).getValue().toString().equals("0"));
|
||||
|| properties.get(1).getValue().toString().equals("0")
|
||||
|| properties.get(2).getValue().toString().equals("0")
|
||||
|| properties.get(3).getValue().toString().equals("0")
|
||||
|| properties.get(4).getValue().toString().equals("0"));
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
@ -126,10 +126,10 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void withInlineEntitySet(final ODataClient client, final ODataFormat format) {
|
||||
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
|
||||
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
|
||||
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().
|
||||
getEntityRequest(uriBuilder.build());
|
||||
getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
||||
|
@ -169,7 +169,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void rawRequest(final ODataFormat format) {
|
||||
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").appendKeySegment(5);
|
||||
appendEntitySetSegment("People").appendKeySegment(5);
|
||||
|
||||
final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
|
||||
req.setFormat(format.getContentType(client.getServiceVersion()).toContentTypeString());
|
||||
|
@ -201,7 +201,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
multiKey.put("ProductDetailID", 1);
|
||||
|
||||
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("ProductDetails").appendKeySegment(multiKey);
|
||||
appendEntitySetSegment("ProductDetails").appendKeySegment(multiKey);
|
||||
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
@ -210,7 +210,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
final ODataEntity entity = res.getBody();
|
||||
assertNotNull(entity);
|
||||
assertEquals(Integer.valueOf(1),
|
||||
entity.getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class));
|
||||
entity.getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -225,7 +225,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void checkForETag(final ODataClient client, final ODataFormat format) {
|
||||
final URIBuilder uriBuilder =
|
||||
client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8);
|
||||
client.newURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8);
|
||||
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
@ -274,8 +274,8 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void reference(final ODataFormat format) {
|
||||
final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Orders").appendKeySegment(8).appendNavigationSegment("CustomerForOrder").
|
||||
appendRefSegment();
|
||||
appendEntitySetSegment("Orders").appendKeySegment(8).appendNavigationSegment("CustomerForOrder").
|
||||
appendRefSegment();
|
||||
|
||||
ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||
req.setFormat(format);
|
||||
|
@ -288,7 +288,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
assertTrue(entity.getId().toASCIIString().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
|
||||
|
||||
final URI referenceURI = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntityIdSegment(entity.getId().toASCIIString()).build();
|
||||
appendEntityIdSegment(entity.getId().toASCIIString()).build();
|
||||
|
||||
req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI);
|
||||
req.setFormat(format);
|
||||
|
@ -310,8 +310,8 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void contained(final ODataClient client, final ODataFormat format) throws EdmPrimitiveTypeException {
|
||||
final URI uri = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Accounts").appendKeySegment(101).
|
||||
appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101902).build();
|
||||
appendEntitySetSegment("Accounts").appendKeySegment(101).
|
||||
appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101902).build();
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
|
||||
req.setFormat(format);
|
||||
|
||||
|
@ -319,8 +319,9 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
assertNotNull(contained);
|
||||
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument", contained.getTypeName().toString());
|
||||
assertEquals(101902,
|
||||
contained.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
contained.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
assertEquals("Edm.DateTimeOffset", contained.getProperty("CreatedDate").getPrimitiveValue().getTypeName());
|
||||
assertNotNull(contained.getProperty("CreatedDate").getPrimitiveValue().toCastValue(Timestamp.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -340,7 +341,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void entitySetNavigationLink(final ODataClient client, final ODataFormat format) {
|
||||
final URI uri = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Accounts").appendKeySegment(101).build();
|
||||
appendEntitySetSegment("Accounts").appendKeySegment(101).build();
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
|
||||
req.setFormat(format);
|
||||
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.serialization;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.data.ServiceDocument;
|
||||
|
@ -54,6 +60,7 @@ 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.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
|
@ -67,15 +74,11 @@ import org.apache.olingo.commons.core.data.EntitySetImpl;
|
|||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.commons.core.serialization.ContextURLParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||
|
||||
/**
|
||||
|
@ -257,9 +260,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString());
|
||||
}
|
||||
|
||||
final URI base = resource.getContextURL() == null ?
|
||||
resource.getPayload().getBaseURI() :
|
||||
ContextURLParser.parse(resource.getContextURL()).getServiceRoot();
|
||||
final URI base = resource.getContextURL() == null
|
||||
? resource.getPayload().getBaseURI()
|
||||
: ContextURLParser.parse(resource.getContextURL()).getServiceRoot();
|
||||
|
||||
final URI next = resource.getPayload().getNext();
|
||||
|
||||
|
@ -414,9 +417,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
}
|
||||
|
||||
final ContextURL contextURL = ContextURLParser.parse(resource.getContextURL());
|
||||
final URI base = resource.getContextURL() == null ?
|
||||
resource.getPayload().getBaseURI() :
|
||||
contextURL.getServiceRoot();
|
||||
final URI base = resource.getContextURL() == null
|
||||
? resource.getPayload().getBaseURI()
|
||||
: contextURL.getServiceRoot();
|
||||
final EdmType edmType = findType(contextURL, resource.getMetadataETag());
|
||||
FullQualifiedName typeName = null;
|
||||
if (resource.getPayload().getType() == null) {
|
||||
|
@ -519,18 +522,40 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
|||
|
||||
ODataValue value = null;
|
||||
if (valuable.isGeospatial()) {
|
||||
value = client.getObjectFactory().newPrimitiveValueBuilder()
|
||||
.setValue(valuable.asGeospatial())
|
||||
.setType(type == null
|
||||
value = client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setValue(valuable.asGeospatial()).
|
||||
setType(type == null
|
||||
|| EdmPrimitiveTypeKind.Geography.getFullQualifiedName().equals(type)
|
||||
|| EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type)
|
||||
? valuable.asGeospatial().getEdmPrimitiveTypeKind()
|
||||
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
|
||||
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).
|
||||
build();
|
||||
} else if (valuable.isPrimitive() || valuable.getValueType() == null) {
|
||||
value = client.getObjectFactory().newPrimitiveValueBuilder()
|
||||
.setValue(valuable.asPrimitive())
|
||||
.setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace()) ? null
|
||||
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
|
||||
// fixes non-string values treated as string when no type information is available at de-serialization level
|
||||
if (type != null && !EdmPrimitiveTypeKind.String.getFullQualifiedName().equals(type)
|
||||
&& EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
|
||||
&& valuable.asPrimitive() instanceof String) {
|
||||
|
||||
final EdmPrimitiveType primitiveType =
|
||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.valueOf(type.getName()));
|
||||
final Class<?> returnType = primitiveType.getDefaultType().isAssignableFrom(Calendar.class)
|
||||
? Timestamp.class : primitiveType.getDefaultType();
|
||||
try {
|
||||
valuable.setValue(valuable.getValueType(),
|
||||
primitiveType.valueOfString(valuable.asPrimitive().toString(),
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null,
|
||||
returnType));
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
value = client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setValue(valuable.asPrimitive()).
|
||||
setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
|
||||
? null
|
||||
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).
|
||||
build();
|
||||
} else if (valuable.isComplex() || valuable.isLinkedComplex()) {
|
||||
value = client.getObjectFactory().newComplexValue(type == null ? null : type.toString());
|
||||
if (!valuable.isNull()) {
|
||||
|
|
|
@ -59,15 +59,15 @@ public abstract class AbstractODataPrimitiveValue extends AbstractODataValue imp
|
|||
public AbstractBuilder setType(final EdmPrimitiveTypeKind type) {
|
||||
if (type != null && !type.getSupportedVersions().contains(version)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Type %s not supported by OData version %s", type.toString(), version));
|
||||
"Type %s not supported by OData version %s", type.toString(), version));
|
||||
}
|
||||
if (type == EdmPrimitiveTypeKind.Stream) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
|
||||
"Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
|
||||
}
|
||||
if (type == EdmPrimitiveTypeKind.Geography || type == EdmPrimitiveTypeKind.Geometry) {
|
||||
throw new IllegalArgumentException(
|
||||
type + "is not an instantiable type. "
|
||||
type + "is not an instantiable type. "
|
||||
+ "An entity can declare a property to be of type Geometry. "
|
||||
+ "An instance of an entity MUST NOT have a value of type Geometry. "
|
||||
+ "Each value MUST be of some subtype.");
|
||||
|
@ -186,14 +186,10 @@ public abstract class AbstractODataPrimitiveValue extends AbstractODataValue imp
|
|||
} else if (typeKind.isGeospatial()) {
|
||||
return reference.cast(value);
|
||||
} else {
|
||||
try {
|
||||
// TODO: when Edm is available, set facets when calling this method
|
||||
return type.valueOfString(type.valueToString(value,
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
// TODO: set facets
|
||||
return type.valueOfString(type.valueToString(value,
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +201,7 @@ public abstract class AbstractODataPrimitiveValue extends AbstractODataValue imp
|
|||
return value.toString();
|
||||
} else {
|
||||
try {
|
||||
// TODO: when Edm is available, set facets when calling this method
|
||||
// TODO: set facets
|
||||
return type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
|
|
Loading…
Reference in New Issue