You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/03/11 10:15:37 UTC
olingo-odata4 git commit: [OLINGO-575] Link refactoring
Repository: olingo-odata4
Updated Branches:
refs/heads/olingo575 [created] 0e5da552b
[OLINGO-575] Link refactoring
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/0e5da552
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0e5da552
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0e5da552
Branch: refs/heads/olingo575
Commit: 0e5da552bdd13f262f36522683929e384956a290
Parents: 40d82fc
Author: Christian Amend <ch...@apache.org>
Authored: Tue Mar 10 17:05:34 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Tue Mar 10 17:05:34 2015 +0100
----------------------------------------------------------------------
.../apache/olingo/commons/api/data/Link.java | 29 --
.../apache/olingo/commons/api/data/Linked.java | 44 ++
.../commons/core/data/AbstractLinked.java | 111 ++++++
.../commons/core/data/ComplexValueImpl.java | 61 +--
.../olingo/commons/core/data/EntityImpl.java | 55 +--
.../olingo/commons/core/data/LinkImpl.java | 24 --
.../core/serialization/AtomDeserializer.java | 20 +-
.../core/serialization/AtomSerializer.java | 58 ++-
.../core/serialization/JsonDeserializer.java | 14 +-
.../serialization/JsonEntityDeserializer.java | 2 +-
.../serialization/JsonEntitySerializer.java | 8 +-
.../core/serialization/JsonSerializer.java | 16 +-
.../serialization/AtomDeserializerTest.java | 399 ++++++++++---------
13 files changed, 434 insertions(+), 407 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
index 88742f5..a40a0cc 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
@@ -93,34 +93,6 @@ public interface Link extends Annotatable {
void setMediaETag(String etag);
/**
- * Gets in-line entity.
- *
- * @return in-line entity.
- */
- Entity getInlineEntity();
-
- /**
- * Sets in-line entity.
- *
- * @param entity entity.
- */
- void setInlineEntity(Entity entity);
-
- /**
- * Gets in-line entity set.
- *
- * @return in-line entity set.
- */
- EntitySet getInlineEntitySet();
-
- /**
- * Sets in-line entity set.
- *
- * @param entitySet entity set.
- */
- void setInlineEntitySet(EntitySet entitySet);
-
- /**
* If this is a "toOne" relationship this method delivers the binding link or <tt>null</tt> if not set.
* @return String the binding link.
*/
@@ -143,5 +115,4 @@ public interface Link extends Annotatable {
* @param bindingLinks
*/
void setBindingLinks(List<String> bindingLinks);
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Linked.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Linked.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Linked.java
index 1c28507..dc4f6a4 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Linked.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Linked.java
@@ -19,6 +19,7 @@
package org.apache.olingo.commons.api.data;
import java.util.List;
+import java.util.Map;
public interface Linked {
@@ -65,4 +66,47 @@ public interface Linked {
* @return links.
*/
List<Link> getNavigationBindings();
+
+
+ /**
+ * Gets in-line entity.
+ *
+ * @param name of the navigation
+ * @return in-line entity for given name, if available, otherwise <tt>null</tt>
+ */
+ Entity getInlineEntity(String name);
+
+ /**
+ * @return all in-line entities for this entity.
+ */
+ Map<String, Entity> getAllInlineEntities();
+
+ /**
+ * Adds an in-line entity for given navigation name. If one is set already it will be replaced with the new value.
+ *
+ * @param name navigation name
+ * @param entity entity.
+ */
+ void addInlineEntity(String name, Entity entity);
+
+ /**
+ * Gets in-line entity set.
+ *
+ * @param name of the navigation
+ * @return in-line entity set for given name, if available, otherwise <tt>null</tt>
+ */
+ EntitySet getInlineEntitySet(String name);
+
+ /**
+ * @return all in-line entity sets for this entity.
+ */
+ Map<String, EntitySet> getAllInlineEntitySets();
+
+ /**
+ * Adds an in-line entity set for given navigation name. If one is set already it will be replaced with the new value.
+ *
+ * @param name navigation name
+ * @param entitySet entity set.
+ */
+ void addInlineEntitySet(String name, EntitySet entitySet);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractLinked.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractLinked.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractLinked.java
new file mode 100644
index 0000000..e7cf27d
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractLinked.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.core.data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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;
+
+public class AbstractLinked extends AbstractODataObject implements Linked{
+
+ private final List<Link> associationLinks = new ArrayList<Link>();
+ private final List<Link> navigationLinks = new ArrayList<Link>();
+ private final List<Link> bindingLinks = new ArrayList<Link>();
+
+ private final HashMap<String, Entity> inlineEntities = new HashMap<String, Entity>();
+ private final HashMap<String, EntitySet> inlineEntitySets = new HashMap<String, EntitySet>();
+
+ private Link getOneByTitle(final String name, final List<Link> links) {
+ Link result = null;
+
+ for (Link link : links) {
+ if (name.equals(link.getTitle())) {
+ result = link;
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public Link getAssociationLink(final String name) {
+ return getOneByTitle(name, associationLinks);
+ }
+
+ @Override
+ public List<Link> getAssociationLinks() {
+ return associationLinks;
+ }
+
+ @Override
+ public Link getNavigationLink(final String name) {
+ return getOneByTitle(name, navigationLinks);
+ }
+
+ @Override
+ public List<Link> getNavigationLinks() {
+ return navigationLinks;
+ }
+
+ @Override
+ public Link getNavigationBinding(String name) {
+ return getOneByTitle(name, bindingLinks);
+ }
+
+ @Override
+ public List<Link> getNavigationBindings() {
+ return bindingLinks;
+ }
+
+ @Override
+ public Entity getInlineEntity(String name) {
+ return inlineEntities.get(name);
+ }
+
+ @Override
+ public Map<String, Entity> getAllInlineEntities() {
+ return inlineEntities;
+ }
+
+ @Override
+ public void addInlineEntity(String name, Entity entity) {
+ inlineEntities.put(name, entity);
+ }
+
+ @Override
+ public EntitySet getInlineEntitySet(String name) {
+ return inlineEntitySets.get(name);
+ }
+
+ @Override
+ public Map<String, EntitySet> getAllInlineEntitySets() {
+ return inlineEntitySets;
+ }
+
+ @Override
+ public void addInlineEntitySet(String name, EntitySet entitySet) {
+ inlineEntitySets.put(name, entitySet);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ComplexValueImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ComplexValueImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ComplexValueImpl.java
index c50f51a..f7317db 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ComplexValueImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ComplexValueImpl.java
@@ -18,71 +18,18 @@
*/
package org.apache.olingo.commons.core.data;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.ComplexValue;
-import org.apache.olingo.commons.api.data.Property;
-
import java.util.ArrayList;
import java.util.List;
-public class ComplexValueImpl implements ComplexValue {
+import org.apache.olingo.commons.api.data.ComplexValue;
+import org.apache.olingo.commons.api.data.Property;
+
+public class ComplexValueImpl extends AbstractLinked implements ComplexValue {
private final List<Property> value = new ArrayList<Property>();
- private final List<Link> associationLinks = new ArrayList<Link>();
- private final List<Link> navigationLinks = new ArrayList<Link>();
- private final List<Link> bindingLinks = new ArrayList<Link>();
- private final List<Annotation> annotations = new ArrayList<Annotation>();
@Override
public List<Property> getValue() {
return value;
}
-
- private Link getOneByTitle(final String name, final List<Link> links) {
- Link result = null;
-
- for (Link link : links) {
- if (name.equals(link.getTitle())) {
- result = link;
- }
- }
-
- return result;
- }
-
- @Override
- public Link getAssociationLink(final String name) {
- return getOneByTitle(name, associationLinks);
- }
-
- @Override
- public List<Link> getAssociationLinks() {
- return associationLinks;
- }
-
- @Override
- public Link getNavigationLink(final String name) {
- return getOneByTitle(name, navigationLinks);
- }
-
- @Override
- public List<Link> getNavigationLinks() {
- return navigationLinks;
- }
-
- @Override
- public List<Annotation> getAnnotations() {
- return annotations;
- }
-
- @Override
- public Link getNavigationBinding(String name) {
- return getOneByTitle(name, bindingLinks);
- }
-
- @Override
- public List<Link> getNavigationBindings() {
- return bindingLinks;
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java
index 38dd748..28eff5a 100755
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java
@@ -18,19 +18,19 @@
*/
package org.apache.olingo.commons.core.data;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.domain.ODataOperation;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Class implementing an OData entity.
*/
-public class EntityImpl extends AbstractODataObject implements Entity {
+public class EntityImpl extends AbstractLinked implements Entity {
private String eTag;
@@ -39,10 +39,7 @@ public class EntityImpl extends AbstractODataObject implements Entity {
private Link readLink;
private Link editLink;
- private final List<Link> associationLinks = new ArrayList<Link>();
- private final List<Link> navigationLinks = new ArrayList<Link>();
private final List<Link> mediaEditLinks = new ArrayList<Link>();
- private final List<Link> bindingLinks = new ArrayList<Link>();
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
@@ -91,52 +88,10 @@ public class EntityImpl extends AbstractODataObject implements Entity {
this.editLink = editLink;
}
- private Link getOneByTitle(final String name, final List<Link> links) {
- Link result = null;
-
- for (Link link : links) {
- if (name.equals(link.getTitle())) {
- result = link;
- }
- }
-
- return result;
- }
-
- @Override
- public Link getAssociationLink(final String name) {
- return getOneByTitle(name, associationLinks);
- }
-
- @Override
- public List<Link> getAssociationLinks() {
- return associationLinks;
- }
-
- @Override
- public Link getNavigationLink(final String name) {
- return getOneByTitle(name, navigationLinks);
- }
-
- @Override
- public List<Link> getNavigationLinks() {
- return navigationLinks;
- }
-
@Override
public List<Link> getMediaEditLinks() {
return mediaEditLinks;
}
-
- @Override
- public Link getNavigationBinding(String name) {
- return getOneByTitle(name, bindingLinks);
- }
-
- @Override
- public List<Link> getNavigationBindings() {
- return bindingLinks;
- }
@Override
public List<ODataOperation> getOperations() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java
index 5d096d6..69ee3f0 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java
@@ -21,8 +21,6 @@ package org.apache.olingo.commons.core.data;
import java.util.ArrayList;
import java.util.List;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
public class LinkImpl extends AbstractAnnotatedObject implements Link {
@@ -32,8 +30,6 @@ public class LinkImpl extends AbstractAnnotatedObject implements Link {
private String href;
private String type;
private String mediaETag;
- private Entity entity;
- private EntitySet entitySet;
private String bindingLink;
private List<String> bindingLinks = new ArrayList<String>();
@@ -88,26 +84,6 @@ public class LinkImpl extends AbstractAnnotatedObject implements Link {
}
@Override
- public Entity getInlineEntity() {
- return entity;
- }
-
- @Override
- public void setInlineEntity(final Entity entity) {
- this.entity = entity;
- }
-
- @Override
- public EntitySet getInlineEntitySet() {
- return entitySet;
- }
-
- @Override
- public void setInlineEntitySet(final EntitySet entitySet) {
- this.entitySet = entitySet;
- }
-
- @Override
public String getBindingLink() {
return bindingLink;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java
index dcfb328..74bd998 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
@@ -56,6 +56,7 @@ 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;
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.AbstractLinked;
import org.apache.olingo.commons.core.data.AbstractODataObject;
import org.apache.olingo.commons.core.data.AnnotationImpl;
import org.apache.olingo.commons.core.data.ComplexValueImpl;
@@ -151,9 +152,9 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
}
if (link.getRel().startsWith(Constants.NS_NAVIGATION_LINK_REL)) {
-
- ((ComplexValue) value).getNavigationLinks().add(link);
- inline(reader, event.asStartElement(), link);
+ ((ComplexValueImpl) value).getNavigationLinks().add(link);
+ String navigationName = link.getRel().substring(Constants.NS_NAVIGATION_LINK_REL.length());
+ inline(reader, event.asStartElement(), navigationName, ((ComplexValueImpl) value));
} else if (link.getRel().startsWith(Constants.NS_ASSOCIATION_LINK_REL)) {
((Valuable) value).asComplex().getAssociationLinks().add(link);
@@ -379,8 +380,8 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
}
}
- private void inline(final XMLEventReader reader, final StartElement start, final LinkImpl link)
- throws XMLStreamException, EdmPrimitiveTypeException {
+ private void inline(final XMLEventReader reader, final StartElement start, final String navigationName,
+ final AbstractLinked linked) throws XMLStreamException, EdmPrimitiveTypeException {
boolean foundEndElement = false;
while (reader.hasNext() && !foundEndElement) {
@@ -391,14 +392,14 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
StartElement inline = getStartElement(reader);
if (inline != null) {
if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(inline.getName())) {
- link.setInlineEntity(entity(reader, inline));
+ linked.addInlineEntity(navigationName, entity(reader, inline));
}
if (Constants.QNAME_ATOM_ELEM_FEED.equals(inline.getName())) {
- link.setInlineEntitySet(entitySet(reader, inline));
+ linked.addInlineEntitySet(navigationName, entitySet(reader, inline));
}
}
} else if (annotationQName.equals(event.asStartElement().getName())) {
- link.getAnnotations().add(annotation(reader, event.asStartElement()));
+ linked.getAnnotations().add(annotation(reader, event.asStartElement()));
}
}
@@ -642,7 +643,8 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria
} else if (link.getRel().startsWith(Constants.NS_NAVIGATION_LINK_REL)) {
entity.getNavigationLinks().add(link);
- inline(reader, event.asStartElement(), link);
+ String navigationName = link.getRel().substring(Constants.NS_NAVIGATION_LINK_REL.length());
+ inline(reader, event.asStartElement(), navigationName, entity);
} else if (link.getRel().startsWith(Constants.NS_ASSOCIATION_LINK_REL)) {
entity.getAssociationLinks().add(link);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
----------------------------------------------------------------------
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 6c36116..eb0d5cb 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
@@ -36,6 +36,7 @@ import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Linked;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.ValueType;
@@ -139,7 +140,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
property.getValue());
if (!property.isNull() && property.isComplex()) {
links(writer, property.asComplex().getAssociationLinks());
- links(writer, property.asComplex().getNavigationLinks());
+ navigationLinks(writer, property.asComplex().getNavigationLinks(), property.asComplex());
}
writer.writeEndElement();
@@ -180,30 +181,51 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
for (Link link : links) {
writer.writeStartElement(Constants.ATOM_ELEM_LINK);
- if (StringUtils.isNotBlank(link.getRel())) {
- writer.writeAttribute(Constants.ATTR_REL, link.getRel());
- }
- if (StringUtils.isNotBlank(link.getTitle())) {
- writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
- }
- if (StringUtils.isNotBlank(link.getHref())) {
- writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
- }
- if (StringUtils.isNotBlank(link.getType())) {
- writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
+ commonLinkAttributes(writer, link);
+
+ for (Annotation annotation : link.getAnnotations()) {
+ annotation(writer, annotation, null);
}
- if (link.getInlineEntity() != null || link.getInlineEntitySet() != null) {
+ writer.writeEndElement();
+ }
+ }
+
+ private void commonLinkAttributes(final XMLStreamWriter writer, Link link) throws XMLStreamException {
+ if (StringUtils.isNotBlank(link.getRel())) {
+ writer.writeAttribute(Constants.ATTR_REL, link.getRel());
+ }
+ if (StringUtils.isNotBlank(link.getTitle())) {
+ writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
+ }
+ if (StringUtils.isNotBlank(link.getHref())) {
+ writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
+ }
+ if (StringUtils.isNotBlank(link.getType())) {
+ writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
+ }
+ }
+
+ private void navigationLinks(final XMLStreamWriter writer, final List<Link> links, Linked linked)
+ throws XMLStreamException, EdmPrimitiveTypeException {
+ for (Link link : links) {
+ writer.writeStartElement(Constants.ATOM_ELEM_LINK);
+
+ commonLinkAttributes(writer, link);
+
+ String navigationName = link.getRel().substring(Constants.NS_NAVIGATION_LINK_REL.length());
+
+ if (linked.getInlineEntity(navigationName) != null || linked.getInlineEntitySet(navigationName) != null) {
writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, namespaceMetadata);
- if (link.getInlineEntity() != null) {
+ if (linked.getInlineEntity(navigationName) != null) {
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
- entity(writer, link.getInlineEntity());
+ entity(writer, linked.getInlineEntity(navigationName));
writer.writeEndElement();
}
- if (link.getInlineEntitySet() != null) {
+ if (linked.getInlineEntitySet(navigationName) != null) {
writer.writeStartElement(Constants.ATOM_ELEM_FEED);
- entitySet(writer, link.getInlineEntitySet());
+ entitySet(writer, linked.getInlineEntitySet(navigationName));
writer.writeEndElement();
}
@@ -299,7 +321,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
}
links(writer, entity.getAssociationLinks());
- links(writer, entity.getNavigationLinks());
+ navigationLinks(writer, entity.getNavigationLinks(), entity);
links(writer, entity.getMediaEditLinks());
if (serverMode) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
index 929ad95..965dd8b 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
@@ -126,7 +126,7 @@ public class JsonDeserializer implements ODataDeserializer {
}
protected String setInline(final String name, final String suffix, final JsonNode tree,
- final ObjectCodec codec, final LinkImpl link) throws IOException {
+ final ObjectCodec codec, final Linked linked) throws IOException {
final String entityNamePrefix = name.substring(0, name.indexOf(suffix));
if (tree.has(entityNamePrefix)) {
@@ -134,18 +134,16 @@ public class JsonDeserializer implements ODataDeserializer {
JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode);
if (inline instanceof ObjectNode) {
- link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
- link.setInlineEntity(entityDeserializer.doDeserialize(inline.traverse(codec)).getPayload());
+ linked.addInlineEntity(entityNamePrefix, entityDeserializer.doDeserialize(inline.traverse(codec)).getPayload());
} else if (inline instanceof ArrayNode) {
- link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
final EntitySet entitySet = new EntitySetImpl();
for (final Iterator<JsonNode> entries = inline.elements(); entries.hasNext();) {
entitySet.getEntities().add(entityDeserializer.doDeserialize(entries.next().traverse(codec)).getPayload());
}
- link.setInlineEntitySet(entitySet);
+ linked.addInlineEntitySet(entityNamePrefix, entitySet);
}
}
return entityNamePrefix;
@@ -176,7 +174,7 @@ public class JsonDeserializer implements ODataDeserializer {
linked.getNavigationLinks().add(link);
toRemove.add(field.getKey());
- toRemove.add(setInline(field.getKey(), jsonNavigationLink, tree, codec, link));
+ toRemove.add(setInline(field.getKey(), jsonNavigationLink, tree, codec, linked));
} else if (field.getKey().endsWith(jsonAssociationLink)) {
final LinkImpl link = new LinkImpl();
link.setTitle(getTitle(field));
@@ -205,7 +203,7 @@ public class JsonDeserializer implements ODataDeserializer {
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
linked.getNavigationLinks().add(link);
- toRemove.add(setInline(field.getKey(), suffix, tree, codec, link));
+ toRemove.add(setInline(field.getKey(), suffix, tree, codec, linked));
} else if (field.getValue().isArray()) {
for (final Iterator<JsonNode> itor = field.getValue().elements(); itor.hasNext();) {
final JsonNode node = itor.next();
@@ -216,7 +214,7 @@ public class JsonDeserializer implements ODataDeserializer {
link.setHref(node.asText());
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
linked.getNavigationLinks().add(link);
- toRemove.add(setInline(field.getKey(), Constants.JSON_BIND_LINK_SUFFIX, tree, codec, link));
+ toRemove.add(setInline(field.getKey(), Constants.JSON_BIND_LINK_SUFFIX, tree, codec, linked));
}
}
toRemove.add(field.getKey());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
----------------------------------------------------------------------
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 5596fb3..f229401 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
@@ -165,7 +165,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
}
toRemove.add(field.getKey());
- toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree, parser.getCodec(), link));
+ toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree, parser.getCodec(), entity));
} else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) {
final String linkTitle = getTitle(field);
for (Link link : entity.getMediaEditLinks()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
----------------------------------------------------------------------
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 b6a32ef..cd9865c 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
@@ -109,12 +109,12 @@ public class JsonEntitySerializer extends JsonSerializer {
jgen.writeStringField(Constants.JSON_MEDIA_EDIT_LINK, link.getHref());
}
- if (link.getInlineEntity() != null) {
- jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
+ if (entity.getInlineEntity(link.getTitle()) != null) {
+ jgen.writeObjectField(link.getTitle(), entity.getInlineEntity(link.getTitle()));
}
- if (link.getInlineEntitySet() != null) {
+ if (entity.getInlineEntitySet(link.getTitle()) != null) {
jgen.writeArrayFieldStart(link.getTitle());
- for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
+ for (Entity subEntry : entity.getInlineEntitySet(link.getTitle()).getEntities()) {
jgen.writeObject(subEntry);
}
jgen.writeEndArray();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
----------------------------------------------------------------------
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 f054be5..ad100fb 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
@@ -181,13 +181,13 @@ public class JsonSerializer implements ODataSerializer {
}
}
- if (link.getInlineEntity() != null) {
+ if (linked.getInlineEntity(link.getTitle()) != null) {
jgen.writeFieldName(link.getTitle());
- new JsonEntitySerializer(serverMode).doSerialize(link.getInlineEntity(), jgen);
- } else if (link.getInlineEntitySet() != null) {
+ new JsonEntitySerializer(serverMode).doSerialize(linked.getInlineEntity(link.getTitle()), jgen);
+ } else if (linked.getInlineEntitySet(link.getTitle()) != null) {
jgen.writeArrayFieldStart(link.getTitle());
final JsonEntitySerializer entitySerializer = new JsonEntitySerializer(serverMode);
- for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
+ for (Entity subEntry : linked.getInlineEntitySet(link.getTitle()).getEntities()) {
entitySerializer.doSerialize(subEntry, jgen);
}
jgen.writeEndArray();
@@ -235,13 +235,13 @@ public class JsonSerializer implements ODataSerializer {
link.getHref());
}
- if (link.getInlineEntity() != null) {
+ if (linked.getInlineEntity(link.getTitle()) != null) {
jgen.writeFieldName(link.getTitle());
- new JsonEntitySerializer(serverMode).doSerialize(link.getInlineEntity(), jgen);
- } else if (link.getInlineEntitySet() != null) {
+ new JsonEntitySerializer(serverMode).doSerialize(linked.getInlineEntity(link.getTitle()), jgen);
+ } else if (linked.getInlineEntitySet(link.getTitle()) != null) {
jgen.writeArrayFieldStart(link.getTitle());
JsonEntitySerializer entitySerializer = new JsonEntitySerializer(serverMode);
- for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
+ for (Entity subEntry : linked.getInlineEntitySet(link.getTitle()).getEntities()) {
entitySerializer.doSerialize(subEntry, jgen);
}
jgen.writeEndArray();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0e5da552/lib/commons-core/src/test/java/org/apache/olingo/commons/core/serialization/AtomDeserializerTest.java
----------------------------------------------------------------------
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 062f46b..4a5de7b 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
@@ -34,294 +34,295 @@ public class AtomDeserializerTest {
@Test
public void emptyInlineEntityOlingo540() throws Exception {
- final String content = "" +
+ final String content = "" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\" "
- + "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
- + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ + "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
+ + "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" "
- + "xml:base=\"http://services.odata.org/V3/OData/OData.svc/\">\r\n" +
- " <id>http://services.odata.org/V3/OData/OData.svc/Products(3)</id>\r\n" +
+ + "xml:base=\"http://services.odata.org/V3/OData/OData.svc/\">\r\n" +
+ " <id>http://services.odata.org/V3/OData/OData.svc/Products(3)</id>\r\n" +
" <category term=\"ODataDemo.Product\" "
- + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
- " \r\n" +
- " <link rel=\"edit\" title=\"Product\" href=\"Products\" />\r\n" +
+ + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
+ " \r\n" +
+ " <link rel=\"edit\" title=\"Product\" href=\"Products\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Categories\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Supplier\" "
- + "type=\"application/atom+xml;type=entry\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
- " <metadata:inline>\r\n" +
- " </metadata:inline>\r\n" +
- " </link>\r\n" +
+ + "type=\"application/atom+xml;type=entry\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
+ " <metadata:inline>\r\n" +
+ " </metadata:inline>\r\n" +
+ " </link>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/ProductDetail\""
+ " type=\"application/atom+xml;type=entry\" title=\"ProductDetail\" "
- + "href=\"Products(3)/ProductDetail\" />\r\n" +
- " <title type=\"text\">Havina Cola</title>\r\n" +
- " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
- " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
- " <author>\r\n" +
- " <name />\r\n" +
- " </author>\r\n" +
+ + "href=\"Products(3)/ProductDetail\" />\r\n" +
+ " <title type=\"text\">Havina Cola</title>\r\n" +
+ " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
+ " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
+ " <author>\r\n" +
+ " <name />\r\n" +
+ " </author>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Categories\" "
- + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
+ + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Supplier\" "
- + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
+ + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/ProductDetail\""
- + " type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
- " <content type=\"application/xml\">\r\n" +
- " <metadata:properties>\r\n" +
- " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
- " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
- " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
- " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
- " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
- " </metadata:properties>\r\n" +
- " </content>\r\n" +
+ + " type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
+ " <content type=\"application/xml\">\r\n" +
+ " <metadata:properties>\r\n" +
+ " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
+ " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
+ " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
+ " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
+ " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
+ " </metadata:properties>\r\n" +
+ " </content>\r\n" +
" </entry>";
final AtomDeserializer deserializer = new AtomDeserializer();
final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
final ResWrap<Entity> entity = deserializer.toEntity(in);
-
+
assertNotNull(entity);
- assertNull(entity.getPayload().getNavigationLink("Supplier").getInlineEntitySet());
+ assertNull(entity.getPayload().getInlineEntitySet("Categories"));
+ assertNull(entity.getPayload().getInlineEntity("Supplier"));
}
-
+
@Test
public void filledInlineEntity() throws Exception {
- final String content = "" +
+ final String content = "" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "xmlns:georss=\"http://www.georss.org/georss\" "
+ "xmlns:gml=\"http://www.opengis.net/gml\" "
- + "xml:base=\"http://services.odata.org/V4/OData/OData.svc/\">\r\n" +
- " <id>http://services.odata.org/V4/OData/OData.svc/Products(3)</id>\r\n" +
+ + "xml:base=\"http://services.odata.org/V4/OData/OData.svc/\">\r\n" +
+ " <id>http://services.odata.org/V4/OData/OData.svc/Products(3)</id>\r\n" +
" <category term=\"#ODataDemo.Product\" "
- + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
- " \r\n" +
- " <link rel=\"edit\" title=\"Product\" href=\"Products\" />\r\n" +
+ + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
+ " \r\n" +
+ " <link rel=\"edit\" title=\"Product\" href=\"Products\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Categories\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Supplier\" "
- + "type=\"application/atom+xml;type=entry\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
- " <metadata:inline>\r\n" +
- " <entry>\r\n" +
- " <id>http://services.odata.org/V4/OData/OData.svc/Suppliers(0)</id>\r\n" +
+ + "type=\"application/atom+xml;type=entry\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
+ " <metadata:inline>\r\n" +
+ " <entry>\r\n" +
+ " <id>http://services.odata.org/V4/OData/OData.svc/Suppliers(0)</id>\r\n" +
" <category term=\"ODataDemo.Supplier\" "
- + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
- " <link rel=\"edit\" title=\"Supplier\" href=\"Suppliers(0)\" />\r\n" +
+ + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
+ " <link rel=\"edit\" title=\"Supplier\" href=\"Suppliers(0)\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Products\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Products\" href=\"Suppliers(0)/Products\" />\r\n" +
- " <title type=\"text\">Exotic Liquids</title>\r\n" +
- " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
- " <author>\r\n" +
- " <name />\r\n" +
- " </author>\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Products\" href=\"Suppliers(0)/Products\" />\r\n" +
+ " <title type=\"text\">Exotic Liquids</title>\r\n" +
+ " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
+ " <author>\r\n" +
+ " <name />\r\n" +
+ " </author>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Products\" "
- + "type=\"application/xml\" title=\"Products\" href=\"Suppliers(0)/$links/Products\" />\r\n" +
- " <content type=\"application/xml\">\r\n" +
- " <metadata:properties>\r\n" +
- " <data:ID metadata:type=\"Edm.Int32\">0</data:ID>\r\n" +
- " <data:Name>Exotic Liquids</data:Name>\r\n" +
- " <data:Address metadata:type=\"ODataDemo.Address\">\r\n" +
- " <data:Street>NE 228th</data:Street>\r\n" +
- " <data:City>Sammamish</data:City>\r\n" +
- " <data:State>WA</data:State>\r\n" +
- " <data:ZipCode>98074</data:ZipCode>\r\n" +
- " <data:Country>USA</data:Country>\r\n" +
- " </data:Address>\r\n" +
- " <data:Location metadata:type=\"Edm.GeographyPoint\">\r\n" +
- " <gml:Point gml:srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\">\r\n" +
- " <gml:pos>47.6316604614258 -122.03547668457</gml:pos>\r\n" +
- " </gml:Point>\r\n" +
- " </data:Location>\r\n" +
- " <data:Concurrency metadata:type=\"Edm.Int32\">0</data:Concurrency>\r\n" +
- " </metadata:properties>\r\n" +
- " </content>\r\n" +
- " </entry>" +
- " </metadata:inline>\r\n" +
- " </link>\r\n" +
+ + "type=\"application/xml\" title=\"Products\" href=\"Suppliers(0)/$links/Products\" />\r\n" +
+ " <content type=\"application/xml\">\r\n" +
+ " <metadata:properties>\r\n" +
+ " <data:ID metadata:type=\"Edm.Int32\">0</data:ID>\r\n" +
+ " <data:Name>Exotic Liquids</data:Name>\r\n" +
+ " <data:Address metadata:type=\"ODataDemo.Address\">\r\n" +
+ " <data:Street>NE 228th</data:Street>\r\n" +
+ " <data:City>Sammamish</data:City>\r\n" +
+ " <data:State>WA</data:State>\r\n" +
+ " <data:ZipCode>98074</data:ZipCode>\r\n" +
+ " <data:Country>USA</data:Country>\r\n" +
+ " </data:Address>\r\n" +
+ " <data:Location metadata:type=\"Edm.GeographyPoint\">\r\n" +
+ " <gml:Point gml:srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\">\r\n" +
+ " <gml:pos>47.6316604614258 -122.03547668457</gml:pos>\r\n" +
+ " </gml:Point>\r\n" +
+ " </data:Location>\r\n" +
+ " <data:Concurrency metadata:type=\"Edm.Int32\">0</data:Concurrency>\r\n" +
+ " </metadata:properties>\r\n" +
+ " </content>\r\n" +
+ " </entry>" +
+ " </metadata:inline>\r\n" +
+ " </link>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/ProductDetail\" "
+ "type=\"application/atom+xml;type=entry\" "
- + "title=\"ProductDetail\" href=\"Products(3)/ProductDetail\" />\r\n" +
- " <title type=\"text\">Havina Cola</title>\r\n" +
- " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
- " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
- " <author>\r\n" +
- " <name />\r\n" +
- " </author>\r\n" +
+ + "title=\"ProductDetail\" href=\"Products(3)/ProductDetail\" />\r\n" +
+ " <title type=\"text\">Havina Cola</title>\r\n" +
+ " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
+ " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
+ " <author>\r\n" +
+ " <name />\r\n" +
+ " </author>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Categories\" "
- + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
+ + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Supplier\" "
- + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
+ + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/ProductDetail\" "
- + "type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
- " <content type=\"application/xml\">\r\n" +
- " <metadata:properties>\r\n" +
- " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
- " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
- " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
- " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
- " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
- " </metadata:properties>\r\n" +
- " </content>\r\n" +
+ + "type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
+ " <content type=\"application/xml\">\r\n" +
+ " <metadata:properties>\r\n" +
+ " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
+ " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
+ " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
+ " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
+ " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
+ " </metadata:properties>\r\n" +
+ " </content>\r\n" +
" </entry>";
final AtomDeserializer deserializer = new AtomDeserializer();
final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
final ResWrap<Entity> entity = deserializer.toEntity(in);
-
+
assertNotNull(entity);
- final Entity inlineEntity = entity.getPayload().getNavigationLink("Supplier").getInlineEntity();
+ final Entity inlineEntity = entity.getPayload().getInlineEntity("Supplier");
assertNotNull(inlineEntity);
-
+
assertEquals(new Integer(0), inlineEntity.getProperty("ID").getValue());
assertEquals("Exotic Liquids", inlineEntity.getProperty("Name").getValue());
}
-
+
@Test
public void emptyInlineEntityCollection() throws Exception {
- final String content = "" +
+ final String content = "" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" "
- + "xml:base=\"http://services.odata.org/V3/OData/OData.svc/\">\r\n" +
- " <id>http://services.odata.org/V3/OData/OData.svc/Products(3)</id>\r\n" +
+ + "xml:base=\"http://services.odata.org/V3/OData/OData.svc/\">\r\n" +
+ " <id>http://services.odata.org/V3/OData/OData.svc/Products(3)</id>\r\n" +
" <category term=\"ODataDemo.Product\" "
- + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
- " \r\n" +
- " <link rel=\"edit\" title=\"Product\" href=\"Products(3)\" />\r\n" +
+ + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
+ " \r\n" +
+ " <link rel=\"edit\" title=\"Product\" href=\"Products(3)\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Categories\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Supplier\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
- " <metadata:inline>\r\n" +
- " <feed>\r\n" +
- " </feed>\r\n" +
- " </metadata:inline>\r\n" +
- " </link>\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
+ " <metadata:inline>\r\n" +
+ " <feed>\r\n" +
+ " </feed>\r\n" +
+ " </metadata:inline>\r\n" +
+ " </link>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/ProductDetail\" "
+ "type=\"application/atom+xml;type=entry\" "
- + "title=\"ProductDetail\" href=\"Products(3)/ProductDetail\" />\r\n" +
- " <title type=\"text\">Havina Cola</title>\r\n" +
- " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
- " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
- " <author>\r\n" +
- " <name />\r\n" +
- " </author>\r\n" +
+ + "title=\"ProductDetail\" href=\"Products(3)/ProductDetail\" />\r\n" +
+ " <title type=\"text\">Havina Cola</title>\r\n" +
+ " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
+ " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
+ " <author>\r\n" +
+ " <name />\r\n" +
+ " </author>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Categories\" "
- + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
+ + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Supplier\" "
- + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
+ + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/ProductDetail\" "
- + "type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
- " <content type=\"application/xml\">\r\n" +
- " <metadata:properties>\r\n" +
- " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
- " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
- " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
- " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
- " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
- " </metadata:properties>\r\n" +
- " </content>\r\n" +
+ + "type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
+ " <content type=\"application/xml\">\r\n" +
+ " <metadata:properties>\r\n" +
+ " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
+ " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
+ " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
+ " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
+ " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
+ " </metadata:properties>\r\n" +
+ " </content>\r\n" +
" </entry>";
final AtomDeserializer deserializer = new AtomDeserializer();
final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
final ResWrap<Entity> entity = deserializer.toEntity(in);
-
+
assertNotNull(entity);
- final EntitySet inlineEntitySet = entity.getPayload().getNavigationLink("Supplier").getInlineEntitySet();
+ final EntitySet inlineEntitySet = entity.getPayload().getInlineEntitySet("Supplier");
assertNotNull(inlineEntitySet);
assertEquals(0, inlineEntitySet.getEntities().size());
}
-
+
@Test
public void filledInlineEntityCollection() throws Exception {
- final String content = "" +
+ final String content = "" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" "
- + "xml:base=\"http://services.odata.org/V3/OData/OData.svc/\">\r\n" +
- " <id>http://services.odata.org/V3/OData/OData.svc/Products(3)</id>\r\n" +
+ + "xml:base=\"http://services.odata.org/V3/OData/OData.svc/\">\r\n" +
+ " <id>http://services.odata.org/V3/OData/OData.svc/Products(3)</id>\r\n" +
" <category term=\"ODataDemo.Product\" "
- + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
- " \r\n" +
- " <link rel=\"edit\" title=\"Product\" href=\"Products(3)\" />\r\n" +
+ + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
+ " \r\n" +
+ " <link rel=\"edit\" title=\"Product\" href=\"Products(3)\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Categories\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Categories\" href=\"Products(3)/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Supplier\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
- " <metadata:inline>\r\n" +
- " <feed>\r\n" +
- " <entry>\r\n" +
- " <id>http://services.odata.org/V3/OData/OData.svc/Suppliers(0)</id>\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Supplier\" href=\"Products(3)/Supplier\">\r\n" +
+ " <metadata:inline>\r\n" +
+ " <feed>\r\n" +
+ " <entry>\r\n" +
+ " <id>http://services.odata.org/V3/OData/OData.svc/Suppliers(0)</id>\r\n" +
" <category term=\"ODataDemo.Supplier\" "
- + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
- " <link rel=\"edit\" title=\"Supplier\" href=\"Suppliers(0)\" />\r\n" +
+ + "scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />\r\n" +
+ " <link rel=\"edit\" title=\"Supplier\" href=\"Suppliers(0)\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/Products\" "
- + "type=\"application/atom+xml;type=feed\" title=\"Products\" href=\"Suppliers(0)/Products\" />\r\n" +
- " <title type=\"text\">Exotic Liquids</title>\r\n" +
- " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
- " <author>\r\n" +
- " <name />\r\n" +
- " </author>\r\n" +
+ + "type=\"application/atom+xml;type=feed\" title=\"Products\" href=\"Suppliers(0)/Products\" />\r\n" +
+ " <title type=\"text\">Exotic Liquids</title>\r\n" +
+ " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
+ " <author>\r\n" +
+ " <name />\r\n" +
+ " </author>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Products\" "
- + "type=\"application/xml\" title=\"Products\" href=\"Suppliers(0)/$links/Products\" />\r\n" +
- " <content type=\"application/xml\">\r\n" +
- " <metadata:properties>\r\n" +
- " <data:ID metadata:type=\"Edm.Int32\">0</data:ID>\r\n" +
- " <data:Name>Exotic Liquids</data:Name>\r\n" +
- " <data:Address metadata:type=\"ODataDemo.Address\">\r\n" +
- " <data:Street>NE 228th</data:Street>\r\n" +
- " <data:City>Sammamish</data:City>\r\n" +
- " <data:State>WA</data:State>\r\n" +
- " <data:ZipCode>98074</data:ZipCode>\r\n" +
- " <data:Country>USA</data:Country>\r\n" +
- " </data:Address>\r\n" +
- " <data:Location metadata:type=\"Edm.GeographyPoint\">\r\n" +
- " <gml:Point gml:srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\">\r\n" +
- " <gml:pos>47.6316604614258 -122.03547668457</gml:pos>\r\n" +
- " </gml:Point>\r\n" +
- " </data:Location>\r\n" +
- " <data:Concurrency metadata:type=\"Edm.Int32\">0</data:Concurrency>\r\n" +
- " </metadata:properties>\r\n" +
- " </content>\r\n" +
+ + "type=\"application/xml\" title=\"Products\" href=\"Suppliers(0)/$links/Products\" />\r\n" +
+ " <content type=\"application/xml\">\r\n" +
+ " <metadata:properties>\r\n" +
+ " <data:ID metadata:type=\"Edm.Int32\">0</data:ID>\r\n" +
+ " <data:Name>Exotic Liquids</data:Name>\r\n" +
+ " <data:Address metadata:type=\"ODataDemo.Address\">\r\n" +
+ " <data:Street>NE 228th</data:Street>\r\n" +
+ " <data:City>Sammamish</data:City>\r\n" +
+ " <data:State>WA</data:State>\r\n" +
+ " <data:ZipCode>98074</data:ZipCode>\r\n" +
+ " <data:Country>USA</data:Country>\r\n" +
+ " </data:Address>\r\n" +
+ " <data:Location metadata:type=\"Edm.GeographyPoint\">\r\n" +
+ " <gml:Point gml:srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\">\r\n" +
+ " <gml:pos>47.6316604614258 -122.03547668457</gml:pos>\r\n" +
+ " </gml:Point>\r\n" +
+ " </data:Location>\r\n" +
+ " <data:Concurrency metadata:type=\"Edm.Int32\">0</data:Concurrency>\r\n" +
+ " </metadata:properties>\r\n" +
+ " </content>\r\n" +
" </entry>\r\n" +
- " </feed>\r\n" +
- " </metadata:inline>\r\n" +
- " </link>\r\n" +
+ " </feed>\r\n" +
+ " </metadata:inline>\r\n" +
+ " </link>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/related/ProductDetail\" "
+ "type=\"application/atom+xml;type=entry\" "
- + "title=\"ProductDetail\" href=\"Products(3)/ProductDetail\" />\r\n" +
- " <title type=\"text\">Havina Cola</title>\r\n" +
- " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
- " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
- " <author>\r\n" +
- " <name />\r\n" +
- " </author>\r\n" +
+ + "title=\"ProductDetail\" href=\"Products(3)/ProductDetail\" />\r\n" +
+ " <title type=\"text\">Havina Cola</title>\r\n" +
+ " <summary type=\"text\">The Original Key Lime Cola</summary>\r\n" +
+ " <updated>2015-01-26T08:57:02Z</updated>\r\n" +
+ " <author>\r\n" +
+ " <name />\r\n" +
+ " </author>\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Categories\" "
- + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
+ + "type=\"application/xml\" title=\"Categories\" href=\"Products(3)/$links/Categories\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/Supplier\" "
- + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
+ + "type=\"application/xml\" title=\"Supplier\" href=\"Products(3)/$links/Supplier\" />\r\n" +
" <link rel=\"http://docs.oasis-open.org/odata/ns/relatedlinks/ProductDetail\" "
- + "type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
- " <content type=\"application/xml\">\r\n" +
- " <metadata:properties>\r\n" +
- " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
- " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
- " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
- " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
- " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
- " </metadata:properties>\r\n" +
- " </content>\r\n" +
+ + "type=\"application/xml\" title=\"ProductDetail\" href=\"Products(3)/$links/ProductDetail\" />\r\n" +
+ " <content type=\"application/xml\">\r\n" +
+ " <metadata:properties>\r\n" +
+ " <data:ID metadata:type=\"Edm.Int32\">3</data:ID>\r\n" +
+ " <data:ReleaseDate metadata:type=\"Edm.DateTime\">2005-10-01T00:00:00</data:ReleaseDate>\r\n" +
+ " <data:DiscontinuedDate metadata:type=\"Edm.DateTime\">2006-10-01T00:00:00</data:DiscontinuedDate>\r\n" +
+ " <data:Rating metadata:type=\"Edm.Int16\">3</data:Rating>\r\n" +
+ " <data:Price metadata:type=\"Edm.Double\">19.9</data:Price>\r\n" +
+ " </metadata:properties>\r\n" +
+ " </content>\r\n" +
" </entry>";
final AtomDeserializer deserializer = new AtomDeserializer();
final InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
final ResWrap<Entity> entity = deserializer.toEntity(in);
-
+
assertNotNull(entity);
- final EntitySet inlineEntitySet = entity.getPayload().getNavigationLink("Supplier").getInlineEntitySet();
+ final EntitySet inlineEntitySet = entity.getPayload().getInlineEntitySet("Supplier");
assertNotNull(inlineEntitySet);
assertEquals(1, inlineEntitySet.getEntities().size());
}