diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java index e17bfdff7..7fac96cd7 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/AbstractService.java @@ -84,7 +84,7 @@ public abstract class AbstractService { IOUtils.closeQuietly(bais); } - final Edm edm = metadata == null ? null : new EdmClientImpl(version, metadata.getSchemaByNsOrAlias()); + final Edm edm = metadata == null ? null : new EdmClientImpl(metadata.getSchemaByNsOrAlias()); //TODO: check runtime exception or not if(version.compareTo(ODataServiceVersion.V40) < 0){ throw new ODataRuntimeException("Only OData V4 or higher supported."); diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java index 77e3478cd..424789f72 100644 --- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java +++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java @@ -149,10 +149,10 @@ public abstract class AbstractServices { this.version = version; this.metadata = metadata; - atomDeserializer = new FITAtomDeserializer(version); - jsonDeserializer = new JsonDeserializer(version, true); - atomSerializer = new AtomSerializer(version, true); - jsonSerializer = new JsonSerializer(version, true); + atomDeserializer = new FITAtomDeserializer(); + jsonDeserializer = new JsonDeserializer(true); + atomSerializer = new AtomSerializer(true); + jsonSerializer = new JsonSerializer(true); xml = new XMLUtilities(version, metadata); json = new JSONUtilities(version, metadata); @@ -1827,7 +1827,7 @@ public abstract class AbstractServices { } private String stringValue(final Property property) { - EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOfFQN(version, property.getType()); + EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOfFQN(property.getType()); try { return EdmPrimitiveTypeFactory.getInstance(kind) .valueToString(property.asPrimitive(), null, null, diff --git a/fit/src/main/java/org/apache/olingo/fit/serializer/FITAtomDeserializer.java b/fit/src/main/java/org/apache/olingo/fit/serializer/FITAtomDeserializer.java index bf932f715..f667d93f5 100644 --- a/fit/src/main/java/org/apache/olingo/fit/serializer/FITAtomDeserializer.java +++ b/fit/src/main/java/org/apache/olingo/fit/serializer/FITAtomDeserializer.java @@ -18,24 +18,24 @@ */ package org.apache.olingo.fit.serializer; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.core.serialization.AtomDeserializer; - -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLStreamException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLStreamException; + +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.core.serialization.AtomDeserializer; + public class FITAtomDeserializer extends AtomDeserializer { private static final Charset ENCODING = Charset.forName(Constants.UTF8); - public FITAtomDeserializer(final ODataServiceVersion version) { - super(version); + public FITAtomDeserializer() { + super(); } @Override diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java index 8305eda54..f8cab0896 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java @@ -103,10 +103,10 @@ public abstract class AbstractUtilities { this.version = version; this.metadata = metadata; fsManager = FSManager.instance(version); - atomDeserializer = new FITAtomDeserializer(version); - jsonDeserializer = new JsonDeserializer(version, true); - atomSerializer = new AtomSerializer(version, true); - jsonSerializer = new JsonSerializer(version, true); + atomDeserializer = new FITAtomDeserializer(); + jsonDeserializer = new JsonDeserializer(true); + atomSerializer = new AtomSerializer(true); + jsonSerializer = new JsonSerializer(true); } public boolean isMediaContent(final String entityName) { @@ -123,8 +123,8 @@ public abstract class AbstractUtilities { * @return */ protected abstract InputStream addLinks( - final String entitySetName, final String entitykey, final InputStream is, final Set links) - throws Exception; + final String entitySetName, final String entitykey, final InputStream is, final Set links) + throws Exception; /** * Retrieve all entity link names. @@ -144,7 +144,7 @@ public abstract class AbstractUtilities { * @return */ protected abstract NavigationLinks retrieveNavigationInfo(final String entitySetName, final InputStream is) - throws Exception; + throws Exception; /** * Normalize navigation info and add edit link if missing. @@ -156,20 +156,20 @@ public abstract class AbstractUtilities { * @return */ protected abstract InputStream normalizeLinks( - final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links) - throws Exception; + final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links) + throws Exception; public InputStream saveSingleEntity( - final String key, - final String entitySetName, - final InputStream is, - final NavigationLinks links) throws Exception { + final String key, + final String entitySetName, + final InputStream is, + final NavigationLinks links) throws Exception { // ----------------------------------------- // 0. Get the path // ----------------------------------------- final String path = - entitySetName + File.separatorChar + Commons.getEntityKey(key) + File.separatorChar + entitySetName + File.separatorChar + Commons.getEntityKey(key) + File.separatorChar + Constants.get(version, ConstantKey.ENTITY); // ----------------------------------------- @@ -196,10 +196,10 @@ public abstract class AbstractUtilities { } public InputStream addOrReplaceEntity( - final String key, - final String entitySetName, - final InputStream is, - final Entity entry) throws Exception { + final String key, + final String entitySetName, + final InputStream is, + final Entity entry) throws Exception { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(is, bos); @@ -214,7 +214,7 @@ public abstract class AbstractUtilities { try { linksToBeKept = new HashSet(navigationProperties.keySet()); } catch (NullPointerException e) { - linksToBeKept = Collections.emptySet(); + linksToBeKept = Collections. emptySet(); } for (String availableLink : new HashSet(linksToBeKept)) { @@ -248,7 +248,7 @@ public abstract class AbstractUtilities { // 3. Normalize navigation info; add edit link; ... and save entity .... // ----------------------------------------- final InputStream createdEntity = saveSingleEntity( - entityKey, entitySetName, new ByteArrayInputStream(bos.toByteArray()), links); + entityKey, entitySetName, new ByteArrayInputStream(bos.toByteArray()), links); // ----------------------------------------- bos.reset(); @@ -258,7 +258,7 @@ public abstract class AbstractUtilities { // 4. Add navigation links to be kept // ----------------------------------------- final InputStream normalizedEntity = - addLinks(entitySetName, entityKey, new ByteArrayInputStream(bos.toByteArray()), linksToBeKept); + addLinks(entitySetName, entityKey, new ByteArrayInputStream(bos.toByteArray()), linksToBeKept); // ----------------------------------------- IOUtils.closeQuietly(bos); @@ -267,8 +267,8 @@ public abstract class AbstractUtilities { // 5. save the entity // ----------------------------------------- final FileObject fo = fsManager.putInMemory( - normalizedEntity, - fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), getDefaultFormat())); + normalizedEntity, + fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), getDefaultFormat())); // ----------------------------------------- // ----------------------------------------- @@ -282,17 +282,17 @@ public abstract class AbstractUtilities { for (final Link link : entry.getNavigationLinks()) { final NavigationProperty navProp = - navigationProperties == null ? null : navigationProperties.get(link.getTitle()); + navigationProperties == null ? null : navigationProperties.get(link.getTitle()); if (navProp != null) { final String inlineEntitySetName = navProp.getTarget(); if (link.getInlineEntity() != null) { final String inlineEntryKey = getDefaultEntryKey(inlineEntitySetName, link.getInlineEntity()); addOrReplaceEntity( - inlineEntryKey, - inlineEntitySetName, - toInputStream(link.getInlineEntity()), - link.getInlineEntity()); + inlineEntryKey, + inlineEntitySetName, + toInputStream(link.getInlineEntity()), + link.getInlineEntity()); hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")"); } else if (link.getInlineEntitySet() != null) { @@ -300,10 +300,10 @@ public abstract class AbstractUtilities { final String inlineEntryKey = getDefaultEntryKey(inlineEntitySetName, subentry); addOrReplaceEntity( - inlineEntryKey, - inlineEntitySetName, - toInputStream(subentry), - subentry); + inlineEntryKey, + inlineEntitySetName, + toInputStream(subentry), + subentry); hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")"); } @@ -320,9 +320,9 @@ public abstract class AbstractUtilities { } public void addMediaEntityValue( - final String entitySetName, - final String entityKey, - final InputStream is) throws Exception { + final String entitySetName, + final String entityKey, + final InputStream is) throws Exception { // ----------------------------------------- // 0. Get default entry key and path (N.B. operation will consume/close the stream; use a copy instead) @@ -334,17 +334,17 @@ public abstract class AbstractUtilities { // 1. save the media entity value // ----------------------------------------- fsManager.putInMemory(is, fsManager.getAbsolutePath(path - + Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME), null)); + + Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME), null)); IOUtils.closeQuietly(is); // ----------------------------------------- } public void putLinksInMemory( - final String basePath, - final String entitySetName, - final String entityKey, - final String linkName, - final Collection links) throws Exception { + final String basePath, + final String entitySetName, + final String entityKey, + final String linkName, + final Collection links) throws Exception { final HashSet uris = new HashSet(); @@ -355,8 +355,7 @@ public abstract class AbstractUtilities { try { final Map.Entry> currents = extractLinkURIs(entitySetName, entityKey, linkName); uris.addAll(currents.getValue()); - } catch (Exception ignore) { - } + } catch (Exception ignore) {} } uris.addAll(links); @@ -365,20 +364,20 @@ public abstract class AbstractUtilities { } public void putLinksInMemory( - final String basePath, final String entitySetName, final String linkName, final Collection uris) - throws Exception { + final String basePath, final String entitySetName, final String linkName, final Collection uris) + throws Exception { fsManager.putInMemory( - Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry>(linkName, uris)), - Commons.getLinksPath(version, basePath, linkName, Accept.JSON_FULLMETA)); + Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry>(linkName, uris)), + Commons.getLinksPath(version, basePath, linkName, Accept.JSON_FULLMETA)); fsManager.putInMemory( - Commons.getLinksAsATOM(version, new SimpleEntry>(linkName, uris)), - Commons.getLinksPath(version, basePath, linkName, Accept.XML)); + Commons.getLinksAsATOM(version, new SimpleEntry>(linkName, uris)), + Commons.getLinksPath(version, basePath, linkName, Accept.XML)); } public Response createResponse( - final String location, final InputStream entity, final String etag, final Accept accept) { + final String location, final InputStream entity, final String etag, final Accept accept) { return createResponse(location, entity, etag, accept, null); } @@ -413,26 +412,26 @@ public abstract class AbstractUtilities { public Response createBatchResponse(final InputStream stream) { final Response.ResponseBuilder builder = version.compareTo(ODataServiceVersion.V30) <= 0 - ? Response.accepted(stream) - : Response.ok(stream); + ? Response.accepted(stream) + : Response.ok(stream); builder.header(Constants.get(version, ConstantKey.ODATA_SERVICE_VERSION), version.toString() + ";"); return builder.build(); } public Response createResponse( - final InputStream entity, - final String etag, - final Accept accept, - final Response.Status status) { + final InputStream entity, + final String etag, + final Accept accept, + final Response.Status status) { return createResponse(null, entity, etag, accept, status); } public Response createResponse( - final String location, - final InputStream entity, - final String etag, - final Accept accept, - final Response.Status status) { + final String location, + final InputStream entity, + final String etag, + final Accept accept, + final Response.Status status) { final Response.ResponseBuilder builder = Response.ok(); if (version.compareTo(ODataServiceVersion.V30) <= 0) { @@ -527,14 +526,14 @@ public abstract class AbstractUtilities { } public EntitySet readEntitySet(final Accept accept, final InputStream entitySet) - throws ODataDeserializerException { + throws ODataDeserializerException { return (accept == Accept.ATOM || accept == Accept.XML ? atomDeserializer.toEntitySet(entitySet) : jsonDeserializer. - toEntitySet(entitySet)) - .getPayload(); + toEntitySet(entitySet)) + .getPayload(); } public InputStream writeEntitySet(final Accept accept, final ResWrap container) - throws ODataSerializerException, IOException { + throws ODataSerializerException, IOException { final StringWriter writer = new StringWriter(); if (accept == Accept.ATOM || accept == Accept.XML) { @@ -549,19 +548,19 @@ public abstract class AbstractUtilities { } public ResWrap readContainerEntity(final Accept accept, final InputStream entity) - throws ODataDeserializerException { + throws ODataDeserializerException { return accept == Accept.ATOM || accept == Accept.XML - ? atomDeserializer.toEntity(entity) - : jsonDeserializer.toEntity(entity); + ? atomDeserializer.toEntity(entity) + : jsonDeserializer.toEntity(entity); } public Entity readEntity(final Accept accept, final InputStream entity) - throws IOException, ODataDeserializerException { + throws IOException, ODataDeserializerException { return readContainerEntity(accept, entity).getPayload(); } public InputStream writeEntity(final Accept accept, final ResWrap container) - throws ODataSerializerException { + throws ODataSerializerException { StringWriter writer = new StringWriter(); if (accept == Accept.ATOM || accept == Accept.XML) { @@ -574,7 +573,7 @@ public abstract class AbstractUtilities { } public InputStream writeProperty(final Accept accept, final Property property) - throws ODataSerializerException { + throws ODataSerializerException { final StringWriter writer = new StringWriter(); if (accept == Accept.XML || accept == Accept.ATOM) { @@ -588,12 +587,12 @@ public abstract class AbstractUtilities { public Property readProperty(final Accept accept, final InputStream property) throws ODataDeserializerException { return (Accept.ATOM == accept || Accept.XML == accept ? atomDeserializer.toProperty(property) : jsonDeserializer. - toProperty(property)) - .getPayload(); + toProperty(property)) + .getPayload(); } public InputStream writeProperty(final Accept accept, final ResWrap container) - throws ODataSerializerException { + throws ODataSerializerException { final StringWriter writer = new StringWriter(); if (accept == Accept.XML || accept == Accept.ATOM) { @@ -606,7 +605,7 @@ public abstract class AbstractUtilities { } private String getDefaultEntryKey(final String entitySetName, final Entity entry, final String propertyName) - throws IOException { + throws IOException { String res; if (entry.getProperty(propertyName) == null) { @@ -639,7 +638,7 @@ public abstract class AbstractUtilities { } else { productID = (Integer) entity.getProperty("OrderID").asPrimitive(); res = "OrderID=" + entity.getProperty("OrderID").asPrimitive() - + ",ProductID=" + entity.getProperty("ProductID").asPrimitive(); + + ",ProductID=" + entity.getProperty("ProductID").asPrimitive(); } Commons.SEQUENCE.put(entitySetName, productID); } else if ("Message".equals(entitySetName)) { @@ -654,7 +653,7 @@ public abstract class AbstractUtilities { } else { messageId = (Integer) entity.getProperty("MessageId").asPrimitive(); res = "FromUsername=" + entity.getProperty("FromUsername").asPrimitive() - + ",MessageId=" + entity.getProperty("MessageId").asPrimitive(); + + ",MessageId=" + entity.getProperty("MessageId").asPrimitive(); } Commons.SEQUENCE.put(entitySetName, messageId); } else if ("PersonDetails".equals(entitySetName)) { @@ -701,7 +700,7 @@ public abstract class AbstractUtilities { productId = (Integer) entity.getProperty("ProductID").asPrimitive(); productDetailId = (Integer) entity.getProperty("ProductDetailID").asPrimitive(); res = "ProductID=" + entity.getProperty("ProductID").asPrimitive() - + ",ProductDetailID=" + entity.getProperty("ProductDetailID").asPrimitive(); + + ",ProductDetailID=" + entity.getProperty("ProductDetailID").asPrimitive(); } Commons.SEQUENCE.put(entitySetName, productDetailId); Commons.SEQUENCE.put("Products", productId); @@ -723,7 +722,7 @@ public abstract class AbstractUtilities { public String getLinksBasePath(final String entitySetName, final String entityId) { return entitySetName + File.separatorChar + Commons.getEntityKey(entityId) + File.separatorChar - + Constants.get(version, ConstantKey.LINKS_FILE_PATH) + File.separatorChar; + + Constants.get(version, ConstantKey.LINKS_FILE_PATH) + File.separatorChar; } /** @@ -736,8 +735,8 @@ public abstract class AbstractUtilities { * @return a pair of ETag/links stream */ public LinkInfo readLinks( - final String entitySetName, final String entityId, final String linkName, final Accept accept) - throws Exception { + final String entitySetName, final String entityId, final String linkName, final Accept accept) + throws Exception { final String basePath = getLinksBasePath(entitySetName, entityId); @@ -751,16 +750,16 @@ public abstract class AbstractUtilities { } public InputStream putMediaInMemory( - final String entitySetName, final String entityId, final InputStream value) - throws IOException { + final String entitySetName, final String entityId, final InputStream value) + throws IOException { return putMediaInMemory(entitySetName, entityId, null, value); } public InputStream putMediaInMemory( - final String entitySetName, final String entityId, final String name, final InputStream value) - throws IOException { + final String entitySetName, final String entityId, final String name, final InputStream value) + throws IOException { final FileObject fo = fsManager.putInMemory(value, fsManager.getAbsolutePath( - Commons.getEntityBasePath(entitySetName, entityId) + Commons.getEntityBasePath(entitySetName, entityId) + (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name), null)); return fo.getContent().getInputStream(); @@ -771,14 +770,14 @@ public abstract class AbstractUtilities { } public Map.Entry readMediaEntity( - final String entitySetName, final String entityId, final String name) { + final String entitySetName, final String entityId, final String name) { final String basePath = Commons.getEntityBasePath(entitySetName, entityId); return new SimpleEntry(basePath, fsManager.readFile(basePath - + (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name))); + + (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name))); } public Map.Entry readEntity( - final String entitySetName, final String entityId, final Accept accept) { + final String entitySetName, final String entityId, final Accept accept) { if (accept == Accept.XML || accept == Accept.TEXT) { throw new UnsupportedMediaTypeException("Unsupported media type"); @@ -786,14 +785,14 @@ public abstract class AbstractUtilities { final String basePath = Commons.getEntityBasePath(entitySetName, entityId); return new SimpleEntry(basePath, - fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), accept)); + fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), accept)); } public InputStream expandEntity( - final String entitySetName, - final String entityId, - final String linkName) - throws Exception { + final String entitySetName, + final String entityId, + final String linkName) + throws Exception { // -------------------------------- // 0. Retrieve all 'linkName' navigation link uris (NotFoundException if missing) @@ -807,18 +806,18 @@ public abstract class AbstractUtilities { final Map navigationProperties = metadata.getNavigationProperties(entitySetName); return readEntities( - links.getValue(), - linkName, - links.getKey(), - navigationProperties.get(linkName).isEntitySet()); + links.getValue(), + linkName, + links.getKey(), + navigationProperties.get(linkName).isEntitySet()); } public InputStream expandEntity( - final String entitySetName, - final String entityId, - final InputStream entity, - final String linkName) - throws Exception { + final String entitySetName, + final String entityId, + final InputStream entity, + final String linkName) + throws Exception { // -------------------------------- // 2. Retrieve expanded object (entry or feed) // -------------------------------- @@ -827,14 +826,14 @@ public abstract class AbstractUtilities { } public InputStream deleteProperty( - final String entitySetName, - final String entityId, - final List path, - final Accept accept) throws Exception { + final String entitySetName, + final String entityId, + final List path, + final Accept accept) throws Exception { final String basePath = Commons.getEntityBasePath(entitySetName, entityId); final Accept acceptType = accept == null || Accept.TEXT == accept - ? Accept.XML : accept.getExtension().equals(Accept.JSON.getExtension()) ? Accept.JSON_FULLMETA : accept; + ? Accept.XML : accept.getExtension().equals(Accept.JSON.getExtension()) ? Accept.JSON_FULLMETA : accept; // read atom InputStream stream = fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType); @@ -844,44 +843,44 @@ public abstract class AbstractUtilities { // save atom fsManager.putInMemory(stream, - fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType)); + fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType)); return fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType); } public abstract InputStream readEntities( - final List links, final String linkName, final String next, final boolean forceFeed) - throws Exception; + final List links, final String linkName, final String next, final boolean forceFeed) + throws Exception; protected abstract InputStream replaceLink( - final InputStream toBeChanged, final String linkName, final InputStream replacement) - throws Exception; + final InputStream toBeChanged, final String linkName, final InputStream replacement) + throws Exception; public abstract InputStream selectEntity(final InputStream entity, final String[] propertyNames) - throws Exception; + throws Exception; protected abstract Accept getDefaultFormat(); protected abstract Map getChanges(final InputStream src) throws Exception; public abstract InputStream addEditLink( - final InputStream content, final String title, final String href) throws Exception; + final InputStream content, final String title, final String href) throws Exception; public abstract InputStream addOperation( - final InputStream content, final String name, final String metaAnchor, final String href) - throws Exception; + final InputStream content, final String name, final String metaAnchor, final String href) + throws Exception; protected abstract InputStream replaceProperty( - final InputStream src, final InputStream replacement, final List path, final boolean justValue) - throws Exception; + final InputStream src, final InputStream replacement, final List path, final boolean justValue) + throws Exception; protected abstract InputStream deleteProperty(final InputStream src, final List path) - throws Exception; + throws Exception; public abstract Map.Entry> extractLinkURIs(final InputStream is) - throws Exception; + throws Exception; public abstract Map.Entry> extractLinkURIs( - final String entitySetName, final String entityId, final String linkName) - throws Exception; + final String entitySetName, final String entityId, final String linkName) + throws Exception; } diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java index dc8e105e3..158807cdf 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java @@ -118,13 +118,13 @@ public class FSManager { ByteArrayOutputStream content = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); - new AtomSerializer(version, true).write(writer, container); + new AtomSerializer(true).write(writer, container); writer.flush(); putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.ATOM)); content.reset(); - new JsonSerializer(version, true).write(writer, container); + new JsonSerializer(true).write(writer, container); writer.flush(); putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.JSON_FULLMETA)); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java index a01ccfb71..bd9282f7f 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientImpl.java @@ -126,14 +126,14 @@ public class ODataClientImpl implements ODataClient { @Override public ClientODataDeserializer getDeserializer(final ODataFormat format) { - return new ClientODataDeserializerImpl(getServiceVersion(), false, format); + return new ClientODataDeserializerImpl(false, format); } @Override public ODataSerializer getSerializer(final ODataFormat format) { return format == ODataFormat.ATOM || format == ODataFormat.XML ? - new AtomSerializer(getServiceVersion()) : - new JsonSerializer(getServiceVersion(), false, format); + new AtomSerializer() : + new JsonSerializer(false, format); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java index fc9b27edd..4d3e83c4d 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java @@ -27,7 +27,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.data.ServiceDocument; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.core.serialization.JsonDeserializer; @@ -39,8 +38,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode; public class JSONServiceDocumentDeserializer extends JsonDeserializer { - public JSONServiceDocumentDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JSONServiceDocumentDeserializer(final boolean serverMode) { + super(serverMode); } protected ResWrap doDeserialize(final JsonParser parser) throws IOException { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java index ee67b5eeb..0b3772290 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java @@ -25,7 +25,6 @@ import java.net.URI; import org.apache.olingo.client.api.data.ServiceDocument; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.core.serialization.JsonDeserializer; @@ -36,8 +35,8 @@ import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser; public class XMLServiceDocumentDeserializer extends JsonDeserializer { - public XMLServiceDocumentDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public XMLServiceDocumentDeserializer(final boolean serverMode) { + super(serverMode); } private String getName(final JsonParser jp) throws IOException { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java index 4a445ab04..f60898409 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java @@ -57,21 +57,16 @@ import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.EdmTerm; import org.apache.olingo.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.AbstractEdm; import org.apache.olingo.commons.core.edm.EdmTypeInfo; public class EdmClientImpl extends AbstractEdm { - private final ODataServiceVersion version; - private final List xmlSchemas; private final Map xmlSchemaByNamespace; - public EdmClientImpl(final ODataServiceVersion version, final Map xmlSchemas) { - this.version = version; - + public EdmClientImpl(final Map xmlSchemas) { this.xmlSchemaByNamespace = xmlSchemas; this.xmlSchemas = new ArrayList(); @@ -100,7 +95,7 @@ public class EdmClientImpl extends AbstractEdm { protected Map createSchemas() { final Map _schemas = new LinkedHashMap(xmlSchemas.size()); for (Schema schema : xmlSchemas) { - _schemas.put(schema.getNamespace(), new EdmSchemaImpl(version, this, xmlSchemas, schema)); + _schemas.put(schema.getNamespace(), new EdmSchemaImpl(this, xmlSchemas, schema)); } return _schemas; } @@ -128,7 +123,7 @@ public class EdmClientImpl extends AbstractEdm { if (schema != null) { final EnumType xmlEnumType = schema.getEnumType(enumName.getName()); if (xmlEnumType != null) { - result = new EdmEnumTypeImpl(version, this, enumName, xmlEnumType); + result = new EdmEnumTypeImpl(this, enumName, xmlEnumType); } } @@ -144,7 +139,7 @@ public class EdmClientImpl extends AbstractEdm { final TypeDefinition xmlTypeDefinition = ((Schema) schema). getTypeDefinition(typeDefinitionName.getName()); if (xmlTypeDefinition != null) { - result = new EdmTypeDefinitionImpl(version, this, typeDefinitionName, xmlTypeDefinition); + result = new EdmTypeDefinitionImpl(this, typeDefinitionName, xmlTypeDefinition); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEnumTypeImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEnumTypeImpl.java index 5b861d7f6..297aecaaa 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEnumTypeImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEnumTypeImpl.java @@ -34,7 +34,6 @@ import org.apache.olingo.commons.api.edm.EdmMember; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.AbstractEdmEnumType; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; @@ -54,7 +53,7 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType { private final Map members; - public EdmEnumTypeImpl(final ODataServiceVersion version, final Edm edm, final FullQualifiedName fqn, + public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName fqn, final EnumType xmlEnumType) { super(edm, fqn, xmlEnumType.isFlags()); @@ -63,7 +62,7 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType { this.underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32); } else { final EdmPrimitiveTypeKind underlyingTipeKind = - EdmPrimitiveTypeKind.valueOfFQN(version, xmlEnumType.getUnderlyingType()); + EdmPrimitiveTypeKind.valueOfFQN(xmlEnumType.getUnderlyingType()); if (!ArrayUtils.contains(VALID_UNDERLYING_TYPES, underlyingTipeKind)) { throw new EdmException("Not allowed as underlying type: " + underlyingTipeKind); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java index e6f0f7d4b..0cc1ca653 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java @@ -46,12 +46,10 @@ import org.apache.olingo.commons.api.edm.EdmFunction; import org.apache.olingo.commons.api.edm.EdmTerm; import org.apache.olingo.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.AbstractEdmSchema; public class EdmSchemaImpl extends AbstractEdmSchema { - private final ODataServiceVersion version; private final Edm edm; @@ -63,12 +61,10 @@ public class EdmSchemaImpl extends AbstractEdmSchema { private List entityContainers; - public EdmSchemaImpl(final ODataServiceVersion version, final Edm edm, - final List xmlSchemas, final Schema schema) { + public EdmSchemaImpl(final Edm edm, final List xmlSchemas, final Schema schema) { super(schema.getNamespace(), schema.getAlias()); - this.version = version; this.edm = edm; this.xmlSchemas = xmlSchemas; this.schema = schema; @@ -133,7 +129,7 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (providerTypeDefinitions != null) { for (TypeDefinition def : providerTypeDefinitions) { typeDefinitions.add( - new EdmTypeDefinitionImpl(version, edm, new FullQualifiedName(namespace, def.getName()), def)); + new EdmTypeDefinitionImpl(edm, new FullQualifiedName(namespace, def.getName()), def)); } } } @@ -147,7 +143,7 @@ public class EdmSchemaImpl extends AbstractEdmSchema { if (providerEnumTypes != null) { for (EnumType enumType : providerEnumTypes) { enumTypes.add( - new EdmEnumTypeImpl(version, edm, new FullQualifiedName(namespace, enumType.getName()), enumType)); + new EdmEnumTypeImpl(edm, new FullQualifiedName(namespace, enumType.getName()), enumType)); } } return enumTypes; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmTypeDefinitionImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmTypeDefinitionImpl.java index 62f514d35..d82e5f655 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmTypeDefinitionImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmTypeDefinitionImpl.java @@ -1,18 +1,18 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -28,7 +28,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmTerm; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.core.edm.AbstractEdmTypeDefinition; import org.apache.olingo.commons.core.edm.EdmAnnotationHelper; @@ -42,14 +41,14 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition { private final EdmAnnotationHelper helper; - public EdmTypeDefinitionImpl(final ODataServiceVersion version, final Edm edm, - final FullQualifiedName typeDefinitionName, final TypeDefinition typeDefinition) { + public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName, + final TypeDefinition typeDefinition) { super(edm, typeDefinitionName); this.typeDefinition = typeDefinition; try { this.edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance( - EdmPrimitiveTypeKind.valueOfFQN(version, typeDefinition.getUnderlyingType())); + EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType())); } catch (IllegalArgumentException e) { throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e); } 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 a6636afec..f0d2ba1f1 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 @@ -58,20 +58,16 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper; public class ClientODataDeserializerImpl implements ClientODataDeserializer { - private final ODataServiceVersion version; - private final ODataDeserializer deserializer; private final ODataFormat format; - public ClientODataDeserializerImpl(final ODataServiceVersion version, final boolean serverMode, - final ODataFormat format) { - this.version = version; + public ClientODataDeserializerImpl(final boolean serverMode, final ODataFormat format) { this.format = format; if (format == ODataFormat.XML || format == ODataFormat.ATOM) { - deserializer = new AtomDeserializer(version); + deserializer = new AtomDeserializer(); } else { - deserializer = new JsonDeserializer(version, serverMode); + deserializer = new JsonDeserializer(serverMode); } } @@ -96,7 +92,7 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer { new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule()); xmlMapper.setInjectableValues(new InjectableValues.Std(). - addValue(ODataServiceVersion.class, version). + addValue(ODataServiceVersion.class, ODataServiceVersion.V40). addValue(Boolean.class, Boolean.FALSE)); xmlMapper.addHandler(new DeserializationProblemHandler() { @@ -126,16 +122,16 @@ public class ClientODataDeserializerImpl implements ClientODataDeserializer { @Override public ResWrap toServiceDocument(final InputStream input) throws ODataDeserializerException { return format == ODataFormat.XML ? - new XMLServiceDocumentDeserializer(version, false).toServiceDocument(input) : - new JSONServiceDocumentDeserializer(version, false).toServiceDocument(input); + new XMLServiceDocumentDeserializer(false).toServiceDocument(input) : + new JSONServiceDocumentDeserializer(false).toServiceDocument(input); } @Override public ResWrap toDelta(final InputStream input) throws ODataDeserializerException { try { return format == ODataFormat.ATOM ? - new AtomDeserializer(version).delta(input) : - new JsonDeltaDeserializer(version, false).toDelta(input); + new AtomDeserializer().delta(input) : + new JsonDeltaDeserializer(false).toDelta(input); } catch (XMLStreamException e) { throw new ODataDeserializerException(e); } catch (final EdmPrimitiveTypeException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java index 823436886..ccf7c81cb 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java @@ -355,7 +355,7 @@ public class ODataBinderImpl implements ODataBinder { annotations(value.asComplex(), lcValueResource); links(value.asComplex(), lcValueResource); valueResource = lcValueResource; - + } else if (value.isCollection()) { final ODataCollectionValue _value = value.asCollection(); ArrayList lcValueResource = new ArrayList(); @@ -450,7 +450,7 @@ public class ODataBinderImpl implements ODataBinder { if (linkType == null) { linkType = link.getType() == null ? ODataLinkType.ENTITY_NAVIGATION : - ODataLinkType.fromString(client.getServiceVersion(), link.getRel(), link.getType()); + ODataLinkType.fromString(link.getRel(), link.getType()); } odataLinked.addLink(linkType == ODataLinkType.ENTITY_NAVIGATION ? @@ -474,7 +474,7 @@ public class ODataBinderImpl implements ODataBinder { private ODataInlineEntity createODataInlineEntity(final Entity inlineEntity, final URI uri, final String title, final String metadataETag) { - return new ODataInlineEntity(client.getServiceVersion(), uri, ODataLinkType.ENTITY_NAVIGATION, title, + return new ODataInlineEntity(uri, ODataLinkType.ENTITY_NAVIGATION, title, getODataEntity(new ResWrap( inlineEntity.getBaseURI() == null ? null : inlineEntity.getBaseURI(), metadataETag, inlineEntity))); @@ -482,7 +482,7 @@ public class ODataBinderImpl implements ODataBinder { private ODataInlineEntitySet createODataInlineEntitySet(final EntitySet inlineEntitySet, final URI uri, final String title, final String metadataETag) { - return new ODataInlineEntitySet(client.getServiceVersion(), uri, ODataLinkType.ENTITY_SET_NAVIGATION, title, + return new ODataInlineEntitySet(uri, ODataLinkType.ENTITY_SET_NAVIGATION, title, getODataEntitySet(new ResWrap( inlineEntitySet.getBaseURI() == null ? null : inlineEntitySet.getBaseURI(), metadataETag, inlineEntitySet))); @@ -777,7 +777,7 @@ public class ODataBinderImpl implements ODataBinder { || EdmPrimitiveTypeKind.Geography.getFullQualifiedName().equals(type) || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type) ? valuable.asGeospatial().getEdmPrimitiveTypeKind() - : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())). + : EdmPrimitiveTypeKind.valueOfFQN(type.toString())). build(); } else if (valuable.isPrimitive() || valuable.getValueType() == null) { // fixes non-string values treated as string when no type information is available at de-serialization level @@ -803,7 +803,7 @@ public class ODataBinderImpl implements ODataBinder { setValue(valuable.asPrimitive()). setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace()) ? null - : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())). + : EdmPrimitiveTypeKind.valueOfFQN(type.toString())). build(); } else if (valuable.isComplex()) { final ODataComplexValue cValue = (ODataComplexValue) client.getObjectFactory(). 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 c6a517172..9afcb132b 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 @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -67,18 +67,18 @@ public class ODataReaderImpl implements ODataReader { @Override public Edm readMetadata(final Map xmlSchemas) { - return new EdmClientImpl(client.getServiceVersion(), xmlSchemas); + return new EdmClientImpl(xmlSchemas); } @Override public ODataServiceDocument readServiceDocument(final InputStream input, final ODataFormat format) throws ODataDeserializerException { return client.getBinder().getODataServiceDocument( - client.getDeserializer(format).toServiceDocument(input).getPayload()); + client.getDeserializer(format).toServiceDocument(input).getPayload()); } @Override - public ODataError readError(final InputStream inputStream, final ODataFormat format ) + public ODataError readError(final InputStream inputStream, final ODataFormat format) throws ODataDeserializerException { return client.getDeserializer(format).toError(inputStream); } @@ -91,55 +91,55 @@ public class ODataReaderImpl implements ODataReader { try { if (ODataEntitySetIterator.class.isAssignableFrom(reference)) { res = new ResWrap( - (URI) null, - null, - reference.cast(new ODataEntitySetIterator( - client, src, ODataFormat.fromString(format)))); + (URI) null, + null, + reference.cast(new ODataEntitySetIterator( + client, src, ODataFormat.fromString(format)))); } else if (ODataEntitySet.class.isAssignableFrom(reference)) { final ResWrap resource = client.getDeserializer(ODataFormat.fromString(format)) .toEntitySet(src); res = new ResWrap( - resource.getContextURL(), - resource.getMetadataETag(), - reference.cast(client.getBinder().getODataEntitySet(resource))); + resource.getContextURL(), + resource.getMetadataETag(), + reference.cast(client.getBinder().getODataEntitySet(resource))); } else if (ODataEntity.class.isAssignableFrom(reference)) { final ResWrap container = client.getDeserializer(ODataFormat.fromString(format)).toEntity(src); res = new ResWrap( - container.getContextURL(), - container.getMetadataETag(), - reference.cast(client.getBinder().getODataEntity(container))); + container.getContextURL(), + container.getMetadataETag(), + reference.cast(client.getBinder().getODataEntity(container))); } else if (ODataProperty.class.isAssignableFrom(reference)) { final ResWrap container = client.getDeserializer(ODataFormat.fromString(format)).toProperty(src); res = new ResWrap( - container.getContextURL(), - container.getMetadataETag(), - reference.cast(client.getBinder().getODataProperty(container))); + container.getContextURL(), + container.getMetadataETag(), + reference.cast(client.getBinder().getODataProperty(container))); } else if (ODataValue.class.isAssignableFrom(reference)) { res = new ResWrap( - (URI) null, - null, - reference.cast(client.getObjectFactory().newPrimitiveValueBuilder(). - setType(ODataFormat.fromString(format) == ODataFormat.TEXT_PLAIN - ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream). - setValue(IOUtils.toString(src)) // TODO: set correct value - .build())); + (URI) null, + null, + reference.cast(client.getObjectFactory().newPrimitiveValueBuilder(). + setType(ODataFormat.fromString(format) == ODataFormat.TEXT_PLAIN + ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream). + setValue(IOUtils.toString(src)) // TODO: set correct value + .build())); } else if (XMLMetadata.class.isAssignableFrom(reference)) { res = new ResWrap( - (URI) null, - null, - reference.cast(readMetadata(src))); + (URI) null, + null, + reference.cast(readMetadata(src))); } else if (ODataServiceDocument.class.isAssignableFrom(reference)) { final ResWrap resource = - client.getDeserializer(ODataFormat.fromString(format)).toServiceDocument(src); + client.getDeserializer(ODataFormat.fromString(format)).toServiceDocument(src); res = new ResWrap( - resource.getContextURL(), - resource.getMetadataETag(), - reference.cast(client.getBinder().getODataServiceDocument(resource.getPayload()))); + resource.getContextURL(), + resource.getMetadataETag(), + reference.cast(client.getBinder().getODataServiceDocument(resource.getPayload()))); } else if (ODataError.class.isAssignableFrom(reference)) { res = new ResWrap( - (URI) null, - null, - reference.cast(readError(src, ODataFormat.fromString(format)))); + (URI) null, + null, + reference.cast(readError(src, ODataFormat.fromString(format)))); } else { throw new IllegalArgumentException("Invalid reference type " + reference); } @@ -154,6 +154,7 @@ public class ODataReaderImpl implements ODataReader { return res; } + @Override public ODataEntitySet readEntitySet(final InputStream input, final ODataFormat format) throws ODataDeserializerException { 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 37cb3095a..09116bd2a 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 @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -51,8 +51,8 @@ public class URIEscapeTest { @Test public void _enum() throws UnsupportedEncodingException { - final EdmEnumType pattern = new EdmEnumTypeImpl(ODataServiceVersion.V40, - null, new FullQualifiedName("Sales", "Pattern"), new EnumTypeImpl()); + final EdmEnumType pattern = + new EdmEnumTypeImpl(null, new FullQualifiedName("Sales", "Pattern"), new EnumTypeImpl()); assertEquals("Sales.Pattern'Yellow'", URIUtils.escape(ODataServiceVersion.V40, pattern.toUriLiteral("Yellow"))); } @@ -63,8 +63,8 @@ public class URIEscapeTest { calendar.clear(); calendar.set(2014, 6, 11, 12, 30, 04); - assertEquals(URLEncoder.encode("2014-07-11T12:30:04+01:00", Constants.UTF8), - URIUtils.escape(ODataServiceVersion.V40, calendar)); + assertEquals(URLEncoder.encode("2014-07-11T12:30:04+01:00", Constants.UTF8), + URIUtils.escape(ODataServiceVersion.V40, calendar)); } @Test @@ -74,18 +74,18 @@ public class URIEscapeTest { point.setY(64.1); assertEquals(URLEncoder.encode("geography'SRID=4326;Point(142.1 64.1)'", Constants.UTF8), - URIUtils.escape(ODataServiceVersion.V40, point)); + URIUtils.escape(ODataServiceVersion.V40, point)); } @Test public void collection() { assertEquals("[\"red\",\"green\"]", - URIUtils.escape(ODataServiceVersion.V40, Arrays.asList(new String[] {"red", "green"}))); + URIUtils.escape(ODataServiceVersion.V40, Arrays.asList(new String[] { "red", "green" }))); } @Test public void complex() { assertEquals("{\"Name\":\"Value\"}", - URIUtils.escape(ODataServiceVersion.V40, Collections.singletonMap("Name", "Value"))); + URIUtils.escape(ODataServiceVersion.V40, Collections.singletonMap("Name", "Value"))); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java index f6b3f9cdf..a643d2358 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/FilterFactoryTest.java @@ -1,23 +1,30 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * 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.uri.v4; +import static org.junit.Assert.assertEquals; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Calendar; +import java.util.TimeZone; + import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.uri.FilterArgFactory; import org.apache.olingo.client.api.uri.FilterFactory; @@ -28,16 +35,8 @@ import org.apache.olingo.client.core.edm.xml.EnumTypeImpl; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.edm.EdmEnumType; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.junit.Test; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Calendar; -import java.util.TimeZone; - -import static org.junit.Assert.assertEquals; - public class FilterFactoryTest extends AbstractTest { @Override @@ -55,8 +54,8 @@ public class FilterFactoryTest extends AbstractTest { @Test public void has() { - final EdmEnumType pattern = new EdmEnumTypeImpl(ODataServiceVersion.V40, - null, new FullQualifiedName("Sales", "Pattern"), new EnumTypeImpl()); + final EdmEnumType pattern = + new EdmEnumTypeImpl(null, new FullQualifiedName("Sales", "Pattern"), new EnumTypeImpl()); final URIFilter filter = getFilterFactory().has(getFilterArgFactory().property("style"), pattern, "Yellow"); assertEquals("(style has Sales.Pattern'Yellow')", filter.build()); @@ -65,7 +64,7 @@ public class FilterFactoryTest extends AbstractTest { @Test public void contains() { final URIFilter filter = getFilterFactory().match(getFilterArgFactory().contains( - getFilterArgFactory().property("CompanyName"), getFilterArgFactory().literal("Alfreds"))); + getFilterArgFactory().property("CompanyName"), getFilterArgFactory().literal("Alfreds"))); assertEquals("contains(CompanyName,'Alfreds')", filter.build()); } @@ -73,8 +72,8 @@ public class FilterFactoryTest extends AbstractTest { @Test public void maxdatetime() { final URIFilter filter = getFilterFactory().eq( - getFilterArgFactory().property("EndTime"), - getFilterArgFactory().maxdatetime()); + getFilterArgFactory().property("EndTime"), + getFilterArgFactory().maxdatetime()); assertEquals("(EndTime eq maxdatetime())", filter.build()); } @@ -82,8 +81,8 @@ public class FilterFactoryTest extends AbstractTest { @Test public void any() { final URIFilter filter = getFilterFactory().match( - getFilterArgFactory().any(getFilterArgFactory().property("Items"), - getFilterFactory().gt("d:d/Quantity", 100))); + getFilterArgFactory().any(getFilterArgFactory().property("Items"), + getFilterFactory().gt("d:d/Quantity", 100))); assertEquals("Items/any(d:d/Quantity gt 100)", filter.build()); } @@ -96,7 +95,7 @@ public class FilterFactoryTest extends AbstractTest { final URIFilter filter = getFilterFactory().ge("OrderDate", calendar); assertEquals("(OrderDate ge " + URLEncoder.encode("2011-03-08T14:21:12-08:00", Constants.UTF8) + ")", - filter.build()); + filter.build()); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java index 170e686dd..19f39e6b7 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -40,7 +40,6 @@ import org.apache.olingo.commons.api.domain.ODataComplexValue; import org.apache.olingo.commons.api.domain.ODataEntity; import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ODataFormat; import org.junit.Test; @@ -66,33 +65,32 @@ public class JSONTest extends AbstractTest { } private void cleanup(final ObjectNode node) { - final ODataServiceVersion version = getClient().getServiceVersion(); if (node.has(Constants.JSON_CONTEXT)) { node.remove(Constants.JSON_CONTEXT); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.ETAG))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.ETAG)); + if (node.has(Constants.JSON_ETAG)) { + node.remove(Constants.JSON_ETAG); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.TYPE))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.TYPE)); + if (node.has(Constants.JSON_TYPE)) { + node.remove(Constants.JSON_TYPE); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK)); + if (node.has(Constants.JSON_EDIT_LINK)) { + node.remove(Constants.JSON_EDIT_LINK); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK)); + if (node.has(Constants.JSON_READ_LINK)) { + node.remove(Constants.JSON_READ_LINK); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK)); + if (node.has(Constants.JSON_MEDIA_EDIT_LINK)) { + node.remove(Constants.JSON_MEDIA_EDIT_LINK); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK)); + if (node.has(Constants.JSON_MEDIA_READ_LINK)) { + node.remove(Constants.JSON_MEDIA_READ_LINK); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE)); + if (node.has(Constants.JSON_MEDIA_CONTENT_TYPE)) { + node.remove(Constants.JSON_MEDIA_CONTENT_TYPE); } - if (node.has(version.getJsonName(ODataServiceVersion.JsonKey.COUNT))) { - node.remove(version.getJsonName(ODataServiceVersion.JsonKey.COUNT)); + if (node.has(Constants.JSON_COUNT)) { + node.remove(Constants.JSON_COUNT); } final List toRemove = new ArrayList(); for (final Iterator> itor = node.fields(); itor.hasNext();) { @@ -100,11 +98,11 @@ public class JSONTest extends AbstractTest { final String key = field.getKey(); if (key.charAt(0) == '#' - || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.TYPE)) - || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK)) - || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE)) - || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.ASSOCIATION_LINK)) - || key.endsWith(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_ETAG))) { + || key.endsWith(Constants.JSON_TYPE) + || key.endsWith(Constants.JSON_MEDIA_EDIT_LINK) + || key.endsWith(Constants.JSON_MEDIA_CONTENT_TYPE) + || key.endsWith(Constants.JSON_ASSOCIATION_LINK) + || key.endsWith(Constants.JSON_MEDIA_ETAG)) { toRemove.add(key); } else if (field.getValue().isObject()) { @@ -123,8 +121,7 @@ public class JSONTest extends AbstractTest { protected void assertSimilar(final String filename, final String actual) throws Exception { final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)). - replace(getClient().getServiceVersion().getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK), - Constants.JSON_BIND_LINK_SUFFIX)); + replace(Constants.JSON_NAVIGATION_LINK, Constants.JSON_BIND_LINK_SUFFIX)); cleanup((ObjectNode) expected); final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())); cleanup(actualNode); @@ -134,7 +131,7 @@ public class JSONTest extends AbstractTest { protected void entitySet(final String filename, final ODataFormat format) throws Exception { final StringWriter writer = new StringWriter(); getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntitySet( - getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); + getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); assertSimilar(filename + "." + getSuffix(format), writer.toString()); } @@ -148,7 +145,7 @@ public class JSONTest extends AbstractTest { protected void entity(final String filename, final ODataFormat format) throws Exception { final StringWriter writer = new StringWriter(); getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntity( - getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); + getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); assertSimilar(filename + "." + getSuffix(format), writer.toString()); } @@ -175,7 +172,7 @@ public class JSONTest extends AbstractTest { protected void property(final String filename, final ODataFormat format) throws Exception { final StringWriter writer = new StringWriter(); getClient().getSerializer(format).write(writer, getClient().getDeserializer(format). - toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); + toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload()); assertSimilar(filename + "." + getSuffix(format), writer.toString()); } @@ -191,12 +188,12 @@ public class JSONTest extends AbstractTest { @Test public void crossjoin() throws Exception { assertNotNull(getClient().getDeserializer(ODataFormat.JSON_FULL_METADATA).toEntitySet( - getClass().getResourceAsStream("crossjoin.json"))); + getClass().getResourceAsStream("crossjoin.json"))); } protected void delta(final String filename, final ODataFormat format) throws Exception { final Delta delta = getClient().getDeserializer(format).toDelta( - getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload(); + getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload(); assertNotNull(delta); assertNotNull(delta.getDeltaLink()); assertEquals(5, delta.getCount(), 0); @@ -229,32 +226,32 @@ public class JSONTest extends AbstractTest { @Test public void issueOLINGO390() throws Exception { final ODataEntity message = getClient().getObjectFactory(). - newEntity(new FullQualifiedName("Microsoft.Exchange.Services.OData.Model.Message")); + newEntity(new FullQualifiedName("Microsoft.Exchange.Services.OData.Model.Message")); final ODataComplexValue toRecipient = getClient().getObjectFactory(). - newComplexValue("Microsoft.Exchange.Services.OData.Model.Recipient"); + newComplexValue("Microsoft.Exchange.Services.OData.Model.Recipient"); toRecipient.add(getClient().getObjectFactory().newPrimitiveProperty("Name", - getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("challen_olingo_client"))); + getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("challen_olingo_client"))); toRecipient.add(getClient().getObjectFactory().newPrimitiveProperty("Address", - getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("challenh@microsoft.com"))); + getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("challenh@microsoft.com"))); final ODataCollectionValue toRecipients = getClient().getObjectFactory(). - newCollectionValue("Microsoft.Exchange.Services.OData.Model.Recipient"); + newCollectionValue("Microsoft.Exchange.Services.OData.Model.Recipient"); toRecipients.add(toRecipient); message.getProperties().add(getClient().getObjectFactory().newCollectionProperty("ToRecipients", toRecipients)); final ODataComplexValue body = - getClient().getObjectFactory().newComplexValue("Microsoft.Exchange.Services.OData.Model.ItemBody"); + getClient().getObjectFactory().newComplexValue("Microsoft.Exchange.Services.OData.Model.ItemBody"); body.add(getClient().getObjectFactory().newPrimitiveProperty("Content", - getClient().getObjectFactory().newPrimitiveValueBuilder(). + getClient().getObjectFactory().newPrimitiveValueBuilder(). buildString("this is a simple email body content"))); body.add(getClient().getObjectFactory().newEnumProperty("ContentType", - getClient().getObjectFactory().newEnumValue("Microsoft.Exchange.Services.OData.Model.BodyType", "text"))); + getClient().getObjectFactory().newEnumValue("Microsoft.Exchange.Services.OData.Model.BodyType", "text"))); message.getProperties().add(getClient().getObjectFactory().newComplexProperty("Body", body)); final String actual = IOUtils.toString(getClient().getWriter().writeEntity(message, ODataFormat.JSON)); - final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream("olingo390.json")). - replace(getClient().getServiceVersion().getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK), - Constants.JSON_BIND_LINK_SUFFIX)); + final JsonNode expected = + OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream("olingo390.json")). + replace(Constants.JSON_NAVIGATION_LINK, Constants.JSON_BIND_LINK_SUFFIX)); final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())); assertEquals(expected, actualNode); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java index e21939200..cec55b3d7 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java @@ -34,6 +34,23 @@ public interface Constants { public final static Integer DEFAULT_PRECISION = 40; public final static Integer DEFAULT_SCALE = 25; + + // Common Namespaces + public final static String NS_BASE = "http://docs.oasis-open.org/odata/ns/"; + + public final static String NS_DATASERVICES = "http://docs.oasis-open.org/odata/ns/data"; + + public final static String NS_METADATA = "http://docs.oasis-open.org/odata/ns/metadata"; + + public final static String NS_SCHEME = "http://docs.oasis-open.org/odata/ns/scheme"; + + public final static String NS_NAVIGATION_LINK_REL = "http://docs.oasis-open.org/odata/ns/related/"; + + public final static String NS_ASSOCIATION_LINK_REL = "http://docs.oasis-open.org/odata/ns/relatedlinks/"; + + public final static String NS_MEDIA_EDIT_LINK_REL = "http://docs.oasis-open.org/odata/ns/edit-media/"; + + public final static String NS_DELTA_LINK_REL = "http://docs.oasis-open.org/odata/ns/delta"; // XML namespaces and prefixes public final static String NS_ATOM = "http://www.w3.org/2005/Atom"; @@ -54,6 +71,7 @@ public interface Constants { public final static String SRS_URLPREFIX = "http://www.opengis.net/def/crs/EPSG/0/"; + // Link rel(s) public static final String EDIT_LINK_REL = "edit"; diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java index a830d269d..ff9a4203c 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java @@ -18,8 +18,6 @@ */ package org.apache.olingo.commons.api.domain; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; - import java.net.URI; /** @@ -38,10 +36,9 @@ public class ODataInlineEntity extends ODataLink { * @param title title. * @param entity entity. */ - public ODataInlineEntity(final ODataServiceVersion version, - final URI uri, final ODataLinkType type, final String title, final ODataEntity entity) { + public ODataInlineEntity(final URI uri, final ODataLinkType type, final String title, final ODataEntity entity) { - super(version, uri, type, title); + super(uri, type, title); this.entity = entity; } @@ -55,10 +52,10 @@ public class ODataInlineEntity extends ODataLink { * @param title title. * @param entity entity. */ - public ODataInlineEntity(final ODataServiceVersion version, final URI baseURI, final String href, - final ODataLinkType type, final String title, final ODataEntity entity) { + public ODataInlineEntity(final URI baseURI, final String href, final ODataLinkType type, final String title, + final ODataEntity entity) { - super(version, baseURI, href, type, title); + super(baseURI, href, type, title); this.entity = entity; } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntitySet.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntitySet.java index cdc0012ac..c1cf32278 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntitySet.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntitySet.java @@ -18,8 +18,6 @@ */ package org.apache.olingo.commons.api.domain; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; - import java.net.URI; /** @@ -32,33 +30,31 @@ public class ODataInlineEntitySet extends ODataLink { /** * Constructor. * - * @param version OData service version. * @param uri edit link. * @param type type. * @param title title. * @param entitySet entity set. */ - public ODataInlineEntitySet(final ODataServiceVersion version, final URI uri, final ODataLinkType type, + public ODataInlineEntitySet(final URI uri, final ODataLinkType type, final String title, final ODataEntitySet entitySet) { - super(version, uri, type, title); + super(uri, type, title); this.entitySet = entitySet; } /** * Constructor. * - * @param version OData service version. * @param baseURI base URI. * @param href href. * @param type type. * @param title title. * @param entitySet entity set. */ - public ODataInlineEntitySet(final ODataServiceVersion version, final URI baseURI, final String href, + public ODataInlineEntitySet(final URI baseURI, final String href, final ODataLinkType type, final String title, final ODataEntitySet entitySet) { - super(version, baseURI, href, type, title); + super(baseURI, href, type, title); this.entitySet = entitySet; } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java index 574ff0d5c..4bc8bdba2 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java @@ -22,28 +22,21 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.Constants; /** * OData link. */ -public class ODataLink extends ODataItem implements ODataAnnotatable{ +public class ODataLink extends ODataItem implements ODataAnnotatable { public static class Builder { - protected ODataServiceVersion version; - protected URI uri; protected ODataLinkType type; protected String title; - public Builder setVersion(final ODataServiceVersion version) { - this.version = version; - return this; - } - public Builder setURI(final URI uri) { this.uri = uri; return this; @@ -65,7 +58,7 @@ public class ODataLink extends ODataItem implements ODataAnnotatable{ } public ODataLink build() { - return new ODataLink(version, uri, type, title); + return new ODataLink(uri, type, title); } } @@ -108,7 +101,7 @@ public class ODataLink extends ODataItem implements ODataAnnotatable{ protected String mediaETag; private final List annotations = new ArrayList(); - + /** * Constructor. * @@ -117,7 +110,7 @@ public class ODataLink extends ODataItem implements ODataAnnotatable{ * @param type type. * @param title title. */ - public ODataLink(final ODataServiceVersion version, final URI uri, final ODataLinkType type, final String title) { + public ODataLink(final URI uri, final ODataLinkType type, final String title) { super(title); link = uri; @@ -125,17 +118,17 @@ public class ODataLink extends ODataItem implements ODataAnnotatable{ switch (this.type) { case ASSOCIATION: - rel = version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL) + title; + rel = Constants.NS_ASSOCIATION_LINK_REL + title; break; case ENTITY_NAVIGATION: case ENTITY_SET_NAVIGATION: - rel = version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + title; + rel = Constants.NS_NAVIGATION_LINK_REL + title; break; case MEDIA_EDIT: default: - rel = version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL) + title; + rel = Constants.NS_MEDIA_EDIT_LINK_REL + title; break; } } @@ -149,10 +142,9 @@ public class ODataLink extends ODataItem implements ODataAnnotatable{ * @param type type. * @param title title. */ - protected ODataLink(final ODataServiceVersion version, - final URI baseURI, final String href, final ODataLinkType type, final String title) { + protected ODataLink(final URI baseURI, final String href, final ODataLinkType type, final String title) { - this(version, getURI(baseURI, href), type, title); + this(getURI(baseURI, href), type, title); } /** @@ -189,7 +181,7 @@ public class ODataLink extends ODataItem implements ODataAnnotatable{ public String getMediaETag() { return mediaETag; } - + public List getAnnotations() { return annotations; } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java index 7c06e9a47..f99aa3e33 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java @@ -19,7 +19,7 @@ package org.apache.olingo.commons.api.domain; import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.format.ContentType; /** @@ -42,13 +42,13 @@ public enum ODataLinkType { /** * Media-edit link. */ - MEDIA_EDIT("*/*"), - + MEDIA_EDIT("*/*"), + /** * Entity binding link. */ ENTITY_BINDING(ContentType.APPLICATION_XML), - + /** * Entity collection binding link. */ @@ -78,9 +78,8 @@ public enum ODataLinkType { * @param type type. * @return ODataLinkType object. */ - public static ODataLinkType fromString(final ODataServiceVersion version, final String rel, final String type) { - if (StringUtils.isNotBlank(rel) - && rel.startsWith(version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL))) { + public static ODataLinkType fromString(final String rel, final String type) { + if (StringUtils.isNotBlank(rel) && rel.startsWith(Constants.NS_MEDIA_EDIT_LINK_REL)) { return MEDIA_EDIT.setType(StringUtils.isBlank(type) ? "*/*" : type); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java index 88b3a53f8..1077b01bc 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.commons.api.edm; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; public enum EdmPrimitiveTypeKind { @@ -86,8 +85,8 @@ public enum EdmPrimitiveTypeKind { * @param fqn full-qualified type name. * @return EdmPrimitiveTypeKind object. */ - public static EdmPrimitiveTypeKind valueOfFQN(final ODataServiceVersion version, final FullQualifiedName fqn) { - return valueOfFQN(version, fqn.toString()); + public static EdmPrimitiveTypeKind valueOfFQN(final FullQualifiedName fqn) { + return valueOfFQN(fqn.toString()); } /** @@ -98,18 +97,12 @@ public enum EdmPrimitiveTypeKind { * @param fqn string value type. * @return EdmPrimitiveTypeKind object. */ - public static EdmPrimitiveTypeKind valueOfFQN(final ODataServiceVersion version, final String fqn) { - if (version == null) { - throw new IllegalArgumentException("No OData protocol version provided"); - } + public static EdmPrimitiveTypeKind valueOfFQN(final String fqn) { if (!fqn.startsWith(EdmPrimitiveType.EDM_NAMESPACE + ".")) { throw new IllegalArgumentException(fqn + " does not look like an Edm primitive type"); } final EdmPrimitiveTypeKind kind = valueOf(fqn.substring(4)); -// if (!kind.versions.contains(version)) { -// throw new IllegalArgumentException(kind + " not allowed in " + version); -// } return kind; } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java index fbebb7140..7bee4b25a 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java @@ -18,10 +18,6 @@ */ package org.apache.olingo.commons.api.edm.constants; -import org.apache.olingo.commons.api.Constants; - -import java.util.HashMap; -import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -35,86 +31,6 @@ public enum ODataServiceVersion { V30("3.0"), V40("4.0"); - public enum NamespaceKey { - DATASERVICES, METADATA, SCHEME, - NAVIGATION_LINK_REL, ASSOCIATION_LINK_REL, MEDIA_EDIT_LINK_REL, DELTA_LINK_REL - } - - private static final Map V30_NAMESPACES = new HashMap() { - private static final long serialVersionUID = 3109256773218160485L; - private static final String BASE = "http://schemas.microsoft.com/ado/2007/08/dataservices"; - { - put(NamespaceKey.DATASERVICES, BASE); - put(NamespaceKey.METADATA, BASE + "/metadata"); - put(NamespaceKey.SCHEME, BASE + "/scheme"); - put(NamespaceKey.NAVIGATION_LINK_REL, BASE + "/related/"); - put(NamespaceKey.ASSOCIATION_LINK_REL, BASE + "/relatedlinks/"); - put(NamespaceKey.MEDIA_EDIT_LINK_REL, BASE + "/edit-media/"); - } - }; - - private static final Map V40_NAMESPACES = new HashMap() { - private static final long serialVersionUID = 3109256773218160485L; - private static final String BASE = "http://docs.oasis-open.org/odata/ns/"; - { - put(NamespaceKey.DATASERVICES, BASE + "data"); - put(NamespaceKey.METADATA, BASE + "metadata"); - put(NamespaceKey.SCHEME, BASE + "scheme"); - put(NamespaceKey.NAVIGATION_LINK_REL, BASE + "related/"); - put(NamespaceKey.ASSOCIATION_LINK_REL, BASE + "relatedlinks/"); - put(NamespaceKey.MEDIA_EDIT_LINK_REL, BASE + "edit-media/"); - put(NamespaceKey.DELTA_LINK_REL, BASE + "delta"); - } - }; - - public enum JsonKey { - TYPE, ID, ETAG, - READ_LINK, EDIT_LINK, MEDIA_READ_LINK, MEDIA_EDIT_LINK, MEDIA_CONTENT_TYPE, MEDIA_ETAG, - ASSOCIATION_LINK, NAVIGATION_LINK, - COUNT, NEXT_LINK, DELTA_LINK, ERROR - } - - private static final Map V30_JSON = new HashMap() { - private static final long serialVersionUID = 3109256773218160485L; - { - put(JsonKey.TYPE, "odata.type"); - put(JsonKey.ID, "odata.id"); - put(JsonKey.ETAG, "odata.etag"); - put(JsonKey.READ_LINK, "odata.readLink"); - put(JsonKey.EDIT_LINK, "odata.editLink"); - put(JsonKey.MEDIA_READ_LINK, "odata.mediaReadLink"); - put(JsonKey.MEDIA_EDIT_LINK, "odata.mediaEditLink"); - put(JsonKey.MEDIA_CONTENT_TYPE, "odata.mediaContentType"); - put(JsonKey.MEDIA_ETAG, "odata.mediaEtag"); - put(JsonKey.ASSOCIATION_LINK, "@odata.associationLinkUrl"); - put(JsonKey.NAVIGATION_LINK, "@odata.navigationLinkUrl"); - put(JsonKey.COUNT, "odata.count"); - put(JsonKey.NEXT_LINK, "odata.nextLink"); - put(JsonKey.ERROR, "odata.error"); - } - }; - - private static final Map V40_JSON = new HashMap() { - private static final long serialVersionUID = 3109256773218160485L; - { - put(JsonKey.TYPE, Constants.JSON_TYPE); - put(JsonKey.ID, Constants.JSON_ID); - put(JsonKey.ETAG, Constants.JSON_ETAG); - put(JsonKey.READ_LINK, Constants.JSON_READ_LINK); - put(JsonKey.EDIT_LINK, Constants.JSON_EDIT_LINK); - put(JsonKey.MEDIA_READ_LINK, Constants.JSON_MEDIA_READ_LINK); - put(JsonKey.MEDIA_EDIT_LINK, Constants.JSON_MEDIA_EDIT_LINK); - put(JsonKey.MEDIA_CONTENT_TYPE, Constants.JSON_MEDIA_CONTENT_TYPE); - put(JsonKey.MEDIA_ETAG, Constants.JSON_MEDIA_ETAG); - put(JsonKey.ASSOCIATION_LINK, Constants.JSON_ASSOCIATION_LINK); - put(JsonKey.NAVIGATION_LINK, Constants.JSON_NAVIGATION_LINK); - put(JsonKey.COUNT, Constants.JSON_COUNT); - put(JsonKey.NEXT_LINK, Constants.JSON_NEXT_LINK); - put(JsonKey.DELTA_LINK, Constants.JSON_DELTA_LINK); - put(JsonKey.ERROR, Constants.JSON_ERROR); - } - }; - private static final Pattern DATASERVICEVERSIONPATTERN = Pattern.compile("(\\p{Digit}+\\.\\p{Digit}+)(:?;.*)?"); /** @@ -169,14 +85,6 @@ public enum ODataServiceVersion { this.version = version; } - public String getNamespace(final NamespaceKey key) { - return this == V10 || this == V20 ? null : this == V30 ? V30_NAMESPACES.get(key) : V40_NAMESPACES.get(key); - } - - public String getJsonName(final JsonKey key) { - return this == V10 || this == V20 ? null : this == V30 ? V30_JSON.get(key) : V40_JSON.get(key); - } - @Override public String toString() { return version; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/ODataObjectFactoryImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/ODataObjectFactoryImpl.java index d7e733c10..b8bb9e63e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/ODataObjectFactoryImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/ODataObjectFactoryImpl.java @@ -48,12 +48,12 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory { @Override public ODataInlineEntitySet newDeepInsertEntitySet(final String name, final ODataEntitySet entitySet) { - return new ODataInlineEntitySet(version, null, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet); + return new ODataInlineEntitySet(null, ODataLinkType.ENTITY_SET_NAVIGATION, name, entitySet); } @Override public ODataInlineEntity newDeepInsertEntity(final String name, final ODataEntity entity) { - return new ODataInlineEntity(version, null, ODataLinkType.ENTITY_NAVIGATION, name, entity); + return new ODataInlineEntity(null, ODataLinkType.ENTITY_NAVIGATION, name, entity); } @Override @@ -85,25 +85,25 @@ public class ODataObjectFactoryImpl implements ODataObjectFactory { @Override public ODataLink newEntityNavigationLink(final String name, final URI link) { - return new ODataLink.Builder().setVersion(version).setURI(link). + return new ODataLink.Builder().setURI(link). setType(ODataLinkType.ENTITY_NAVIGATION).setTitle(name).build(); } @Override public ODataLink newEntitySetNavigationLink(final String name, final URI link) { - return new ODataLink.Builder().setVersion(version).setURI(link). + return new ODataLink.Builder().setURI(link). setType(ODataLinkType.ENTITY_SET_NAVIGATION).setTitle(name).build(); } @Override public ODataLink newAssociationLink(final String name, final URI link) { - return new ODataLink.Builder().setVersion(version).setURI(link). + return new ODataLink.Builder().setURI(link). setType(ODataLinkType.ASSOCIATION).setTitle(name).build(); } @Override public ODataLink newMediaEditLink(final String name, final URI link) { - return new ODataLink.Builder().setVersion(version).setURI(link). + return new ODataLink.Builder().setURI(link). setType(ODataLinkType.MEDIA_EDIT).setTitle(name).build(); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java index 13b24363e..c6adc5e04 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java @@ -28,7 +28,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; public class EdmTypeInfo { @@ -156,19 +155,17 @@ public class EdmTypeInfo { return deserialize.toString(); } - public String external(final ODataServiceVersion version) { + public String external() { final StringBuilder serialize = new StringBuilder(); if (isCollection()) { - if (version.compareTo(ODataServiceVersion.V40) >= 0) { - serialize.append('#'); - } + serialize.append('#'); serialize.append("Collection("); } - if (isPrimitiveType() && version.compareTo(ODataServiceVersion.V40) >= 0) { + if (isPrimitiveType()) { serialize.append(getFullQualifiedName().getName()); - } else { + }else{ serialize.append(getFullQualifiedName().toString()); } @@ -176,7 +173,7 @@ public class EdmTypeInfo { serialize.append(")"); } - if (version.compareTo(ODataServiceVersion.V40) >= 0 && !isPrimitiveType() && !isCollection()) { + if (!isPrimitiveType() && !isCollection()) { serialize.insert(0, '#'); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java index 5a382870f..2795c2e3e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AbstractAtomDealer.java @@ -18,21 +18,18 @@ */ package org.apache.olingo.commons.core.serialization; -import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; - import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.Constants; + abstract class AbstractAtomDealer { protected static final String TYPE_TEXT = "text"; - protected final ODataServiceVersion version; - protected final String namespaceMetadata; protected final String namespaceData; @@ -59,11 +56,9 @@ abstract class AbstractAtomDealer { protected final QName errorMessageQName; protected final QName errorTargetQName; - public AbstractAtomDealer(final ODataServiceVersion version) { - this.version = version; - - namespaceMetadata = version.getNamespace(ODataServiceVersion.NamespaceKey.METADATA); - namespaceData = version.getNamespace(ODataServiceVersion.NamespaceKey.DATASERVICES); + public AbstractAtomDealer() { + namespaceMetadata = Constants.NS_METADATA; + namespaceData = Constants.NS_DATASERVICES; etagQName = new QName(namespaceMetadata, Constants.ATOM_ATTR_ETAG); metadataEtagQName = new QName(namespaceMetadata, Constants.ATOM_ATTR_METADATAETAG); @@ -72,8 +67,7 @@ abstract class AbstractAtomDealer { propertiesQName = new QName(namespaceMetadata, Constants.PROPERTIES); typeQName = new QName(namespaceMetadata, Constants.ATTR_TYPE); nullQName = new QName(namespaceMetadata, Constants.ATTR_NULL); - elementQName = new QName(version.compareTo(ODataServiceVersion.V40) < 0 ? namespaceData : namespaceMetadata, - Constants.ELEM_ELEMENT); + elementQName = new QName(namespaceMetadata, Constants.ELEM_ELEMENT); countQName = new QName(namespaceMetadata, Constants.ATOM_ELEM_COUNT); uriQName = new QName(namespaceData, Constants.ELEM_URI); nextQName = new QName(namespaceData, Constants.NEXT_LINK_REL); @@ -95,9 +89,8 @@ abstract class AbstractAtomDealer { protected void namespaces(final XMLStreamWriter writer) throws XMLStreamException { writer.writeNamespace(StringUtils.EMPTY, Constants.NS_ATOM); writer.writeNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI); - writer.writeNamespace(Constants.PREFIX_METADATA, version.getNamespace(ODataServiceVersion.NamespaceKey.METADATA)); - writer.writeNamespace(Constants.PREFIX_DATASERVICES, - version.getNamespace(ODataServiceVersion.NamespaceKey.DATASERVICES)); + writer.writeNamespace(Constants.PREFIX_METADATA, Constants.NS_METADATA); + writer.writeNamespace(Constants.PREFIX_DATASERVICES, Constants.NS_DATASERVICES); writer.writeNamespace(Constants.PREFIX_GML, Constants.NS_GML); writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS); } 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 44771ca13..0d212337d 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 @@ -52,8 +52,6 @@ import org.apache.olingo.commons.api.domain.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; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion.NamespaceKey; import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataDeserializer; @@ -82,8 +80,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria return FACTORY.createXMLEventReader(input); } - public AtomDeserializer(final ODataServiceVersion version) { - super(version); + public AtomDeserializer() { geoDeserializer = new AtomGeoValueDeserializer(); } @@ -97,8 +94,8 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria final XMLEvent event = reader.nextEvent(); if (event.isStartElement() && typeInfo != null && typeInfo.getPrimitiveTypeKind().isGeospatial()) { - final EdmPrimitiveTypeKind geoType = EdmPrimitiveTypeKind.valueOfFQN( - version, typeInfo.getFullQualifiedName().toString()); + final EdmPrimitiveTypeKind geoType = + EdmPrimitiveTypeKind.valueOfFQN(typeInfo.getFullQualifiedName().toString()); value = geoDeserializer.deserialize(reader, event.asStartElement(), geoType); } @@ -153,13 +150,11 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria link.setType(type.getValue()); } - if (link.getRel().startsWith( - version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL))) { + if (link.getRel().startsWith(Constants.NS_NAVIGATION_LINK_REL)) { ((ComplexValue) value).getNavigationLinks().add(link); inline(reader, event.asStartElement(), link); - } else if (link.getRel().startsWith( - version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL))) { + } else if (link.getRel().startsWith(Constants.NS_ASSOCIATION_LINK_REL)) { ((Valuable) value).asComplex().getAssociationLinks().add(link); } @@ -267,7 +262,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria final PropertyImpl property = new PropertyImpl(); - if (ODataServiceVersion.V40 == version && propertyValueQName.equals(start.getName())) { + if (propertyValueQName.equals(start.getName())) { // retrieve name from context final Attribute context = start.getAttributeByName(contextQName); if (context != null) { @@ -468,7 +463,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria delta.setNext(URI.create(href.getValue())); } } - if (ODataServiceVersion.V40.getNamespace(NamespaceKey.DELTA_LINK_REL).equals(rel.getValue())) { + if (Constants.NS_DELTA_LINK_REL.equals(rel.getValue())) { final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF)); if (href != null) { delta.setDeltaLink(URI.create(href.getValue())); @@ -644,17 +639,14 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria if (mediaETag != null) { entity.setMediaETag(mediaETag.getValue()); } - } else if (link.getRel().startsWith( - version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL))) { + } else if (link.getRel().startsWith(Constants.NS_NAVIGATION_LINK_REL)) { entity.getNavigationLinks().add(link); inline(reader, event.asStartElement(), link); - } else if (link.getRel().startsWith( - version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL))) { + } else if (link.getRel().startsWith(Constants.NS_ASSOCIATION_LINK_REL)) { entity.getAssociationLinks().add(link); - } else if (link.getRel().startsWith( - version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL))) { + } else if (link.getRel().startsWith(Constants.NS_MEDIA_EDIT_LINK_REL)) { final Attribute metag = event.asStartElement().getAttributeByName(etagQName); if (metag != null) { @@ -777,7 +769,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria entitySet.setNext(URI.create(href.getValue())); } } - if (ODataServiceVersion.V40.getNamespace(NamespaceKey.DELTA_LINK_REL).equals(rel.getValue())) { + if (Constants.NS_DELTA_LINK_REL.equals(rel.getValue())) { final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF)); if (href != null) { entitySet.setDeltaLink(URI.create(href.getValue())); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java index 7d07f5eb7..6c361168a 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java @@ -42,8 +42,6 @@ import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.domain.ODataOperation; 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; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion.NamespaceKey; import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.serialization.ODataSerializer; @@ -65,12 +63,11 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize private final boolean serverMode; - public AtomSerializer(final ODataServiceVersion version) { - this(version, false); + public AtomSerializer() { + this(false); } - public AtomSerializer(final ODataServiceVersion version, final boolean serverMode) { - super(version); + public AtomSerializer(final boolean serverMode) { geoSerializer = new AtomGeoValueSerializer(); this.serverMode = serverMode; } @@ -79,11 +76,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize final ValueType valueType, final EdmPrimitiveTypeKind kind, final List value) throws XMLStreamException, EdmPrimitiveTypeException { for (Object item : value) { - if (version.compareTo(ODataServiceVersion.V40) < 0) { - writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT, namespaceData); - } else { - writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, namespaceMetadata); - } + writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, namespaceMetadata); value(writer, valueType, kind, item); writer.writeEndElement(); } @@ -126,22 +119,19 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize public void property(final XMLStreamWriter writer, final Property property, final boolean standalone) throws XMLStreamException, EdmPrimitiveTypeException { - if (version.compareTo(ODataServiceVersion.V40) >= 0 && standalone) { + if (standalone) { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.VALUE, namespaceData); + namespaces(writer); } else { writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(), namespaceData); } - if (standalone) { - namespaces(writer); - } - EdmTypeInfo typeInfo = null; if (StringUtils.isNotBlank(property.getType())) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { writer.writeAttribute(Constants.PREFIX_METADATA, namespaceMetadata, - Constants.ATTR_TYPE, typeInfo.external(version)); + Constants.ATTR_TYPE, typeInfo.external()); } } @@ -260,7 +250,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { writer.writeAttribute(Constants.PREFIX_METADATA, namespaceMetadata, - Constants.ATTR_TYPE, typeInfo.external(version)); + Constants.ATTR_TYPE, typeInfo.external()); } } @@ -287,10 +277,10 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY); - writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespace(ODataServiceVersion.NamespaceKey.SCHEME)); + writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, Constants.NS_SCHEME); if (StringUtils.isNotBlank(entity.getType())) { writer.writeAttribute(Constants.ATOM_ATTR_TERM, - new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); + new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external()); } writer.writeEndElement(); @@ -447,7 +437,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize } if (entitySet.getDeltaLink() != null) { final LinkImpl next = new LinkImpl(); - next.setRel(ODataServiceVersion.V40.getNamespace(NamespaceKey.DELTA_LINK_REL)); + next.setRel(Constants.NS_DELTA_LINK_REL); next.setHref(entitySet.getDeltaLink().toASCIIString()); links(writer, Collections. singletonList(next)); @@ -526,7 +516,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize writer.writeStartDocument(); writer.writeStartElement(Constants.ATTR_METADATA, Constants.ATTR_REF); - writer.writeNamespace(Constants.ATTR_METADATA, version.getNamespace(NamespaceKey.METADATA)); + writer.writeNamespace(Constants.ATTR_METADATA, Constants.NS_METADATA); writer.writeAttribute(Constants.ATTR_METADATA, Constants.CONTEXT, container.getContextURL().toASCIIString()); writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().toASCIIString()); writer.writeEndElement(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java index 037b43664..5cb207632 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java @@ -18,31 +18,30 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.Delta; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; import org.apache.olingo.commons.core.data.DeletedEntityImpl; import org.apache.olingo.commons.core.data.DeltaImpl; import org.apache.olingo.commons.core.data.DeltaLinkImpl; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; public class JsonDeltaDeserializer extends JsonDeserializer { - public JsonDeltaDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonDeltaDeserializer(final boolean serverMode) { + super(serverMode); } protected ResWrap doDeserialize(final JsonParser parser) throws IOException { @@ -68,7 +67,7 @@ public class JsonDeltaDeserializer extends JsonDeserializer { } if (tree.hasNonNull(Constants.VALUE)) { - JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(version, serverMode); + JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode); for (JsonNode jsonNode : tree.get(Constants.VALUE)) { final ObjectNode item = (ObjectNode) jsonNode; final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT) ? 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 77d0ded8d..929ad9594 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 @@ -18,43 +18,6 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Annotatable; -import org.apache.olingo.commons.api.data.Annotation; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.EntitySet; -import org.apache.olingo.commons.api.data.Linked; -import org.apache.olingo.commons.api.data.ComplexValue; -import org.apache.olingo.commons.api.data.Property; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Valuable; -import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.domain.ODataLinkType; -import org.apache.olingo.commons.api.domain.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; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.api.edm.geo.Geospatial; -import org.apache.olingo.commons.api.serialization.ODataDeserializer; -import org.apache.olingo.commons.api.serialization.ODataDeserializerException; -import org.apache.olingo.commons.core.data.AnnotationImpl; -import org.apache.olingo.commons.core.data.EntitySetImpl; -import org.apache.olingo.commons.core.data.LinkImpl; -import org.apache.olingo.commons.core.data.ComplexValueImpl; -import org.apache.olingo.commons.core.data.PropertyImpl; -import org.apache.olingo.commons.core.edm.EdmTypeInfo; - import java.io.IOException; import java.io.InputStream; import java.util.AbstractMap.SimpleEntry; @@ -67,72 +30,89 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Annotatable; +import org.apache.olingo.commons.api.data.Annotation; +import org.apache.olingo.commons.api.data.ComplexValue; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; +import org.apache.olingo.commons.api.data.Linked; +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.ODataLinkType; +import org.apache.olingo.commons.api.domain.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; +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.serialization.ODataDeserializer; +import org.apache.olingo.commons.api.serialization.ODataDeserializerException; +import org.apache.olingo.commons.core.data.AnnotationImpl; +import org.apache.olingo.commons.core.data.ComplexValueImpl; +import org.apache.olingo.commons.core.data.EntitySetImpl; +import org.apache.olingo.commons.core.data.LinkImpl; +import org.apache.olingo.commons.core.data.PropertyImpl; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + public class JsonDeserializer implements ODataDeserializer { protected final Pattern CUSTOM_ANNOTATION = Pattern.compile("(.+)@(.+)\\.(.+)"); - protected final ODataServiceVersion version; - protected final boolean serverMode; - protected String jsonType; + protected String jsonType = Constants.JSON_TYPE; - protected String jsonId; + protected String jsonId = Constants.JSON_ID; - protected String jsonETag; + protected String jsonETag = Constants.JSON_ETAG; - protected String jsonReadLink; + protected String jsonReadLink = Constants.JSON_READ_LINK; - protected String jsonEditLink; + protected String jsonEditLink = Constants.JSON_EDIT_LINK; - protected String jsonMediaEditLink; + protected String jsonMediaEditLink = Constants.JSON_MEDIA_EDIT_LINK; - protected String jsonMediaReadLink; + protected String jsonMediaReadLink = Constants.JSON_MEDIA_READ_LINK; - protected String jsonMediaContentType; + protected String jsonMediaContentType = Constants.JSON_MEDIA_CONTENT_TYPE; - protected String jsonMediaETag; + protected String jsonMediaETag = Constants.JSON_MEDIA_ETAG; - protected String jsonAssociationLink; + protected String jsonAssociationLink = Constants.JSON_ASSOCIATION_LINK; - protected String jsonNavigationLink; + protected String jsonNavigationLink = Constants.JSON_NAVIGATION_LINK; - protected String jsonCount; + protected String jsonCount = Constants.JSON_COUNT; - protected String jsonNextLink; + protected String jsonNextLink = Constants.JSON_NEXT_LINK; - protected String jsonDeltaLink; + protected String jsonDeltaLink = Constants.JSON_DELTA_LINK; - protected String jsonError; + protected String jsonError = Constants.JSON_ERROR; private JsonGeoValueDeserializer geoDeserializer; private JsonParser parser; - public JsonDeserializer(final ODataServiceVersion version, final boolean serverMode) { - this.version = version; + public JsonDeserializer(final boolean serverMode) { this.serverMode = serverMode; - - jsonType = version.getJsonName(ODataServiceVersion.JsonKey.TYPE); - jsonId = version.getJsonName(ODataServiceVersion.JsonKey.ID); - jsonETag = version.getJsonName(ODataServiceVersion.JsonKey.ETAG); - jsonReadLink = version.getJsonName(ODataServiceVersion.JsonKey.READ_LINK); - jsonEditLink = version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK); - jsonMediaReadLink = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK); - jsonMediaEditLink = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK); - jsonMediaContentType = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_CONTENT_TYPE); - jsonMediaETag = version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_ETAG); - jsonAssociationLink = version.getJsonName(ODataServiceVersion.JsonKey.ASSOCIATION_LINK); - jsonNavigationLink = version.getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK); - jsonCount = version.getJsonName(ODataServiceVersion.JsonKey.COUNT); - jsonNextLink = version.getJsonName(ODataServiceVersion.JsonKey.NEXT_LINK); - jsonDeltaLink = version.getJsonName(ODataServiceVersion.JsonKey.DELTA_LINK); - jsonError = version.getJsonName(ODataServiceVersion.JsonKey.ERROR); } private JsonGeoValueDeserializer getGeoDeserializer() { if (geoDeserializer == null) { - geoDeserializer = new JsonGeoValueDeserializer(version); + geoDeserializer = new JsonGeoValueDeserializer(); } return geoDeserializer; } @@ -151,7 +131,7 @@ public class JsonDeserializer implements ODataDeserializer { final String entityNamePrefix = name.substring(0, name.indexOf(suffix)); if (tree.has(entityNamePrefix)) { final JsonNode inline = tree.path(entityNamePrefix); - JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(version, serverMode); + JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode); if (inline instanceof ObjectNode) { link.setType(ODataLinkType.ENTITY_NAVIGATION.toString()); @@ -186,7 +166,7 @@ public class JsonDeserializer implements ODataDeserializer { if (field.getKey().endsWith(jsonNavigationLink)) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + getTitle(field)); + link.setRel(Constants.NS_NAVIGATION_LINK_REL + getTitle(field)); if (field.getValue().isValueNode()) { link.setHref(field.getValue().textValue()); @@ -200,7 +180,7 @@ public class JsonDeserializer implements ODataDeserializer { } else if (field.getKey().endsWith(jsonAssociationLink)) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.ASSOCIATION_LINK_REL) + getTitle(field)); + link.setRel(Constants.NS_ASSOCIATION_LINK_REL + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.ASSOCIATION.toString()); linked.getAssociationLinks().add(link); @@ -220,7 +200,7 @@ public class JsonDeserializer implements ODataDeserializer { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + getTitle(field)); + link.setRel(Constants.NS_NAVIGATION_LINK_REL + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.ENTITY_NAVIGATION.toString()); linked.getNavigationLinks().add(link); @@ -232,7 +212,7 @@ public class JsonDeserializer implements ODataDeserializer { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.NAVIGATION_LINK_REL) + getTitle(field)); + link.setRel(Constants.NS_NAVIGATION_LINK_REL + getTitle(field)); link.setHref(node.asText()); link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString()); linked.getNavigationLinks().add(link); @@ -438,7 +418,7 @@ public class JsonDeserializer implements ODataDeserializer { public ResWrap toEntitySet(final InputStream input) throws ODataDeserializerException { try { parser = new JsonFactory(new ObjectMapper()).createParser(input); - return new JsonEntitySetDeserializer(version, serverMode).doDeserialize(parser); + return new JsonEntitySetDeserializer(serverMode).doDeserialize(parser); } catch (final IOException e) { throw new ODataDeserializerException(e); } @@ -448,7 +428,7 @@ public class JsonDeserializer implements ODataDeserializer { public ResWrap toEntity(final InputStream input) throws ODataDeserializerException { try { parser = new JsonFactory(new ObjectMapper()).createParser(input); - return new JsonEntityDeserializer(version, serverMode).doDeserialize(parser); + return new JsonEntityDeserializer(serverMode).doDeserialize(parser); } catch (final IOException e) { throw new ODataDeserializerException(e); } @@ -458,7 +438,7 @@ public class JsonDeserializer implements ODataDeserializer { public ResWrap toProperty(final InputStream input) throws ODataDeserializerException { try { parser = new JsonFactory(new ObjectMapper()).createParser(input); - return new JsonPropertyDeserializer(version, serverMode).doDeserialize(parser); + return new JsonPropertyDeserializer(serverMode).doDeserialize(parser); } catch (final IOException e) { throw new ODataDeserializerException(e); } @@ -468,7 +448,7 @@ public class JsonDeserializer implements ODataDeserializer { public ODataError toError(final InputStream input) throws ODataDeserializerException { try { parser = new JsonFactory(new ObjectMapper()).createParser(input); - return new JsonODataErrorDeserializer(version, serverMode).doDeserialize(parser); + return new JsonODataErrorDeserializer(serverMode).doDeserialize(parser); } catch (final IOException e) { throw new ODataDeserializerException(e); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java index 6099c1678..4f0b28812 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java @@ -18,25 +18,6 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Annotation; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.Link; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.domain.ODataLinkType; -import org.apache.olingo.commons.api.domain.ODataOperation; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.core.data.AnnotationImpl; -import org.apache.olingo.commons.core.data.EntityImpl; -import org.apache.olingo.commons.core.data.LinkImpl; -import org.apache.olingo.commons.core.edm.EdmTypeInfo; - import java.io.IOException; import java.net.URI; import java.util.ArrayList; @@ -48,6 +29,25 @@ import java.util.Map; import java.util.Set; import java.util.regex.Matcher; +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Annotation; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.Link; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.domain.ODataLinkType; +import org.apache.olingo.commons.api.domain.ODataOperation; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; +import org.apache.olingo.commons.core.data.AnnotationImpl; +import org.apache.olingo.commons.core.data.EntityImpl; +import org.apache.olingo.commons.core.data.LinkImpl; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + /** * Reads JSON string into an entity. *
@@ -55,8 +55,8 @@ import java.util.regex.Matcher; */ public class JsonEntityDeserializer extends JsonDeserializer { - public JsonEntityDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonEntityDeserializer(final boolean serverMode) { + super(serverMode); } protected ResWrap doDeserialize(final JsonParser parser) throws IOException { @@ -154,7 +154,7 @@ public class JsonEntityDeserializer extends JsonDeserializer { if (field.getKey().endsWith(getJSONAnnotation(jsonMediaEditLink))) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); - link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL) + getTitle(field)); + link.setRel(Constants.NS_MEDIA_EDIT_LINK_REL + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.MEDIA_EDIT.toString()); entity.getMediaEditLinks().add(link); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java index 5576e19a9..b6a32ef14 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java @@ -1,24 +1,25 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonGenerator; +import java.io.IOException; + import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.Annotation; @@ -28,22 +29,22 @@ import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.ODataOperation; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.core.edm.EdmTypeInfo; -import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; /** * Writes out JSON string from an entity. */ public class JsonEntitySerializer extends JsonSerializer { - public JsonEntitySerializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonEntitySerializer(final boolean serverMode) { + super(serverMode); } - public JsonEntitySerializer(ODataServiceVersion version, boolean serverMode, ODataFormat format) { - super(version, serverMode, format); + public JsonEntitySerializer(boolean serverMode, ODataFormat format) { + super(serverMode, format); } protected void doSerialize(final Entity entity, final JsonGenerator jgen) @@ -61,26 +62,24 @@ public class JsonEntitySerializer extends JsonSerializer { if (serverMode) { if (container.getContextURL() != null) { - jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0 - ? Constants.JSON_CONTEXT : Constants.JSON_METADATA, - container.getContextURL().toASCIIString()); + jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString()); } - if (version.compareTo(ODataServiceVersion.V40) >= 0 && StringUtils.isNotBlank(container.getMetadataETag())) { + if (StringUtils.isNotBlank(container.getMetadataETag())) { jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag()); } if (StringUtils.isNotBlank(entity.getETag())) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ETAG), entity.getETag()); + jgen.writeStringField(Constants.JSON_ETAG, entity.getETag()); } } if (StringUtils.isNotBlank(entity.getType()) && format != ODataFormat.JSON_NO_METADATA) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), - new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); + jgen.writeStringField(Constants.JSON_TYPE, + new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external()); } if (entity.getId() != null && format != ODataFormat.JSON_NO_METADATA) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ID), entity.getId().toASCIIString()); + jgen.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString()); } for (Annotation annotation : entity.getAnnotations()) { @@ -92,12 +91,12 @@ public class JsonEntitySerializer extends JsonSerializer { } if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.EDIT_LINK), - entity.getEditLink().getHref()); + jgen.writeStringField(Constants.JSON_EDIT_LINK, + entity.getEditLink().getHref()); if (entity.isMediaEntity()) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_READ_LINK), - entity.getEditLink().getHref() + "/$value"); + jgen.writeStringField(Constants.JSON_MEDIA_READ_LINK, + entity.getEditLink().getHref() + "/$value"); } } @@ -107,7 +106,7 @@ public class JsonEntitySerializer extends JsonSerializer { for (Link link : entity.getMediaEditLinks()) { if (link.getTitle() == null) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK), link.getHref()); + jgen.writeStringField(Constants.JSON_MEDIA_EDIT_LINK, link.getHref()); } if (link.getInlineEntity() != null) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java index aba91089f..00b807e00 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java @@ -18,23 +18,23 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.net.URI; +import java.util.Iterator; +import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.Annotation; import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.data.AnnotationImpl; import org.apache.olingo.commons.core.data.EntitySetImpl; -import java.io.IOException; -import java.net.URI; -import java.util.Iterator; -import java.util.Map; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; /** * Reads JSON string into an entity set. @@ -43,8 +43,8 @@ import java.util.Map; */ public class JsonEntitySetDeserializer extends JsonDeserializer { - public JsonEntitySetDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonEntitySetDeserializer(final boolean serverMode) { + super(serverMode); } protected ResWrap doDeserialize(final JsonParser parser) throws IOException { @@ -93,7 +93,7 @@ public class JsonEntitySetDeserializer extends JsonDeserializer { } if (tree.hasNonNull(Constants.VALUE)) { - final JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(version, serverMode); + final JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode); for (JsonNode jsonNode : tree.get(Constants.VALUE)) { entitySet.getEntities().add( entityDeserializer.doDeserialize(jsonNode.traverse(parser.getCodec())).getPayload()); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java index 256376c5b..a7407bd49 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetSerializer.java @@ -18,7 +18,9 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonGenerator; +import java.io.IOException; +import java.net.URI; + import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.Annotation; @@ -26,15 +28,13 @@ import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import java.io.IOException; -import java.net.URI; +import com.fasterxml.jackson.core.JsonGenerator; public class JsonEntitySetSerializer extends JsonSerializer { - public JsonEntitySetSerializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonEntitySetSerializer(final boolean serverMode) { + super(serverMode); } protected void doSerialize(final EntitySet entitySet, final JsonGenerator jgen) @@ -51,12 +51,10 @@ public class JsonEntitySetSerializer extends JsonSerializer { if (serverMode) { if (container.getContextURL() != null) { - jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0 - ? Constants.JSON_CONTEXT : Constants.JSON_METADATA, - container.getContextURL().toASCIIString()); + jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString()); } - if (version.compareTo(ODataServiceVersion.V40) >= 0 && StringUtils.isNotBlank(container.getMetadataETag())) { + if (StringUtils.isNotBlank(container.getMetadataETag())) { jgen.writeStringField( Constants.JSON_METADATA_ETAG, container.getMetadataETag()); @@ -64,17 +62,17 @@ public class JsonEntitySetSerializer extends JsonSerializer { } if (entitySet.getId() != null) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.ID), entitySet.getId().toASCIIString()); + jgen.writeStringField(Constants.JSON_ID, entitySet.getId().toASCIIString()); } - jgen.writeNumberField(version.getJsonName(ODataServiceVersion.JsonKey.COUNT), + jgen.writeNumberField(Constants.JSON_COUNT, entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount()); if (serverMode) { if (entitySet.getNext() != null) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.NEXT_LINK), + jgen.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString()); } if (entitySet.getDeltaLink() != null) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.DELTA_LINK), + jgen.writeStringField(Constants.JSON_DELTA_LINK, entitySet.getDeltaLink().toASCIIString()); } } @@ -84,7 +82,7 @@ public class JsonEntitySetSerializer extends JsonSerializer { } jgen.writeArrayFieldStart(Constants.VALUE); - final JsonEntitySerializer entitySerializer = new JsonEntitySerializer(version, serverMode); + final JsonEntitySerializer entitySerializer = new JsonEntitySerializer(serverMode); for (Entity entity : entitySet.getEntities()) { entitySerializer.doSerialize(entity, jgen); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java index bed29dd69..8c439f754 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java @@ -18,12 +18,15 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.databind.JsonNode; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.GeoUtils; 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; import org.apache.olingo.commons.api.edm.geo.Geospatial; import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; import org.apache.olingo.commons.api.edm.geo.LineString; @@ -36,19 +39,10 @@ import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.core.edm.EdmTypeInfo; import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; +import com.fasterxml.jackson.databind.JsonNode; class JsonGeoValueDeserializer { - private final ODataServiceVersion version; - - public JsonGeoValueDeserializer(final ODataServiceVersion version) { - this.version = version; - } - private Point point(final Iterator itor, final EdmPrimitiveTypeKind type, final SRID srid) { Point point = null; @@ -208,7 +202,7 @@ class JsonGeoValueDeserializer { final int yIdx = nodeType.indexOf('y'); nodeType = nodeType.substring(yIdx + 1); } - actualType = EdmPrimitiveTypeKind.valueOfFQN(version, typeInfo.getFullQualifiedName().toString() + nodeType); + actualType = EdmPrimitiveTypeKind.valueOfFQN(typeInfo.getFullQualifiedName().toString() + nodeType); } else { actualType = typeInfo.getPrimitiveTypeKind(); } 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 0611ff25e..8e49a28d6 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 @@ -18,24 +18,24 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -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.edm.constants.ODataServiceVersion; - import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; 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 com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + public class JsonODataErrorDeserializer extends JsonDeserializer { - public JsonODataErrorDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonODataErrorDeserializer(final boolean serverMode) { + super(serverMode); } protected ODataError doDeserialize(final JsonParser parser) throws IOException { @@ -62,8 +62,7 @@ public class JsonODataErrorDeserializer extends JsonDeserializer { } if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) { List details = new ArrayList(); - JsonODataErrorDetailDeserializer detailDeserializer = - new JsonODataErrorDetailDeserializer(version, serverMode); + JsonODataErrorDetailDeserializer detailDeserializer = new JsonODataErrorDetailDeserializer(serverMode); for (JsonNode jsonNode : errorNode.get(Constants.ERROR_DETAILS)) { details.add(detailDeserializer.doDeserialize(jsonNode.traverse(parser.getCodec())) .getPayload()); 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 40d93fe7c..138bad3c5 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 @@ -18,20 +18,20 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; -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.edm.constants.ODataServiceVersion; - import java.io.IOException; 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 com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; + public class JsonODataErrorDetailDeserializer extends JsonDeserializer { - public JsonODataErrorDetailDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonODataErrorDetailDeserializer(final boolean serverMode) { + super(serverMode); } protected ResWrap doDeserialize(final JsonParser parser) throws IOException { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java index ab78a4445..b5bda8cd1 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java @@ -18,9 +18,11 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.net.URI; +import java.util.Iterator; +import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.Annotation; @@ -28,23 +30,21 @@ import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.data.AnnotationImpl; import org.apache.olingo.commons.core.data.PropertyImpl; import org.apache.olingo.commons.core.edm.EdmTypeInfo; -import java.io.IOException; -import java.net.URI; -import java.util.Iterator; -import java.util.Map; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; /** * Parse JSON string into Property. */ public class JsonPropertyDeserializer extends JsonDeserializer { - public JsonPropertyDeserializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonPropertyDeserializer(final boolean serverMode) { + super(serverMode); } protected ResWrap doDeserialize(final JsonParser parser) throws IOException { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java index 14407a0c8..da28791c0 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java @@ -18,26 +18,26 @@ */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonGenerator; +import java.io.IOException; +import java.net.URI; + import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.Annotation; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.EdmTypeInfo; -import java.io.IOException; -import java.net.URI; +import com.fasterxml.jackson.core.JsonGenerator; /** * Writes out JSON string from PropertyImpl. */ public class JsonPropertySerializer extends JsonSerializer { - public JsonPropertySerializer(final ODataServiceVersion version, final boolean serverMode) { - super(version, serverMode); + public JsonPropertySerializer(final boolean serverMode) { + super(serverMode); } protected void doSerialize(final Property property, final JsonGenerator jgen) @@ -53,14 +53,12 @@ public class JsonPropertySerializer extends JsonSerializer { jgen.writeStartObject(); if (serverMode && container.getContextURL() != null) { - jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0 - ? Constants.JSON_CONTEXT : Constants.JSON_METADATA, - container.getContextURL().toASCIIString()); + jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString()); } if (StringUtils.isNotBlank(property.getType())) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), - new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build().external(version)); + jgen.writeStringField(Constants.JSON_TYPE, + new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build().external()); } for (Annotation annotation : property.getAnnotations()) { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java index 6a50ad3d8..f054be585 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java @@ -1,51 +1,23 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.olingo.commons.core.serialization; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Annotatable; -import org.apache.olingo.commons.api.data.Annotation; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.EntitySet; -import org.apache.olingo.commons.api.data.Link; -import org.apache.olingo.commons.api.data.Linked; -import org.apache.olingo.commons.api.data.ComplexValue; -import org.apache.olingo.commons.api.data.Property; -import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Valuable; -import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.domain.ODataLinkType; -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; -import org.apache.olingo.commons.api.edm.geo.Geospatial; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.api.serialization.ODataSerializer; -import org.apache.olingo.commons.api.serialization.ODataSerializerException; -import org.apache.olingo.commons.core.edm.EdmTypeInfo; -import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; - import java.io.IOException; import java.io.Writer; import java.net.URI; @@ -54,6 +26,33 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Annotatable; +import org.apache.olingo.commons.api.data.Annotation; +import org.apache.olingo.commons.api.data.ComplexValue; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; +import org.apache.olingo.commons.api.data.Link; +import org.apache.olingo.commons.api.data.Linked; +import org.apache.olingo.commons.api.data.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.ODataLinkType; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.commons.api.serialization.ODataSerializer; +import org.apache.olingo.commons.api.serialization.ODataSerializerException; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; +import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; + public class JsonSerializer implements ODataSerializer { private static final EdmPrimitiveTypeKind[] NUMBER_TYPES = { @@ -65,18 +64,15 @@ public class JsonSerializer implements ODataSerializer { private final JsonGeoValueSerializer geoSerializer = new JsonGeoValueSerializer(); - protected ODataServiceVersion version; - protected boolean serverMode; protected ODataFormat format; - public JsonSerializer(final ODataServiceVersion version, final boolean serverMode) { - this(version, serverMode, ODataFormat.JSON_FULL_METADATA); + public JsonSerializer(final boolean serverMode) { + this(serverMode, ODataFormat.JSON_FULL_METADATA); } - public JsonSerializer(final ODataServiceVersion version, final boolean serverMode, ODataFormat format) { - this.version = version; + public JsonSerializer(final boolean serverMode, ODataFormat format) { this.serverMode = serverMode; this.format = format; } @@ -86,11 +82,11 @@ public class JsonSerializer implements ODataSerializer { try { final JsonGenerator json = new JsonFactory().createGenerator(writer); if (obj instanceof EntitySet) { - new JsonEntitySetSerializer(version, serverMode).doSerialize((EntitySet) obj, json); + new JsonEntitySetSerializer(serverMode).doSerialize((EntitySet) obj, json); } else if (obj instanceof Entity) { - new JsonEntitySerializer(version, serverMode, format).doSerialize((Entity) obj, json); + new JsonEntitySerializer(serverMode, format).doSerialize((Entity) obj, json); } else if (obj instanceof Property) { - new JsonPropertySerializer(version, serverMode).doSerialize((Property) obj, json); + new JsonPropertySerializer(serverMode).doSerialize((Property) obj, json); } else if (obj instanceof Link) { link((Link) obj, json); } @@ -102,12 +98,12 @@ public class JsonSerializer implements ODataSerializer { } } - private void reference(ResWrapcontainer, JsonGenerator json) throws IOException { + private void reference(ResWrap container, JsonGenerator json) throws IOException { json.writeStartObject(); - + json.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString()); json.writeStringField(Constants.JSON_ID, container.getPayload().toASCIIString()); - + json.writeEndObject(); } @@ -118,14 +114,14 @@ public class JsonSerializer implements ODataSerializer { try { final JsonGenerator json = new JsonFactory().createGenerator(writer); if (obj instanceof EntitySet) { - new JsonEntitySetSerializer(version, serverMode).doContainerSerialize((ResWrap) container, json); + new JsonEntitySetSerializer(serverMode).doContainerSerialize((ResWrap) container, json); } else if (obj instanceof Entity) { - new JsonEntitySerializer(version, serverMode).doContainerSerialize((ResWrap) container, json); + new JsonEntitySerializer(serverMode).doContainerSerialize((ResWrap) container, json); } else if (obj instanceof Property) { - new JsonPropertySerializer(version, serverMode).doContainerSerialize((ResWrap) container, json); + new JsonPropertySerializer(serverMode).doContainerSerialize((ResWrap) container, json); } else if (obj instanceof Link) { link((Link) obj, json); - } else if(obj instanceof URI) { + } else if (obj instanceof URI) { reference((ResWrap) container, json); } json.flush(); @@ -143,7 +139,7 @@ public class JsonSerializer implements ODataSerializer { } protected void links(final Linked linked, final JsonGenerator jgen) - throws IOException, EdmPrimitiveTypeException { + throws IOException, EdmPrimitiveTypeException { if (serverMode) { serverLinks(linked, jgen); @@ -153,7 +149,7 @@ public class JsonSerializer implements ODataSerializer { } protected void clientLinks(final Linked linked, final JsonGenerator jgen) - throws IOException, EdmPrimitiveTypeException { + throws IOException, EdmPrimitiveTypeException { final Map> entitySetLinks = new HashMap>(); for (Link link : linked.getNavigationLinks()) { @@ -163,7 +159,7 @@ public class JsonSerializer implements ODataSerializer { ODataLinkType type = null; try { - type = ODataLinkType.fromString(version, link.getRel(), link.getType()); + type = ODataLinkType.fromString(link.getRel(), link.getType()); } catch (IllegalArgumentException e) { // ignore } @@ -187,10 +183,10 @@ public class JsonSerializer implements ODataSerializer { if (link.getInlineEntity() != null) { jgen.writeFieldName(link.getTitle()); - new JsonEntitySerializer(version, serverMode).doSerialize(link.getInlineEntity(), jgen); + new JsonEntitySerializer(serverMode).doSerialize(link.getInlineEntity(), jgen); } else if (link.getInlineEntitySet() != null) { jgen.writeArrayFieldStart(link.getTitle()); - final JsonEntitySerializer entitySerializer = new JsonEntitySerializer(version, serverMode); + final JsonEntitySerializer entitySerializer = new JsonEntitySerializer(serverMode); for (Entity subEntry : link.getInlineEntitySet().getEntities()) { entitySerializer.doSerialize(subEntry, jgen); } @@ -214,8 +210,7 @@ public class JsonSerializer implements ODataSerializer { for (Link link : ((Entity) linked).getMediaEditLinks()) { if (StringUtils.isNotBlank(link.getHref())) { jgen.writeStringField( - link.getTitle() + StringUtils.prependIfMissing( - version.getJsonName(ODataServiceVersion.JsonKey.MEDIA_EDIT_LINK), "@"), + link.getTitle() + StringUtils.prependIfMissing(Constants.JSON_MEDIA_EDIT_LINK, "@"), link.getHref()); } } @@ -224,7 +219,7 @@ public class JsonSerializer implements ODataSerializer { for (Link link : linked.getAssociationLinks()) { if (StringUtils.isNotBlank(link.getHref())) { jgen.writeStringField( - link.getTitle() + version.getJsonName(ODataServiceVersion.JsonKey.ASSOCIATION_LINK), + link.getTitle() + Constants.JSON_ASSOCIATION_LINK, link.getHref()); } } @@ -236,16 +231,16 @@ public class JsonSerializer implements ODataSerializer { if (StringUtils.isNotBlank(link.getHref())) { jgen.writeStringField( - link.getTitle() + version.getJsonName(ODataServiceVersion.JsonKey.NAVIGATION_LINK), + link.getTitle() + Constants.JSON_NAVIGATION_LINK, link.getHref()); } if (link.getInlineEntity() != null) { jgen.writeFieldName(link.getTitle()); - new JsonEntitySerializer(version, serverMode).doSerialize(link.getInlineEntity(), jgen); + new JsonEntitySerializer(serverMode).doSerialize(link.getInlineEntity(), jgen); } else if (link.getInlineEntitySet() != null) { jgen.writeArrayFieldStart(link.getTitle()); - JsonEntitySerializer entitySerializer = new JsonEntitySerializer(version, serverMode); + JsonEntitySerializer entitySerializer = new JsonEntitySerializer(serverMode); for (Entity subEntry : link.getInlineEntitySet().getEntities()) { entitySerializer.doSerialize(subEntry, jgen); } @@ -255,36 +250,36 @@ public class JsonSerializer implements ODataSerializer { } private void collection(final JsonGenerator jgen, final EdmTypeInfo typeInfo, - final ValueType valueType, final List value) + final ValueType valueType, final List value) throws IOException, EdmPrimitiveTypeException { jgen.writeStartArray(); for (Object item : value) { final EdmTypeInfo itemTypeInfo = typeInfo == null - ? null - : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build(); + ? null + : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build(); switch (valueType) { - case COLLECTION_PRIMITIVE: - primitiveValue(jgen, itemTypeInfo, item); - break; + case COLLECTION_PRIMITIVE: + primitiveValue(jgen, itemTypeInfo, item); + break; - case COLLECTION_GEOSPATIAL: - jgen.writeStartObject(); - geoSerializer.serialize(jgen, (Geospatial) item); - jgen.writeEndObject(); - break; + case COLLECTION_GEOSPATIAL: + jgen.writeStartObject(); + geoSerializer.serialize(jgen, (Geospatial) item); + jgen.writeEndObject(); + break; - case COLLECTION_ENUM: - jgen.writeString(item.toString()); - break; + case COLLECTION_ENUM: + jgen.writeString(item.toString()); + break; - case COLLECTION_COMPLEX: - final ComplexValue complexItem2 = (ComplexValue) item; - complexValue(jgen, itemTypeInfo, complexItem2.getValue(), complexItem2); - break; + case COLLECTION_COMPLEX: + final ComplexValue complexItem2 = (ComplexValue) item; + complexValue(jgen, itemTypeInfo, complexItem2.getValue(), complexItem2); + break; - default: + default: } } @@ -292,7 +287,7 @@ public class JsonSerializer implements ODataSerializer { } protected void primitiveValue(final JsonGenerator jgen, final EdmTypeInfo typeInfo, final Object value) - throws IOException, EdmPrimitiveTypeException { + throws IOException, EdmPrimitiveTypeException { final EdmPrimitiveTypeKind kind = typeInfo == null ? null : typeInfo.getPrimitiveTypeKind(); final boolean isNumber = kind == null ? value instanceof Number : ArrayUtils.contains(NUMBER_TYPES, kind); @@ -304,9 +299,9 @@ public class JsonSerializer implements ODataSerializer { jgen.writeBoolean((Boolean) value); } else { final String serialized = kind == null - ? value.toString() - // TODO: add facets - : EdmPrimitiveTypeFactory.getInstance(kind). + ? value.toString() + // TODO: add facets + : EdmPrimitiveTypeFactory.getInstance(kind). valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null); if (isNumber) { jgen.writeNumber(serialized); @@ -317,12 +312,12 @@ public class JsonSerializer implements ODataSerializer { } private void complexValue(final JsonGenerator jgen, final EdmTypeInfo typeInfo, - final List value, final Linked linked) + final List value, final Linked linked) throws IOException, EdmPrimitiveTypeException { jgen.writeStartObject(); if (typeInfo != null && format != ODataFormat.JSON_NO_METADATA) { - jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), typeInfo.external(version)); + jgen.writeStringField(Constants.JSON_TYPE, typeInfo.external()); } for (Property property : value) { @@ -336,7 +331,7 @@ public class JsonSerializer implements ODataSerializer { } private void value(final JsonGenerator jgen, final String type, final Valuable value) - throws IOException, EdmPrimitiveTypeException { + throws IOException, EdmPrimitiveTypeException { final EdmTypeInfo typeInfo = type == null ? null : new EdmTypeInfo.Builder().setTypeExpression(type).build(); if (value.isNull()) { @@ -357,10 +352,10 @@ public class JsonSerializer implements ODataSerializer { } protected void valuable(final JsonGenerator jgen, final Valuable valuable, final String name) - throws IOException, EdmPrimitiveTypeException { + throws IOException, EdmPrimitiveTypeException { if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation) - && !valuable.isComplex() && !valuable.isComplex()) { + && !valuable.isComplex() && !valuable.isComplex()) { String type = valuable.getType(); if (StringUtils.isBlank(type) && valuable.isPrimitive() || valuable.isNull()) { @@ -368,8 +363,8 @@ public class JsonSerializer implements ODataSerializer { } if (StringUtils.isNotBlank(type) && format != ODataFormat.JSON_NO_METADATA) { jgen.writeFieldName( - name + StringUtils.prependIfMissing(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), "@")); - jgen.writeString(new EdmTypeInfo.Builder().setTypeExpression(type).build().external(version)); + name + StringUtils.prependIfMissing(Constants.JSON_TYPE, "@")); + jgen.writeString(new EdmTypeInfo.Builder().setTypeExpression(type).build().external()); } } diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/serialization/AtomDeserializerTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/serialization/AtomDeserializerTest.java index 3126fc240..0c471604f 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/serialization/AtomDeserializerTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/serialization/AtomDeserializerTest.java @@ -18,7 +18,9 @@ */ package org.apache.olingo.commons.core.serialization; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -26,7 +28,6 @@ import java.io.InputStream; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.junit.Test; public class AtomDeserializerTest { @@ -35,23 +36,23 @@ public class AtomDeserializerTest { public void emptyInlineEntityOlingo540() throws Exception { final String content = "" + "\r\n" + " http://services.odata.org/V3/OData/OData.svc/Products(3)\r\n" + " \r\n" + + + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + " \r\n" + + " \r\n" + " \r\n" + - " \r\n" + " Havina Cola\r\n" + @@ -60,24 +61,25 @@ public class AtomDeserializerTest { " \r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + " \r\n" + - " \r\n" + - " 3\r\n" + - " 2005-10-01T00:00:00\r\n" + - " 2006-10-01T00:00:00\r\n" + - " 3\r\n" + - " 19.9\r\n" + - " \r\n" + + " \r\n" + + " 3\r\n" + + " 2005-10-01T00:00:00\r\n" + + " 2006-10-01T00:00:00\r\n" + + " 3\r\n" + + " 19.9\r\n" + + " \r\n" + " \r\n" + " "; - final AtomDeserializer deserializer = new AtomDeserializer(ODataServiceVersion.V30); + //TODO: THis was a test for V3 + final AtomDeserializer deserializer = new AtomDeserializer(); final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); final ResWrap entity = deserializer.toEntity(in); @@ -89,58 +91,58 @@ public class AtomDeserializerTest { public void filledInlineEntity() throws Exception { final String content = "" + "\r\n" + - " http://services.odata.org/V3/OData/OData.svc/Products(3)\r\n" + - " \r\n" + + + "xml:base=\"http://services.odata.org/V4/OData/OData.svc/\">\r\n" + + " http://services.odata.org/V4/OData/OData.svc/Products(3)\r\n" + + " \r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + " \r\n" + " \r\n" + - " http://services.odata.org/V3/OData/OData.svc/Suppliers(0)\r\n" + + " http://services.odata.org/V4/OData/OData.svc/Suppliers(0)\r\n" + " \r\n" + + + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" + " \r\n" + - " \r\n" + " Exotic Liquids\r\n" + " 2015-01-26T08:57:02Z\r\n" + " \r\n" + " \r\n" + " \r\n" + - " \r\n" + " \r\n" + - " \r\n" + - " 0\r\n" + - " Exotic Liquids\r\n" + - " \r\n" + - " NE 228th\r\n" + - " Sammamish\r\n" + - " WA\r\n" + - " 98074\r\n" + - " USA\r\n" + - " \r\n" + - " \r\n" + + " \r\n" + + " 0\r\n" + + " Exotic Liquids\r\n" + + " \r\n" + + " NE 228th\r\n" + + " Sammamish\r\n" + + " WA\r\n" + + " 98074\r\n" + + " USA\r\n" + + " \r\n" + + " \r\n" + " \r\n" + " 47.6316604614258 -122.03547668457\r\n" + " \r\n" + - " \r\n" + - " 0\r\n" + - " \r\n" + + " \r\n" + + " 0\r\n" + + " \r\n" + " \r\n" + " " + - " \r\n" + + " \r\n" + " \r\n" + - " \r\n" + " Havina Cola\r\n" + @@ -149,24 +151,23 @@ public class AtomDeserializerTest { " \r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + " \r\n" + - " \r\n" + - " 3\r\n" + - " 2005-10-01T00:00:00\r\n" + - " 2006-10-01T00:00:00\r\n" + - " 3\r\n" + - " 19.9\r\n" + - " \r\n" + + " \r\n" + + " 3\r\n" + + " 2005-10-01T00:00:00\r\n" + + " 2006-10-01T00:00:00\r\n" + + " 3\r\n" + + " 19.9\r\n" + + " \r\n" + " \r\n" + " "; - - final AtomDeserializer deserializer = new AtomDeserializer(ODataServiceVersion.V30); + final AtomDeserializer deserializer = new AtomDeserializer(); final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); final ResWrap entity = deserializer.toEntity(in); @@ -182,25 +183,25 @@ public class AtomDeserializerTest { public void emptyInlineEntityCollection() throws Exception { final String content = "" + "\r\n" + " http://services.odata.org/V3/OData/OData.svc/Products(3)\r\n" + " \r\n" + + + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + " \r\n" + " \r\n" + " \r\n" + - " \r\n" + + " \r\n" + " \r\n" + - " \r\n" + " Havina Cola\r\n" + @@ -209,24 +210,24 @@ public class AtomDeserializerTest { " \r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + " \r\n" + - " \r\n" + - " 3\r\n" + - " 2005-10-01T00:00:00\r\n" + - " 2006-10-01T00:00:00\r\n" + - " 3\r\n" + - " 19.9\r\n" + - " \r\n" + + " \r\n" + + " 3\r\n" + + " 2005-10-01T00:00:00\r\n" + + " 2006-10-01T00:00:00\r\n" + + " 3\r\n" + + " 19.9\r\n" + + " \r\n" + " \r\n" + " "; - - final AtomDeserializer deserializer = new AtomDeserializer(ODataServiceVersion.V30); + //TODO: THis was a test for V3 + final AtomDeserializer deserializer = new AtomDeserializer(); final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); final ResWrap entity = deserializer.toEntity(in); @@ -240,59 +241,59 @@ public class AtomDeserializerTest { public void filledInlineEntityCollection() throws Exception { final String content = "" + "\r\n" + " http://services.odata.org/V3/OData/OData.svc/Products(3)\r\n" + " \r\n" + + + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + + " \r\n" + " \r\n" + " \r\n" + " http://services.odata.org/V3/OData/OData.svc/Suppliers(0)\r\n" + " \r\n" + + + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" + " \r\n" + - " \r\n" + " Exotic Liquids\r\n" + " 2015-01-26T08:57:02Z\r\n" + " \r\n" + " \r\n" + " \r\n" + - " \r\n" + " \r\n" + - " \r\n" + - " 0\r\n" + - " Exotic Liquids\r\n" + - " \r\n" + - " NE 228th\r\n" + - " Sammamish\r\n" + - " WA\r\n" + - " 98074\r\n" + - " USA\r\n" + - " \r\n" + - " \r\n" + + " \r\n" + + " 0\r\n" + + " Exotic Liquids\r\n" + + " \r\n" + + " NE 228th\r\n" + + " Sammamish\r\n" + + " WA\r\n" + + " 98074\r\n" + + " USA\r\n" + + " \r\n" + + " \r\n" + " \r\n" + " 47.6316604614258 -122.03547668457\r\n" + " \r\n" + - " \r\n" + - " 0\r\n" + - " \r\n" + + " \r\n" + + " 0\r\n" + + " \r\n" + " \r\n" + " \r\n" + " \r\n" + - " \r\n" + + " \r\n" + " \r\n" + - " \r\n" + " Havina Cola\r\n" + @@ -301,24 +302,24 @@ public class AtomDeserializerTest { " \r\n" + " \r\n" + " \r\n" + - " \r\n" + - " \r\n" + - " \r\n" + " \r\n" + - " \r\n" + - " 3\r\n" + - " 2005-10-01T00:00:00\r\n" + - " 2006-10-01T00:00:00\r\n" + - " 3\r\n" + - " 19.9\r\n" + - " \r\n" + + " \r\n" + + " 3\r\n" + + " 2005-10-01T00:00:00\r\n" + + " 2006-10-01T00:00:00\r\n" + + " 3\r\n" + + " 19.9\r\n" + + " \r\n" + " \r\n" + " "; - - final AtomDeserializer deserializer = new AtomDeserializer(ODataServiceVersion.V30); + //TODO: THis was a test for V3 + final AtomDeserializer deserializer = new AtomDeserializer(); final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); final ResWrap entity = deserializer.toEntity(in);