[OLINGO-575] Start merging ComplexValue and LinkedComplexValue
This commit is contained in:
parent
033f35d617
commit
0d57a0763a
|
@ -18,16 +18,6 @@
|
|||
*/
|
||||
package org.apache.olingo.ext.proxy.commons;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.ext.proxy.api.AbstractTerm;
|
||||
import org.apache.olingo.ext.proxy.api.Annotatable;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.Namespace;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.Term;
|
||||
import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
|
||||
import org.apache.olingo.ext.proxy.utils.CoreUtils;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
@ -37,7 +27,16 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.ext.proxy.AbstractService;
|
||||
import org.apache.olingo.ext.proxy.api.AbstractTerm;
|
||||
import org.apache.olingo.ext.proxy.api.Annotatable;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.Namespace;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.Term;
|
||||
import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
|
||||
import org.apache.olingo.ext.proxy.utils.CoreUtils;
|
||||
|
||||
public class AnnotatableInvocationHandler extends AbstractInvocationHandler implements Annotatable {
|
||||
|
||||
|
@ -87,11 +86,11 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl
|
|||
? ((org.apache.olingo.commons.api.domain.ODataLink) ((ODataEntity) targetHandler.getInternal()).
|
||||
getNavigationLink(navPropName)).getAnnotations()
|
||||
: ((ODataEntity) targetHandler.getInternal()).getProperty(propName).getAnnotations();
|
||||
} else if (targetHandler.getInternal() instanceof ODataLinkedComplexValue) {
|
||||
} else if (targetHandler.getInternal() instanceof ODataComplexValue) {
|
||||
result = propName == null
|
||||
? ((org.apache.olingo.commons.api.domain.ODataLink) ((ODataLinkedComplexValue) targetHandler.
|
||||
? ((org.apache.olingo.commons.api.domain.ODataLink) ((ODataComplexValue) targetHandler.
|
||||
getInternal()).getNavigationLink(navPropName)).getAnnotations()
|
||||
: ((ODataLinkedComplexValue) targetHandler.getInternal()).get(propName).getAnnotations();
|
||||
: ((ODataComplexValue) targetHandler.getInternal()).get(propName).getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.olingo.ext.proxy.utils.ClassUtils;
|
|||
|
||||
public class ComplexInvocationHandler extends AbstractStructuredInvocationHandler {
|
||||
|
||||
private static Pair<ODataComplexValue<? extends ODataProperty>, Class<?>> init(
|
||||
private static Pair<ODataComplexValue, Class<?>> init(
|
||||
final Class<?> typeRef,
|
||||
final AbstractService<?> service) {
|
||||
|
||||
|
@ -57,10 +57,10 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
|
||||
final FullQualifiedName typeName =
|
||||
new FullQualifiedName(ClassUtils.getNamespace(complexTypeRef), annotation.name());
|
||||
final ODataComplexValue<? extends ODataProperty> complex =
|
||||
final ODataComplexValue complex =
|
||||
service.getClient().getObjectFactory().newComplexValue(typeName.toString());
|
||||
|
||||
return new ImmutablePair<ODataComplexValue<? extends ODataProperty>, Class<?>>(complex, complexTypeRef);
|
||||
return new ImmutablePair<ODataComplexValue, Class<?>>(complex, complexTypeRef);
|
||||
}
|
||||
|
||||
public static ComplexInvocationHandler getInstance(
|
||||
|
@ -68,12 +68,12 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
final EntityInvocationHandler handler,
|
||||
final Class<?> typeRef) {
|
||||
|
||||
final Pair<ODataComplexValue<? extends ODataProperty>, Class<?>> init = init(typeRef, handler.service);
|
||||
final Pair<ODataComplexValue, Class<?>> init = init(typeRef, handler.service);
|
||||
return new ComplexInvocationHandler(init.getLeft(), init.getRight(), handler);
|
||||
}
|
||||
|
||||
public static ComplexInvocationHandler getInstance(
|
||||
final ODataComplexValue<?> complex,
|
||||
final ODataComplexValue complex,
|
||||
final Class<?> typeRef,
|
||||
final AbstractService<?> service) {
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
final Class<?> typeRef,
|
||||
final AbstractService<?> service) {
|
||||
|
||||
final Pair<ODataComplexValue<? extends ODataProperty>, Class<?>> init = init(typeRef, service);
|
||||
final Pair<ODataComplexValue, Class<?>> init = init(typeRef, service);
|
||||
return new ComplexInvocationHandler(init.getLeft(), init.getRight(), service);
|
||||
}
|
||||
|
||||
|
@ -93,12 +93,12 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
final AbstractService<?> service,
|
||||
final URIBuilder uri) {
|
||||
|
||||
final Pair<ODataComplexValue<? extends ODataProperty>, Class<?>> init = init(typeRef, service);
|
||||
final Pair<ODataComplexValue, Class<?>> init = init(typeRef, service);
|
||||
return new ComplexInvocationHandler(init.getLeft(), init.getRight(), service, uri);
|
||||
}
|
||||
|
||||
public static ComplexInvocationHandler getInstance(
|
||||
final ODataComplexValue<? extends ODataProperty> complex,
|
||||
final ODataComplexValue complex,
|
||||
final Class<?> typeRef,
|
||||
final AbstractService<?> service,
|
||||
final URIBuilder uri) {
|
||||
|
@ -107,7 +107,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
}
|
||||
|
||||
private ComplexInvocationHandler(
|
||||
final ODataComplexValue<? extends ODataProperty> complex,
|
||||
final ODataComplexValue complex,
|
||||
final Class<?> typeRef,
|
||||
final AbstractService<?> service,
|
||||
final URIBuilder uri) {
|
||||
|
@ -118,7 +118,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
}
|
||||
|
||||
private ComplexInvocationHandler(
|
||||
final ODataComplexValue<? extends ODataProperty> complex,
|
||||
final ODataComplexValue complex,
|
||||
final Class<?> typeRef,
|
||||
final EntityInvocationHandler handler) {
|
||||
|
||||
|
@ -127,7 +127,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
}
|
||||
|
||||
private ComplexInvocationHandler(
|
||||
final ODataComplexValue<? extends ODataProperty> complex,
|
||||
final ODataComplexValue complex,
|
||||
final Class<?> typeRef,
|
||||
final AbstractService<?> service) {
|
||||
|
||||
|
@ -135,9 +135,8 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
this.uri = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ODataComplexValue<ODataProperty> getComplex() {
|
||||
return (ODataComplexValue<ODataProperty>) this.internal;
|
||||
public ODataComplexValue getComplex() {
|
||||
return (ODataComplexValue) this.internal;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,12 +173,11 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T extends ODataProperty> List<T> getInternalProperties() {
|
||||
final List<T> res = new ArrayList<T>();
|
||||
protected List<ODataProperty> getInternalProperties() {
|
||||
final List<ODataProperty> res = new ArrayList<ODataProperty>();
|
||||
if (getComplex() != null) {
|
||||
for (ODataProperty property : getComplex()) {
|
||||
res.add((T) property);
|
||||
res.add(property);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
|
|
@ -308,7 +308,7 @@ public final class CoreUtils {
|
|||
public static void addProperties(
|
||||
final EdmEnabledODataClient client,
|
||||
final Map<String, Object> changes,
|
||||
final ODataComplexValue<ODataProperty> entity) {
|
||||
final ODataComplexValue entity) {
|
||||
|
||||
for (Map.Entry<String, Object> entry : changes.entrySet()) {
|
||||
entity.add(getODataComplexProperty(
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1310,10 +1310,10 @@ public class V4Services extends AbstractServices {
|
|||
}
|
||||
|
||||
assert property.isComplex();
|
||||
assert 1 == property.asComplex().size();
|
||||
assert "Edm.Int32".equals(property.asComplex().get(0).getType());
|
||||
assert property.asComplex().get(0).isPrimitive();
|
||||
assert "percentage".equals(property.asComplex().get(0).getName());
|
||||
assert 1 == property.asComplex().getValue().size();
|
||||
assert "Edm.Int32".equals(property.asComplex().getValue().get(0).getType());
|
||||
assert property.asComplex().getValue().get(0).isPrimitive();
|
||||
assert "percentage".equals(property.asComplex().getValue().get(0).getName());
|
||||
|
||||
return xml.createResponse(null, null, null, acceptType, Response.Status.NO_CONTENT);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -51,10 +51,10 @@ import org.apache.olingo.client.api.edm.xml.Reference;
|
|||
import org.apache.olingo.client.api.edm.xml.XMLMetadata;
|
||||
import org.apache.olingo.client.core.ODataClientFactory;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataError;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
|
||||
|
@ -295,9 +295,9 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
|||
final ODataObjectFactory factory = client.getObjectFactory();
|
||||
ODataEntity patchEntity = factory.newEntity(new FullQualifiedName("olingo.odata.test1", "ETCompComp"));
|
||||
patchEntity.getProperties().add(factory.newComplexProperty("PropertyComp",
|
||||
factory.newLinkedComplexValue("olingo.odata.test1.CTCompComp").add(
|
||||
factory.newComplexValue("olingo.odata.test1.CTCompComp").add(
|
||||
factory.newComplexProperty("PropertyComp",
|
||||
factory.newLinkedComplexValue("olingo.odata.test1.CTTwoPrim").add(
|
||||
factory.newComplexValue("olingo.odata.test1.CTTwoPrim").add(
|
||||
factory.newPrimitiveProperty("PropertyInt16",
|
||||
factory.newPrimitiveValueBuilder().buildInt32(42)))))));
|
||||
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESCompComp").appendKeySegment(1).build();
|
||||
|
@ -314,8 +314,8 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
|||
assertEquals(HttpStatusCode.OK.getStatusCode(), entityResponse.getStatusCode());
|
||||
final ODataEntity entity = entityResponse.getBody();
|
||||
assertNotNull(entity);
|
||||
final ODataLinkedComplexValue complex = entity.getProperty("PropertyComp").getLinkedComplexValue()
|
||||
.get("PropertyComp").getLinkedComplexValue();
|
||||
final ODataComplexValue complex = entity.getProperty("PropertyComp").getComplexValue()
|
||||
.get("PropertyComp").getComplexValue();
|
||||
assertNotNull(complex);
|
||||
final ODataProperty property1 = complex.get("PropertyInt16");
|
||||
assertNotNull(property1);
|
||||
|
@ -358,8 +358,8 @@ public class BasicITCase extends AbstractBaseTestITCase {
|
|||
assertEquals(HttpStatusCode.OK.getStatusCode(), entityResponse.getStatusCode());
|
||||
final ODataEntity entity = entityResponse.getBody();
|
||||
assertNotNull(entity);
|
||||
final ODataLinkedComplexValue complex = entity.getProperty("PropertyCompComp").getLinkedComplexValue()
|
||||
.get("PropertyComp").getLinkedComplexValue();
|
||||
final ODataComplexValue complex = entity.getProperty("PropertyCompComp").getComplexValue()
|
||||
.get("PropertyComp").getComplexValue();
|
||||
assertNotNull(complex);
|
||||
final ODataProperty property = complex.get("PropertyInt16");
|
||||
assertNotNull(property);
|
||||
|
|
|
@ -321,8 +321,8 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
|||
final ODataCollectionValue<org.apache.olingo.commons.api.domain.ODataValue> addresses =
|
||||
client.getObjectFactory().
|
||||
newCollectionValue("Collection(Microsoft.Test.OData.Services.ODataWCFService.Address)");
|
||||
final ODataComplexValue<ODataProperty> address = client.getObjectFactory().
|
||||
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
final ODataComplexValue address = client.getObjectFactory().
|
||||
newComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
address.add(client.getObjectFactory().newPrimitiveProperty("Street",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().buildString("Piazza La Bomba E Scappa")));
|
||||
address.add(client.getObjectFactory().newPrimitiveProperty("City",
|
||||
|
@ -411,8 +411,8 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
|||
final ODataCollectionValue<org.apache.olingo.commons.api.domain.ODataValue> addresses =
|
||||
edmClient.getObjectFactory().
|
||||
newCollectionValue("Collection(Microsoft.Test.OData.Services.ODataWCFService.Address)");
|
||||
final ODataComplexValue<ODataProperty> address = edmClient.getObjectFactory().
|
||||
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
final ODataComplexValue address = edmClient.getObjectFactory().
|
||||
newComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
address.add(edmClient.getObjectFactory().newPrimitiveProperty("Street",
|
||||
edmClient.getObjectFactory().newPrimitiveValueBuilder().buildString("Piazza La Bomba E Scappa")));
|
||||
address.add(edmClient.getObjectFactory().newPrimitiveProperty("City",
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
*/
|
||||
package org.apache.olingo.fit.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
|
||||
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
|
@ -27,19 +33,12 @@ import org.apache.olingo.client.api.uri.URIBuilder;
|
|||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValuable;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class DerivedTypeTestITCase extends AbstractTestITCase {
|
||||
|
||||
private void read(final ODataFormat format) {
|
||||
|
@ -89,7 +88,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase {
|
|||
customer.getProperties().add(client.getObjectFactory().newPrimitiveProperty("LastName",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().buildString("Test")));
|
||||
|
||||
final ODataComplexValue<ODataProperty> homeAddress =
|
||||
final ODataComplexValue homeAddress =
|
||||
client.getObjectFactory().newComplexValue("Microsoft.Test.OData.Services.ODataWCFService.CompanyAddress");
|
||||
homeAddress.add(client.getObjectFactory().newPrimitiveProperty("Street",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().buildString("V.le Gabriele D'Annunzio")));
|
||||
|
|
|
@ -18,13 +18,20 @@
|
|||
*/
|
||||
package org.apache.olingo.fit.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
||||
import org.apache.olingo.client.api.uri.URIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
|
@ -32,14 +39,6 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
|
@ -115,7 +114,7 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
|||
getClient().getObjectFactory().newEnumProperty("aColor", getClient().getObjectFactory().
|
||||
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue")));
|
||||
|
||||
final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
|
||||
final ODataComplexValue contactDetails = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.OpenTypesServiceV4.ContactDetails");
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("FirstContacted",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
*/
|
||||
package org.apache.olingo.fit.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
|
||||
import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
|
@ -32,14 +40,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
|||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class OperationImportInvokeTestITCase extends AbstractTestITCase {
|
||||
|
||||
private void functionImports(final ODataFormat format) throws EdmPrimitiveTypeException {
|
||||
|
@ -68,8 +68,8 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
|
|||
assertEquals(1, person2.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
|
||||
// GetPerson
|
||||
final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
|
||||
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
final ODataComplexValue address = getClient().getObjectFactory().
|
||||
newComplexValue("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",
|
||||
|
@ -144,8 +144,8 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
|
|||
assertEquals(1, person2.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
|
||||
// GetPerson
|
||||
final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
|
||||
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
final ODataComplexValue address = getClient().getObjectFactory().
|
||||
newComplexValue("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",
|
||||
|
@ -194,8 +194,8 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
|
|||
assertNotNull(discount);
|
||||
|
||||
// ResetBossAddress
|
||||
final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
|
||||
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
final ODataComplexValue address = getClient().getObjectFactory().
|
||||
newComplexValue("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",
|
||||
|
@ -234,8 +234,8 @@ public class OperationImportInvokeTestITCase extends AbstractTestITCase {
|
|||
assertNotNull(discount);
|
||||
|
||||
// ResetBossAddress
|
||||
final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
|
||||
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
final ODataComplexValue address = getClient().getObjectFactory().
|
||||
newComplexValue("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",
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.olingo.client.core.uri.URIUtils;
|
|||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.Annotatable;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.DeletedEntity;
|
||||
import org.apache.olingo.commons.api.data.Delta;
|
||||
|
@ -43,7 +44,6 @@ import org.apache.olingo.commons.api.data.Entity;
|
|||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Linked;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
|
@ -62,7 +62,6 @@ import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
|||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinked;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
|
||||
|
@ -89,10 +88,10 @@ import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
|||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataAnnotationImpl;
|
||||
import org.apache.olingo.commons.core.domain.ODataDeletedEntityImpl;
|
||||
|
@ -165,15 +164,12 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
propertyResource.setValue(ValueType.ENUM, propertyValue);
|
||||
} else if (odataValuable.hasComplexValue()) {
|
||||
propertyResource.setType(odataValuable.getComplexValue().getTypeName());
|
||||
propertyResource.setValue(
|
||||
propertyValue instanceof LinkedComplexValue ? ValueType.LINKED_COMPLEX : ValueType.COMPLEX,
|
||||
propertyValue);
|
||||
propertyResource.setValue(ValueType.COMPLEX, propertyValue);
|
||||
} else if (odataValuable.hasCollectionValue()) {
|
||||
final ODataCollectionValue<org.apache.olingo.commons.api.domain.ODataValue> collectionValue =
|
||||
final ODataCollectionValue<ODataValue> collectionValue =
|
||||
odataValuable.getCollectionValue();
|
||||
propertyResource.setType(collectionValue.getTypeName());
|
||||
final org.apache.olingo.commons.api.domain.ODataValue value =
|
||||
collectionValue.iterator().hasNext() ? collectionValue.iterator().next() : null;
|
||||
final ODataValue value = collectionValue.iterator().hasNext() ? collectionValue.iterator().next() : null;
|
||||
ValueType valueType = ValueType.COLLECTION_PRIMITIVE;
|
||||
if (value == null) {
|
||||
valueType = ValueType.COLLECTION_PRIMITIVE;
|
||||
|
@ -182,8 +178,6 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
? ValueType.COLLECTION_GEOSPATIAL : ValueType.COLLECTION_PRIMITIVE;
|
||||
} else if (value.isEnum()) {
|
||||
valueType = ValueType.COLLECTION_ENUM;
|
||||
} else if (value.isLinkedComplex()) {
|
||||
valueType = ValueType.COLLECTION_LINKED_COMPLEX;
|
||||
} else if (value.isComplex()) {
|
||||
valueType = ValueType.COLLECTION_COMPLEX;
|
||||
}
|
||||
|
@ -343,58 +337,35 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
return propertyResource;
|
||||
}
|
||||
|
||||
// TODO: Refactor away the v3 code
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object getValue(final ODataValue value) {
|
||||
Object valueResource;
|
||||
if (value instanceof org.apache.olingo.commons.api.domain.ODataValue
|
||||
&& ((org.apache.olingo.commons.api.domain.ODataValue) value).isEnum()) {
|
||||
|
||||
valueResource =
|
||||
((org.apache.olingo.commons.api.domain.ODataValue) value).asEnum().getValue();
|
||||
} else {
|
||||
valueResource = getValueInternal(value);
|
||||
|
||||
if (value instanceof org.apache.olingo.commons.api.domain.ODataValue
|
||||
&& ((org.apache.olingo.commons.api.domain.ODataValue) value).isLinkedComplex()) {
|
||||
|
||||
final LinkedComplexValue lcValueResource = new LinkedComplexValueImpl();
|
||||
lcValueResource.getValue().addAll((List<Property>) valueResource);
|
||||
|
||||
final ODataLinkedComplexValue linked =
|
||||
((org.apache.olingo.commons.api.domain.ODataValue) value).asLinkedComplex();
|
||||
annotations(linked, lcValueResource);
|
||||
links(linked, lcValueResource);
|
||||
|
||||
valueResource = lcValueResource;
|
||||
}
|
||||
}
|
||||
return valueResource;
|
||||
}
|
||||
|
||||
protected Object getValueInternal(final ODataValue value) {
|
||||
Object valueResource = null;
|
||||
if (value == null) {
|
||||
return null;
|
||||
valueResource = null;
|
||||
} else if (value.isEnum()) {
|
||||
valueResource = value.asEnum().getValue();
|
||||
} else if (value.isPrimitive()) {
|
||||
return value.asPrimitive().toValue();
|
||||
valueResource = value.asPrimitive().toValue();
|
||||
} else if (value.isComplex()) {
|
||||
final ODataComplexValue<? extends ODataProperty> _value = value.asComplex();
|
||||
List<Property> valueResource = new ArrayList<Property>();
|
||||
|
||||
for (final ODataProperty propertyValue : _value) {
|
||||
valueResource.add(getProperty(propertyValue));
|
||||
List<Property> complexProperties = new ArrayList<Property>();
|
||||
for (final ODataProperty propertyValue : value.asComplex()) {
|
||||
complexProperties.add(getProperty(propertyValue));
|
||||
}
|
||||
return valueResource;
|
||||
final ComplexValue lcValueResource = new ComplexValueImpl();
|
||||
lcValueResource.getValue().addAll(complexProperties);
|
||||
annotations(value.asComplex(), lcValueResource);
|
||||
links(value.asComplex(), lcValueResource);
|
||||
valueResource = lcValueResource;
|
||||
|
||||
} else if (value.isCollection()) {
|
||||
final ODataCollectionValue<? extends ODataValue> _value = value.asCollection();
|
||||
ArrayList<Object> valueResource = new ArrayList<Object>();
|
||||
ArrayList<Object> lcValueResource = new ArrayList<Object>();
|
||||
|
||||
for (final ODataValue collectionValue : _value) {
|
||||
valueResource.add(getValue(collectionValue));
|
||||
lcValueResource.add(getValue(collectionValue));
|
||||
}
|
||||
return valueResource;
|
||||
valueResource = lcValueResource;
|
||||
}
|
||||
return null;
|
||||
return valueResource;
|
||||
}
|
||||
|
||||
private void odataAnnotations(final Annotatable annotatable, final ODataAnnotatable odataAnnotatable) {
|
||||
|
@ -604,17 +575,14 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
for (final Object inlined : property.asCollection()) {
|
||||
Entity inlineEntity = new EntityImpl();
|
||||
inlineEntity.setType(propertyTypeName);
|
||||
inlineEntity.getProperties().addAll(
|
||||
inlined instanceof LinkedComplexValue ? ((LinkedComplexValue) inlined).getValue() :
|
||||
inlined instanceof Property ? ((Property) inlined).asComplex() : null);
|
||||
inlineEntity.getProperties().addAll(((ComplexValue) inlined).getValue());
|
||||
inlineEntitySet.getEntities().add(inlineEntity);
|
||||
}
|
||||
return createODataInlineEntitySet(inlineEntitySet, null, property.getName(), null);
|
||||
} else {
|
||||
Entity inlineEntity = new EntityImpl();
|
||||
inlineEntity.setType(propertyTypeName);
|
||||
inlineEntity.getProperties().addAll(
|
||||
property.isLinkedComplex() ? property.asLinkedComplex().getValue() : property.asComplex());
|
||||
inlineEntity.getProperties().addAll(property.asComplex().getValue());
|
||||
return createODataInlineEntity(inlineEntity, null, property.getName(), null);
|
||||
}
|
||||
}
|
||||
|
@ -777,16 +745,16 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
if (valuable.isEnum()) {
|
||||
value = ((ODataClient) client).getObjectFactory().newEnumValue(type == null ? null : type.toString(),
|
||||
valuable.asEnum().toString());
|
||||
} else if (valuable.isLinkedComplex()) {
|
||||
final ODataLinkedComplexValue lcValue =
|
||||
((ODataClient) client).getObjectFactory().newLinkedComplexValue(type == null ? null : type.toString());
|
||||
} else if (valuable.isComplex()) {
|
||||
final ODataComplexValue lcValue =
|
||||
((ODataClient) client).getObjectFactory().newComplexValue(type == null ? null : type.toString());
|
||||
|
||||
EdmComplexType edmType = null;
|
||||
if (client instanceof EdmEnabledODataClient && type != null) {
|
||||
edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getComplexType(type);
|
||||
}
|
||||
|
||||
for (Property property : valuable.asLinkedComplex().getValue()) {
|
||||
for (Property property : valuable.asComplex().getValue()) {
|
||||
EdmType edmPropertyType = null;
|
||||
if (edmType != null) {
|
||||
final EdmElement edmProp = edmType.getProperty(property.getName());
|
||||
|
@ -797,8 +765,8 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
lcValue.add(getODataProperty(edmPropertyType, property));
|
||||
}
|
||||
|
||||
odataNavigationLinks(edmType, valuable.asLinkedComplex(), lcValue, metadataETag, contextURL);
|
||||
odataAnnotations(valuable.asLinkedComplex(), lcValue);
|
||||
odataNavigationLinks(edmType, valuable.asComplex(), lcValue, metadataETag, contextURL);
|
||||
odataAnnotations(valuable.asComplex(), lcValue);
|
||||
|
||||
value = lcValue;
|
||||
} else {
|
||||
|
@ -838,9 +806,8 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
: EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).
|
||||
build();
|
||||
} else if (valuable.isComplex()) {
|
||||
final ODataComplexValue<ODataProperty> cValue =
|
||||
(ODataComplexValue<ODataProperty>) client.getObjectFactory().
|
||||
newComplexValue(type == null ? null : type.toString());
|
||||
final ODataComplexValue cValue = (ODataComplexValue) client.getObjectFactory().
|
||||
newComplexValue(type == null ? null : type.toString());
|
||||
|
||||
if (!valuable.isNull()) {
|
||||
EdmComplexType edmType = null;
|
||||
|
@ -848,7 +815,7 @@ public class ODataBinderImpl implements ODataBinder {
|
|||
edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getComplexType(type);
|
||||
}
|
||||
|
||||
for (Property property : valuable.asComplex()) {
|
||||
for (Property property : valuable.asComplex().getValue()) {
|
||||
EdmType edmPropertyType = null;
|
||||
if (edmType != null) {
|
||||
final EdmElement edmProp = edmType.getProperty(property.getName());
|
||||
|
|
|
@ -34,11 +34,11 @@ import org.apache.olingo.client.core.EdmEnabledODataClientImpl;
|
|||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValuable;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
@ -287,7 +287,7 @@ public class EntityTest extends AbstractTest {
|
|||
getClient().getDeserializer(format).toEntity(input));
|
||||
assertNotNull(entity);
|
||||
|
||||
final ODataLinkedComplexValue addressValue = entity.getProperty("Address").getLinkedComplexValue();
|
||||
final ODataComplexValue addressValue = entity.getProperty("Address").getComplexValue();
|
||||
assertNotNull(addressValue);
|
||||
assertNotNull(addressValue.getNavigationLink("Country"));
|
||||
|
||||
|
@ -336,7 +336,7 @@ public class EntityTest extends AbstractTest {
|
|||
assertEquals("com.contoso.display.styleType", annotation.getValue().getTypeName());
|
||||
assertTrue(annotation.hasComplexValue());
|
||||
assertEquals(2,
|
||||
annotation.getValue().asLinkedComplex().get("order").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
annotation.getValue().asComplex().get("order").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
|
||||
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||
new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
|
||||
|
|
|
@ -22,10 +22,6 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
|
@ -42,13 +38,16 @@ import org.apache.olingo.commons.api.data.Property;
|
|||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
public class JSONTest extends AbstractTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
@ -219,7 +218,7 @@ public class JSONTest extends AbstractTest {
|
|||
assertTrue(property.isPrimitive());
|
||||
property = delta.getEntities().get(1).getProperty("ShippingAddress");
|
||||
assertNotNull(property);
|
||||
assertTrue(property.isLinkedComplex());
|
||||
assertTrue(property.isComplex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -232,7 +231,7 @@ public class JSONTest extends AbstractTest {
|
|||
final ODataEntity message = getClient().getObjectFactory().
|
||||
newEntity(new FullQualifiedName("Microsoft.Exchange.Services.OData.Model.Message"));
|
||||
|
||||
final ODataComplexValue<ODataProperty> toRecipient = getClient().getObjectFactory().
|
||||
final ODataComplexValue toRecipient = getClient().getObjectFactory().
|
||||
newComplexValue("Microsoft.Exchange.Services.OData.Model.Recipient");
|
||||
toRecipient.add(getClient().getObjectFactory().newPrimitiveProperty("Name",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("challen_olingo_client")));
|
||||
|
@ -243,7 +242,7 @@ public class JSONTest extends AbstractTest {
|
|||
toRecipients.add(toRecipient);
|
||||
message.getProperties().add(getClient().getObjectFactory().newCollectionProperty("ToRecipients", toRecipients));
|
||||
|
||||
final ODataComplexValue<ODataProperty> body =
|
||||
final ODataComplexValue body =
|
||||
getClient().getObjectFactory().newComplexValue("Microsoft.Exchange.Services.OData.Model.ItemBody");
|
||||
body.add(getClient().getObjectFactory().newPrimitiveProperty("Content",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
|
|
|
@ -81,7 +81,7 @@ public class PropertyTest extends AbstractTest {
|
|||
final ODataProperty written = getClient().getReader().readProperty(
|
||||
getClient().getWriter().writeProperty(property, format), format);
|
||||
// This is needed because type information gets lost with JSON serialization
|
||||
final ODataComplexValue<ODataProperty> typedValue = getClient().getObjectFactory().
|
||||
final ODataComplexValue typedValue = getClient().getObjectFactory().
|
||||
newComplexValue(property.getComplexValue().getTypeName());
|
||||
for (final Iterator<ODataProperty> itor = written.getComplexValue().iterator(); itor.hasNext();) {
|
||||
final ODataProperty prop = itor.next();
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.olingo.commons.api.data;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public interface LinkedComplexValue extends Linked, Annotatable {
|
||||
public interface ComplexValue extends Linked, Annotatable {
|
||||
|
||||
List<Property> getValue();
|
||||
}
|
|
@ -38,8 +38,6 @@ public interface Valuable {
|
|||
|
||||
boolean isComplex();
|
||||
|
||||
boolean isLinkedComplex();
|
||||
|
||||
boolean isCollection();
|
||||
|
||||
Object getValue();
|
||||
|
@ -50,9 +48,7 @@ public interface Valuable {
|
|||
|
||||
Geospatial asGeospatial();
|
||||
|
||||
List<Property> asComplex();
|
||||
|
||||
LinkedComplexValue asLinkedComplex();
|
||||
ComplexValue asComplex();
|
||||
|
||||
List<?> asCollection();
|
||||
|
||||
|
|
|
@ -19,12 +19,11 @@
|
|||
package org.apache.olingo.commons.api.data;
|
||||
|
||||
public enum ValueType {
|
||||
PRIMITIVE, GEOSPATIAL, ENUM, COMPLEX, LINKED_COMPLEX,
|
||||
PRIMITIVE, GEOSPATIAL, ENUM, COMPLEX,
|
||||
COLLECTION_PRIMITIVE(PRIMITIVE),
|
||||
COLLECTION_GEOSPATIAL(GEOSPATIAL),
|
||||
COLLECTION_ENUM(ENUM),
|
||||
COLLECTION_COMPLEX(COMPLEX),
|
||||
COLLECTION_LINKED_COMPLEX(LINKED_COMPLEX);
|
||||
COLLECTION_COMPLEX(COMPLEX);
|
||||
|
||||
private final ValueType baseType;
|
||||
|
||||
|
|
|
@ -77,10 +77,9 @@ public abstract class AbstractODataValue implements ODataValue {
|
|||
*
|
||||
* @return complex value.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <OP extends ODataProperty> ODataComplexValue<OP> asComplex() {
|
||||
return isComplex() ? (ODataComplexValue<OP>) this : null;
|
||||
public ODataComplexValue asComplex() {
|
||||
return isComplex() ? (ODataComplexValue) this : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Map;
|
|||
*
|
||||
* @param <OP> The actual ODataProperty interface.
|
||||
*/
|
||||
public interface ODataComplexValue<OP extends ODataProperty> extends ODataValue, Iterable<OP> {
|
||||
public interface ODataComplexValue extends ODataValue, ODataLinked, ODataAnnotatable, Iterable<ODataProperty> {
|
||||
|
||||
/**
|
||||
* Adds field to the complex type.
|
||||
|
@ -33,7 +33,7 @@ public interface ODataComplexValue<OP extends ODataProperty> extends ODataValue,
|
|||
* @param field field to be added.
|
||||
* @return this (for fluent-style calls)
|
||||
*/
|
||||
ODataComplexValue<OP> add(OP field);
|
||||
ODataComplexValue add(ODataProperty field);
|
||||
|
||||
/**
|
||||
* Gets field.
|
||||
|
@ -41,7 +41,7 @@ public interface ODataComplexValue<OP extends ODataProperty> extends ODataValue,
|
|||
* @param name name of the field to be retrieved.
|
||||
* @return requested field.
|
||||
*/
|
||||
OP get(String name);
|
||||
ODataProperty get(String name);
|
||||
|
||||
/**
|
||||
* Gets number of fields.
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* 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.commons.api.domain;
|
||||
|
||||
|
||||
public interface ODataLinkedComplexValue
|
||||
extends ODataValue, ODataLinked, ODataComplexValue<ODataProperty>, ODataAnnotatable {
|
||||
|
||||
}
|
|
@ -111,9 +111,7 @@ public interface ODataObjectFactory {
|
|||
|
||||
ODataEnumValue newEnumValue(String typeName, String value);
|
||||
|
||||
ODataComplexValue<ODataProperty> newComplexValue(String typeName);
|
||||
|
||||
ODataLinkedComplexValue newLinkedComplexValue(String typeName);
|
||||
ODataComplexValue newComplexValue(String typeName);
|
||||
|
||||
ODataCollectionValue<ODataValue> newCollectionValue(String typeName);
|
||||
|
||||
|
@ -133,7 +131,7 @@ public interface ODataObjectFactory {
|
|||
* @param value value.
|
||||
* @return complex property.
|
||||
*/
|
||||
ODataProperty newComplexProperty(String name, ODataComplexValue<? extends ODataProperty> value);
|
||||
ODataProperty newComplexProperty(String name, ODataComplexValue value);
|
||||
|
||||
/**
|
||||
* Instantiates a new collection property.
|
||||
|
|
|
@ -75,14 +75,7 @@ public interface ODataValuable {
|
|||
*
|
||||
* @return complex value if exists; null otherwise.
|
||||
*/
|
||||
ODataComplexValue<ODataProperty> getComplexValue();
|
||||
|
||||
/**
|
||||
* Gets complex value with link information (if available).
|
||||
*
|
||||
* @return complex value if exists; null otherwise.
|
||||
*/
|
||||
ODataLinkedComplexValue getLinkedComplexValue();
|
||||
ODataComplexValue getComplexValue();
|
||||
|
||||
/**
|
||||
* Checks if has enum value.
|
||||
|
|
|
@ -60,34 +60,19 @@ public interface ODataValue {
|
|||
*/
|
||||
<OV extends ODataValue> ODataCollectionValue<OV> asCollection();
|
||||
|
||||
/**
|
||||
* Check is is a complex value.
|
||||
*
|
||||
* @return 'TRUE' if complex; 'FALSE' otherwise.
|
||||
*/
|
||||
boolean isComplex();
|
||||
|
||||
/**
|
||||
* Casts to complex value.
|
||||
*
|
||||
* @param <OP> The actual ODataProperty interface.
|
||||
* @return complex value.
|
||||
*/
|
||||
<OP extends ODataProperty> ODataComplexValue<OP> asComplex();
|
||||
ODataComplexValue asComplex();
|
||||
|
||||
/**
|
||||
* Check is is a linked complex value.
|
||||
*
|
||||
* @return 'TRUE' if linked complex; 'FALSE' otherwise.
|
||||
*/
|
||||
boolean isLinkedComplex();
|
||||
|
||||
/**
|
||||
* Casts to complex value with link information (if available).
|
||||
*
|
||||
* @return complex value with link information.
|
||||
*/
|
||||
ODataLinkedComplexValue asLinkedComplex();
|
||||
boolean isComplex();
|
||||
|
||||
/**
|
||||
* Check is is an enum value.
|
||||
|
|
|
@ -18,21 +18,20 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import org.apache.olingo.commons.api.data.Annotatable;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractValuable implements Valuable, Annotatable {
|
||||
|
||||
private ValueType valueType = null;
|
||||
|
@ -64,11 +63,6 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
|
|||
return valueType == ValueType.COMPLEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLinkedComplex() {
|
||||
return valueType == ValueType.LINKED_COMPLEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollection() {
|
||||
return valueType != null && valueType != valueType.getBaseType();
|
||||
|
@ -89,15 +83,9 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
|
|||
return isEnum() ? value : null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Property> asComplex() {
|
||||
return isComplex() ? (List<Property>) value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedComplexValue asLinkedComplex() {
|
||||
return isLinkedComplex() ? (LinkedComplexValue) value : null;
|
||||
public ComplexValue asComplex() {
|
||||
return isComplex() ? (ComplexValue) value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,13 +20,13 @@ package org.apache.olingo.commons.core.data;
|
|||
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LinkedComplexValueImpl implements LinkedComplexValue {
|
||||
public class ComplexValueImpl implements ComplexValue {
|
||||
|
||||
private final List<Property> value = new ArrayList<Property>();
|
||||
private final List<Link> associationLinks = new ArrayList<Link>();
|
|
@ -22,9 +22,7 @@ import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
|||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValuable;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
|
@ -80,15 +78,10 @@ public class ODataAnnotationImpl implements ODataAnnotation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> getComplexValue() {
|
||||
public ODataComplexValue getComplexValue() {
|
||||
return valuable.getComplexValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue getLinkedComplexValue() {
|
||||
return valuable.getLinkedComplexValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEnumValue() {
|
||||
return valuable.hasEnumValue();
|
||||
|
|
|
@ -18,17 +18,16 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
public class ODataCollectionValueImpl<OV extends ODataValue> extends AbstractODataValue
|
||||
implements ODataCollectionValue<OV>, ODataValue {
|
||||
|
||||
|
@ -56,15 +55,10 @@ public class ODataCollectionValueImpl<OV extends ODataValue> extends AbstractODa
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isLinkedComplex() {
|
||||
public boolean isComplex() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue asLinkedComplex() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> asJavaCollection() {
|
||||
final List<Object> result = new ArrayList<Object>();
|
||||
|
|
|
@ -18,22 +18,20 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ODataComplexValueImpl extends AbstractODataValue implements ODataComplexValue<ODataProperty>,
|
||||
ODataLinkedComplexValue {
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
|
||||
public class ODataComplexValueImpl extends AbstractODataValue implements ODataComplexValue {
|
||||
|
||||
/**
|
||||
* Navigation links (might contain in-line entities or entity sets).
|
||||
|
@ -61,8 +59,7 @@ public class ODataComplexValueImpl extends AbstractODataValue implements ODataCo
|
|||
super(typeName);
|
||||
}
|
||||
|
||||
|
||||
protected ODataComplexValue<ODataProperty> getThis() {
|
||||
protected ODataComplexValue getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -77,15 +74,10 @@ public class ODataComplexValueImpl extends AbstractODataValue implements ODataCo
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isLinkedComplex() {
|
||||
public boolean isComplex() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue asLinkedComplex() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLink(final ODataLink link) {
|
||||
boolean result = false;
|
||||
|
@ -171,15 +163,13 @@ public class ODataComplexValueImpl extends AbstractODataValue implements ODataCo
|
|||
return annotations;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds field to the complex type.
|
||||
*
|
||||
* @param field field to be added.
|
||||
*/
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> add(final ODataProperty field) {
|
||||
public ODataComplexValue add(final ODataProperty field) {
|
||||
fields.put(field.getName(), field);
|
||||
return getThis();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.olingo.commons.core.domain;
|
|||
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
|
||||
public class ODataEnumValueImpl extends AbstractODataValue implements ODataEnumValue {
|
||||
|
||||
|
@ -47,15 +46,10 @@ public class ODataEnumValueImpl extends AbstractODataValue implements ODataEnumV
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isLinkedComplex() {
|
||||
public boolean isComplex() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue asLinkedComplex() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getTypeName() + "'" + getValue() + "'";
|
||||
|
|
|
@ -18,27 +18,26 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataDelta;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkType;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataObjectFactory;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataSingleton;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class ODataObjectFactoryImpl implements ODataObjectFactory {
|
||||
|
||||
protected final ODataServiceVersion version;
|
||||
|
@ -119,12 +118,7 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> newComplexValue(final String typeName) {
|
||||
return new ODataComplexValueImpl(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue newLinkedComplexValue(final String typeName) {
|
||||
public ODataComplexValue newComplexValue(final String typeName) {
|
||||
return new ODataComplexValueImpl(typeName);
|
||||
}
|
||||
|
||||
|
@ -139,8 +133,7 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ODataProperty newComplexProperty(final String name,
|
||||
final ODataComplexValue<? extends ODataProperty> value) {
|
||||
public ODataProperty newComplexProperty(final String name, final ODataComplexValue value) {
|
||||
|
||||
return new ODataPropertyImpl(name, value);
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.domain.AbstractODataValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
|
@ -32,8 +33,6 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
|||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ODataPrimitiveValueImpl extends AbstractODataValue implements ODataValue, ODataPrimitiveValue {
|
||||
|
||||
public static class BuilderImpl implements Builder {
|
||||
|
@ -224,13 +223,8 @@ public class ODataPrimitiveValueImpl extends AbstractODataValue implements OData
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isLinkedComplex() {
|
||||
public boolean isComplex() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue asLinkedComplex() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,22 +18,21 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotatable;
|
||||
import org.apache.olingo.commons.api.domain.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValuable;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ODataPropertyImpl implements ODataProperty, ODataAnnotatable, ODataValuable {
|
||||
|
||||
|
||||
|
@ -139,15 +138,10 @@ public class ODataPropertyImpl implements ODataProperty, ODataAnnotatable, OData
|
|||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> getComplexValue() {
|
||||
public ODataComplexValue getComplexValue() {
|
||||
return valuable.getComplexValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue getLinkedComplexValue() {
|
||||
return valuable.getLinkedComplexValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataCollectionValue<ODataValue> getCollectionValue() {
|
||||
return valuable.getCollectionValue();
|
||||
|
|
|
@ -25,9 +25,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataEnumValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataValuable;
|
||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||
|
||||
|
@ -77,16 +75,9 @@ public class ODataValuableImpl implements ODataValuable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ODataComplexValue<ODataProperty> getComplexValue() {
|
||||
public ODataComplexValue getComplexValue() {
|
||||
return hasComplexValue()
|
||||
? getValue().<ODataProperty> asComplex()
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataLinkedComplexValue getLinkedComplexValue() {
|
||||
return hasComplexValue()
|
||||
? getValue().asLinkedComplex()
|
||||
? getValue().asComplex()
|
||||
: null;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ import javax.xml.stream.events.XMLEvent;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.DeletedEntity.Reason;
|
||||
import org.apache.olingo.commons.api.data.Delta;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
|
@ -60,13 +60,13 @@ import org.apache.olingo.commons.api.serialization.ODataDeserializer;
|
|||
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
||||
import org.apache.olingo.commons.core.data.AbstractODataObject;
|
||||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.DeletedEntityImpl;
|
||||
import org.apache.olingo.commons.core.data.DeltaImpl;
|
||||
import org.apache.olingo.commons.core.data.DeltaLinkImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
|
||||
|
@ -120,7 +120,6 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
return value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object fromComplexOrEnum(final XMLEventReader reader, final StartElement start)
|
||||
throws XMLStreamException, EdmPrimitiveTypeException {
|
||||
|
||||
|
@ -132,8 +131,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
|
||||
if (event.isStartElement()) {
|
||||
if (value == null) {
|
||||
value = version.compareTo(ODataServiceVersion.V40) < 0 ?
|
||||
new ArrayList<Property>() : new LinkedComplexValueImpl();
|
||||
value = new ComplexValueImpl();
|
||||
}
|
||||
|
||||
if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
|
||||
|
@ -158,16 +156,15 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
if (link.getRel().startsWith(
|
||||
version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL))) {
|
||||
|
||||
((LinkedComplexValue) value).getNavigationLinks().add(link);
|
||||
((ComplexValue) value).getNavigationLinks().add(link);
|
||||
inline(reader, event.asStartElement(), link);
|
||||
} else if (link.getRel().startsWith(
|
||||
version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL))) {
|
||||
|
||||
((Valuable) value).asLinkedComplex().getAssociationLinks().add(link);
|
||||
((Valuable) value).asComplex().getAssociationLinks().add(link);
|
||||
}
|
||||
} else {
|
||||
(value instanceof LinkedComplexValue ? ((LinkedComplexValue) value).getValue() : (List<Property>) value)
|
||||
.add(property(reader, event.asStartElement()));
|
||||
((ComplexValue) value).getValue().add(property(reader, event.asStartElement()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,8 +197,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
switch (guessPropertyType(reader, typeInfo)) {
|
||||
case COMPLEX:
|
||||
final Object complexValue = fromComplexOrEnum(reader, event.asStartElement());
|
||||
valueType = complexValue instanceof LinkedComplexValue ?
|
||||
ValueType.COLLECTION_LINKED_COMPLEX : ValueType.COLLECTION_COMPLEX;
|
||||
valueType = ValueType.COLLECTION_COMPLEX;
|
||||
values.add(complexValue);
|
||||
break;
|
||||
|
||||
|
@ -313,8 +309,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
|
|||
|
||||
case COMPLEX:
|
||||
final Object complexValue = fromComplexOrEnum(reader, start);
|
||||
valuable.setValue(complexValue instanceof LinkedComplexValue ? ValueType.LINKED_COMPLEX :
|
||||
complexValue instanceof List<?> ? ValueType.COMPLEX : ValueType.ENUM,
|
||||
valuable.setValue(complexValue instanceof ComplexValue ? ValueType.COMPLEX : ValueType.ENUM,
|
||||
complexValue);
|
||||
break;
|
||||
|
||||
|
|
|
@ -18,16 +18,24 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.serialization;
|
||||
|
||||
import com.fasterxml.aalto.stax.OutputFactoryImpl;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.Annotation;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
|
@ -47,15 +55,7 @@ import org.apache.olingo.commons.core.data.LinkImpl;
|
|||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import com.fasterxml.aalto.stax.OutputFactoryImpl;
|
||||
|
||||
public class AtomSerializer extends AbstractAtomDealer implements ODataSerializer {
|
||||
|
||||
|
@ -89,7 +89,6 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void value(final XMLStreamWriter writer,
|
||||
final ValueType valueType, final EdmPrimitiveTypeKind kind, final Object value)
|
||||
throws XMLStreamException, EdmPrimitiveTypeException {
|
||||
|
@ -114,16 +113,10 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
case COLLECTION_GEOSPATIAL:
|
||||
case COLLECTION_ENUM:
|
||||
case COLLECTION_COMPLEX:
|
||||
case COLLECTION_LINKED_COMPLEX:
|
||||
collection(writer, valueType.getBaseType(), kind, (List<?>) value);
|
||||
break;
|
||||
case LINKED_COMPLEX:
|
||||
for (Property property : ((LinkedComplexValue) value).getValue()) {
|
||||
property(writer, property, false);
|
||||
}
|
||||
break;
|
||||
case COMPLEX:
|
||||
for (Property property : (List<Property>) value) {
|
||||
for (Property property : ((ComplexValue) value).getValue()) {
|
||||
property(writer, property, false);
|
||||
}
|
||||
break;
|
||||
|
@ -154,9 +147,9 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
|
||||
value(writer, property.getValueType(), typeInfo == null ? null : typeInfo.getPrimitiveTypeKind(),
|
||||
property.getValue());
|
||||
if (!property.isNull() && property.isLinkedComplex()) {
|
||||
links(writer, property.asLinkedComplex().getAssociationLinks());
|
||||
links(writer, property.asLinkedComplex().getNavigationLinks());
|
||||
if (!property.isNull() && property.isComplex()) {
|
||||
links(writer, property.asComplex().getAssociationLinks());
|
||||
links(writer, property.asComplex().getNavigationLinks());
|
||||
}
|
||||
|
||||
writer.writeEndElement();
|
||||
|
@ -529,15 +522,15 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
|
||||
private void reference(final Writer outWriter, final ResWrap<URI> container) throws XMLStreamException {
|
||||
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
||||
|
||||
|
||||
writer.writeStartDocument();
|
||||
|
||||
|
||||
writer.writeStartElement(Constants.ATTR_METADATA, Constants.ATTR_REF);
|
||||
writer.writeNamespace(Constants.ATTR_METADATA, version.getNamespace(NamespaceKey.METADATA));
|
||||
writer.writeAttribute(Constants.ATTR_METADATA, Constants.CONTEXT, container.getContextURL().toASCIIString());
|
||||
writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().toASCIIString());
|
||||
writer.writeEndElement();
|
||||
|
||||
|
||||
writer.writeEndDocument();
|
||||
}
|
||||
|
||||
|
@ -555,8 +548,8 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
|
|||
property(writer, (Property) obj);
|
||||
} else if (obj instanceof Link) {
|
||||
link(writer, (Link) obj);
|
||||
} else if(obj instanceof URI) {
|
||||
reference(writer,(ResWrap<URI>) container);
|
||||
} else if (obj instanceof URI) {
|
||||
reference(writer, (ResWrap<URI>) container);
|
||||
}
|
||||
} catch (final XMLStreamException e) {
|
||||
throw new ODataSerializerException(e);
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.apache.olingo.commons.api.data.Annotation;
|
|||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Linked;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
|
@ -51,7 +51,7 @@ import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
|||
import org.apache.olingo.commons.core.data.AnnotationImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
protected String setInline(final String name, final String suffix, final JsonNode tree,
|
||||
final ObjectCodec codec, final LinkImpl link) throws IOException {
|
||||
final ObjectCodec codec, final LinkImpl link) throws IOException {
|
||||
|
||||
final String entityNamePrefix = name.substring(0, name.indexOf(suffix));
|
||||
if (tree.has(entityNamePrefix)) {
|
||||
|
@ -172,7 +172,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
protected void links(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
|
||||
final JsonNode tree, final ObjectCodec codec) throws IOException {
|
||||
final JsonNode tree, final ObjectCodec codec) throws IOException {
|
||||
if (serverMode) {
|
||||
serverLinks(field, linked, toRemove, tree, codec);
|
||||
} else {
|
||||
|
@ -181,7 +181,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
private void clientLinks(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
|
||||
final JsonNode tree, final ObjectCodec codec) throws IOException {
|
||||
final JsonNode tree, final ObjectCodec codec) throws IOException {
|
||||
|
||||
if (field.getKey().endsWith(jsonNavigationLink)) {
|
||||
final LinkImpl link = new LinkImpl();
|
||||
|
@ -210,10 +210,10 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
private void serverLinks(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
|
||||
final JsonNode tree, final ObjectCodec codec) throws IOException {
|
||||
final JsonNode tree, final ObjectCodec codec) throws IOException {
|
||||
|
||||
if (field.getKey().endsWith(Constants.JSON_BIND_LINK_SUFFIX)
|
||||
|| field.getKey().endsWith(jsonNavigationLink)) {
|
||||
|| field.getKey().endsWith(jsonNavigationLink)) {
|
||||
|
||||
if (field.getValue().isValueNode()) {
|
||||
final String suffix = field.getKey().replaceAll("^.*@", "@");
|
||||
|
@ -272,19 +272,19 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
private EdmPrimitiveTypeKind guessPrimitiveTypeKind(final JsonNode node) {
|
||||
return node.isShort() ? EdmPrimitiveTypeKind.Int16 :
|
||||
node.isInt() ? EdmPrimitiveTypeKind.Int32 :
|
||||
node.isLong() ? EdmPrimitiveTypeKind.Int64 :
|
||||
node.isBoolean() ? EdmPrimitiveTypeKind.Boolean :
|
||||
node.isFloat() ? EdmPrimitiveTypeKind.Single :
|
||||
node.isDouble() ? EdmPrimitiveTypeKind.Double :
|
||||
node.isBigDecimal() ? EdmPrimitiveTypeKind.Decimal :
|
||||
EdmPrimitiveTypeKind.String;
|
||||
return node.isShort() ? EdmPrimitiveTypeKind.Int16 :
|
||||
node.isInt() ? EdmPrimitiveTypeKind.Int32 :
|
||||
node.isLong() ? EdmPrimitiveTypeKind.Int64 :
|
||||
node.isBoolean() ? EdmPrimitiveTypeKind.Boolean :
|
||||
node.isFloat() ? EdmPrimitiveTypeKind.Single :
|
||||
node.isDouble() ? EdmPrimitiveTypeKind.Double :
|
||||
node.isBigDecimal() ? EdmPrimitiveTypeKind.Decimal :
|
||||
EdmPrimitiveTypeKind.String;
|
||||
}
|
||||
|
||||
protected void populate(final Annotatable annotatable, final List<Property> properties,
|
||||
final ObjectNode tree, final ObjectCodec codec)
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
final ObjectNode tree, final ObjectCodec codec)
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
String type = null;
|
||||
Annotation annotation = null;
|
||||
|
@ -310,8 +310,8 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
final PropertyImpl property = new PropertyImpl();
|
||||
property.setName(field.getKey());
|
||||
property.setType(type == null
|
||||
? null
|
||||
: new EdmTypeInfo.Builder().setTypeExpression(type).build().internal());
|
||||
? null
|
||||
: new EdmTypeInfo.Builder().setTypeExpression(type).build().internal());
|
||||
type = null;
|
||||
|
||||
value(property, field.getValue(), codec);
|
||||
|
@ -327,45 +327,39 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
|
||||
private Object fromPrimitive(final JsonNode node, final EdmTypeInfo typeInfo) throws EdmPrimitiveTypeException {
|
||||
return node.isNull() ? null
|
||||
: typeInfo == null ? node.asText()
|
||||
: typeInfo == null ? node.asText()
|
||||
: typeInfo.getPrimitiveTypeKind().isGeospatial()
|
||||
? getGeoDeserializer().deserialize(node, typeInfo)
|
||||
: ((EdmPrimitiveType) typeInfo.getType())
|
||||
.valueOfString(node.asText(), true, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true,
|
||||
((EdmPrimitiveType) typeInfo.getType()).getDefaultType());
|
||||
? getGeoDeserializer().deserialize(node, typeInfo)
|
||||
: ((EdmPrimitiveType) typeInfo.getType())
|
||||
.valueOfString(node.asText(), true, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true,
|
||||
((EdmPrimitiveType) typeInfo.getType()).getDefaultType());
|
||||
}
|
||||
|
||||
private Object fromComplex(final ObjectNode node, final ObjectCodec codec)
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
if (version.compareTo(ODataServiceVersion.V40) < 0) {
|
||||
final List<Property> properties = new ArrayList<Property>();
|
||||
populate(null, properties, node, codec);
|
||||
return properties;
|
||||
} else {
|
||||
final LinkedComplexValue linkComplexValue = new LinkedComplexValueImpl();
|
||||
final Set<String> toRemove = new HashSet<String>();
|
||||
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
|
||||
final Map.Entry<String, JsonNode> field = itor.next();
|
||||
final ComplexValue complexValue = new ComplexValueImpl();
|
||||
final Set<String> toRemove = new HashSet<String>();
|
||||
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
|
||||
final Map.Entry<String, JsonNode> field = itor.next();
|
||||
|
||||
links(field, linkComplexValue, toRemove, node, codec);
|
||||
}
|
||||
node.remove(toRemove);
|
||||
|
||||
populate(linkComplexValue, linkComplexValue.getValue(), node, codec);
|
||||
return linkComplexValue;
|
||||
links(field, complexValue, toRemove, node, codec);
|
||||
}
|
||||
node.remove(toRemove);
|
||||
|
||||
populate(complexValue, complexValue.getValue(), node, codec);
|
||||
return complexValue;
|
||||
}
|
||||
|
||||
private void fromCollection(final Valuable valuable, final Iterator<JsonNode> nodeItor, final EdmTypeInfo typeInfo,
|
||||
final ObjectCodec codec) throws IOException, EdmPrimitiveTypeException {
|
||||
final ObjectCodec codec) throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
final List<Object> values = new ArrayList<Object>();
|
||||
ValueType valueType = ValueType.COLLECTION_PRIMITIVE;
|
||||
|
||||
final EdmTypeInfo type = typeInfo == null ? null
|
||||
: new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build();
|
||||
: new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build();
|
||||
|
||||
while (nodeItor.hasNext()) {
|
||||
final JsonNode child = nodeItor.next();
|
||||
|
@ -384,8 +378,7 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
((ObjectNode) child).remove(jsonType);
|
||||
}
|
||||
final Object value = fromComplex((ObjectNode) child, codec);
|
||||
valueType = value instanceof LinkedComplexValue ? ValueType.COLLECTION_LINKED_COMPLEX
|
||||
: ValueType.COLLECTION_COMPLEX;
|
||||
valueType = ValueType.COLLECTION_COMPLEX;
|
||||
values.add(value);
|
||||
}
|
||||
}
|
||||
|
@ -393,10 +386,10 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
protected void value(final Valuable valuable, final JsonNode node, final ObjectCodec codec)
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
EdmTypeInfo typeInfo = StringUtils.isBlank(valuable.getType()) ? null
|
||||
: new EdmTypeInfo.Builder().setTypeExpression(valuable.getType()).build();
|
||||
: new EdmTypeInfo.Builder().setTypeExpression(valuable.getType()).build();
|
||||
|
||||
final Map.Entry<ODataPropertyType, EdmTypeInfo> guessed = guessPropertyType(node);
|
||||
if (typeInfo == null) {
|
||||
|
@ -404,40 +397,40 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
|
||||
final ODataPropertyType propType = typeInfo == null ? guessed.getKey()
|
||||
: typeInfo.isCollection() ? ODataPropertyType.COLLECTION
|
||||
: typeInfo.isCollection() ? ODataPropertyType.COLLECTION
|
||||
: typeInfo.isPrimitiveType() ? ODataPropertyType.PRIMITIVE
|
||||
: node.isValueNode() ? ODataPropertyType.ENUM : ODataPropertyType.COMPLEX;
|
||||
: node.isValueNode() ? ODataPropertyType.ENUM : ODataPropertyType.COMPLEX;
|
||||
|
||||
switch (propType) {
|
||||
case COLLECTION:
|
||||
fromCollection(valuable, node.elements(), typeInfo, codec);
|
||||
break;
|
||||
case COLLECTION:
|
||||
fromCollection(valuable, node.elements(), typeInfo, codec);
|
||||
break;
|
||||
|
||||
case COMPLEX:
|
||||
if (node.has(jsonType)) {
|
||||
valuable.setType(node.get(jsonType).asText());
|
||||
((ObjectNode) node).remove(jsonType);
|
||||
}
|
||||
final Object value = fromComplex((ObjectNode) node, codec);
|
||||
valuable.setValue(value instanceof LinkedComplexValue ? ValueType.LINKED_COMPLEX : ValueType.COMPLEX, value);
|
||||
break;
|
||||
case COMPLEX:
|
||||
if (node.has(jsonType)) {
|
||||
valuable.setType(node.get(jsonType).asText());
|
||||
((ObjectNode) node).remove(jsonType);
|
||||
}
|
||||
final Object value = fromComplex((ObjectNode) node, codec);
|
||||
valuable.setValue(ValueType.COMPLEX, value);
|
||||
break;
|
||||
|
||||
case ENUM:
|
||||
valuable.setValue(ValueType.ENUM, node.asText());
|
||||
break;
|
||||
case ENUM:
|
||||
valuable.setValue(ValueType.ENUM, node.asText());
|
||||
break;
|
||||
|
||||
case PRIMITIVE:
|
||||
if (valuable.getType() == null && typeInfo != null) {
|
||||
valuable.setType(typeInfo.getFullQualifiedName().toString());
|
||||
}
|
||||
final Object primitiveValue = fromPrimitive(node, typeInfo);
|
||||
valuable.setValue(primitiveValue instanceof Geospatial ? ValueType.GEOSPATIAL : ValueType.PRIMITIVE,
|
||||
primitiveValue);
|
||||
break;
|
||||
case PRIMITIVE:
|
||||
if (valuable.getType() == null && typeInfo != null) {
|
||||
valuable.setType(typeInfo.getFullQualifiedName().toString());
|
||||
}
|
||||
final Object primitiveValue = fromPrimitive(node, typeInfo);
|
||||
valuable.setValue(primitiveValue instanceof Geospatial ? ValueType.GEOSPATIAL : ValueType.PRIMITIVE,
|
||||
primitiveValue);
|
||||
break;
|
||||
|
||||
case EMPTY:
|
||||
default:
|
||||
valuable.setValue(ValueType.PRIMITIVE, StringUtils.EMPTY);
|
||||
case EMPTY:
|
||||
default:
|
||||
valuable.setValue(ValueType.PRIMITIVE, StringUtils.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,12 +80,12 @@ public class JsonPropertySerializer extends JsonSerializer {
|
|||
jgen.writeStringField(Constants.VALUE, property.asEnum().toString());
|
||||
} else if (property.isGeospatial() || property.isCollection()) {
|
||||
valuable(jgen, property, Constants.VALUE);
|
||||
} else if (property.isLinkedComplex()) {
|
||||
for (Property cproperty : property.asLinkedComplex().getValue()) {
|
||||
} else if (property.isComplex()) {
|
||||
for (Property cproperty : property.asComplex().getValue()) {
|
||||
valuable(jgen, cproperty, cproperty.getName());
|
||||
}
|
||||
} else if (property.isComplex()) {
|
||||
for (Property cproperty : property.asComplex()) {
|
||||
for (Property cproperty : property.asComplex().getValue()) {
|
||||
valuable(jgen, cproperty, cproperty.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.olingo.commons.api.data.Entity;
|
|||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Linked;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ResWrap;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
|
@ -280,13 +280,7 @@ public class JsonSerializer implements ODataSerializer {
|
|||
break;
|
||||
|
||||
case COLLECTION_COMPLEX:
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<Property> complexItem = (List<Property>) item;
|
||||
complexValue(jgen, itemTypeInfo, complexItem, null);
|
||||
break;
|
||||
|
||||
case COLLECTION_LINKED_COMPLEX:
|
||||
final LinkedComplexValue complexItem2 = (LinkedComplexValue) item;
|
||||
final ComplexValue complexItem2 = (ComplexValue) item;
|
||||
complexValue(jgen, itemTypeInfo, complexItem2.getValue(), complexItem2);
|
||||
break;
|
||||
|
||||
|
@ -357,10 +351,8 @@ public class JsonSerializer implements ODataSerializer {
|
|||
jgen.writeEndObject();
|
||||
} else if (value.isCollection()) {
|
||||
collection(jgen, typeInfo, value.getValueType(), value.asCollection());
|
||||
} else if (value.isLinkedComplex()) {
|
||||
complexValue(jgen, typeInfo, value.asLinkedComplex().getValue(), value.asLinkedComplex());
|
||||
} else if (value.isComplex()) {
|
||||
complexValue(jgen, typeInfo, value.asComplex(), null);
|
||||
complexValue(jgen, typeInfo, value.asComplex().getValue(), value.asComplex());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,7 +360,7 @@ public class JsonSerializer implements ODataSerializer {
|
|||
throws IOException, EdmPrimitiveTypeException {
|
||||
|
||||
if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation)
|
||||
&& !valuable.isComplex() && !valuable.isLinkedComplex()) {
|
||||
&& !valuable.isComplex() && !valuable.isComplex()) {
|
||||
|
||||
String type = valuable.getType();
|
||||
if (StringUtils.isBlank(type) && valuable.isPrimitive() || valuable.isNull()) {
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
|
@ -43,6 +44,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
|||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
|
@ -357,7 +359,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
private Object readComplexNode(final EdmProperty edmProperty, final JsonNode jsonNode)
|
||||
throws DeserializerException {
|
||||
// read and add all complex properties
|
||||
Object value = readComplexValue(edmProperty, jsonNode);
|
||||
ComplexValue value = readComplexValue(edmProperty, jsonNode);
|
||||
|
||||
final List<String> toRemove = new ArrayList<String>();
|
||||
Iterator<Entry<String, JsonNode>> fieldsIterator = jsonNode.fields();
|
||||
|
@ -430,7 +432,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
}
|
||||
}
|
||||
|
||||
private Object readComplexValue(EdmProperty edmComplexProperty, JsonNode jsonNode) throws DeserializerException {
|
||||
private ComplexValue readComplexValue(EdmProperty edmComplexProperty, JsonNode jsonNode)
|
||||
throws DeserializerException {
|
||||
if (isValidNull(edmComplexProperty, jsonNode)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -440,7 +443,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, edmComplexProperty.getName());
|
||||
}
|
||||
// Even if there are no properties defined we have to give back an empty list
|
||||
List<Property> propertyList = new ArrayList<Property>();
|
||||
ComplexValueImpl complexValue = new ComplexValueImpl();
|
||||
EdmComplexType edmType = (EdmComplexType) edmComplexProperty.getType();
|
||||
// Check and consume all Properties
|
||||
for (String propertyName : edmType.getPropertyNames()) {
|
||||
|
@ -452,11 +455,11 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName);
|
||||
}
|
||||
Property property = consumePropertyNode(edmProperty, subNode);
|
||||
propertyList.add(property);
|
||||
complexValue.getValue().add(property);
|
||||
((ObjectNode) jsonNode).remove(propertyName);
|
||||
}
|
||||
}
|
||||
return propertyList;
|
||||
return complexValue;
|
||||
}
|
||||
|
||||
private boolean isNullable(EdmProperty edmProperty) {
|
||||
|
|
|
@ -25,12 +25,12 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Linked;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
|
@ -47,10 +47,10 @@ import org.apache.olingo.server.api.ODataServerError;
|
|||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
|
||||
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
|
@ -318,11 +318,9 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
}
|
||||
} else if (edmProperty.isCollection()) {
|
||||
writeComplexCollection((EdmComplexType) edmProperty.getType(), property, selectedPaths, json);
|
||||
} else if (property.isLinkedComplex()) {
|
||||
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asLinkedComplex().getValue(),
|
||||
selectedPaths, json);
|
||||
} else if (property.isComplex()) {
|
||||
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex(), selectedPaths, json);
|
||||
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
|
||||
selectedPaths, json);
|
||||
} else {
|
||||
throw new SerializerException("Property type not yet supported!",
|
||||
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
|
||||
|
@ -364,11 +362,8 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
json.writeStartArray();
|
||||
for (Object value : property.asCollection()) {
|
||||
switch (property.getValueType()) {
|
||||
case COLLECTION_LINKED_COMPLEX:
|
||||
writeComplexValue(type, ((LinkedComplexValue) value).getValue(), selectedPaths, json);
|
||||
break;
|
||||
case COLLECTION_COMPLEX:
|
||||
writeComplexValue(type, ((Property) value).asComplex(), selectedPaths, json);
|
||||
writeComplexValue(type, ((ComplexValue) value).getValue(), selectedPaths, json);
|
||||
break;
|
||||
default:
|
||||
throw new SerializerException("Property type not yet supported!",
|
||||
|
@ -487,11 +482,11 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
if (contextURL != null) {
|
||||
json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
final List<Property> values = property.isNull() ? Collections.<Property> emptyList() :
|
||||
property.isComplex() ? property.asComplex() : property.asLinkedComplex().getValue();
|
||||
final List<Property> values =
|
||||
property.isNull() ? Collections.<Property> emptyList() : property.asComplex().getValue();
|
||||
writeProperties(type, values, options == null ? null : options.getSelect(), json);
|
||||
if (!property.isNull() && property.isLinkedComplex()) {
|
||||
writeNavigationProperties(type, property.asLinkedComplex(),
|
||||
if (!property.isNull() && property.isComplex()) {
|
||||
writeNavigationProperties(type, property.asComplex(),
|
||||
options == null ? null : options.getExpand(), json);
|
||||
}
|
||||
json.writeEndObject();
|
||||
|
|
|
@ -28,10 +28,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataException;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
|
||||
import org.junit.Test;
|
||||
|
@ -39,9 +41,9 @@ import org.junit.Test;
|
|||
public class ODataJsonSerializerTest {
|
||||
@Test
|
||||
public void testCollectionComplex() throws ODataException, IOException {
|
||||
final List<Property> col = new ArrayList<Property>();
|
||||
col.add(new PropertyImpl(null, "ComplexOne", ValueType.COMPLEX, getValues(1)));
|
||||
col.add(new PropertyImpl(null, "ComplexTwo", ValueType.COMPLEX, getValues(2)));
|
||||
final List<ComplexValue> col = new ArrayList<ComplexValue>();
|
||||
col.add(getValues(1));
|
||||
col.add(getValues(2));
|
||||
final Property complexCollection = new PropertyImpl(null, "ComplexCol", ValueType.COLLECTION_COMPLEX, col);
|
||||
|
||||
final ODataJsonSerializer serializer = new ODataJsonSerializer(ODataFormat.APPLICATION_JSON);
|
||||
|
@ -60,12 +62,10 @@ public class ODataJsonSerializerTest {
|
|||
|
||||
}
|
||||
|
||||
private List<Property> getValues(int i) {
|
||||
final List<Property> values = new ArrayList<Property>();
|
||||
|
||||
values.add(new PropertyImpl(null, "prop1", ValueType.PRIMITIVE, "test" + i));
|
||||
values.add(new PropertyImpl(null, "prop2", ValueType.PRIMITIVE, "test" + i + i));
|
||||
|
||||
return values;
|
||||
private ComplexValue getValues(int i) {
|
||||
ComplexValue value = new ComplexValueImpl();
|
||||
value.getValue().add(new PropertyImpl(null, "prop1", ValueType.PRIMITIVE, "test" + i));
|
||||
value.getValue().add(new PropertyImpl(null, "prop2", ValueType.PRIMITIVE, "test" + i + i));
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ import java.util.UUID;
|
|||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.core.data.EntityImpl;
|
||||
import org.apache.olingo.commons.core.data.EntitySetImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||
import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||
import org.apache.olingo.commons.core.data.PropertyImpl;
|
||||
|
||||
public class DataCreator {
|
||||
|
@ -97,10 +97,10 @@ public class DataCreator {
|
|||
|
||||
private Entity createETKeyNavEntity(int propertyInt16, String propertyString) {
|
||||
// PropertyCompAllPrim
|
||||
LinkedComplexValue cvCompAllPrim = createKeyNavAllPrimComplexValue();
|
||||
ComplexValue cvCompAllPrim = createKeyNavAllPrimComplexValue();
|
||||
|
||||
// CollPropertyComp
|
||||
List<LinkedComplexValue> ccComp = new ArrayList<LinkedComplexValue>();
|
||||
List<ComplexValue> ccComp = new ArrayList<ComplexValue>();
|
||||
ccComp.add(createCTPrimCompValue(1));
|
||||
ccComp.add(createCTPrimCompValue(2));
|
||||
ccComp.add(createCTPrimCompValue(3));
|
||||
|
@ -110,7 +110,7 @@ public class DataCreator {
|
|||
.addProperty(createPrimitive("PropertyString", propertyString))
|
||||
.addProperty(createComplex("PropertyComp",
|
||||
createPrimitive("PropertyInt16", 1)))
|
||||
.addProperty(new PropertyImpl(null, "PropertyCompAllPrim", ValueType.LINKED_COMPLEX, cvCompAllPrim))
|
||||
.addProperty(new PropertyImpl(null, "PropertyCompAllPrim", ValueType.COMPLEX, cvCompAllPrim))
|
||||
.addProperty(createComplex("PropertyCompTwoPrim",
|
||||
createPrimitive("PropertyInt16", 16),
|
||||
createPrimitive("PropertyString", "Test123")))
|
||||
|
@ -119,18 +119,18 @@ public class DataCreator {
|
|||
"Employee2@company.example",
|
||||
"Employee3@company.example"))
|
||||
.addProperty(createPrimitiveCollection("CollPropertyInt16", 1000, 2000, 30112))
|
||||
.addProperty(new PropertyImpl(null, "CollPropertyComp", ValueType.COLLECTION_LINKED_COMPLEX, ccComp))
|
||||
.addProperty(new PropertyImpl(null, "CollPropertyComp", ValueType.COLLECTION_COMPLEX, ccComp))
|
||||
.addProperty(createComplex("PropertyCompComp",
|
||||
createPrimitive("PropertyString", "1"),
|
||||
createComplex("PropertyComp", createPrimitive("PropertyInt16", 1))));
|
||||
}
|
||||
|
||||
private LinkedComplexValue createCTPrimCompValue(int properyInt16) {
|
||||
final LinkedComplexValue cvBasePrimCompNav = new LinkedComplexValueImpl();
|
||||
final LinkedComplexValue cvAllPrim = createKeyNavAllPrimComplexValue();
|
||||
private ComplexValue createCTPrimCompValue(int properyInt16) {
|
||||
final ComplexValue cvBasePrimCompNav = new ComplexValueImpl();
|
||||
final ComplexValue cvAllPrim = createKeyNavAllPrimComplexValue();
|
||||
|
||||
cvBasePrimCompNav.getValue().add(createPrimitive("PropertyInt16", properyInt16));
|
||||
cvBasePrimCompNav.getValue().add(new PropertyImpl(null, "PropertyComp", ValueType.LINKED_COMPLEX, cvAllPrim));
|
||||
cvBasePrimCompNav.getValue().add(new PropertyImpl(null, "PropertyComp", ValueType.COMPLEX, cvAllPrim));
|
||||
|
||||
return cvBasePrimCompNav;
|
||||
}
|
||||
|
@ -171,9 +171,9 @@ public class DataCreator {
|
|||
createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59))
|
||||
)
|
||||
))
|
||||
.addProperty(new PropertyImpl(null, "PropertyCompNav", ValueType.LINKED_COMPLEX, createCTPrimCompValue(1)))
|
||||
.addProperty(new PropertyImpl(null, "CollPropertyComp", ValueType.COLLECTION_LINKED_COMPLEX,
|
||||
new ArrayList<LinkedComplexValue>()))
|
||||
.addProperty(new PropertyImpl(null, "PropertyCompNav", ValueType.COMPLEX, createCTPrimCompValue(1)))
|
||||
.addProperty(new PropertyImpl(null, "CollPropertyComp", ValueType.COLLECTION_COMPLEX,
|
||||
new ArrayList<ComplexValue>()))
|
||||
.addProperty(createComplexCollection("CollPropertyCompNav",
|
||||
Arrays.asList(createPrimitive("PropertyInt16", 1))))
|
||||
.addProperty(createPrimitiveCollection("CollPropertyString", 1, 2))
|
||||
|
@ -183,9 +183,9 @@ public class DataCreator {
|
|||
));
|
||||
}
|
||||
|
||||
private LinkedComplexValue createKeyNavAllPrimComplexValue() {
|
||||
LinkedComplexValue cvAllPrim;
|
||||
cvAllPrim = new LinkedComplexValueImpl();
|
||||
private ComplexValue createKeyNavAllPrimComplexValue() {
|
||||
ComplexValue cvAllPrim;
|
||||
cvAllPrim = new ComplexValueImpl();
|
||||
cvAllPrim.getValue().add(createPrimitive("PropertyString", "First Resource - positive values"));
|
||||
cvAllPrim.getValue().add(createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 } ));
|
||||
cvAllPrim.getValue().add(createPrimitive("PropertyBoolean", true));
|
||||
|
@ -677,21 +677,21 @@ public class DataCreator {
|
|||
}
|
||||
|
||||
protected static Property createComplex(final String name, final Property... properties) {
|
||||
LinkedComplexValue complexValue = new LinkedComplexValueImpl();
|
||||
ComplexValue complexValue = new ComplexValueImpl();
|
||||
for (final Property property : properties) {
|
||||
complexValue.getValue().add(property);
|
||||
}
|
||||
return new PropertyImpl(null, name, ValueType.LINKED_COMPLEX, complexValue);
|
||||
return new PropertyImpl(null, name, ValueType.COMPLEX, complexValue);
|
||||
}
|
||||
|
||||
protected static Property createComplexCollection(final String name, final List<Property>... propertiesList) {
|
||||
List<LinkedComplexValue> complexCollection = new ArrayList<LinkedComplexValue>();
|
||||
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
|
||||
for (final List<Property> properties : propertiesList) {
|
||||
LinkedComplexValue complexValue = new LinkedComplexValueImpl();
|
||||
ComplexValue complexValue = new ComplexValueImpl();
|
||||
complexValue.getValue().addAll(properties);
|
||||
complexCollection.add(complexValue);
|
||||
}
|
||||
return new PropertyImpl(null, name, ValueType.COLLECTION_LINKED_COMPLEX, complexCollection);
|
||||
return new PropertyImpl(null, name, ValueType.COLLECTION_COMPLEX, complexCollection);
|
||||
}
|
||||
|
||||
private Calendar getDateTime(final int year, final int month, final int day,
|
||||
|
|
|
@ -244,7 +244,7 @@ public class DataProvider {
|
|||
newProperty = newProperty2;
|
||||
} else {
|
||||
newProperty = DataCreator.createComplex(propertyName);
|
||||
createProperties((EdmComplexType) edmProperty.getType(), newProperty.asLinkedComplex().getValue());
|
||||
createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
|
||||
}
|
||||
}
|
||||
properties.add(newProperty);
|
||||
|
@ -282,7 +282,7 @@ public class DataProvider {
|
|||
|
||||
private void applyNavigationBinding(final String rawBaseUri, final EdmEntitySet edmEntitySet,
|
||||
final Entity entity, final List<Link> navigationBindings) throws DataProviderException {
|
||||
|
||||
|
||||
for (final Link link : navigationBindings) {
|
||||
final EdmNavigationProperty edmNavProperty = edmEntitySet.getEntityType().getNavigationProperty(link.getTitle());
|
||||
final EdmEntitySet edmTargetEntitySet =
|
||||
|
@ -308,11 +308,11 @@ public class DataProvider {
|
|||
final List<UriParameter> keys = odata.createUriHelper()
|
||||
.getKeyPredicatesFromEntityLink(edm, bindingLink, rawBaseUri);
|
||||
final Entity entity = read(edmEntitySetTarget, keys);
|
||||
|
||||
if(entity == null) {
|
||||
|
||||
if (entity == null) {
|
||||
throw new DataProviderException("Entity " + bindingLink + " not found");
|
||||
}
|
||||
|
||||
|
||||
return entity;
|
||||
} catch (DeserializerException e) {
|
||||
throw new DataProviderException("Invalid entity binding link", e);
|
||||
|
@ -383,7 +383,7 @@ public class DataProvider {
|
|||
// TODO Duplicated code in DataCreator
|
||||
private void setLink(final EdmNavigationProperty navigationProperty, final Entity srcEntity,
|
||||
final Entity destEntity) {
|
||||
|
||||
|
||||
Link link = srcEntity.getNavigationLink(navigationProperty.getName());
|
||||
if (link == null) {
|
||||
link = new LinkImpl();
|
||||
|
@ -423,10 +423,12 @@ public class DataProvider {
|
|||
} else {
|
||||
final EdmComplexType type = (EdmComplexType) edmProperty.getType();
|
||||
for (final String propertyName : type.getPropertyNames()) {
|
||||
final List<Property> newProperties = newProperty == null ? null :
|
||||
newProperty.isComplex() ? newProperty.asComplex() : newProperty.asLinkedComplex().getValue();
|
||||
List<Property> newProperties = null;
|
||||
if(newProperty != null && newProperty.asComplex() != null){
|
||||
newProperties = newProperty.asComplex().getValue();
|
||||
}
|
||||
updateProperty(type.getStructuralProperty(propertyName),
|
||||
findProperty(propertyName, property.asLinkedComplex().getValue()),
|
||||
findProperty(propertyName, property.asComplex().getValue()),
|
||||
newProperties == null ? null : findProperty(propertyName, newProperties),
|
||||
patch);
|
||||
}
|
||||
|
@ -459,7 +461,7 @@ public class DataProvider {
|
|||
public void setOData(final OData odata) {
|
||||
this.odata = odata;
|
||||
}
|
||||
|
||||
|
||||
public static class DataProviderException extends ODataApplicationException {
|
||||
private static final long serialVersionUID = 5098059649321796156L;
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
|||
private void deleteProperty(final ODataResponse response, final UriInfo uriInfo) throws ODataApplicationException {
|
||||
final UriInfoResource resource = uriInfo.asUriInfoResource();
|
||||
validatePath(resource);
|
||||
getEdmEntitySet(uriInfo); // including checks
|
||||
getEdmEntitySet(uriInfo); // including checks
|
||||
|
||||
final List<UriResource> resourceParts = resource.getUriResourceParts();
|
||||
final List<String> path = getPropertyPath(resourceParts, 0);
|
||||
|
@ -281,9 +281,8 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
|||
throws ODataApplicationException {
|
||||
Property property = entity.getProperty(path.get(0));
|
||||
for (final String name : path.subList(1, path.size())) {
|
||||
if (property != null && (property.isLinkedComplex() || property.isComplex())) {
|
||||
final List<Property> complex = property.isLinkedComplex() ?
|
||||
property.asLinkedComplex().getValue() : property.asComplex();
|
||||
if (property != null && (property.isComplex() || property.isComplex())) {
|
||||
final List<Property> complex = property.asComplex().getValue();
|
||||
property = null;
|
||||
for (final Property innerProperty : complex) {
|
||||
if (innerProperty.getName().equals(name)) {
|
||||
|
@ -320,7 +319,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
|
|||
final UriInfoResource resource = uriInfo.asUriInfoResource();
|
||||
validateOptions(resource);
|
||||
validatePath(resource);
|
||||
getEdmEntitySet(uriInfo); // including checks
|
||||
getEdmEntitySet(uriInfo); // including checks
|
||||
|
||||
final List<UriResource> resourceParts = resource.getUriResourceParts();
|
||||
final List<String> path = getPropertyPath(resourceParts, 1);
|
||||
|
|
|
@ -189,9 +189,8 @@ public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand>
|
|||
for (int i = 1; i < uriResourceParts.size(); i++) {
|
||||
currentType = ((UriResourcePartTyped) uriResourceParts.get(i)).getType();
|
||||
|
||||
if (currentProperty.isComplex() || currentProperty.isLinkedComplex()) {
|
||||
final List<Property> complex = currentProperty.isLinkedComplex() ?
|
||||
currentProperty.asLinkedComplex().getValue() : currentProperty.asComplex();
|
||||
if (currentProperty.isComplex()) {
|
||||
final List<Property> complex = currentProperty.asComplex().getValue();
|
||||
|
||||
for (final Property innerProperty : complex) {
|
||||
if (innerProperty.getName().equals(uriResourceParts.get(i).toString())) {
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
|
@ -125,8 +125,8 @@ public class DataProviderTest {
|
|||
Assert.assertEquals(3, outSet.getEntities().size());
|
||||
Assert.assertEquals(2, outSet.getEntities().get(0).getProperties().size());
|
||||
Property complex = outSet.getEntities().get(0).getProperties().get(1);
|
||||
Assert.assertTrue(complex.isLinkedComplex());
|
||||
Assert.assertEquals(16, complex.asLinkedComplex().getValue().size());
|
||||
Assert.assertTrue(complex.isComplex());
|
||||
Assert.assertEquals(16, complex.asComplex().getValue().size());
|
||||
Assert.assertEquals(2, outSet.getEntities().get(1).getProperties().size());
|
||||
Assert.assertEquals(2, outSet.getEntities().get(2).getProperties().size());
|
||||
}
|
||||
|
@ -138,13 +138,13 @@ public class DataProviderTest {
|
|||
Assert.assertEquals(3, outSet.getEntities().size());
|
||||
Assert.assertEquals(4, outSet.getEntities().get(0).getProperties().size());
|
||||
Property complex = outSet.getEntities().get(0).getProperties().get(2);
|
||||
Assert.assertTrue(complex.isLinkedComplex());
|
||||
Assert.assertEquals(2, complex.asLinkedComplex().getValue().size());
|
||||
Assert.assertTrue(complex.isComplex());
|
||||
Assert.assertEquals(2, complex.asComplex().getValue().size());
|
||||
Property complexCollection = outSet.getEntities().get(0).getProperties().get(3);
|
||||
Assert.assertTrue(complexCollection.isCollection());
|
||||
List<?> linkedComplexValues = complexCollection.asCollection();
|
||||
Assert.assertEquals(3, linkedComplexValues.size());
|
||||
LinkedComplexValue linkedComplexValue = (LinkedComplexValue) linkedComplexValues.get(0);
|
||||
ComplexValue linkedComplexValue = (ComplexValue) linkedComplexValues.get(0);
|
||||
Assert.assertEquals(2, linkedComplexValue.getValue().size());
|
||||
Property lcProp = linkedComplexValue.getValue().get(0);
|
||||
Assert.assertFalse(lcProp.isCollection());
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
|
@ -231,7 +232,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
|
||||
assertNotNull(entity.getProperty("PropertyComp"));
|
||||
assertNotNull(entity.getProperty("PropertyComp") instanceof List);
|
||||
List<Property> complexProperties = entity.getProperty("PropertyComp").asComplex();
|
||||
List<Property> complexProperties = entity.getProperty("PropertyComp").asComplex().getValue();
|
||||
assertEquals(16, complexProperties.size());
|
||||
}
|
||||
|
||||
|
@ -284,7 +285,6 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
assertEquals(true, asCollection.get(2));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void simpleEntityETMixPrimCollComp() throws Exception {
|
||||
final String entityString = "{"
|
||||
|
@ -314,13 +314,12 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
assertEquals(3, asCollection.size());
|
||||
|
||||
for (Object arrayElement : asCollection) {
|
||||
assertTrue(arrayElement instanceof List);
|
||||
List<Object> castedArrayElement = (List<Object>) arrayElement;
|
||||
assertTrue(arrayElement instanceof ComplexValue);
|
||||
List<Property> castedArrayElement = (List<Property>) ((ComplexValue) arrayElement).getValue();
|
||||
assertEquals(2, castedArrayElement.size());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void eTMixPrimCollCompMIssingPropertyInComplexType() throws Exception {
|
||||
final String entityString = "{"
|
||||
|
@ -341,7 +340,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
|
||||
Property complexProperty = entity.getProperty("PropertyComp");
|
||||
assertEquals(ValueType.COMPLEX, complexProperty.getValueType());
|
||||
List<Property> complexPropertyValues = (List<Property>) complexProperty.getValue();
|
||||
List<Property> complexPropertyValues = (List<Property>) complexProperty.asComplex().getValue();
|
||||
assertEquals(1, complexPropertyValues.size());
|
||||
|
||||
Property property = entity.getProperty("CollPropertyComp");
|
||||
|
@ -352,8 +351,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
assertEquals(3, asCollection.size());
|
||||
|
||||
for (Object arrayElement : asCollection) {
|
||||
assertTrue(arrayElement instanceof List);
|
||||
List<Object> castedArrayElement = (List<Object>) arrayElement;
|
||||
assertTrue(arrayElement instanceof ComplexValue);
|
||||
List<Property> castedArrayElement = (List<Property>) ((ComplexValue) arrayElement).getValue();
|
||||
assertEquals(1, castedArrayElement.size());
|
||||
}
|
||||
}
|
||||
|
@ -495,7 +494,6 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
assertTrue(bindingToMany.getBindingLinks().isEmpty());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void eTMixEnumDefCollCompTest() throws Exception {
|
||||
InputStream stream = getFileAsStream("EntityETMixEnumDefCollComp.json");
|
||||
|
@ -515,7 +513,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
assertEquals("string", defProperty.getValue());
|
||||
|
||||
Property complexProperty = entity.getProperty("PropertyCompMixedEnumDef");
|
||||
List<Property> value = (List<Property>) complexProperty.getValue();
|
||||
List<Property> value = (List<Property>) complexProperty.asComplex().getValue();
|
||||
assertEquals((short) 2, value.get(0).getValue());
|
||||
}
|
||||
|
||||
|
@ -566,7 +564,6 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
assertNull(entity.getProperty("PropertyComp").getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void validJsonValueForComplexCollectionNullValue() throws Exception {
|
||||
final String entityString = "{"
|
||||
|
@ -580,7 +577,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
|
||||
List<?> collPropertyComp = entity.getProperty("CollPropertyComp").asCollection();
|
||||
assertNull(collPropertyComp.get(0));
|
||||
List<Property> complexPropertyProperties = (List<Property>) collPropertyComp.get(1);
|
||||
List<Property> complexPropertyProperties = (List<Property>) ((ComplexValue) collPropertyComp.get(1)).getValue();
|
||||
assertEquals(Short.valueOf((short) 789), complexPropertyProperties.get(0).getValue());
|
||||
assertEquals("TEST 3", complexPropertyProperties.get(1).getValue());
|
||||
}
|
||||
|
@ -595,8 +592,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
Entity entity = deserializer.entity(stream, edm.getEntityType(
|
||||
new FullQualifiedName("Namespace1_Alias", "ETCompAllPrim")));
|
||||
|
||||
assertEquals("TEST A", entity.getProperty("PropertyComp").asComplex().get(0).getValue());
|
||||
assertNull(entity.getProperty("PropertyComp").asComplex().get(1).getValue());
|
||||
assertEquals("TEST A", entity.getProperty("PropertyComp").asComplex().getValue().get(0).getValue());
|
||||
assertNull(entity.getProperty("PropertyComp").asComplex().getValue().get(1).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -614,7 +611,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
|
||||
assertEquals((short) 2, e.getProperty("PropertyEnumString").getValue());
|
||||
Property propertyCompMixedEnumDef = e.getProperty("PropertyCompMixedEnumDef");
|
||||
assertNull(propertyCompMixedEnumDef.asComplex().get(0).getValue());
|
||||
assertNull(propertyCompMixedEnumDef.asComplex().getValue().get(0).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue