http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/ODataServiceVersion.java ---------------------------------------------------------------------- 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 96d9937..5442d1d 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 @@ -52,6 +52,8 @@ public enum ODataServiceVersion { public static final String JSON_ID = "jsonId"; + public static final String JSON_ETAG = "jsonETag"; + public static final String JSON_READ_LINK = "jsonReadLink"; public static final String JSON_EDIT_LINK = "jsonEditLink"; @@ -60,6 +62,10 @@ public enum ODataServiceVersion { public static final String JSON_MEDIAEDIT_LINK = "jsonMediaEditLink"; + public static final String JSON_MEDIA_CONTENT_TYPE = "jsonMediaContentType"; + + public static final String JSON_MEDIA_ETAG = "jsonMediaETag"; + public static final String JSON_ASSOCIATION_LINK = "jsonAssociationLink"; public static final String JSON_NAVIGATION_LINK = "jsonNavigationLink"; @@ -85,10 +91,13 @@ public enum ODataServiceVersion { { put(JSON_TYPE, "odata.type"); put(JSON_ID, "odata.id"); + put(JSON_ETAG, "odata.etag"); put(JSON_READ_LINK, "odata.readLink"); put(JSON_EDIT_LINK, "odata.editLink"); put(JSON_MEDIAREAD_LINK, "odata.mediaReadLink"); put(JSON_MEDIAEDIT_LINK, "odata.mediaEditLink"); + put(JSON_MEDIA_CONTENT_TYPE, "odata.mediaContentType"); + put(JSON_MEDIA_ETAG, "odata.mediaEtag"); put(JSON_ASSOCIATION_LINK, "@odata.associationLinkUrl"); put(JSON_NAVIGATION_LINK, "@odata.navigationLinkUrl"); } @@ -115,10 +124,13 @@ public enum ODataServiceVersion { { put(JSON_TYPE, "@odata.type"); put(JSON_ID, "@odata.id"); + put(JSON_ETAG, "@odata.etag"); put(JSON_READ_LINK, "@odata.readLink"); put(JSON_EDIT_LINK, "@odata.editLink"); put(JSON_MEDIAREAD_LINK, "@odata.mediaReadLink"); put(JSON_MEDIAEDIT_LINK, "@odata.mediaEditLink"); + put(JSON_MEDIA_CONTENT_TYPE, "@odata.mediaContentType"); + put(JSON_MEDIA_ETAG, "@odata.mediaEtag"); put(JSON_ASSOCIATION_LINK, "@odata.associationLink"); put(JSON_NAVIGATION_LINK, "@odata.navigationLink"); }
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntry.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntry.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntry.java index 85d6775..4c0f346 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntry.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntry.java @@ -55,6 +55,8 @@ public abstract class AbstractEntry extends AbstractODataObject implements Entry private String mediaContentType; + private String mediaETag; + @Override public String getETag() { return eTag; @@ -153,6 +155,16 @@ public abstract class AbstractEntry extends AbstractODataObject implements Entry } @Override + public String getMediaETag() { + return mediaETag; + } + + @Override + public void setMediaETag(final String eTag) { + this.mediaETag = eTag; + } + + @Override public boolean isMediaEntry() { return StringUtils.isNotBlank(this.mediaContentSource); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java index a16d4ed..c2ffd8e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java @@ -232,6 +232,11 @@ public class AtomDeserializer extends AbstractAtomDealer { entry.setSelfLink(link); } else if (Constants.EDIT_LINK_REL.equals(link.getRel())) { entry.setEditLink(link); + } else if (Constants.EDITMEDIA_LINK_REL.equals(link.getRel())) { + final Attribute mediaETag = event.asStartElement().getAttributeByName(etagQName); + if (mediaETag != null) { + entry.setMediaETag(mediaETag.getValue()); + } } else if (link.getRel().startsWith( version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) { entry.getNavigationLinks().add(link); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java index 97da12d..d9106a7 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyDeserializer.java @@ -66,8 +66,8 @@ class AtomPropertyDeserializer extends AbstractAtomDealer { foundEndProperty = true; } } - - return value == null? new PrimitiveValueImpl(StringUtils.EMPTY): value; + + return value == null ? new PrimitiveValueImpl(StringUtils.EMPTY) : value; } private Value fromComplexOrEnum(final XMLEventReader reader, final StartElement start) http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java index eaaa653..ef3eaf1 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java @@ -100,14 +100,9 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp entry.setBaseURI(contextURL.substring(0, contextURL.indexOf(Constants.METADATA))); } - if (tree.hasNonNull(Constants.JSON_MEDIA_ETAG)) { - entry.setMediaETag(tree.get(Constants.JSON_MEDIA_ETAG).textValue()); - tree.remove(Constants.JSON_MEDIA_ETAG); - } - - if (tree.hasNonNull(Constants.JSON_ETAG)) { - entry.setETag(tree.get(Constants.JSON_ETAG).textValue()); - tree.remove(Constants.JSON_ETAG); + if (tree.hasNonNull(jsonETag)) { + entry.setETag(tree.get(jsonETag).textValue()); + tree.remove(jsonETag); } if (tree.hasNonNull(jsonType)) { @@ -143,11 +138,16 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp tree.remove(jsonMediaReadLink); } if (tree.hasNonNull(jsonMediaEditLink)) { + entry.setMediaContentSource(tree.get(jsonMediaEditLink).textValue()); tree.remove(jsonMediaEditLink); } - if (tree.hasNonNull(Constants.JSON_MEDIA_CONTENT_TYPE)) { - entry.setMediaContentType(tree.get(Constants.JSON_MEDIA_CONTENT_TYPE).textValue()); - tree.remove(Constants.JSON_MEDIA_CONTENT_TYPE); + if (tree.hasNonNull(jsonMediaContentType)) { + entry.setMediaContentType(tree.get(jsonMediaContentType).textValue()); + tree.remove(jsonMediaContentType); + } + if (tree.hasNonNull(jsonMediaETag)) { + entry.setMediaETag(tree.get(jsonMediaETag).textValue()); + tree.remove(jsonMediaETag); } final Set<String> toRemove = new HashSet<String>(); @@ -190,14 +190,14 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp link.setType(ODataLinkType.MEDIA_EDIT.toString()); entry.getMediaEditLinks().add(link); - if (tree.has(link.getTitle() + Constants.JSON_MEDIA_ETAG_SUFFIX)) { - link.setMediaETag(tree.get(link.getTitle() + Constants.JSON_MEDIA_ETAG_SUFFIX).asText()); - toRemove.add(link.getTitle() + Constants.JSON_MEDIA_ETAG_SUFFIX); + if (tree.has(link.getTitle() + getJSONAnnotation(jsonMediaETag))) { + link.setMediaETag(tree.get(link.getTitle() + getJSONAnnotation(jsonMediaETag)).asText()); + toRemove.add(link.getTitle() + getJSONAnnotation(jsonMediaETag)); } toRemove.add(field.getKey()); toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree, parser.getCodec(), link)); - } else if (field.getKey().endsWith(Constants.JSON_MEDIA_CONTENT_TYPE)) { + } else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) { final String linkTitle = getTitle(field); for (Link link : entry.getMediaEditLinks()) { if (linkTitle.equals(link.getTitle())) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java index a83332a..edf4366 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java @@ -30,25 +30,4 @@ public class JSONEntryImpl extends AbstractEntry { private static final long serialVersionUID = -5275365545400797758L; - private String mediaETag; - - /** - * The odata.mediaEtag annotation MAY be included; its value MUST be the ETag of the binary stream represented by this - * media entity or named stream property. - * - * @return odata.mediaEtag annotation value. - */ - public String getMediaETag() { - return mediaETag; - } - - /** - * The odata.mediaEtag annotation MAY be included; its value MUST be the ETag of the binary stream represented by this - * media entity or named stream property. - * - * @param eTag odata.mediaEtag annotation value. - */ - public void setMediaETag(final String eTag) { - this.mediaETag = eTag; - } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java index 1215c5d..737ed53 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; +import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; /** @@ -40,20 +41,17 @@ public class JSONPropertyDeserializer extends AbstractJsonDeserializer<JSONPrope final JSONPropertyImpl property = new JSONPropertyImpl(); - String contextURL = null; if (tree.hasNonNull(Constants.JSON_CONTEXT)) { - contextURL = tree.get(Constants.JSON_CONTEXT).textValue(); + final String contextURL = tree.get(Constants.JSON_CONTEXT).textValue(); + property.setName(StringUtils.substringAfterLast(contextURL, "/")); tree.remove(Constants.JSON_CONTEXT); } else if (tree.hasNonNull(Constants.JSON_METADATA)) { - contextURL = tree.get(Constants.JSON_METADATA).textValue(); - tree.remove(Constants.JSON_METADATA); - } - - if (contextURL != null) { - final int dashIdx = contextURL.lastIndexOf('#'); + final String metadata = tree.get(Constants.JSON_METADATA).textValue(); + final int dashIdx = metadata.lastIndexOf('#'); if (dashIdx != -1) { - property.setType(contextURL.substring(dashIdx + 1)); + property.setType(metadata.substring(dashIdx + 1)); } + tree.remove(Constants.JSON_METADATA); } if (tree.has(jsonType) && property.getType() == null) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java index baf418d..fa6e38f 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java @@ -34,6 +34,8 @@ public abstract class ODataJacksonDeserializer<T> extends JsonDeserializer<T> { protected String jsonId; + protected String jsonETag; + protected String jsonReadLink; protected String jsonEditLink; @@ -42,6 +44,10 @@ public abstract class ODataJacksonDeserializer<T> extends JsonDeserializer<T> { protected String jsonMediaReadLink; + protected String jsonMediaContentType; + + protected String jsonMediaETag; + protected String jsonAssociationLink; protected String jsonNavigationLink; @@ -61,10 +67,13 @@ public abstract class ODataJacksonDeserializer<T> extends JsonDeserializer<T> { jsonType = version.getJSONMap().get(ODataServiceVersion.JSON_TYPE); jsonId = version.getJSONMap().get(ODataServiceVersion.JSON_ID); + jsonETag = version.getJSONMap().get(ODataServiceVersion.JSON_ETAG); jsonReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_READ_LINK); jsonEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK); jsonMediaReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK); jsonMediaEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK); + jsonMediaContentType = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE); + jsonMediaETag = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG); jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK); jsonNavigationLink = version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java index fe2fd52..181f2da 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataCollectionValue.java @@ -56,9 +56,7 @@ public abstract class AbstractODataCollectionValue<OV extends ODataValue> */ @Override public void add(final OV value) { - if (value.isPrimitive() || value.isComplex()) { - values.add(value); - } + values.add(value); } /** http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/eeb5d9b4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java index a1b729f..06b525c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntity.java @@ -56,6 +56,11 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement private String mediaContentSource; /** + * Media ETag. + */ + private String mediaETag; + + /** * Edit link. */ private URI editLink; @@ -80,41 +85,20 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement */ private final List<ODataOperation> operations = new ArrayList<ODataOperation>(); - /** - * Constructor. - * - * @param name OData entity name. - */ public AbstractODataEntity(final String name) { super(name); } - /** - * Gets ETag. - * - * @return ETag. - */ @Override public String getETag() { return eTag; } - /** - * Sets ETag. - * - * @param eTag ETag. - */ @Override public void setETag(final String eTag) { this.eTag = eTag; } - /** - * Searches for operation with given title. - * - * @param title operation to look for - * @return operation if found with given title, <tt>null</tt> otherwise - */ @Override public ODataOperation getOperation(final String title) { ODataOperation result = null; @@ -137,12 +121,6 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement return this.operations; } - /** - * Searches for property with given name. - * - * @param name property to look for - * @return property if found with given name, <tt>null</tt> otherwise - */ @Override public CommonODataProperty getProperty(final String name) { CommonODataProperty result = null; @@ -158,12 +136,6 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement return result; } - /** - * Puts the given link into one of available lists, based on its type. - * - * @param link to be added - * @return <tt>true</tt> if the given link was added in one of available lists - */ @Override public boolean addLink(final ODataLink link) { boolean result = false; @@ -188,62 +160,57 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement return result; } - /** - * Removes the given link from any list (association, navigation, edit-media). - * - * @param link to be removed - * @return <tt>true</tt> if the given link was contained in one of available lists - */ @Override public boolean removeLink(final ODataLink link) { return associationLinks.remove(link) || navigationLinks.remove(link) || editMediaLinks.remove(link); } - /** - * Returns all entity navigation links (including inline entities / feeds). - * - * @return OData entity links. - */ + private ODataLink getLink(final List<ODataLink> links, final String name) { + ODataLink result = null; + for (ODataLink link : links) { + if (name.equals(link.getName())) { + result = link; + } + } + + return result; + } + + @Override + public ODataLink getNavigationLink(final String name) { + return getLink(navigationLinks, name); + } + @Override public List<ODataLink> getNavigationLinks() { return navigationLinks; } - /** - * Returns all entity association links. - * - * @return OData entity links. - */ + @Override + public ODataLink getAssociationLink(final String name) { + return getLink(associationLinks, name); + } + @Override public List<ODataLink> getAssociationLinks() { return associationLinks; } - /** - * Returns all entity media edit links. - * - * @return OData entity links. - */ + @Override + public ODataLink getEditMediaLink(final String name) { + return getLink(editMediaLinks, name); + } + @Override public List<ODataLink> getEditMediaLinks() { return editMediaLinks; } - /** - * Returns OData entity edit link. - * - * @return entity edit link. - */ @Override public URI getEditLink() { return editLink; } - /** - * Sets OData entity edit link. - * - * @param editLink edit link. - */ @Override public void setEditLink(final URI editLink) { this.editLink = editLink; @@ -254,73 +221,48 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement return super.getLink() == null ? getEditLink() : super.getLink(); } - /** - * TRUE if read-only entity. - * - * @return TRUE if read-only; FALSE otherwise. - */ @Override public boolean isReadOnly() { return super.getLink() != null; } - /** - * Checks if the current entity is a media entity. - * - * @return 'TRUE' if media entity; 'FALSE' otherwise. - */ @Override public boolean isMediaEntity() { return mediaEntity; } - /** - * Sets media entity flag. - * - * @param isMediaEntity media entity flag value. - */ @Override public void setMediaEntity(final boolean isMediaEntity) { this.mediaEntity = isMediaEntity; } - /** - * Gets media content type. - * - * @return media content type. - */ @Override public String getMediaContentType() { return mediaContentType; } - /** - * Sets media content type. - * - * @param mediaContentType media content type. - */ @Override public void setMediaContentType(final String mediaContentType) { this.mediaContentType = mediaContentType; } - /** - * Gets media content source. - * - * @return media content source. - */ @Override public String getMediaContentSource() { return mediaContentSource; } - /** - * Sets media content source. - * - * @param mediaContentSource media content source. - */ @Override public void setMediaContentSource(final String mediaContentSource) { this.mediaContentSource = mediaContentSource; } + + @Override + public String getMediaETag() { + return mediaETag; + } + + @Override + public void setMediaETag(final String eTag) { + this.mediaETag = eTag; + } }
