diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java index 14fa946b9..0d8da5226 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java @@ -51,16 +51,6 @@ public interface CommonODataBinder extends Serializable { */ Entry getEntry(CommonODataEntity entity, Class reference); - /** - * Gets an Entry from the given OData entity. - * - * @param entity OData entity. - * @param reference reference class. - * @param setType whether to explicitly output type information. - * @return Entry object. - */ - Entry getEntry(CommonODataEntity entity, Class reference, boolean setType); - /** * Gets a Link from the given OData link. * @@ -75,10 +65,9 @@ public interface CommonODataBinder extends Serializable { * * @param property OData property. * @param reference reference class. - * @param setType whether to explicitly output type information. * @return Property object. */ - Property getProperty(CommonODataProperty property, Class reference, boolean setType); + Property getProperty(CommonODataProperty property, Class reference); /** * Adds the given property to the given entity. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java index a7ead37b2..2f54ecd37 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java @@ -45,16 +45,6 @@ public interface ODataWriter extends Serializable { */ InputStream writeEntities(Collection entities, ODataPubFormat format); - /** - * Writes a collection of OData entities. - * - * @param entities entities to be serialized. - * @param format serialization format. - * @param outputType whether to explicitly output type information. - * @return stream of serialized objects. - */ - InputStream writeEntities(Collection entities, ODataPubFormat format, boolean outputType); - /** * Serializes a single OData entity. * @@ -64,16 +54,6 @@ public interface ODataWriter extends Serializable { */ InputStream writeEntity(CommonODataEntity entity, ODataPubFormat format); - /** - * Serializes a single OData entity. - * - * @param entity entity to be serialized. - * @param format serialization format. - * @param outputType whether to explicitly output type information. - * @return stream of serialized object. - */ - InputStream writeEntity(CommonODataEntity entity, ODataPubFormat format, boolean outputType); - /** * Writes a single OData entity property. * diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java similarity index 77% rename from lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java rename to lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java index 4e7be37ee..7018baf9d 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/ODataInvokeRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java @@ -21,7 +21,6 @@ package org.apache.olingo.client.core.communication.request.invoke; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.net.URISyntaxException; import java.util.LinkedHashMap; import java.util.Map; import org.apache.commons.io.IOUtils; @@ -30,7 +29,6 @@ import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.client.utils.URIBuilder; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.ODataBatchableRequest; import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest; @@ -45,6 +43,7 @@ import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataPubFormat; import org.apache.olingo.client.api.http.HttpClientException; import org.apache.olingo.client.api.http.HttpMethod; +import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; @@ -52,7 +51,7 @@ import org.apache.olingo.client.core.communication.response.AbstractODataRespons /** * This class implements an OData invoke operation request. */ -public class ODataInvokeRequestImpl +public abstract class AbstractODataInvokeRequest extends AbstractODataBasicRequest, ODataPubFormat> implements ODataInvokeRequest, ODataBatchableRequest { @@ -61,7 +60,7 @@ public class ODataInvokeRequestImpl /** * Function parameters. */ - private Map parameters; + protected Map parameters; /** * Constructor. @@ -71,7 +70,7 @@ public class ODataInvokeRequestImpl * @param method HTTP method of the request. * @param uri URI that identifies the operation. */ - public ODataInvokeRequestImpl( + public AbstractODataInvokeRequest( final CommonODataClient odataClient, final Class reference, final HttpMethod method, @@ -94,18 +93,24 @@ public class ODataInvokeRequestImpl } } + private String getActualFormat(final ODataPubFormat format) { + return (CommonODataProperty.class.isAssignableFrom(reference) && format == ODataPubFormat.ATOM) + ? ODataFormat.XML.toString(odataClient.getServiceVersion()) + : format.toString(odataClient.getServiceVersion()); + } + /** * {@inheritDoc } */ @Override public void setFormat(final ODataPubFormat format) { - final String _format = (reference.isAssignableFrom(CommonODataProperty.class) && format == ODataPubFormat.ATOM) - ? ODataFormat.XML.toString(odataClient.getServiceVersion()) - : format.toString(odataClient.getServiceVersion()); + final String _format = getActualFormat(format); setAccept(_format); setContentType(_format); } + protected abstract ODataPubFormat getPOSTParameterFormat(); + @Override protected InputStream getPayload() { if (!this.parameters.isEmpty() && this.method == HttpMethod.POST) { @@ -123,6 +128,12 @@ public class ODataInvokeRequestImpl } else if (param.getValue().isCollection()) { property = odataClient.getObjectFactory(). newCollectionProperty(param.getKey(), param.getValue().asCollection()); + } else if (param.getValue() instanceof org.apache.olingo.commons.api.domain.v4.ODataValue + && ((org.apache.olingo.commons.api.domain.v4.ODataValue) param.getValue()).isEnum()) { + + property = ((ODataClient) odataClient).getObjectFactory(). + newEnumProperty(param.getKey(), + ((org.apache.olingo.commons.api.domain.v4.ODataValue) param.getValue()).asEnum()); } if (property != null) { @@ -130,12 +141,14 @@ public class ODataInvokeRequestImpl } } - return odataClient.getWriter().writeEntity(tmp, ODataPubFormat.JSON, false); + return odataClient.getWriter().writeEntity(tmp, getPOSTParameterFormat()); } return null; } + protected abstract URI buildGETURI(); + /** * {@inheritDoc } */ @@ -145,23 +158,11 @@ public class ODataInvokeRequestImpl if (!this.parameters.isEmpty()) { if (this.method == HttpMethod.GET) { - final URIBuilder uriBuilder = new URIBuilder(this.uri); - for (Map.Entry param : parameters.entrySet()) { - if (!param.getValue().isPrimitive()) { - throw new IllegalArgumentException("Only primitive values can be passed via GET"); - } - - uriBuilder.addParameter(param.getKey(), URIUtils.escape(odataClient.getServiceVersion(), param.getValue())); - } - try { - ((HttpRequestBase) this.request).setURI(uriBuilder.build()); - } catch (URISyntaxException e) { - throw new IllegalArgumentException("While adding GET parameters", e); - } + ((HttpRequestBase) this.request).setURI(buildGETURI()); } else if (this.method == HttpMethod.POST) { ((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); - setContentType(ODataPubFormat.JSON.toString(odataClient.getServiceVersion())); + setContentType(getActualFormat(getPOSTParameterFormat())); } } @@ -201,25 +202,24 @@ public class ODataInvokeRequestImpl * {@inheritDoc } */ @Override - @SuppressWarnings("unchecked") public T getBody() { if (invokeResult == null) { - if (reference.isAssignableFrom(ODataNoContent.class)) { - invokeResult = (T) new ODataNoContent(); + if (ODataNoContent.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(new ODataNoContent()); } try { - if (reference.isAssignableFrom(CommonODataEntitySet.class)) { - invokeResult = (T) odataClient.getReader().readEntitySet(res.getEntity().getContent(), - ODataPubFormat.fromString(getContentType())); + if (CommonODataEntitySet.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(odataClient.getReader().readEntitySet(res.getEntity().getContent(), + ODataPubFormat.fromString(getContentType()))); } - if (reference.isAssignableFrom(CommonODataEntity.class)) { - invokeResult = (T) odataClient.getReader().readEntity(res.getEntity().getContent(), - ODataPubFormat.fromString(getContentType())); + if (CommonODataEntity.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(odataClient.getReader().readEntity(res.getEntity().getContent(), + ODataPubFormat.fromString(getContentType()))); } - if (reference.isAssignableFrom(CommonODataProperty.class)) { - invokeResult = (T) odataClient.getReader().readProperty(res.getEntity().getContent(), - ODataFormat.fromString(getContentType())); + if (CommonODataProperty.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(odataClient.getReader().readProperty(res.getEntity().getContent(), + ODataFormat.fromString(getContentType()))); } } catch (IOException e) { throw new HttpClientException(e); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v3/InvokeRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v3/InvokeRequestFactoryImpl.java index 8781840a6..662f9db40 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v3/InvokeRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v3/InvokeRequestFactoryImpl.java @@ -24,14 +24,13 @@ import org.apache.olingo.client.api.v3.ODataClient; import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest; import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent; import org.apache.olingo.client.api.communication.request.invoke.v3.InvokeRequestFactory; -import org.apache.olingo.commons.api.domain.CommonODataEntity; -import org.apache.olingo.commons.api.domain.CommonODataEntitySet; import org.apache.olingo.commons.api.domain.ODataInvokeResult; -import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.client.api.http.HttpMethod; import org.apache.olingo.client.core.communication.request.invoke.AbstractInvokeRequestFactory; -import org.apache.olingo.client.core.communication.request.invoke.ODataInvokeRequestImpl; +import org.apache.olingo.commons.api.domain.v3.ODataEntity; +import org.apache.olingo.commons.api.domain.v3.ODataEntitySet; +import org.apache.olingo.commons.api.domain.v3.ODataProperty; import org.apache.olingo.commons.api.edm.EdmAction; import org.apache.olingo.commons.api.edm.EdmOperation; import org.apache.olingo.commons.api.edm.EdmReturnType; @@ -61,14 +60,14 @@ public class InvokeRequestFactoryImpl extends AbstractInvokeRequestFactory imple client, ODataNoContent.class, method, uri); } else { if (returnType.isCollection() && returnType.getType().getKind() == EdmTypeKind.ENTITY) { - request = (ODataInvokeRequest) new ODataInvokeRequestImpl( - client, CommonODataEntitySet.class, method, uri); + request = (ODataInvokeRequest) new ODataInvokeRequestImpl( + client, ODataEntitySet.class, method, uri); } else if (!returnType.isCollection() && returnType.getType().getKind() == EdmTypeKind.ENTITY) { - request = (ODataInvokeRequest) new ODataInvokeRequestImpl( - client, CommonODataEntity.class, method, uri); + request = (ODataInvokeRequest) new ODataInvokeRequestImpl( + client, ODataEntity.class, method, uri); } else { - request = (ODataInvokeRequest) new ODataInvokeRequestImpl( - client, CommonODataProperty.class, method, uri); + request = (ODataInvokeRequest) new ODataInvokeRequestImpl( + client, ODataProperty.class, method, uri); } } if (parameters != null) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v3/ODataInvokeRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v3/ODataInvokeRequestImpl.java new file mode 100644 index 000000000..1d0fb6521 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v3/ODataInvokeRequestImpl.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.client.core.communication.request.invoke.v3; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; +import org.apache.http.client.utils.URIBuilder; +import org.apache.olingo.client.api.CommonODataClient; +import org.apache.olingo.client.api.http.HttpMethod; +import org.apache.olingo.client.core.communication.request.invoke.AbstractODataInvokeRequest; +import org.apache.olingo.client.core.uri.URIUtils; +import org.apache.olingo.commons.api.domain.ODataInvokeResult; +import org.apache.olingo.commons.api.domain.ODataValue; +import org.apache.olingo.commons.api.format.ODataPubFormat; + +public class ODataInvokeRequestImpl extends AbstractODataInvokeRequest { + + public ODataInvokeRequestImpl(final CommonODataClient odataClient, final Class reference, final HttpMethod method, + final URI uri) { + + super(odataClient, reference, method, uri); + } + + @Override + protected ODataPubFormat getPOSTParameterFormat() { + return ODataPubFormat.JSON; + } + + @Override + protected URI buildGETURI() { + final URIBuilder uriBuilder = new URIBuilder(this.uri); + for (Map.Entry param : parameters.entrySet()) { + if (!param.getValue().isPrimitive()) { + throw new IllegalArgumentException("Only primitive values can be passed via GET"); + } + + uriBuilder.addParameter(param.getKey(), URIUtils.escape(odataClient.getServiceVersion(), param.getValue())); + } + + try { + return uriBuilder.build(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("While adding GET parameters", e); + } + } + +} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v4/InvokeRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v4/InvokeRequestFactoryImpl.java index da49df48a..4d5a4b1f8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v4/InvokeRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v4/InvokeRequestFactoryImpl.java @@ -20,14 +20,21 @@ package org.apache.olingo.client.core.communication.request.invoke.v4; import java.net.URI; import java.util.Map; -import org.apache.commons.lang3.NotImplementedException; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest; +import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent; import org.apache.olingo.client.api.communication.request.invoke.v4.InvokeRequestFactory; +import org.apache.olingo.client.api.http.HttpMethod; import org.apache.olingo.commons.api.domain.ODataInvokeResult; import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.client.core.communication.request.invoke.AbstractInvokeRequestFactory; +import org.apache.olingo.commons.api.domain.v4.ODataEntity; +import org.apache.olingo.commons.api.domain.v4.ODataEntitySet; +import org.apache.olingo.commons.api.domain.v4.ODataProperty; +import org.apache.olingo.commons.api.edm.EdmAction; import org.apache.olingo.commons.api.edm.EdmOperation; +import org.apache.olingo.commons.api.edm.EdmReturnType; +import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; public class InvokeRequestFactoryImpl extends AbstractInvokeRequestFactory implements InvokeRequestFactory { @@ -37,10 +44,36 @@ public class InvokeRequestFactoryImpl extends AbstractInvokeRequestFactory imple super(client); } + @SuppressWarnings("unchecked") @Override public ODataInvokeRequest getInvokeRequest( final URI uri, final EdmOperation operation, final Map parameters) { - throw new NotImplementedException("Not available yet."); + final HttpMethod method = operation instanceof EdmAction + ? HttpMethod.POST + : HttpMethod.GET; + final EdmReturnType returnType = operation.getReturnType(); + + ODataInvokeRequest request; + if (returnType == null) { + request = (ODataInvokeRequest) new ODataInvokeRequestImpl( + client, ODataNoContent.class, method, uri); + } else { + if (returnType.isCollection() && returnType.getType().getKind() == EdmTypeKind.ENTITY) { + request = (ODataInvokeRequest) new ODataInvokeRequestImpl( + client, ODataEntitySet.class, method, uri); + } else if (!returnType.isCollection() && returnType.getType().getKind() == EdmTypeKind.ENTITY) { + request = (ODataInvokeRequest) new ODataInvokeRequestImpl( + client, ODataEntity.class, method, uri); + } else { + request = (ODataInvokeRequest) new ODataInvokeRequestImpl( + client, ODataProperty.class, method, uri); + } + } + if (parameters != null) { + request.setParameters(parameters); + } + + return request; } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v4/ODataInvokeRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v4/ODataInvokeRequestImpl.java new file mode 100644 index 000000000..a59b727a2 --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/v4/ODataInvokeRequestImpl.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.client.core.communication.request.invoke.v4; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; +import java.util.Map; +import org.apache.olingo.client.api.CommonODataClient; +import org.apache.olingo.client.api.http.HttpMethod; +import org.apache.olingo.client.core.communication.request.invoke.AbstractODataInvokeRequest; +import org.apache.olingo.client.core.uri.URIUtils; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.domain.ODataInvokeResult; +import org.apache.olingo.commons.api.domain.ODataValue; +import org.apache.olingo.commons.api.format.ODataPubFormat; + +public class ODataInvokeRequestImpl extends AbstractODataInvokeRequest { + + private ODataPubFormat format; + + public ODataInvokeRequestImpl(final CommonODataClient odataClient, final Class reference, final HttpMethod method, + final URI uri) { + + super(odataClient, reference, method, uri); + } + + @Override + public void setFormat(final ODataPubFormat format) { + super.setFormat(format); + this.format = format; + } + + @Override + protected ODataPubFormat getPOSTParameterFormat() { + return format; + } + + @Override + protected URI buildGETURI() { + String baseURI = this.uri.toASCIIString(); + if (baseURI.endsWith("()")) { + baseURI = baseURI.substring(0, baseURI.length() - 2); + } else if (!baseURI.endsWith("(")) { + baseURI = baseURI.substring(0, baseURI.length() - 1); + } + + final StringBuilder inlineParams = new StringBuilder(); + for (Map.Entry param : parameters.entrySet()) { + inlineParams.append(param.getKey()).append("="); + + Object value = null; + if (param.getValue().isPrimitive()) { + value = param.getValue().asPrimitive().toValue(); + } else if (param.getValue().isComplex()) { + value = param.getValue().asComplex().asJavaMap(); + } else if (param.getValue().isCollection()) { + value = param.getValue().asCollection().asJavaCollection(); + } else if (param.getValue() instanceof org.apache.olingo.commons.api.domain.v4.ODataValue + && ((org.apache.olingo.commons.api.domain.v4.ODataValue) param.getValue()).isEnum()) { + + value = ((org.apache.olingo.commons.api.domain.v4.ODataValue) param.getValue()).asEnum().toString(); + } + + inlineParams.append(URIUtils.escape(odataClient.getServiceVersion(), value)).append(','); + } + inlineParams.deleteCharAt(inlineParams.length() - 1); + + try { + return URI.create(baseURI + "(" + URLEncoder.encode(inlineParams.toString(), Constants.UTF8) + ")"); + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException("While adding GET parameters", e); + } + } + +} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java index 71e08bb18..d927136d2 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java @@ -110,11 +110,6 @@ public abstract class AbstractODataBinder implements CommonODataBinder { return feed; } - @Override - public Entry getEntry(final CommonODataEntity entity, final Class reference) { - return getEntry(entity, reference, true); - } - protected void links(final ODataLinked odataLinked, final Linked linked, final Class reference) { // ------------------------------------------------------------- // Append navigation links (handling inline entry / feed as well) @@ -140,7 +135,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder { } @Override - public Entry getEntry(final CommonODataEntity entity, final Class reference, final boolean setType) { + public Entry getEntry(final CommonODataEntity entity, final Class reference) { final Entry entry = ResourceFactory.newEntry(reference); entry.setType(entity.getName()); @@ -185,7 +180,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder { } for (CommonODataProperty property : entity.getProperties()) { - entry.getProperties().add(getProperty(property, reference, setType)); + entry.getProperties().add(getProperty(property, reference)); } return entry; @@ -217,7 +212,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder { return linkResource; } - protected Value getValue(final ODataValue value, final Class reference, final boolean setType) { + protected Value getValue(final ODataValue value, final Class reference) { Value valueResource = null; if (value == null) { @@ -231,14 +226,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder { valueResource = new ComplexValueImpl(); for (final Iterator itor = _value.iterator(); itor.hasNext();) { - valueResource.asComplex().get().add(getProperty(itor.next(), reference, setType)); + valueResource.asComplex().get().add(getProperty(itor.next(), reference)); } } else if (value.isCollection()) { final ODataCollectionValue _value = value.asCollection(); valueResource = new CollectionValueImpl(); for (final Iterator itor = _value.iterator(); itor.hasNext();) { - valueResource.asCollection().get().add(getValue(itor.next(), reference, setType)); + valueResource.asCollection().get().add(getValue(itor.next(), reference)); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java index 7ea9c99b1..723070410 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java @@ -45,18 +45,11 @@ public class ODataWriterImpl implements ODataWriter { @Override public InputStream writeEntities(final Collection entities, final ODataPubFormat format) { - return writeEntities(entities, format, true); - } - - @Override - public InputStream writeEntities( - final Collection entities, final ODataPubFormat format, final boolean outputType) { - final ByteArrayOutputStream output = new ByteArrayOutputStream(); try { for (CommonODataEntity entity : entities) { client.getSerializer().entry(client.getBinder().getEntry( - entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM), outputType), output); + entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)), output); } return new ByteArrayInputStream(output.toByteArray()); @@ -67,14 +60,7 @@ public class ODataWriterImpl implements ODataWriter { @Override public InputStream writeEntity(final CommonODataEntity entity, final ODataPubFormat format) { - return writeEntity(entity, format, true); - } - - @Override - public InputStream writeEntity(final CommonODataEntity entity, final ODataPubFormat format, - final boolean outputType) { - - return writeEntities(Collections.singleton(entity), format, outputType); + return writeEntities(Collections.singleton(entity), format); } @Override @@ -82,7 +68,7 @@ public class ODataWriterImpl implements ODataWriter { final ByteArrayOutputStream output = new ByteArrayOutputStream(); try { client.getSerializer().property(client.getBinder().getProperty( - property, ResourceFactory.entryClassForFormat(format == ODataFormat.XML), true), output); + property, ResourceFactory.entryClassForFormat(format == ODataFormat.XML)), output); return new ByteArrayInputStream(output.toByteArray()); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java index ab973d32d..c0ce3f384 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java @@ -56,21 +56,17 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override - public Property getProperty(final CommonODataProperty property, final Class reference, - final boolean setType) { - + public Property getProperty(final CommonODataProperty property, final Class reference) { final Property propertyResource = ResourceFactory.newProperty(reference); propertyResource.setName(property.getName()); - propertyResource.setValue(getValue(property.getValue(), reference, setType)); + propertyResource.setValue(getValue(property.getValue(), reference)); - if (setType) { - if (property.hasPrimitiveValue()) { - propertyResource.setType(property.getPrimitiveValue().getTypeName()); - } else if (property.hasComplexValue()) { - propertyResource.setType(((ODataProperty) property).getComplexValue().getTypeName()); - } else if (property.hasCollectionValue()) { - propertyResource.setType(((ODataProperty) property).getCollectionValue().getTypeName()); - } + if (property.hasPrimitiveValue()) { + propertyResource.setType(property.getPrimitiveValue().getTypeName()); + } else if (property.hasComplexValue()) { + propertyResource.setType(((ODataProperty) property).getComplexValue().getTypeName()); + } else if (property.hasCollectionValue()) { + propertyResource.setType(((ODataProperty) property).getCollectionValue().getTypeName()); } return propertyResource; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java index adce2eedf..950ea532c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java @@ -88,39 +88,35 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override - public Entry getEntry(final CommonODataEntity entity, final Class reference, final boolean setType) { - final Entry entry = super.getEntry(entity, reference, setType); + public Entry getEntry(final CommonODataEntity entity, final Class reference) { + final Entry entry = super.getEntry(entity, reference); entry.setId(((ODataEntity) entity).getReference()); return entry; } @Override - public Property getProperty(final CommonODataProperty property, final Class reference, - final boolean setType) { - + public Property getProperty(final CommonODataProperty property, final Class reference) { final ODataProperty _property = (ODataProperty) property; final Property propertyResource = ResourceFactory.newProperty(reference); propertyResource.setName(_property.getName()); - propertyResource.setValue(getValue(_property.getValue(), reference, setType)); + propertyResource.setValue(getValue(_property.getValue(), reference)); - if (setType) { - if (_property.hasPrimitiveValue()) { - propertyResource.setType(_property.getPrimitiveValue().getTypeName()); - } else if (_property.hasEnumValue()) { - propertyResource.setType(_property.getEnumValue().getTypeName()); - } else if (_property.hasComplexValue()) { - propertyResource.setType(_property.getComplexValue().getTypeName()); - } else if (_property.hasCollectionValue()) { - propertyResource.setType(_property.getCollectionValue().getTypeName()); - } + if (_property.hasPrimitiveValue()) { + propertyResource.setType(_property.getPrimitiveValue().getTypeName()); + } else if (_property.hasEnumValue()) { + propertyResource.setType(_property.getEnumValue().getTypeName()); + } else if (_property.hasComplexValue()) { + propertyResource.setType(_property.getComplexValue().getTypeName()); + } else if (_property.hasCollectionValue()) { + propertyResource.setType(_property.getCollectionValue().getTypeName()); } return propertyResource; } @Override - protected Value getValue(final ODataValue value, final Class reference, final boolean setType) { + protected Value getValue(final ODataValue value, final Class reference) { Value valueResource; if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue && ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isEnum()) { @@ -128,7 +124,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder valueResource = new EnumValueImpl( ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asEnum().getValue()); } else { - valueResource = super.getValue(value, reference, setType); + valueResource = super.getValue(value, reference); if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue && ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isLinkedComplex()) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java index 841af8ff6..3496cec2c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java @@ -41,7 +41,6 @@ import org.apache.http.entity.InputStreamEntity; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmOperationImport; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; @@ -143,17 +142,17 @@ public final class URIUtils { * Gets operation import URI segment. * * @param entityContainer entity container. - * @param operationImport function import. + * @param operationImportName action / function import name. * @return URI segment. */ public static String operationImportURISegment( - final EdmEntityContainer entityContainer, final EdmOperationImport operationImport) { + final EdmEntityContainer entityContainer, final String operationImportName) { final StringBuilder result = new StringBuilder(); if (!entityContainer.isDefault()) { result.append(entityContainer.getName()).append('.'); } - result.append(operationImport.getName()); + result.append(operationImportName); return result.toString(); } @@ -282,12 +281,11 @@ public final class URIUtils { private static String quoteString(final String string, final boolean singleQuoteEscape) throws UnsupportedEncodingException { - final String encoded = URLEncoder.encode(string, Constants.UTF8); return ENUM_VALUE.matcher(string).matches() - ? encoded + ? string : singleQuoteEscape - ? "'" + encoded + "'" - : "\"" + encoded + "\""; + ? "'" + string + "'" + : "\"" + string + "\""; } /** @@ -322,11 +320,11 @@ public final class URIUtils { } else if (version.compareTo(ODataServiceVersion.V40) >= 0 && obj instanceof Map) { final StringBuffer buffer = new StringBuffer("{"); for (@SuppressWarnings("unchecked") - final Iterator> itor = - ((Map) obj).entrySet().iterator(); itor.hasNext();) { + final Iterator> itor = + ((Map) obj).entrySet().iterator(); itor.hasNext();) { - final Map.Entry entry = itor.next(); - buffer.append("\"").append(URLEncoder.encode(entry.getKey().toString(), Constants.UTF8)).append("\""); + final Map.Entry entry = itor.next(); + buffer.append("\"").append(entry.getKey()).append("\""); buffer.append(':').append(escape(version, entry.getValue(), false)); if (itor.hasNext()) { diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java index 19cf96f1d..1031fbee8 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java @@ -62,7 +62,7 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase { assertEquals(EdmInt32.getInstance(), unbound.getReturnType().getType()); final URIBuilder unboundBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL). - appendOperationCallSegment(URIUtils.operationImportURISegment(container, actImp)); + appendOperationCallSegment(URIUtils.operationImportURISegment(container, actImp.getName())); final ODataInvokeResponse unboundRes = getClient().getInvokeRequestFactory(). getInvokeRequest(unboundBuilder.build(), unbound).execute(); assertNotNull(unboundRes); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java index e25c9fd14..17e6c1d40 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java @@ -153,7 +153,7 @@ public class ErrorTestITCase extends AbstractTestITCase { final EdmEntityContainer container = metadata.getSchemas().get(0).getEntityContainer(); final EdmFunctionImport funcImp = container.getFunctionImport("InStreamErrorGetCustomer"); final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL). - appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp)); + appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName())); final ODataInvokeRequest req = client.getInvokeRequestFactory().getInvokeRequest(builder.build(), funcImp.getUnboundFunction(null)); req.setFormat(format); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java index 1cc4e1440..50e95c553 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java @@ -73,7 +73,7 @@ public class InvokeTestITCase extends AbstractTestITCase { EdmFunction func = funcImp.getUnboundFunction(null); URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL). - appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp)); + appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName())); ODataInvokeRequest req = getClient().getInvokeRequestFactory(). getInvokeRequest(builder.build(), func); @@ -90,7 +90,7 @@ public class InvokeTestITCase extends AbstractTestITCase { func = funcImp.getUnboundFunction(null); builder = getClient().getURIBuilder(testStaticServiceRootURL). - appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp)); + appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName())); req = getClient().getInvokeRequestFactory().getInvokeRequest(builder.build(), func); req.setFormat(format); @@ -123,7 +123,7 @@ public class InvokeTestITCase extends AbstractTestITCase { EdmFunctionImport funcImp = container.getFunctionImport("GetArgumentPlusOne"); URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL). - appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp)); + appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName())); EdmFunction function = funcImp.getUnboundFunction(Collections.singletonList("arg1")); EdmParameter param = function.getParameter(function.getParameterNames().get(0)); @@ -148,7 +148,7 @@ public class InvokeTestITCase extends AbstractTestITCase { funcImp = container.getFunctionImport("GetSpecificCustomer"); builder = getClient().getURIBuilder(testStaticServiceRootURL). - appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp)); + appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName())); function = funcImp.getUnboundFunction(Collections.singletonList("Name")); param = function.getParameter(function.getParameterNames().get(0)); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java index 886d1e8bd..ca226a379 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/URIEscapeTest.java @@ -51,8 +51,7 @@ public class URIEscapeTest { final EdmEnumType pattern = new EdmEnumTypeImpl(ODataServiceVersion.V40, null, new FullQualifiedName("Sales", "Pattern"), new EnumTypeImpl()); - assertEquals(URLEncoder.encode("Sales.Pattern'Yellow'", Constants.UTF8), - URIUtils.escape(ODataServiceVersion.V40, pattern.toUriLiteral("Yellow"))); + assertEquals("Sales.Pattern'Yellow'", URIUtils.escape(ODataServiceVersion.V40, pattern.toUriLiteral("Yellow"))); } @Test diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataCollectionValue.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataCollectionValue.java index 088bbc0f0..8b5f5319b 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataCollectionValue.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataCollectionValue.java @@ -18,6 +18,8 @@ */ package org.apache.olingo.commons.api.domain; +import java.util.Collection; + /** * OData collection property value. * @@ -45,4 +47,11 @@ public interface ODataCollectionValue extends ODataValue, * @return collection size. */ int size(); + + /** + * Converts this instance as POJO collection. + * + * @return this instance as POJO collection + */ + Collection asJavaCollection(); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java index 7eb02c0ec..b66aed662 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java @@ -18,6 +18,8 @@ */ package org.apache.olingo.commons.api.domain; +import java.util.Map; + /** * OData complex property value. * @@ -47,4 +49,10 @@ public interface ODataComplexValue extends OData */ int size(); + /** + * Converts this instance as POJO collection. + * + * @return this instance as POJO collection + */ + Map asJavaMap(); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataEnumValue.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataEnumValue.java index 2e3699d61..e6148084e 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataEnumValue.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/v4/ODataEnumValue.java @@ -21,4 +21,7 @@ package org.apache.olingo.commons.api.domain.v4; public interface ODataEnumValue extends ODataValue { String getValue(); + + @Override + String toString(); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java index 2f8236b04..619cf021c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java @@ -19,6 +19,7 @@ package org.apache.olingo.commons.core.domain; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import org.apache.olingo.commons.api.domain.AbstractODataValue; @@ -38,7 +39,7 @@ public abstract class AbstractODataCollectionValue /** * Values. */ - private final List values = new ArrayList(); + protected final List values = new ArrayList(); /** * Constructor. @@ -89,4 +90,21 @@ public abstract class AbstractODataCollectionValue public boolean isEmpty() { return values.isEmpty(); } + + @Override + public Collection asJavaCollection() { + final List result = new ArrayList(); + for (OV value : values) { + if (value.isPrimitive()) { + result.add(value.asPrimitive().toValue()); + } else if (value.isComplex()) { + result.add(value.asComplex().asJavaMap()); + } else if (value.isCollection()) { + result.add(value.asCollection().asJavaCollection()); + } + } + + return result; + } + } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataComplexValue.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataComplexValue.java index 6a0966454..4e4e40da2 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataComplexValue.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataComplexValue.java @@ -38,7 +38,7 @@ public abstract class AbstractODataComplexValue /** * Complex type fields. */ - private final Map fields = new LinkedHashMap(); + protected final Map fields = new LinkedHashMap(); /** * Constructor. @@ -90,4 +90,24 @@ public abstract class AbstractODataComplexValue public int size() { return fields.size(); } + + @Override + public Map asJavaMap() { + final Map result = new LinkedHashMap(); + for (Map.Entry entry : fields.entrySet()) { + Object value = null; + if (entry.getValue().hasPrimitiveValue()) { + value = entry.getValue().getPrimitiveValue().toValue(); + } else if (entry.getValue().hasComplexValue()) { + value = entry.getValue().getValue().asComplex().asJavaMap(); + } else if (entry.getValue().hasCollectionValue()) { + value = entry.getValue().getValue().asCollection().asJavaCollection(); + } + + result.put(entry.getKey(), value); + } + + return result; + } + } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataCollectionValueImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataCollectionValueImpl.java index f130d9019..46a553c24 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataCollectionValueImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataCollectionValueImpl.java @@ -18,6 +18,9 @@ */ package org.apache.olingo.commons.core.domain.v4; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import org.apache.olingo.commons.api.domain.v4.ODataLinkedComplexValue; import org.apache.olingo.commons.api.domain.v4.ODataEnumValue; import org.apache.olingo.commons.api.domain.v4.ODataValue; @@ -50,4 +53,22 @@ public class ODataCollectionValueImpl extends AbstractODataCollectionValue asJavaCollection() { + final List result = new ArrayList(); + for (ODataValue value : values) { + if (value.isPrimitive()) { + result.add(value.asPrimitive().toValue()); + } else if (value.isComplex()) { + result.add(value.asComplex().asJavaMap()); + } else if (value.isCollection()) { + result.add(value.asCollection().asJavaCollection()); + } else if (value.isEnum()) { + result.add(value.asEnum().toString()); + } + } + + return result; + } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java index 711fd536d..d8d5fc99d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java @@ -19,7 +19,9 @@ package org.apache.olingo.commons.core.domain.v4; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.apache.olingo.commons.api.domain.ODataLink; import org.apache.olingo.commons.api.domain.v4.ODataLinkedComplexValue; import org.apache.olingo.commons.api.domain.v4.ODataEnumValue; @@ -123,4 +125,25 @@ public class ODataComplexValueImpl extends AbstractODataComplexValue asJavaMap() { + final Map result = new LinkedHashMap(); + for (Map.Entry entry : fields.entrySet()) { + Object value = null; + if (entry.getValue().hasPrimitiveValue()) { + value = entry.getValue().getPrimitiveValue().toValue(); + } else if (entry.getValue().hasComplexValue()) { + value = entry.getValue().getComplexValue().asJavaMap(); + } else if (entry.getValue().hasCollectionValue()) { + value = entry.getValue().getCollectionValue().asJavaCollection(); + } else if (entry.getValue().hasEnumValue()) { + value = entry.getValue().getEnumValue().toString(); + } + + result.put(entry.getKey(), value); + } + + return result; + } + } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEnumValueImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEnumValueImpl.java index f68fc7f3a..682803320 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEnumValueImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataEnumValueImpl.java @@ -57,4 +57,11 @@ public class ODataEnumValueImpl extends AbstractODataValue implements ODataEnumV public ODataLinkedComplexValue asLinkedComplex() { return null; } + + @Override + public String toString() { + return getTypeName() + "'" + getValue() + "'"; + + } + } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataPropertyImpl.java index 34b4cfa37..541c360fe 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataPropertyImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataPropertyImpl.java @@ -49,7 +49,9 @@ public class ODataPropertyImpl extends AbstractODataProperty implements ODataPro @Override public ODataComplexValue getComplexValue() { - return hasComplexValue() ? getValue().asComplex() : null; + return hasComplexValue() + ? getValue().asComplex() + : null; } @Override