Repository: olingo-odata4 Updated Branches: refs/heads/OLINGO-564 17152920f -> 61500e685
[OLINGO-564] Clean up Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/61500e68 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/61500e68 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/61500e68 Branch: refs/heads/OLINGO-564 Commit: 61500e685fca852fac301f473fcca8a2918f887e Parents: 1715292 Author: Michael Bolz <[email protected]> Authored: Thu Apr 30 08:38:19 2015 +0200 Committer: Michael Bolz <[email protected]> Committed: Thu Apr 30 08:38:19 2015 +0200 ---------------------------------------------------------------------- .../olingo/fit/tecsvc/client/BasicITCase.java | 34 +- .../olingo/fit/v4/EntitySetTestITCase.java | 6 +- .../olingo/fit/v4/ErrorResponseTestITCase.java | 4 +- .../olingo/fit/v4/MetadataTestITCase.java | 6 +- .../ODataClientErrorException.java | 2 +- .../retrieve/ODataEntitySetIteratorRequest.java | 4 +- .../api/domain/ClientEntitySetIterator.java | 315 +++++++++++++++++++ .../api/domain/ODataEntitySetIterator.java | 315 ------------------- .../client/api/serialization/ODataReader.java | 2 +- .../header/ODataErrorResponseChecker.java | 2 +- .../ODataEntitySetIteratorRequestImpl.java | 12 +- .../ClientODataDeserializerImpl.java | 2 +- .../core/serialization/ODataReaderImpl.java | 10 +- .../apache/olingo/client/core/v4/ErrorTest.java | 2 +- .../olingo/client/core/v4/MetadataTest.java | 2 +- .../apache/olingo/commons/api/ODataError.java | 132 ++++++++ .../olingo/commons/api/ODataErrorDetail.java | 73 +++++ .../olingo/commons/api/ODataPropertyType.java | 44 +++ .../olingo/commons/api/domain/ODataError.java | 132 -------- .../commons/api/domain/ODataErrorDetail.java | 73 ----- .../commons/api/domain/ODataPropertyType.java | 44 --- .../EdmConstantAnnotationExpression.java | 1 + .../api/serialization/ODataDeserializer.java | 2 +- .../EdmConstantAnnotationExpressionImpl.java | 24 +- .../core/serialization/AtomDeserializer.java | 4 +- .../core/serialization/JsonDeserializer.java | 4 +- .../JsonODataErrorDeserializer.java | 4 +- .../JsonODataErrorDetailDeserializer.java | 2 +- .../olingo/server/api/ClientServerError.java | 4 +- .../serializer/json/ODataErrorSerializer.java | 4 +- .../json/ClientErrorSerializerTest.java | 2 +- 31 files changed, 628 insertions(+), 639 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java index 5463ffa..003dad4 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java @@ -57,7 +57,7 @@ import org.apache.olingo.client.api.domain.ClientAnnotation; import org.apache.olingo.client.api.domain.ClientComplexValue; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.client.api.domain.ClientInlineEntity; import org.apache.olingo.client.api.domain.ClientInlineEntitySet; import org.apache.olingo.client.api.domain.ClientObjectFactory; @@ -464,27 +464,27 @@ public class BasicITCase extends AbstractBaseTestITCase { .add( of.newComplexValue("CTPrimComp") .add( - of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder() - .buildInt16( - (short) 42))) + of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder() + .buildInt16( + (short) 42))) .add( - of.newComplexProperty("PropertyComp", of.newComplexValue("CTAllPrim") - .add( - of.newPrimitiveProperty("PropertyString", of - .newPrimitiveValueBuilder() - .buildString("42")))))) + of.newComplexProperty("PropertyComp", of.newComplexValue("CTAllPrim") + .add( + of.newPrimitiveProperty("PropertyString", of + .newPrimitiveValueBuilder() + .buildString("42")))))) .add( of.newComplexValue("CTPrimComp") .add( - of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder() - .buildInt16( - (short) 43))) + of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder() + .buildInt16( + (short) 43))) .add( - of.newComplexProperty("PropertyComp", of.newComplexValue("CTAllPrim") - .add( - of.newPrimitiveProperty("PropertyString", of - .newPrimitiveValueBuilder() - .buildString("43")))))))); + of.newComplexProperty("PropertyComp", of.newComplexValue("CTAllPrim") + .add( + of.newPrimitiveProperty("PropertyString", of + .newPrimitiveValueBuilder() + .buildString("43")))))))); final URI uri = getClient().newURIBuilder(SERVICE_URI) .appendEntitySetSegment("ESKeyNav") http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java index 3e001b0..9e99457 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java @@ -24,7 +24,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySe import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest; import org.apache.olingo.client.api.communication.response.ODataRawResponse; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; -import org.apache.olingo.client.api.domain.ODataEntitySetIterator; +import org.apache.olingo.client.api.domain.ClientEntitySetIterator; import org.apache.olingo.client.api.uri.URIBuilder; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.data.ResWrap; @@ -108,8 +108,8 @@ public class EntitySetTestITCase extends AbstractTestITCase { client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build()); req.setFormat(format); - final ODataRetrieveResponse<ODataEntitySetIterator<ClientEntitySet, ClientEntity>> res = req.execute(); - final ODataEntitySetIterator<ClientEntitySet, ClientEntity> feedIterator = res.getBody(); + final ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> res = req.execute(); + final ClientEntitySetIterator<ClientEntitySet, ClientEntity> feedIterator = res.getBody(); assertNotNull(feedIterator); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java index 8cdd2db..0b47a9e 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java @@ -19,8 +19,8 @@ package org.apache.olingo.fit.v4; import org.apache.olingo.client.api.communication.ODataClientErrorException; -import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; +import org.apache.olingo.commons.api.ODataError; +import org.apache.olingo.commons.api.ODataErrorDetail; import org.apache.olingo.commons.api.format.ODataFormat; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java index c591394..8ee9f20 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java @@ -108,8 +108,10 @@ public class MetadataTestITCase extends AbstractTestITCase { final EdmAnnotation description = core.getAnnotation(descriptionTerm); assertNotNull(description); +// assertEquals("Core terms needed to write vocabularies", +// description.getExpression().asConstant().getValue().asPrimitive().toString()); assertEquals("Core terms needed to write vocabularies", - description.getExpression().asConstant().getValue().asPrimitive().toString()); + description.getExpression().asConstant().getValueAsString()); final EdmTerm isLanguageDependent = edm.getTerm(new FullQualifiedName("Core.IsLanguageDependent")); assertNotNull(isLanguageDependent); @@ -133,7 +135,7 @@ public class MetadataTestITCase extends AbstractTestITCase { final EdmAnnotation requiresTypeInScale = edm.getAnnotation( scale.getFullQualifiedName(), edm.getTerm(new FullQualifiedName("Core.RequiresType"))); assertNotNull(requiresTypeInScale); - assertEquals("Edm.Decimal", requiresTypeInScale.getExpression().asConstant().toString()); + assertEquals("Edm.Decimal", requiresTypeInScale.getExpression().asConstant().getValueAsString()); // 3. capabilities final EdmTerm deleteRestrictions = edm.getTerm(new FullQualifiedName("Capabilities.DeleteRestrictions")); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java index 178241a..64faf35 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java @@ -21,7 +21,7 @@ package org.apache.olingo.client.api.communication; import org.apache.commons.lang3.StringUtils; import org.apache.http.StatusLine; import org.apache.olingo.commons.api.ODataRuntimeException; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; /** * Represents a client error in OData. http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java index 4b3f05e..d20eaca 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java @@ -18,7 +18,7 @@ */ package org.apache.olingo.client.api.communication.request.retrieve; -import org.apache.olingo.client.api.domain.ODataEntitySetIterator; +import org.apache.olingo.client.api.domain.ClientEntitySetIterator; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; @@ -26,6 +26,6 @@ import org.apache.olingo.client.api.domain.ClientEntitySet; * This class implements an OData EntitySet query request. */ public interface ODataEntitySetIteratorRequest<ES extends ClientEntitySet, E extends ClientEntity> - extends ODataRetrieveRequest<ODataEntitySetIterator<ES, E>> { + extends ODataRetrieveRequest<ClientEntitySetIterator<ES, E>> { //No additional methods needed for now. } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java new file mode 100644 index 0000000..accfce6 --- /dev/null +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ClientEntitySetIterator.java @@ -0,0 +1,315 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.client.api.domain; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.serialization.ODataDeserializerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * OData entity set iterator class. + * <br/> + * <b>Please don't forget to call the <tt>close()>/</tt> method when not needed any more.</b> + * + * @param <E> concrete ODataEntity implementation + * @param <ES> concrete ODataEntitySet implementation + */ +public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends ClientEntity> + implements Iterator<E> { + + /** + * Logger. + */ + private static final Logger LOG = LoggerFactory.getLogger(ClientEntitySetIterator.class); + + protected final ODataClient odataClient; + + protected ResWrap<Entity> cached; + + private final InputStream stream; + + private final ODataFormat format; + + private ES entitySet; + + private final ByteArrayOutputStream osEntitySet; + + private final String namespaces; + + private boolean available = true; + + /** + * Constructor. + * + * @param odataClient client instance getting this request + * @param stream source stream. + * @param format OData format. + */ + public ClientEntitySetIterator(final ODataClient odataClient, final InputStream stream, + final ODataFormat format) { + + this.odataClient = odataClient; + this.stream = stream; + this.format = format; + this.osEntitySet = new ByteArrayOutputStream(); + + if (format == ODataFormat.ATOM) { + namespaces = getAllElementAttributes(stream, "feed", osEntitySet); + } else { + namespaces = null; + try { + if (consume(stream, "\"value\":", osEntitySet, true) >= 0) { + int c = 0; + while (c != '[' && (c = stream.read()) >= 0) { + osEntitySet.write(c); + } + } + } catch (IOException e) { + LOG.error("Error parsing entity set", e); + throw new IllegalStateException(e); + } + } + } + + /** + * {@inheritDoc } + */ + @Override + @SuppressWarnings("unchecked") + public boolean hasNext() { + if (available && cached == null) { + if (format == ODataFormat.ATOM) { + cached = nextAtomEntityFromEntitySet(stream, osEntitySet, namespaces); + } else { + cached = nextJSONEntityFromEntitySet(stream, osEntitySet); + } + + if (cached == null) { + available = false; + try { + entitySet = (ES) odataClient.getReader(). + readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), format); + } catch (final ODataDeserializerException e) { + available = false; + } + close(); + } + } + + return available; + } + + /** + * {@inheritDoc } + */ + @Override + public E next() { + if (hasNext()) { + @SuppressWarnings("unchecked") + final E res = (E) odataClient.getBinder().getODataEntity(cached); + cached = null; + return res; + } + + throw new NoSuchElementException("No entity found"); + } + + /** + * Unsupported operation. + */ + @Override + public void remove() { + throw new UnsupportedOperationException("Operation not supported"); + } + + /** + * Closes the current iterator. + */ + public void close() { + IOUtils.closeQuietly(stream); + IOUtils.closeQuietly(osEntitySet); + } + + /** + * Gets the next link if exists. + * + * @return next link if exists; null otherwise. + */ + public URI getNext() { + if (entitySet == null) { + throw new IllegalStateException("Iteration must be completed in order to retrieve the link for next page"); + } + return entitySet.getNext(); + } + + private ResWrap<Entity> nextJSONEntityFromEntitySet(final InputStream input, final OutputStream osEntitySet) { + final ByteArrayOutputStream entity = new ByteArrayOutputStream(); + + ResWrap<Entity> jsonEntity = null; + try { + int c; + + boolean foundNewOne = false; + + do { + c = input.read(); + if (c == '{') { + entity.write(c); + c = -1; + foundNewOne = true; + } + if (c == ']') { + osEntitySet.write(c); + c = -1; + } + } while (c >= 0); + + if (foundNewOne) { + int count = 1; + c = 0; + + while (count > 0 && c >= 0) { + c = input.read(); + if (c == '{') { + count++; + } else if (c == '}') { + count--; + } + entity.write(c); + } + + if (c >= 0) { + jsonEntity = odataClient.getDeserializer(ODataFormat.JSON).toEntity( + new ByteArrayInputStream(entity.toByteArray())); + } + } else { + while ((c = input.read()) >= 0) { + osEntitySet.write(c); + } + } + } catch (Exception e) { + LOG.error("Error retrieving entities from EntitySet", e); + } + + return jsonEntity; + } + + private ResWrap<Entity> nextAtomEntityFromEntitySet( + final InputStream input, final OutputStream osEntitySet, final String namespaces) { + + final ByteArrayOutputStream entity = new ByteArrayOutputStream(); + + ResWrap<Entity> atomEntity = null; + + try { + if (consume(input, "<entry>", osEntitySet, false) >= 0) { + entity.write("<entry ".getBytes(Constants.UTF8)); + entity.write(namespaces.getBytes(Constants.UTF8)); + entity.write(">".getBytes(Constants.UTF8)); + + if (consume(input, "</entry>", entity, true) >= 0) { + atomEntity = odataClient.getDeserializer(ODataFormat.ATOM). + toEntity(new ByteArrayInputStream(entity.toByteArray())); + } + } + } catch (Exception e) { + LOG.error("Error retrieving entities from EntitySet", e); + } + + return atomEntity; + } + + private String getAllElementAttributes(final InputStream input, final String name, final OutputStream os) { + final ByteArrayOutputStream attrs = new ByteArrayOutputStream(); + + String res; + + try { + byte[] attrsDeclaration = null; + + final String key = "<" + name + " "; + if (consume(input, key, os, true) >= 0 && consume(input, ">", attrs, false) >= 0) { + attrsDeclaration = attrs.toByteArray(); + os.write(attrsDeclaration); + os.write('>'); + } + + res = attrsDeclaration == null + ? StringUtils.EMPTY + : new String(attrsDeclaration, Constants.UTF8).trim(); + } catch (Exception e) { + LOG.error("Error retrieving entities from EntitySet", e); + res = StringUtils.EMPTY; + } + + return res.endsWith("/") ? res.substring(0, res.length() - 1) : res; + } + + private int consume( + final InputStream input, final String end, final OutputStream os, final boolean includeEndKey) + throws IOException { + + final char[] endKey = end.toCharArray(); + final char[] endLowerKey = end.toLowerCase().toCharArray(); + final char[] endUpperKey = end.toUpperCase().toCharArray(); + + int pos = 0; + int c = 0; + while (pos < endKey.length && (c = input.read()) >= 0) { + if (c == endLowerKey[pos] || c == endUpperKey[pos]) { + pos++; + if (includeEndKey && os != null) { + os.write(c); + } + } else if (pos > 0) { + if (!includeEndKey && os != null) { + for (int i = 0; i < pos; i++) { + os.write(endKey[i]); + } + } + if (os != null) { + os.write(c); + } + pos = 0; + } else { + if (os != null) { + os.write(c); + } + } + } + + return c; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java deleted file mode 100644 index 64bf0f2..0000000 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java +++ /dev/null @@ -1,315 +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.client.api.domain; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.api.serialization.ODataDeserializerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * OData entity set iterator class. - * <br/> - * <b>Please don't forget to call the <tt>close()>/</tt> method when not needed any more.</b> - * - * @param <E> concrete ODataEntity implementation - * @param <ES> concrete ODataEntitySet implementation - */ -public class ODataEntitySetIterator<ES extends ClientEntitySet, E extends ClientEntity> - implements Iterator<E> { - - /** - * Logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(ODataEntitySetIterator.class); - - protected final ODataClient odataClient; - - protected ResWrap<Entity> cached; - - private final InputStream stream; - - private final ODataFormat format; - - private ES entitySet; - - private final ByteArrayOutputStream osEntitySet; - - private final String namespaces; - - private boolean available = true; - - /** - * Constructor. - * - * @param odataClient client instance getting this request - * @param stream source stream. - * @param format OData format. - */ - public ODataEntitySetIterator(final ODataClient odataClient, final InputStream stream, - final ODataFormat format) { - - this.odataClient = odataClient; - this.stream = stream; - this.format = format; - this.osEntitySet = new ByteArrayOutputStream(); - - if (format == ODataFormat.ATOM) { - namespaces = getAllElementAttributes(stream, "feed", osEntitySet); - } else { - namespaces = null; - try { - if (consume(stream, "\"value\":", osEntitySet, true) >= 0) { - int c = 0; - while (c != '[' && (c = stream.read()) >= 0) { - osEntitySet.write(c); - } - } - } catch (IOException e) { - LOG.error("Error parsing entity set", e); - throw new IllegalStateException(e); - } - } - } - - /** - * {@inheritDoc } - */ - @Override - @SuppressWarnings("unchecked") - public boolean hasNext() { - if (available && cached == null) { - if (format == ODataFormat.ATOM) { - cached = nextAtomEntityFromEntitySet(stream, osEntitySet, namespaces); - } else { - cached = nextJSONEntityFromEntitySet(stream, osEntitySet); - } - - if (cached == null) { - available = false; - try { - entitySet = (ES) odataClient.getReader(). - readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), format); - } catch (final ODataDeserializerException e) { - available = false; - } - close(); - } - } - - return available; - } - - /** - * {@inheritDoc } - */ - @Override - public E next() { - if (hasNext()) { - @SuppressWarnings("unchecked") - final E res = (E) odataClient.getBinder().getODataEntity(cached); - cached = null; - return res; - } - - throw new NoSuchElementException("No entity found"); - } - - /** - * Unsupported operation. - */ - @Override - public void remove() { - throw new UnsupportedOperationException("Operation not supported"); - } - - /** - * Closes the current iterator. - */ - public void close() { - IOUtils.closeQuietly(stream); - IOUtils.closeQuietly(osEntitySet); - } - - /** - * Gets the next link if exists. - * - * @return next link if exists; null otherwise. - */ - public URI getNext() { - if (entitySet == null) { - throw new IllegalStateException("Iteration must be completed in order to retrieve the link for next page"); - } - return entitySet.getNext(); - } - - private ResWrap<Entity> nextJSONEntityFromEntitySet(final InputStream input, final OutputStream osEntitySet) { - final ByteArrayOutputStream entity = new ByteArrayOutputStream(); - - ResWrap<Entity> jsonEntity = null; - try { - int c; - - boolean foundNewOne = false; - - do { - c = input.read(); - if (c == '{') { - entity.write(c); - c = -1; - foundNewOne = true; - } - if (c == ']') { - osEntitySet.write(c); - c = -1; - } - } while (c >= 0); - - if (foundNewOne) { - int count = 1; - c = 0; - - while (count > 0 && c >= 0) { - c = input.read(); - if (c == '{') { - count++; - } else if (c == '}') { - count--; - } - entity.write(c); - } - - if (c >= 0) { - jsonEntity = odataClient.getDeserializer(ODataFormat.JSON).toEntity( - new ByteArrayInputStream(entity.toByteArray())); - } - } else { - while ((c = input.read()) >= 0) { - osEntitySet.write(c); - } - } - } catch (Exception e) { - LOG.error("Error retrieving entities from EntitySet", e); - } - - return jsonEntity; - } - - private ResWrap<Entity> nextAtomEntityFromEntitySet( - final InputStream input, final OutputStream osEntitySet, final String namespaces) { - - final ByteArrayOutputStream entity = new ByteArrayOutputStream(); - - ResWrap<Entity> atomEntity = null; - - try { - if (consume(input, "<entry>", osEntitySet, false) >= 0) { - entity.write("<entry ".getBytes(Constants.UTF8)); - entity.write(namespaces.getBytes(Constants.UTF8)); - entity.write(">".getBytes(Constants.UTF8)); - - if (consume(input, "</entry>", entity, true) >= 0) { - atomEntity = odataClient.getDeserializer(ODataFormat.ATOM). - toEntity(new ByteArrayInputStream(entity.toByteArray())); - } - } - } catch (Exception e) { - LOG.error("Error retrieving entities from EntitySet", e); - } - - return atomEntity; - } - - private String getAllElementAttributes(final InputStream input, final String name, final OutputStream os) { - final ByteArrayOutputStream attrs = new ByteArrayOutputStream(); - - String res; - - try { - byte[] attrsDeclaration = null; - - final String key = "<" + name + " "; - if (consume(input, key, os, true) >= 0 && consume(input, ">", attrs, false) >= 0) { - attrsDeclaration = attrs.toByteArray(); - os.write(attrsDeclaration); - os.write('>'); - } - - res = attrsDeclaration == null - ? StringUtils.EMPTY - : new String(attrsDeclaration, Constants.UTF8).trim(); - } catch (Exception e) { - LOG.error("Error retrieving entities from EntitySet", e); - res = StringUtils.EMPTY; - } - - return res.endsWith("/") ? res.substring(0, res.length() - 1) : res; - } - - private int consume( - final InputStream input, final String end, final OutputStream os, final boolean includeEndKey) - throws IOException { - - final char[] endKey = end.toCharArray(); - final char[] endLowerKey = end.toLowerCase().toCharArray(); - final char[] endUpperKey = end.toUpperCase().toCharArray(); - - int pos = 0; - int c = 0; - while (pos < endKey.length && (c = input.read()) >= 0) { - if (c == endLowerKey[pos] || c == endUpperKey[pos]) { - pos++; - if (includeEndKey && os != null) { - os.write(c); - } - } else if (pos > 0) { - if (!includeEndKey && os != null) { - for (int i = 0; i < pos; i++) { - os.write(endKey[i]); - } - } - if (os != null) { - os.write(c); - } - pos = 0; - } else { - if (os != null) { - os.write(c); - } - } - } - - return c; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java index 8c5ccc4..7e4aa96 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/serialization/ODataReader.java @@ -24,7 +24,7 @@ import java.util.Map; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientServiceDocument; import org.apache.olingo.commons.api.edm.Edm; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java index f1cc64a..2008149 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java @@ -25,7 +25,7 @@ import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.ODataClientErrorException; import org.apache.olingo.client.api.communication.ODataServerErrorException; import org.apache.olingo.commons.api.ODataRuntimeException; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.slf4j.Logger; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java index 9c47b69..dcb31e9 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java @@ -25,7 +25,7 @@ import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; -import org.apache.olingo.client.api.domain.ODataEntitySetIterator; +import org.apache.olingo.client.api.domain.ClientEntitySetIterator; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; import org.apache.olingo.commons.api.format.ODataFormat; @@ -34,10 +34,10 @@ import org.apache.olingo.commons.api.format.ODataFormat; * This class implements an OData EntitySet query request. */ public class ODataEntitySetIteratorRequestImpl<ES extends ClientEntitySet, E extends ClientEntity> - extends AbstractODataRetrieveRequest<ODataEntitySetIterator<ES, E>> + extends AbstractODataRetrieveRequest<ClientEntitySetIterator<ES, E>> implements ODataEntitySetIteratorRequest<ES, E> { - private ODataEntitySetIterator<ES, E> entitySetIterator = null; + private ClientEntitySetIterator<ES, E> entitySetIterator = null; /** * Private constructor. @@ -55,7 +55,7 @@ public class ODataEntitySetIteratorRequestImpl<ES extends ClientEntitySet, E ext } @Override - public ODataRetrieveResponse<ODataEntitySetIterator<ES, E>> execute() { + public ODataRetrieveResponse<ClientEntitySetIterator<ES, E>> execute() { final HttpResponse res = doExecute(); return new ODataEntitySetIteratorResponseImpl(odataClient, httpClient, res); } @@ -72,9 +72,9 @@ public class ODataEntitySetIteratorRequestImpl<ES extends ClientEntitySet, E ext } @Override - public ODataEntitySetIterator<ES, E> getBody() { + public ClientEntitySetIterator<ES, E> getBody() { if (entitySetIterator == null) { - entitySetIterator = new ODataEntitySetIterator<ES, E>( + entitySetIterator = new ClientEntitySetIterator<ES, E>( odataClient, getRawResponse(), ODataFormat.fromString(getContentType())); } return entitySetIterator; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java index a668aaf..92bd57b 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ClientODataDeserializerImpl.java @@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.serialization.ODataDeserializer; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java index 8f3c8be..6c97cdb 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataReaderImpl.java @@ -25,7 +25,7 @@ import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.data.ServiceDocument; -import org.apache.olingo.client.api.domain.ODataEntitySetIterator; +import org.apache.olingo.client.api.domain.ClientEntitySetIterator; import org.apache.olingo.client.api.edm.xml.XMLMetadata; import org.apache.olingo.client.api.serialization.ODataReader; import org.apache.olingo.client.core.edm.ClientCsdlEdmProvider; @@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientEntity; import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.client.api.domain.ClientProperty; import org.apache.olingo.client.api.domain.ClientServiceDocument; import org.apache.olingo.client.api.domain.ClientValue; @@ -91,11 +91,11 @@ public class ODataReaderImpl implements ODataReader { ResWrap<T> res; try { - if (ODataEntitySetIterator.class.isAssignableFrom(reference)) { + if (ClientEntitySetIterator.class.isAssignableFrom(reference)) { res = new ResWrap<T>( (URI) null, null, - reference.cast(new ODataEntitySetIterator<ClientEntitySet, ClientEntity>( + reference.cast(new ClientEntitySetIterator<ClientEntitySet, ClientEntity>( client, src, ODataFormat.fromString(format)))); } else if (ClientEntitySet.class.isAssignableFrom(reference)) { final ResWrap<EntityCollection> resource = client.getDeserializer(ODataFormat.fromString(format)) @@ -149,7 +149,7 @@ public class ODataReaderImpl implements ODataReader { LOG.warn("Cast error", e); res = null; } finally { - if (!ODataEntitySetIterator.class.isAssignableFrom(reference)) { + if (!ClientEntitySetIterator.class.isAssignableFrom(reference)) { IOUtils.closeQuietly(src); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java index c0067bc..057c0de 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java @@ -20,7 +20,7 @@ package org.apache.olingo.client.core.v4; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java index e4778cb..562a255 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java @@ -273,7 +273,7 @@ public class MetadataTest extends AbstractTest { assertNotNull(weight); assertEquals(EdmInt32.getInstance(), weight.getUnderlyingType()); assertFalse(weight.getAnnotations().isEmpty()); - assertEquals("Kilograms", weight.getAnnotations().get(0).getExpression().asConstant().getValue().getValue()); + assertEquals("Kilograms", weight.getAnnotations().get(0).getExpression().asConstant().getValueAsString()); } /** http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataError.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataError.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataError.java new file mode 100644 index 0000000..9ac0a80 --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataError.java @@ -0,0 +1,132 @@ +/* + * 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; + +import java.util.List; +import java.util.Map; + +/** + * OData error. + */ +public class ODataError { + + private String code; + private String message; + private String target; + private List<ODataErrorDetail> details; + private Map<String, String> innerError; + + /** + * The value for the code name/value pair is a language-independent string. Its value is a service-defined error code. + * This code serves as a sub-status for the HTTP error code specified in the response. MAY be null. + * @return the error code as a string + */ + public String getCode() { + return code; + } + + /** + * The value for the code name/value pair is a language-independent string. Its value is a service-defined error code. + * This code serves as a sub-status for the HTTP error code specified in the response. MAY be null. + * @param code + * @return this for method chaining + */ + public ODataError setCode(String code) { + this.code = code; + return this; + } + + /** + * The value for the message name/value pair MUST be a human-readable, language-dependent representation of the error. + * MUST not be null + * @return the message string + */ + public String getMessage() { + return message; + } + + /** + * The value for the message name/value pair MUST be a human-readable, language-dependent representation of the error. + * MUST not be null + * @param message + * @return this for method chaining + */ + public ODataError setMessage(String message) { + this.message = message; + return this; + } + + /** + * The value for the target name/value pair is the target of the particular error (for example, the name of the + * property in error). MAY be null. + * @return the target string + */ + public String getTarget() { + return target; + } + + /** + * The value for the target name/value pair is the target of the particular error (for example, the name of the + * property in error). MAY be null. + * @param target + * @return this for method chaining + */ + public ODataError setTarget(String target) { + this.target = target; + return this; + } + + /** + * Gets error details. + * + * @return ODataErrorDetail list. + */ + public List<ODataErrorDetail> getDetails() { + return details; + } + + /** + * Sets error details. + * + * @return this for method chaining. + */ + public ODataError setDetails(List<ODataErrorDetail> details) { + this.details = details; + return this; + } + + /** + * Gets server defined key-value pairs for debug environment only. + * + * @return a pair representing server defined object. MAY be null. + */ + public Map<String, String> getInnerError() { + return innerError; + } + + /** + * Sets server defined key-value pairs for debug environment only. + * + * @return this for method chaining. + */ + public ODataError setInnerError(Map<String, String> innerError) { + this.innerError = innerError; + return this; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataErrorDetail.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataErrorDetail.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataErrorDetail.java new file mode 100644 index 0000000..f8b1fa5 --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataErrorDetail.java @@ -0,0 +1,73 @@ +/* + * 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; + +/** + * OData detailsï¼ for example <tt>{ "error": {..., "details":[ + * {"code": "301","target": "$search" ,"message": "$search query option not supported"} + * ],...}}</tt>. + */ +public class ODataErrorDetail { + + private String code; + private String message; + private String target; + + /** + * Gets error code. + * + * @return error code. + */ + public String getCode() { + return code; + } + + public ODataErrorDetail setCode(final String code) { + this.code = code; + return this; + } + + /** + * Gets error message. + * + * @return error message. + */ + public String getMessage() { + return message; + } + + public ODataErrorDetail setMessage(final String message) { + this.message = message; + return this; + } + + /** + * Gets error target. + * + * @return error message. + */ + public String getTarget() { + return target; + } + + public ODataErrorDetail setTarget(final String target) { + this.target = target; + return this; + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataPropertyType.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataPropertyType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataPropertyType.java new file mode 100644 index 0000000..94c9fb0 --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ODataPropertyType.java @@ -0,0 +1,44 @@ +/* + * 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; + +public enum ODataPropertyType { + + /** + * Primitive (including geospatial). + */ + PRIMITIVE, + /** + * Enum. + */ + ENUM, + /** + * Collection. + */ + COLLECTION, + /** + * Complex. + */ + COMPLEX, + /** + * Empty type (possibly, no type information could be retrieved). + */ + EMPTY + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataError.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataError.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataError.java deleted file mode 100644 index a910f08..0000000 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataError.java +++ /dev/null @@ -1,132 +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; - -import java.util.List; -import java.util.Map; - -/** - * OData error. - */ -public class ODataError { - - private String code; - private String message; - private String target; - private List<ODataErrorDetail> details; - private Map<String, String> innerError; - - /** - * The value for the code name/value pair is a language-independent string. Its value is a service-defined error code. - * This code serves as a sub-status for the HTTP error code specified in the response. MAY be null. - * @return the error code as a string - */ - public String getCode() { - return code; - } - - /** - * The value for the code name/value pair is a language-independent string. Its value is a service-defined error code. - * This code serves as a sub-status for the HTTP error code specified in the response. MAY be null. - * @param code - * @return this for method chaining - */ - public ODataError setCode(String code) { - this.code = code; - return this; - } - - /** - * The value for the message name/value pair MUST be a human-readable, language-dependent representation of the error. - * MUST not be null - * @return the message string - */ - public String getMessage() { - return message; - } - - /** - * The value for the message name/value pair MUST be a human-readable, language-dependent representation of the error. - * MUST not be null - * @param message - * @return this for method chaining - */ - public ODataError setMessage(String message) { - this.message = message; - return this; - } - - /** - * The value for the target name/value pair is the target of the particular error (for example, the name of the - * property in error). MAY be null. - * @return the target string - */ - public String getTarget() { - return target; - } - - /** - * The value for the target name/value pair is the target of the particular error (for example, the name of the - * property in error). MAY be null. - * @param target - * @return this for method chaining - */ - public ODataError setTarget(String target) { - this.target = target; - return this; - } - - /** - * Gets error details. - * - * @return ODataErrorDetail list. - */ - public List<ODataErrorDetail> getDetails() { - return details; - } - - /** - * Sets error details. - * - * @return this for method chaining. - */ - public ODataError setDetails(List<ODataErrorDetail> details) { - this.details = details; - return this; - } - - /** - * Gets server defined key-value pairs for debug environment only. - * - * @return a pair representing server defined object. MAY be null. - */ - public Map<String, String> getInnerError() { - return innerError; - } - - /** - * Sets server defined key-value pairs for debug environment only. - * - * @return this for method chaining. - */ - public ODataError setInnerError(Map<String, String> innerError) { - this.innerError = innerError; - return this; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataErrorDetail.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataErrorDetail.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataErrorDetail.java deleted file mode 100644 index 573525d..0000000 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataErrorDetail.java +++ /dev/null @@ -1,73 +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; - -/** - * OData detailsï¼ for example <tt>{ "error": {..., "details":[ - * {"code": "301","target": "$search" ,"message": "$search query option not supported"} - * ],...}}</tt>. - */ -public class ODataErrorDetail { - - private String code; - private String message; - private String target; - - /** - * Gets error code. - * - * @return error code. - */ - public String getCode() { - return code; - } - - public ODataErrorDetail setCode(final String code) { - this.code = code; - return this; - } - - /** - * Gets error message. - * - * @return error message. - */ - public String getMessage() { - return message; - } - - public ODataErrorDetail setMessage(final String message) { - this.message = message; - return this; - } - - /** - * Gets error target. - * - * @return error message. - */ - public String getTarget() { - return target; - } - - public ODataErrorDetail setTarget(final String target) { - this.target = target; - return this; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java deleted file mode 100644 index e7b5b85..0000000 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataPropertyType.java +++ /dev/null @@ -1,44 +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 enum ODataPropertyType { - - /** - * Primitive (including geospatial). - */ - PRIMITIVE, - /** - * Enum. - */ - ENUM, - /** - * Collection. - */ - COLLECTION, - /** - * Complex. - */ - COMPLEX, - /** - * Empty type (possibly, no type information could be retrieved). - */ - EMPTY - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantAnnotationExpression.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantAnnotationExpression.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantAnnotationExpression.java index 0f0a34f..11fbe5f 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantAnnotationExpression.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/annotation/EdmConstantAnnotationExpression.java @@ -24,4 +24,5 @@ public interface EdmConstantAnnotationExpression extends EdmAnnotationExpression Valuable getValue(); + String getValueAsString(); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-api/src/main/java/org/apache/olingo/commons/api/serialization/ODataDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/serialization/ODataDeserializer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/serialization/ODataDeserializer.java index 8e313b1..21bcbe5 100755 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/serialization/ODataDeserializer.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/serialization/ODataDeserializer.java @@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.domain.ODataError; +import org.apache.olingo.commons.api.ODataError; import java.io.InputStream; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java index 9763596..cc9f4fb 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmConstantAnnotationExpressionImpl.java @@ -55,7 +55,7 @@ public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotatio for (Property enumValue : enumValues) { collValue.add(enumValue); } - value = new Property(enumTypeName, "name", ValueType.COLLECTION_ENUM, collValue); + value = new Property(enumTypeName, null, ValueType.COLLECTION_ENUM, collValue); } type = null; } else { @@ -95,27 +95,13 @@ public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotatio default: kind = EdmPrimitiveTypeKind.String; } -// final ClientPrimitiveValueImpl.BuilderImpl primitiveValueBuilder = new ClientPrimitiveValueImpl.BuilderImpl(); -// primitiveValueBuilder.setType(kind); -// try { -// final EdmPrimitiveType type = EdmPrimitiveTypeFactory.getInstance(kind); -// primitiveValueBuilder.setValue( -// type.valueOfString(constExprConstruct.getValue(), -// null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, -// type.getDefaultType())); -// } catch (final EdmPrimitiveTypeException e) { -// throw new IllegalArgumentException(e); -// } -// -// value = primitiveValueBuilder.build(); - type = EdmPrimitiveTypeFactory.getInstance(kind); try { - Object test = type.valueOfString(constExprConstruct.getValue(), + final Object valueOfString = type.valueOfString(constExprConstruct.getValue(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, type.getDefaultType()); value = new Property(kind.getFullQualifiedName().getFullQualifiedNameAsString(), - "name", ValueType.PRIMITIVE, test); + null, ValueType.PRIMITIVE, valueOfString); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException(e); } @@ -147,7 +133,8 @@ public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotatio return value; } - public String toString() { + @Override + public String getValueAsString() { if (value == null) { return ""; } else if(value.isEnum()) { @@ -164,5 +151,4 @@ public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotatio } } } - } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java index 6b4b72c..f2faaa9 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java @@ -51,8 +51,8 @@ import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.data.Valuable; import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataPropertyType; +import org.apache.olingo.commons.api.ODataError; +import org.apache.olingo.commons.api.ODataPropertyType; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java index 1047bdf..2c13d35 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java @@ -43,8 +43,8 @@ import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.data.Valuable; import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataPropertyType; +import org.apache.olingo.commons.api.ODataError; +import org.apache.olingo.commons.api.ODataPropertyType; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java index 89252dc..8679c6e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java @@ -25,8 +25,8 @@ import java.util.Iterator; import java.util.List; import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; +import org.apache.olingo.commons.api.ODataError; +import org.apache.olingo.commons.api.ODataErrorDetail; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonNode; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDetailDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDetailDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDetailDeserializer.java index 138bad3..a4a5ec9 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDetailDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDetailDeserializer.java @@ -23,7 +23,7 @@ import java.net.URI; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; +import org.apache.olingo.commons.api.ODataErrorDetail; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonNode; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/server-api/src/main/java/org/apache/olingo/server/api/ClientServerError.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ClientServerError.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ClientServerError.java index 6bbde22..af91875 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ClientServerError.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ClientServerError.java @@ -22,8 +22,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; +import org.apache.olingo.commons.api.ODataError; +import org.apache.olingo.commons.api.ODataErrorDetail; /** * Server error. http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java index 14381bb..70d6364 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializer.java @@ -21,8 +21,8 @@ package org.apache.olingo.server.core.serializer.json; import java.io.IOException; import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; +import org.apache.olingo.commons.api.ODataError; +import org.apache.olingo.commons.api.ODataErrorDetail; import org.apache.olingo.server.api.serializer.SerializerException; import com.fasterxml.jackson.core.JsonGenerator; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61500e68/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java index adf0eb4..7c72e45 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java @@ -26,7 +26,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; +import org.apache.olingo.commons.api.ODataErrorDetail; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ClientServerError;
