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 a3a414d87..202d118d7 100644 --- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java +++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java @@ -68,22 +68,21 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.core.data.AtomFeedImpl; +import org.apache.olingo.commons.core.data.AtomEntitySetImpl; import org.apache.olingo.commons.core.data.LinkImpl; -import org.apache.olingo.commons.core.data.AtomEntryImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; import org.apache.olingo.commons.core.data.AtomPropertyImpl; import org.apache.olingo.commons.core.data.AtomSerializer; -import org.apache.olingo.commons.core.data.JSONEntryImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; import org.apache.olingo.commons.core.data.NullValueImpl; import org.apache.olingo.commons.core.data.PrimitiveValueImpl; -import org.apache.olingo.fit.metadata.EntitySet; import org.apache.olingo.fit.metadata.EntityType; import org.apache.olingo.fit.metadata.NavigationProperty; import org.apache.olingo.fit.methods.MERGE; @@ -401,22 +400,22 @@ public abstract class AbstractServices { final Accept contentTypeValue = Accept.parse(contentType, version); - final AtomEntryImpl entryChanges; + final AtomEntityImpl entryChanges; if (contentTypeValue == Accept.XML || contentTypeValue == Accept.TEXT) { throw new UnsupportedMediaTypeException("Unsupported media type"); } else if (contentTypeValue == Accept.ATOM) { - entryChanges = atomDeserializer.read( - IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntryImpl.class).getPayload(); + entryChanges = atomDeserializer.read( + IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntityImpl.class).getPayload(); } else { - final ResWrap jcont = mapper.readValue(IOUtils.toInputStream(changes, Constants.ENCODING), - new TypeReference() { + final ResWrap jcont = mapper.readValue(IOUtils.toInputStream(changes, Constants.ENCODING), + new TypeReference() { }); - entryChanges = dataBinder.toAtomEntry(jcont.getPayload()); + entryChanges = dataBinder.toAtomEntity(jcont.getPayload()); } - final ResWrap container = atomDeserializer.read(entityInfo.getValue(), AtomEntryImpl.class); + final ResWrap container = atomDeserializer.read(entityInfo.getValue(), AtomEntityImpl.class); for (Property property : entryChanges.getProperties()) { container.getPayload().getProperty(property.getName()).setValue(property.getValue()); @@ -435,7 +434,7 @@ public abstract class AbstractServices { final InputStream res = xml.addOrReplaceEntity( entityId, entitySetName, new ByteArrayInputStream(content.toByteArray()), container.getPayload()); - final ResWrap cres = atomDeserializer.read(res, AtomEntryImpl.class); + final ResWrap cres = atomDeserializer.read(res, AtomEntityImpl.class); normalizeAtomEntry(cres.getPayload(), entitySetName, entityId); @@ -492,14 +491,14 @@ public abstract class AbstractServices { IOUtils.toInputStream(entity, Constants.ENCODING), xml.readEntry(acceptType, IOUtils.toInputStream(entity, Constants.ENCODING))); - final ResWrap cres; + final ResWrap cres; if (acceptType == Accept.ATOM) { - cres = atomDeserializer.read(res, AtomEntryImpl.class); + cres = atomDeserializer.read(res, AtomEntityImpl.class); } else { - final ResWrap jcont = mapper.readValue(res, new TypeReference() { + final ResWrap jcont = mapper.readValue(res, new TypeReference() { }); - cres = new ResWrap(jcont.getContextURL(), jcont.getMetadataETag(), - dataBinder.toAtomEntry(jcont.getPayload())); + cres = new ResWrap(jcont.getContextURL(), jcont.getMetadataETag(), + dataBinder.toAtomEntity(jcont.getPayload())); } final String path = Commons.getEntityBasePath(entitySetName, entityId); @@ -552,14 +551,14 @@ public abstract class AbstractServices { throw new UnsupportedMediaTypeException("Unsupported media type"); } - final ResWrap container; + final ResWrap container; - final EntitySet entitySet = getMetadataObj().getEntitySet(entitySetName); + final org.apache.olingo.fit.metadata.EntitySet entitySet = getMetadataObj().getEntitySet(entitySetName); - final AtomEntryImpl entry; + final AtomEntityImpl entry; final String entityKey; if (xml.isMediaContent(entitySetName)) { - entry = new AtomEntryImpl(); + entry = new AtomEntityImpl(); entry.setMediaContentType(ContentType.WILDCARD); entry.setType(entitySet.getType()); @@ -584,21 +583,21 @@ public abstract class AbstractServices { entry.setMediaContentSource(editLink.getHref() + "/$value"); - container = new ResWrap((URI) null, null, entry); + container = new ResWrap((URI) null, null, entry); } else { final Accept contentTypeValue = Accept.parse(contentType, version); if (Accept.ATOM == contentTypeValue) { - container = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntryImpl.class); + container = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntityImpl.class); entry = container.getPayload(); } else { - final ResWrap jcontainer = + final ResWrap jcontainer = mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING), - new TypeReference() { + new TypeReference() { }); - entry = dataBinder.toAtomEntry(jcontainer.getPayload()); + entry = dataBinder.toAtomEntity(jcontainer.getPayload()); - container = new ResWrap( + container = new ResWrap( jcontainer.getContextURL(), jcontainer.getMetadataETag(), entry); @@ -618,8 +617,8 @@ public abstract class AbstractServices { final InputStream serialization = xml.addOrReplaceEntity(null, entitySetName, new ByteArrayInputStream(content.toByteArray()), entry); - ResWrap result = atomDeserializer.read(serialization, AtomEntryImpl.class); - result = new ResWrap( + ResWrap result = atomDeserializer.read(serialization, AtomEntityImpl.class); + result = new ResWrap( URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)), null, result.getPayload()); @@ -862,7 +861,7 @@ public abstract class AbstractServices { final InputStream feed = FSManager.instance(version).readFile(builder.toString(), Accept.ATOM); - final ResWrap container = atomDeserializer.read(feed, AtomFeedImpl.class); + final ResWrap container = atomDeserializer.read(feed, AtomEntitySetImpl.class); setInlineCount(container.getPayload(), count); @@ -872,7 +871,7 @@ public abstract class AbstractServices { // ----------------------------------------------- // Evaluate $skip and $top // ----------------------------------------------- - List entries = new ArrayList(container.getPayload().getEntries()); + List entries = new ArrayList(container.getPayload().getEntities()); if (StringUtils.isNotBlank(skip)) { entries = entries.subList(Integer.valueOf(skip), entries.size()); @@ -882,8 +881,8 @@ public abstract class AbstractServices { entries = entries.subList(0, Integer.valueOf(top)); } - container.getPayload().getEntries().clear(); - container.getPayload().getEntries().addAll(entries); + container.getPayload().getEntities().clear(); + container.getPayload().getEntities().addAll(entries); // ----------------------------------------------- if (acceptType == Accept.ATOM) { @@ -893,7 +892,7 @@ public abstract class AbstractServices { } else { mapper.writeValue( writer, new JSONFeedContainer(container.getContextURL(), container.getMetadataETag(), - dataBinder.toJSONFeed(container.getPayload()))); + dataBinder.toJSONEntitySet(container.getPayload()))); } return xml.createResponse( @@ -907,7 +906,7 @@ public abstract class AbstractServices { } } - protected abstract void setInlineCount(final Feed feed, final String count); + protected abstract void setInlineCount(final EntitySet feed, final String count); /** * Retrieve entity with key as segment. @@ -1000,13 +999,13 @@ public abstract class AbstractServices { final InputStream entity = entityInfo.getValue(); - ResWrap container = atomDeserializer.read(entity, AtomEntryImpl.class); + ResWrap container = atomDeserializer.read(entity, AtomEntityImpl.class); if (container.getContextURL() == null) { - container = new ResWrap(URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + container = new ResWrap(URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)), container.getMetadataETag(), container.getPayload()); } - final Entry entry = container.getPayload(); + final Entity entry = container.getPayload(); if (keyAsSegment) { final Link editLink = new LinkImpl(); @@ -1055,16 +1054,16 @@ public abstract class AbstractServices { rep.setType(link.getType()); if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_ENTRY))) { // inline entry - final Entry inline = atomDeserializer.read( + final Entity inline = atomDeserializer.read( xml.expandEntity(entitySetName, entityId, link.getTitle()), - AtomEntryImpl.class).getPayload(); - rep.setInlineEntry(inline); + AtomEntityImpl.class).getPayload(); + rep.setInlineEntity(inline); } else if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_FEED))) { // inline feed - final Feed inline = atomDeserializer.read( + final EntitySet inline = atomDeserializer.read( xml.expandEntity(entitySetName, entityId, link.getTitle()), - AtomFeedImpl.class).getPayload(); - rep.setInlineFeed(inline); + AtomEntitySetImpl.class).getPayload(); + rep.setInlineEntitySet(inline); } replace.put(link, rep); } @@ -1508,7 +1507,8 @@ public abstract class AbstractServices { final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); if (linkInfo.isFeed()) { - final ResWrap container = atomDeserializer.read(stream, AtomFeedImpl.class); + final ResWrap container = + atomDeserializer.read(stream, AtomEntitySetImpl.class); if (acceptType == Accept.ATOM) { atomSerializer.write(writer, container); @@ -1519,10 +1519,11 @@ public abstract class AbstractServices { writer, new JSONFeedContainer(container.getContextURL(), container.getMetadataETag(), - dataBinder.toJSONFeed((AtomFeedImpl) container.getPayload()))); + dataBinder.toJSONEntitySet((AtomEntitySetImpl) container.getPayload()))); } } else { - final ResWrap container = atomDeserializer.read(stream, AtomEntryImpl.class); + final ResWrap container = + atomDeserializer.read(stream, AtomEntityImpl.class); if (acceptType == Accept.ATOM) { atomSerializer.write(writer, container); writer.flush(); @@ -1532,7 +1533,7 @@ public abstract class AbstractServices { writer, new JSONEntryContainer(container.getContextURL(), container.getMetadataETag(), - dataBinder.toJSONEntry((AtomEntryImpl) container.getPayload()))); + dataBinder.toJSONEntityType((AtomEntityImpl) container.getPayload()))); } } @@ -1581,7 +1582,7 @@ public abstract class AbstractServices { final InputStream entity = entityInfo.getValue(); - final ResWrap entryContainer = atomDeserializer.read(entity, AtomEntryImpl.class); + final ResWrap entryContainer = atomDeserializer.read(entity, AtomEntityImpl.class); final String[] pathElems = StringUtils.split(path, "/"); AtomPropertyImpl property = (AtomPropertyImpl) entryContainer.getPayload().getProperty(pathElems[0]); @@ -1676,8 +1677,8 @@ public abstract class AbstractServices { return utils; } - protected void normalizeAtomEntry(final AtomEntryImpl entry, final String entitySetName, final String entityKey) { - final EntitySet entitySet = getMetadataObj().getEntitySet(entitySetName); + protected void normalizeAtomEntry(final AtomEntityImpl entry, final String entitySetName, final String entityKey) { + final org.apache.olingo.fit.metadata.EntitySet entitySet = getMetadataObj().getEntitySet(entitySetName); final EntityType entityType = getMetadataObj().getEntityType(entitySet.getType()); for (Map.Entry property : entityType.getPropertyMap().entrySet()) { @@ -1700,7 +1701,7 @@ public abstract class AbstractServices { if (!found) { final LinkImpl link = new LinkImpl(); link.setTitle(property.getKey()); - link.setType(property.getValue().isFeed() + link.setType(property.getValue().isEntitySet() ? Constants.get(version, ConstantKey.ATOM_LINK_FEED) : Constants.get(version, ConstantKey.ATOM_LINK_ENTRY)); link.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getKey()); diff --git a/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java b/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java index 974014b27..b87b6386b 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java @@ -40,7 +40,7 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import static org.apache.olingo.fit.AbstractServices.LOG; import org.apache.olingo.fit.utils.AbstractUtilities; @@ -206,7 +206,7 @@ public class V3ActionOverloading extends AbstractServices { } @Override - protected void setInlineCount(Feed feed, String count) { + protected void setInlineCount(EntitySet feed, String count) { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/fit/src/main/java/org/apache/olingo/fit/V3Services.java b/fit/src/main/java/org/apache/olingo/fit/V3Services.java index 66b1150c1..4c08cf939 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3Services.java @@ -45,7 +45,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.cxf.interceptor.InInterceptors; import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.fit.methods.MERGE; import org.apache.olingo.fit.methods.PATCH; @@ -109,9 +109,9 @@ public class V3Services extends AbstractServices { } @Override - protected void setInlineCount(final Feed feed, final String count) { + protected void setInlineCount(final EntitySet feed, final String count) { if ("allpages".equals(count)) { - feed.setCount(feed.getEntries().size()); + feed.setCount(feed.getEntities().size()); } } diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java index 38d869698..386d97b33 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java @@ -55,17 +55,17 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; import org.apache.olingo.commons.api.data.CollectionValue; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.core.data.AtomEntryImpl; -import org.apache.olingo.commons.core.data.AtomFeedImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; +import org.apache.olingo.commons.core.data.AtomEntitySetImpl; import org.apache.olingo.commons.core.data.AtomPropertyImpl; import org.apache.olingo.commons.core.data.CollectionValueImpl; import org.apache.olingo.commons.core.data.EnumValueImpl; -import org.apache.olingo.commons.core.data.JSONEntryImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; import org.apache.olingo.commons.core.data.JSONPropertyImpl; import org.apache.olingo.commons.core.data.PrimitiveValueImpl; import org.apache.olingo.commons.core.edm.EdmTypeInfo; @@ -192,7 +192,7 @@ public class V4Services extends AbstractServices { final UUID uuid = UUID.randomUUID(); providedAsync.put(uuid.toString(), bos.toString(Constants.ENCODING.toString())); - + bos.flush(); bos.close(); @@ -242,9 +242,9 @@ public class V4Services extends AbstractServices { } @Override - protected void setInlineCount(final Feed feed, final String count) { + protected void setInlineCount(final EntitySet feed, final String count) { if ("true".equals(count)) { - feed.setCount(feed.getEntries().size()); + feed.setCount(feed.getEntities().size()); } } @@ -392,7 +392,7 @@ public class V4Services extends AbstractServices { } final Accept contentTypeValue = Accept.parse(contentType, version); - final Entry entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); + final Entity entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); return xml.createResponse( null, @@ -419,7 +419,7 @@ public class V4Services extends AbstractServices { acceptType = Accept.parse(accept, version); } - final AtomEntryImpl entry = new AtomEntryImpl(); + final AtomEntityImpl entry = new AtomEntityImpl(); entry.setType("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail"); final Property productId = new AtomPropertyImpl(); productId.setName("ProductID"); @@ -432,10 +432,10 @@ public class V4Services extends AbstractServices { productDetailId.setValue(new PrimitiveValueImpl("2")); entry.getProperties().add(productDetailId); - final AtomFeedImpl feed = new AtomFeedImpl(); - feed.getEntries().add(entry); + final AtomEntitySetImpl feed = new AtomEntitySetImpl(); + feed.getEntities().add(entry); - final ResWrap container = new ResWrap( + final ResWrap container = new ResWrap( URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + "ProductDetail"), null, feed); @@ -466,7 +466,7 @@ public class V4Services extends AbstractServices { } final Accept contentTypeValue = Accept.parse(contentType, version); - final Entry entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); + final Entity entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); assert 1 == entry.getProperties().size(); assert entry.getProperty("accessRight") != null; @@ -495,7 +495,7 @@ public class V4Services extends AbstractServices { try { final Accept contentTypeValue = Accept.parse(contentType, version); - final Entry entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); + final Entity entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); assert 2 == entry.getProperties().size(); assert entry.getProperty("addresses") != null; @@ -532,7 +532,7 @@ public class V4Services extends AbstractServices { try { final Accept contentTypeValue = Accept.parse(contentType, version); - final Entry entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); + final Entity entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); assert 1 == entry.getProperties().size(); assert entry.getProperty("newDate") != null; @@ -619,7 +619,7 @@ public class V4Services extends AbstractServices { return utils.getValue().createResponse( FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF) - + File.separatorChar + filename, utils.getKey()), + + File.separatorChar + filename, utils.getKey()), null, utils.getKey()); } catch (Exception e) { @@ -641,7 +641,7 @@ public class V4Services extends AbstractServices { final Response response = getEntityInternal(uriInfo.getRequestUri().toASCIIString(), - accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false); + accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false); return response.getStatus() >= 400 ? postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes) : super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes); @@ -699,7 +699,7 @@ public class V4Services extends AbstractServices { } final InputStream entry = FSManager.instance(version).readFile(containedPath.toString(), Accept.ATOM); - final ResWrap container = atomDeserializer.read(entry, AtomEntryImpl.class); + final ResWrap container = atomDeserializer.read(entry, AtomEntityImpl.class); return xml.createResponse( null, @@ -730,21 +730,21 @@ public class V4Services extends AbstractServices { final AbstractUtilities utils = getUtilities(acceptType); // 1. parse the entry (from Atom or JSON) into AtomEntryImpl - final ResWrap entryContainer; - final AtomEntryImpl entry; + final ResWrap entryContainer; + final AtomEntityImpl entry; final Accept contentTypeValue = Accept.parse(contentType, version); if (Accept.ATOM == contentTypeValue) { - entryContainer = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntryImpl.class); + entryContainer = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntityImpl.class); entry = entryContainer.getPayload(); } else { - final ResWrap jcontainer = + final ResWrap jcontainer = mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING), - new TypeReference() { - }); + new TypeReference() { + }); - entry = dataBinder.toAtomEntry(jcontainer.getPayload()); + entry = dataBinder.toAtomEntity(jcontainer.getPayload()); - entryContainer = new ResWrap( + entryContainer = new ResWrap( jcontainer.getContextURL(), jcontainer.getMetadataETag(), entry); @@ -765,8 +765,8 @@ public class V4Services extends AbstractServices { // 3. Update the contained entity set final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString(); final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM); - final ResWrap feedContainer = atomDeserializer.read(feedIS, AtomFeedImpl.class); - feedContainer.getPayload().getEntries().add(entry); + final ResWrap feedContainer = atomDeserializer.read(feedIS, AtomEntitySetImpl.class); + feedContainer.getPayload().getEntities().add(entry); final ByteArrayOutputStream content = new ByteArrayOutputStream(); final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); @@ -823,12 +823,12 @@ public class V4Services extends AbstractServices { final LinkInfo links = xml.readLinks( entitySetName, entityId, containedEntitySetName + "(" + containedEntityId + ")", Accept.ATOM); - ResWrap container = atomDeserializer.read(links.getLinks(), AtomEntryImpl.class); - final AtomEntryImpl original = container.getPayload(); + ResWrap container = atomDeserializer.read(links.getLinks(), AtomEntityImpl.class); + final AtomEntityImpl original = container.getPayload(); - final AtomEntryImpl entryChanges; + final AtomEntityImpl entryChanges; if (Accept.ATOM == contentTypeValue) { - container = atomDeserializer.read(IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntryImpl.class); + container = atomDeserializer.read(IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntityImpl.class); entryChanges = container.getPayload(); } else { final String entityType = getMetadataObj().getEntitySet(entitySetName).getType(); @@ -836,11 +836,11 @@ public class V4Services extends AbstractServices { getNavigationProperty(containedEntitySetName).getType(); final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(containedType).build(); - final ResWrap jsonContainer = mapper.readValue( - IOUtils.toInputStream(changes, Constants.ENCODING), new TypeReference() { - }); + final ResWrap jsonContainer = mapper.readValue( + IOUtils.toInputStream(changes, Constants.ENCODING), new TypeReference() { + }); jsonContainer.getPayload().setType(typeInfo.getFullQualifiedName().toString()); - entryChanges = dataBinder.toAtomEntry(jsonContainer.getPayload()); + entryChanges = dataBinder.toAtomEntity(jsonContainer.getPayload()); } for (Property property : entryChanges.getProperties()) { @@ -851,7 +851,7 @@ public class V4Services extends AbstractServices { original.getProperties().add(property); } - FSManager.instance(version).putInMemory(new ResWrap((URI) null, null, original), + FSManager.instance(version).putInMemory(new ResWrap((URI) null, null, original), xml.getLinksBasePath(entitySetName, entityId) + containedEntitySetName + "(" + containedEntityId + ")"); return xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT); @@ -871,8 +871,8 @@ public class V4Services extends AbstractServices { // 1. Fetch the contained entity to be removed final InputStream entry = FSManager.instance(version). readFile(containedPath(entityId, containedEntitySetName). - append('(').append(containedEntityId).append(')').toString(), Accept.ATOM); - final ResWrap container = atomDeserializer.read(entry, AtomEntryImpl.class); + append('(').append(containedEntityId).append(')').toString(), Accept.ATOM); + final ResWrap container = atomDeserializer.read(entry, AtomEntityImpl.class); // 2. Remove the contained entity final String atomEntryRelativePath = containedPath(entityId, containedEntitySetName). @@ -882,8 +882,8 @@ public class V4Services extends AbstractServices { // 3. Update the contained entity set final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString(); final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM); - final ResWrap feedContainer = atomDeserializer.read(feedIS, AtomFeedImpl.class); - feedContainer.getPayload().getEntries().remove(container.getPayload()); + final ResWrap feedContainer = atomDeserializer.read(feedIS, AtomEntitySetImpl.class); + feedContainer.getPayload().getEntities().remove(container.getPayload()); final ByteArrayOutputStream content = new ByteArrayOutputStream(); final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING); @@ -927,7 +927,7 @@ public class V4Services extends AbstractServices { final InputStream feed = FSManager.instance(version). readFile(containedPath(entityId, containedEntitySetName).toString(), Accept.ATOM); - final ResWrap container = atomDeserializer.read(feed, AtomFeedImpl.class); + final ResWrap container = atomDeserializer.read(feed, AtomEntitySetImpl.class); return xml.createResponse( null, @@ -1100,8 +1100,8 @@ public class V4Services extends AbstractServices { } else { final ResWrap paramContainer = mapper.readValue(IOUtils.toInputStream(param, Constants.ENCODING), - new TypeReference() { - }); + new TypeReference() { + }); property = paramContainer.getPayload(); } @@ -1142,8 +1142,8 @@ public class V4Services extends AbstractServices { } else { final ResWrap paramContainer = mapper.readValue(IOUtils.toInputStream(param, Constants.ENCODING), - new TypeReference() { - }); + new TypeReference() { + }); property = paramContainer.getPayload(); } @@ -1177,7 +1177,7 @@ public class V4Services extends AbstractServices { } final Accept contentTypeValue = Accept.parse(contentType, version); - final Entry entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); + final Entity entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); assert 1 == entry.getProperties().size(); assert "Collection(Edm.String)".equals(entry.getProperty("emails").getType()); diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java b/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java index ebd599b12..af6518ca6 100644 --- a/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java +++ b/fit/src/main/java/org/apache/olingo/fit/metadata/Metadata.java @@ -81,7 +81,7 @@ public class Metadata extends AbstractMetadataElement { property.getReleationship().replaceAll(schemaEntry.getKey() + "\\.", "")); final Association.Role role = association.getRole(property.getToRole()); property.setFeed(role.getMultiplicity().equals("*")); - property.setType(property.isFeed() ? "Collection(" + role.getType() + ")" : role.getType()); + property.setType(property.isEntitySet() ? "Collection(" + role.getType() + ")" : role.getType()); // let me assume that it will be just a single container final AssociationSet associationSet = schemaEntry.getValue().getContainers().iterator().next(). diff --git a/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java b/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java index eb3a74f6f..ab3a88be9 100644 --- a/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java +++ b/fit/src/main/java/org/apache/olingo/fit/metadata/NavigationProperty.java @@ -34,7 +34,7 @@ public class NavigationProperty extends AbstractMetadataElement { private String target; - private boolean feed; + private boolean entitySet; public NavigationProperty(final String name) { this.name = name; @@ -76,11 +76,11 @@ public class NavigationProperty extends AbstractMetadataElement { this.target = target; } - public boolean isFeed() { - return feed; + public boolean isEntitySet() { + return entitySet; } - public void setFeed(boolean feed) { - this.feed = feed; + public void setFeed(boolean entitySet) { + this.entitySet = entitySet; } } diff --git a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java b/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java index 364380d3a..0d3318d17 100644 --- a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java +++ b/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java @@ -22,15 +22,15 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.core.data.JSONEntryDeserializer; -import org.apache.olingo.commons.core.data.JSONEntryImpl; -import org.apache.olingo.commons.core.data.JSONEntrySerializer; +import org.apache.olingo.commons.core.data.JSONEntityDeserializer; +import org.apache.olingo.commons.core.data.JSONEntityImpl; +import org.apache.olingo.commons.core.data.JSONEntitySerializer; -@JsonDeserialize(using = JSONEntryDeserializer.class) -@JsonSerialize(using = JSONEntrySerializer.class) -public class JSONEntryContainer extends ResWrap { +@JsonDeserialize(using = JSONEntityDeserializer.class) +@JsonSerialize(using = JSONEntitySerializer.class) +public class JSONEntryContainer extends ResWrap { - public JSONEntryContainer(final ContextURL contextURL, final String metadataETag, final JSONEntryImpl object) { + public JSONEntryContainer(final ContextURL contextURL, final String metadataETag, final JSONEntityImpl object) { super(contextURL, metadataETag, object); } } diff --git a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java b/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java index 7a53213cd..c641444ed 100644 --- a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java +++ b/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java @@ -22,15 +22,15 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.core.data.JSONFeedDeserializer; -import org.apache.olingo.commons.core.data.JSONFeedImpl; -import org.apache.olingo.commons.core.data.JSONFeedSerializer; +import org.apache.olingo.commons.core.data.JSONEntitySetDeserializer; +import org.apache.olingo.commons.core.data.JSONEntitySetImpl; +import org.apache.olingo.commons.core.data.JSONEntitySetSerializer; -@JsonDeserialize(using = JSONFeedDeserializer.class) -@JsonSerialize(using = JSONFeedSerializer.class) -public class JSONFeedContainer extends ResWrap { +@JsonDeserialize(using = JSONEntitySetDeserializer.class) +@JsonSerialize(using = JSONEntitySetSerializer.class) +public class JSONFeedContainer extends ResWrap { - public JSONFeedContainer(final ContextURL contextURL, final String metadataETag, final JSONFeedImpl object) { + public JSONFeedContainer(final ContextURL contextURL, final String metadataETag, final JSONEntitySetImpl object) { super(contextURL, metadataETag, object); } } 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 c01718628..57e2049a8 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 @@ -43,16 +43,16 @@ import javax.xml.stream.XMLStreamException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileObject; -import org.apache.olingo.commons.api.data.Entry; +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.data.ResWrap; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.core.data.AtomEntryImpl; -import org.apache.olingo.commons.core.data.AtomFeedImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; +import org.apache.olingo.commons.core.data.AtomEntitySetImpl; import org.apache.olingo.commons.core.data.AtomPropertyImpl; import org.apache.olingo.commons.core.data.AtomSerializer; -import org.apache.olingo.commons.core.data.JSONEntryImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; import org.apache.olingo.commons.core.data.JSONPropertyImpl; import org.apache.olingo.fit.UnsupportedMediaTypeException; import org.apache.olingo.fit.metadata.Metadata; @@ -199,7 +199,7 @@ public abstract class AbstractUtilities { return fo.getContent().getInputStream(); } - private InputStream toInputStream(final AtomEntryImpl entry) throws XMLStreamException { + private InputStream toInputStream(final AtomEntityImpl entry) throws XMLStreamException { final StringWriter writer = new StringWriter(); atomSerializer.write(writer, entry); @@ -210,7 +210,7 @@ public abstract class AbstractUtilities { final String key, final String entitySetName, final InputStream is, - final AtomEntryImpl entry) throws Exception { + final AtomEntityImpl entry) throws Exception { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(is, bos); @@ -297,27 +297,27 @@ public abstract class AbstractUtilities { navigationProperties == null ? null : navigationProperties.get(link.getTitle()); if (navProp != null) { final String inlineEntitySetName = navProp.getTarget(); - if (link.getInlineEntry() != null) { + if (link.getInlineEntity() != null) { final String inlineEntryKey = getDefaultEntryKey( - inlineEntitySetName, (AtomEntryImpl) link.getInlineEntry()); + inlineEntitySetName, (AtomEntityImpl) link.getInlineEntity()); addOrReplaceEntity( inlineEntryKey, inlineEntitySetName, - toInputStream((AtomEntryImpl) link.getInlineEntry()), - (AtomEntryImpl) link.getInlineEntry()); + toInputStream((AtomEntityImpl) link.getInlineEntity()), + (AtomEntityImpl) link.getInlineEntity()); hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")"); - } else if (link.getInlineFeed() != null) { - for (Entry subentry : link.getInlineFeed().getEntries()) { + } else if (link.getInlineEntitySet() != null) { + for (Entity subentry : link.getInlineEntitySet().getEntities()) { final String inlineEntryKey = getDefaultEntryKey( - inlineEntitySetName, (AtomEntryImpl) subentry); + inlineEntitySetName, (AtomEntityImpl) subentry); addOrReplaceEntity( inlineEntryKey, inlineEntitySetName, - toInputStream((AtomEntryImpl) subentry), - (AtomEntryImpl) subentry); + toInputStream((AtomEntityImpl) subentry), + (AtomEntityImpl) subentry); hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")"); } @@ -365,7 +365,7 @@ public abstract class AbstractUtilities { final Metadata metadata = Commons.getMetadata(version); final Map navigationProperties = metadata.getNavigationProperties(entitySetName); - if (navigationProperties.get(linkName).isFeed()) { + if (navigationProperties.get(linkName).isEntitySet()) { try { final Map.Entry> currents = extractLinkURIs(entitySetName, entityKey, linkName); uris.addAll(currents.getValue()); @@ -540,7 +540,7 @@ public abstract class AbstractUtilities { return builder.build(); } - public InputStream writeFeed(final Accept accept, final ResWrap container) + public InputStream writeFeed(final Accept accept, final ResWrap container) throws XMLStreamException, IOException { final StringWriter writer = new StringWriter(); @@ -551,31 +551,31 @@ public abstract class AbstractUtilities { } else { mapper.writeValue( writer, new JSONFeedContainer(container.getContextURL(), - container.getMetadataETag(), dataBinder.toJSONFeed(container.getPayload()))); + container.getMetadataETag(), dataBinder.toJSONEntitySet(container.getPayload()))); } return IOUtils.toInputStream(writer.toString(), Constants.ENCODING); } - public AtomEntryImpl readEntry(final Accept accept, final InputStream entity) + public AtomEntityImpl readEntry(final Accept accept, final InputStream entity) throws XMLStreamException, IOException { - final AtomEntryImpl entry; + final AtomEntityImpl entry; if (accept == Accept.ATOM || accept == Accept.XML) { - final ResWrap container = atomDeserializer.read(entity, AtomEntryImpl.class); + final ResWrap container = atomDeserializer.read(entity, AtomEntityImpl.class); entry = container.getPayload(); } else { - final ResWrap container = - mapper.readValue(entity, new TypeReference() { + final ResWrap container = + mapper.readValue(entity, new TypeReference() { }); - entry = dataBinder.toAtomEntry(container.getPayload()); + entry = dataBinder.toAtomEntity(container.getPayload()); } return entry; } - public InputStream writeEntry(final Accept accept, final ResWrap container) + public InputStream writeEntry(final Accept accept, final ResWrap container) throws XMLStreamException, IOException { final StringWriter writer = new StringWriter(); @@ -584,7 +584,7 @@ public abstract class AbstractUtilities { } else { mapper.writeValue( writer, new JSONEntryContainer(container.getContextURL(), container.getMetadataETag(), - dataBinder.toJSONEntry(container.getPayload()))); + dataBinder.toJSONEntityType(container.getPayload()))); } return IOUtils.toInputStream(writer.toString(), Constants.ENCODING); @@ -620,7 +620,7 @@ public abstract class AbstractUtilities { return IOUtils.toInputStream(writer.toString(), Constants.ENCODING); } - private String getDefaultEntryKey(final String entitySetName, final AtomEntryImpl entry, final String propertyName) + private String getDefaultEntryKey(final String entitySetName, final AtomEntityImpl entry, final String propertyName) throws Exception { String res; @@ -638,7 +638,7 @@ public abstract class AbstractUtilities { return res; } - public String getDefaultEntryKey(final String entitySetName, final AtomEntryImpl entry) throws IOException { + public String getDefaultEntryKey(final String entitySetName, final AtomEntityImpl entry) throws IOException { try { String res; @@ -734,7 +734,7 @@ public abstract class AbstractUtilities { final Metadata metadata = Commons.getMetadata(version); final Map navigationProperties = metadata.getNavigationProperties(entitySetName); - linkInfo.setFeed(navigationProperties.get(linkName.replaceAll("\\(.*\\)", "")).isFeed()); + linkInfo.setFeed(navigationProperties.get(linkName.replaceAll("\\(.*\\)", "")).isEntitySet()); return linkInfo; } @@ -800,7 +800,7 @@ public abstract class AbstractUtilities { links.getValue(), linkName, links.getKey(), - navigationProperties.get(linkName).isFeed()); + navigationProperties.get(linkName).isEntitySet()); } public InputStream expandEntity( @@ -832,8 +832,8 @@ public abstract class AbstractUtilities { InputStream stream = fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType); stream = replaceProperty(stream, changes, path, justValue); - final AtomEntryImpl entry = readEntry(acceptType, stream); - final ResWrap container = new ResWrap((URI) null, null, entry); + final AtomEntityImpl entry = readEntry(acceptType, stream); + final ResWrap container = new ResWrap((URI) null, null, entry); fsManager.putInMemory(writeEntry(Accept.ATOM, container), fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), Accept.ATOM)); diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java b/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java index c9b364610..2b69f399c 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java @@ -18,25 +18,24 @@ */ package org.apache.olingo.fit.utils; -import java.net.URI; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +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.Property; import org.apache.olingo.commons.api.data.Value; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.core.data.AtomEntryImpl; -import org.apache.olingo.commons.core.data.AtomFeedImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; +import org.apache.olingo.commons.core.data.AtomEntitySetImpl; import org.apache.olingo.commons.core.data.AtomPropertyImpl; import org.apache.olingo.commons.core.data.CollectionValueImpl; import org.apache.olingo.commons.core.data.ComplexValueImpl; -import org.apache.olingo.commons.core.data.JSONEntryImpl; -import org.apache.olingo.commons.core.data.JSONFeedImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; +import org.apache.olingo.commons.core.data.JSONEntitySetImpl; import org.apache.olingo.commons.core.data.JSONPropertyImpl; import org.apache.olingo.commons.core.data.LinkImpl; import org.apache.olingo.fit.metadata.EntityType; @@ -52,157 +51,157 @@ public class DataBinder { this.version = version; } - public JSONFeedImpl toJSONFeed(final AtomFeedImpl atomfeed) { - final JSONFeedImpl jsonfeed = new JSONFeedImpl(); + public JSONEntitySetImpl toJSONEntitySet(final AtomEntitySetImpl atomEntitySet) { + final JSONEntitySetImpl jsonEntitySet = new JSONEntitySetImpl(); - BeanUtils.copyProperties(atomfeed, jsonfeed, "baseURI", "metadataContextURL"); - jsonfeed.setMetadataContextURL(atomfeed.getBaseURI() == null + BeanUtils.copyProperties(atomEntitySet, jsonEntitySet, "baseURI", "metadataContextURL"); + jsonEntitySet.setBaseURI(atomEntitySet.getBaseURI() == null ? null - : URI.create(atomfeed.getBaseURI().toASCIIString() + "/$metadata").normalize()); + : atomEntitySet.getBaseURI().toASCIIString() + "/$metadata"); - final Collection entries = jsonfeed.getEntries(); - for (Entry entry : atomfeed.getEntries()) { - entries.add(toJSONEntry((AtomEntryImpl) entry)); + final Collection entries = jsonEntitySet.getEntities(); + for (Entity entity : atomEntitySet.getEntities()) { + entries.add(toJSONEntityType((AtomEntityImpl) entity)); } - return jsonfeed; + return jsonEntitySet; } - public AtomFeedImpl toAtomFeed(final JSONFeedImpl jsonfeed) { - final AtomFeedImpl atomfeed = new AtomFeedImpl(); + public AtomEntitySetImpl toAtomEntitySet(final JSONEntitySetImpl jsonEntitySet) { + final AtomEntitySetImpl atomEntitySet = new AtomEntitySetImpl(); - BeanUtils.copyProperties(jsonfeed, atomfeed, "baseURI", "metadataContextURL"); - atomfeed.setBaseURI(jsonfeed.getBaseURI() == null + BeanUtils.copyProperties(jsonEntitySet, atomEntitySet, "baseURI", "metadataContextURL"); + atomEntitySet.setBaseURI(jsonEntitySet.getBaseURI() == null ? null - : jsonfeed.getBaseURI().toASCIIString() + "/$metadata"); + : jsonEntitySet.getBaseURI().toASCIIString() + "/$metadata"); - final Collection entries = atomfeed.getEntries(); - for (Entry entry : jsonfeed.getEntries()) { - entries.add(toAtomEntry((JSONEntryImpl) entry)); + final Collection entries = atomEntitySet.getEntities(); + for (Entity entity : jsonEntitySet.getEntities()) { + entries.add(toAtomEntity((JSONEntityImpl) entity)); } - return atomfeed; + return atomEntitySet; } - public JSONEntryImpl toJSONEntry(final AtomEntryImpl atomentry) { - final JSONEntryImpl jsonentry = new JSONEntryImpl(); + public JSONEntityImpl toJSONEntityType(final AtomEntityImpl atomEntity) { + final JSONEntityImpl jsonEntity = new JSONEntityImpl(); - BeanUtils.copyProperties(atomentry, jsonentry, "baseURI", "properties", "links"); - jsonentry.setBaseURI(atomentry.getBaseURI() == null ? null : atomentry.getBaseURI().toASCIIString()); - jsonentry.getOperations().addAll(atomentry.getOperations()); + BeanUtils.copyProperties(atomEntity, jsonEntity, "baseURI", "properties", "links"); + jsonEntity.setBaseURI(atomEntity.getBaseURI() == null ? null : atomEntity.getBaseURI().toASCIIString()); + jsonEntity.getOperations().addAll(atomEntity.getOperations()); - for (Link link : atomentry.getNavigationLinks()) { + for (Link link : atomEntity.getNavigationLinks()) { final Link jlink = new LinkImpl(); jlink.setHref(link.getHref()); jlink.setTitle(link.getTitle()); jlink.setType(link.getType()); jlink.setRel(link.getRel()); - if (link.getInlineEntry() instanceof AtomEntryImpl) { - final Entry inlineEntry = link.getInlineEntry(); - if (inlineEntry instanceof AtomEntryImpl) { - jlink.setInlineEntry(toJSONEntry((AtomEntryImpl) link.getInlineEntry())); + if (link.getInlineEntity() instanceof AtomEntityImpl) { + final Entity inlineEntity = link.getInlineEntity(); + if (inlineEntity instanceof AtomEntityImpl) { + jlink.setInlineEntity(toJSONEntityType((AtomEntityImpl) link.getInlineEntity())); } - } else if (link.getInlineFeed() instanceof AtomFeedImpl) { - final Feed inlineFeed = link.getInlineFeed(); - if (inlineFeed instanceof AtomFeedImpl) { - jlink.setInlineFeed(toJSONFeed((AtomFeedImpl) link.getInlineFeed())); + } else if (link.getInlineEntitySet() instanceof AtomEntitySetImpl) { + final EntitySet inlineEntitySet = link.getInlineEntitySet(); + if (inlineEntitySet instanceof AtomEntitySetImpl) { + jlink.setInlineEntitySet(toJSONEntitySet((AtomEntitySetImpl) link.getInlineEntitySet())); } } - jsonentry.getNavigationLinks().add(jlink); + jsonEntity.getNavigationLinks().add(jlink); } - final Collection properties = jsonentry.getProperties(); - for (Property property : atomentry.getProperties()) { + final Collection properties = jsonEntity.getProperties(); + for (Property property : atomEntity.getProperties()) { properties.add(toJSONProperty((AtomPropertyImpl) property)); } - return jsonentry; + return jsonEntity; } - public AtomEntryImpl toAtomEntry(final JSONEntryImpl jsonentry) { - final AtomEntryImpl atomentry = new AtomEntryImpl(); + public AtomEntityImpl toAtomEntity(final JSONEntityImpl jsonEntity) { + final AtomEntityImpl atomEntity = new AtomEntityImpl(); final Metadata metadata = Commons.getMetadata(version); - BeanUtils.copyProperties(jsonentry, atomentry, "baseURI", "properties", "links"); - atomentry.setBaseURI(jsonentry.getBaseURI() == null ? null : jsonentry.getBaseURI().toASCIIString()); + BeanUtils.copyProperties(jsonEntity, atomEntity, "baseURI", "properties", "links"); + atomEntity.setBaseURI(jsonEntity.getBaseURI() == null ? null : jsonEntity.getBaseURI().toASCIIString()); - for (Link link : jsonentry.getNavigationLinks()) { + for (Link link : jsonEntity.getNavigationLinks()) { final Link alink = new LinkImpl(); alink.setHref(link.getHref()); alink.setTitle(link.getTitle()); final NavigationProperty navPropDetails = - metadata.getEntityType(jsonentry.getType()).getNavigationProperty(link.getTitle()); + metadata.getEntityType(jsonEntity.getType()).getNavigationProperty(link.getTitle()); - alink.setType(navPropDetails != null && navPropDetails.isFeed() + alink.setType(navPropDetails != null && navPropDetails.isEntitySet() ? Constants.get(ConstantKey.ATOM_LINK_FEED) : Constants.get(ConstantKey.ATOM_LINK_ENTRY)); alink.setRel(link.getRel()); - if (link.getInlineEntry() instanceof JSONEntryImpl) { - final Entry inlineEntry = link.getInlineEntry(); - if (inlineEntry instanceof JSONEntryImpl) { - alink.setInlineEntry(toAtomEntry((JSONEntryImpl) link.getInlineEntry())); + if (link.getInlineEntity() instanceof JSONEntityImpl) { + final Entity inlineEntity = link.getInlineEntity(); + if (inlineEntity instanceof JSONEntityImpl) { + alink.setInlineEntity(toAtomEntity((JSONEntityImpl) link.getInlineEntity())); } - } else if (link.getInlineFeed() instanceof JSONFeedImpl) { - final Feed inlineFeed = link.getInlineFeed(); - if (inlineFeed instanceof JSONFeedImpl) { - alink.setInlineFeed(toAtomFeed((JSONFeedImpl) link.getInlineFeed())); + } else if (link.getInlineEntitySet() instanceof JSONEntitySetImpl) { + final EntitySet inlineEntitySet = link.getInlineEntitySet(); + if (inlineEntitySet instanceof JSONEntitySetImpl) { + alink.setInlineEntitySet(toAtomEntitySet((JSONEntitySetImpl) link.getInlineEntitySet())); } } - atomentry.getNavigationLinks().add(alink); + atomEntity.getNavigationLinks().add(alink); } - final EntityType entityType = StringUtils.isBlank(jsonentry.getType()) - ? null : metadata.getEntityType(jsonentry.getType()); + final EntityType entityType = StringUtils.isBlank(jsonEntity.getType()) + ? null : metadata.getEntityType(jsonEntity.getType()); final Map navProperties = entityType == null ? Collections.emptyMap() : entityType.getNavigationPropertyMap(); - final List properties = atomentry.getProperties(); + final List properties = atomEntity.getProperties(); - for (Property property : jsonentry.getProperties()) { + for (Property property : jsonEntity.getProperties()) { if (navProperties.containsKey(property.getName())) { final Link alink = new LinkImpl(); alink.setTitle(property.getName()); - alink.setType(navProperties.get(property.getName()).isFeed() + alink.setType(navProperties.get(property.getName()).isEntitySet() ? Constants.get(version, ConstantKey.ATOM_LINK_FEED) : Constants.get(version, ConstantKey.ATOM_LINK_ENTRY)); alink.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getName()); if (property.getValue().isComplex()) { - final Entry inline = new AtomEntryImpl(); + final Entity inline = new AtomEntityImpl(); inline.setType(navProperties.get(property.getName()).getType()); for (Property prop : property.getValue().asComplex().get()) { inline.getProperties().add(prop); } - alink.setInlineEntry(inline); + alink.setInlineEntity(inline); } else if (property.getValue().isCollection()) { - final Feed inline = new AtomFeedImpl(); - for (Value entry : property.getValue().asCollection().get()) { - final Entry inlineEntry = new AtomEntryImpl(); - inlineEntry.setType(navProperties.get(property.getName()).getType()); - for (Property prop : entry.asComplex().get()) { - inlineEntry.getProperties().add(toAtomProperty((JSONPropertyImpl) prop, inlineEntry.getType())); + final EntitySet inline = new AtomEntitySetImpl(); + for (Value value : property.getValue().asCollection().get()) { + final Entity inlineEntity = new AtomEntityImpl(); + inlineEntity.setType(navProperties.get(property.getName()).getType()); + for (Property prop : value.asComplex().get()) { + inlineEntity.getProperties().add(toAtomProperty((JSONPropertyImpl) prop, inlineEntity.getType())); } - inline.getEntries().add(inlineEntry); + inline.getEntities().add(inlineEntity); } - alink.setInlineFeed(inline); + alink.setInlineEntitySet(inline); } else { throw new IllegalStateException("Invalid navigation property " + property); } - atomentry.getNavigationLinks().add(alink); + atomEntity.getNavigationLinks().add(alink); } else { - properties.add(toAtomProperty((JSONPropertyImpl) property, atomentry.getType())); + properties.add(toAtomProperty((JSONPropertyImpl) property, atomEntity.getType())); } } - return atomentry; + return atomEntity; } public JSONPropertyImpl toJSONProperty(final AtomPropertyImpl atomproperty) { 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 9304454fb..ae89ec447 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 @@ -38,7 +38,7 @@ import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.VFS; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -import org.apache.olingo.commons.core.data.AtomEntryImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; import org.apache.olingo.commons.core.data.AtomSerializer; import org.apache.olingo.fit.serializer.JSONEntryContainer; import org.slf4j.Logger; @@ -98,7 +98,7 @@ public class FSManager { return memObject; } - public void putInMemory(final ResWrap container, final String relativePath) + public void putInMemory(final ResWrap container, final String relativePath) throws IOException { try { final AtomSerializer atomSerializer = Commons.getAtomSerializer(version); @@ -117,7 +117,7 @@ public class FSManager { writer, new JSONEntryContainer( container.getContextURL(), container.getMetadataETag(), - new DataBinder(version).toJSONEntry(container.getPayload()))); + new DataBinder(version).toJSONEntityType(container.getPayload()))); putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.JSON_FULLMETA)); } catch (Exception e) { diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java index 162221a2e..0b385245b 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java @@ -159,7 +159,7 @@ public class XMLUtilities extends AbstractUtilities { attributes.add(eventFactory.createAttribute(new QName("rel"), Constants.get(version, ConstantKey.ATOM_LINK_REL) + link)); attributes.add(eventFactory.createAttribute(new QName("type"), - navigationProperties.get(link).isFeed() + navigationProperties.get(link).isEntitySet() ? Constants.get(version, ConstantKey.ATOM_LINK_FEED) : Constants.get(version, ConstantKey.ATOM_LINK_ENTRY))); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java index 2b5478f34..4967fc6b4 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonEdmEnabledODataClient.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.client.api; -import java.net.URI; import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType; import org.apache.olingo.commons.api.edm.Edm; diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestFactory.java index 17b510f9e..45dfc11c6 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestFactory.java @@ -22,7 +22,6 @@ import org.apache.olingo.client.api.communication.request.ODataRequest; import org.apache.olingo.client.api.communication.request.batch.v4.ODataBatchRequest; import org.apache.olingo.client.api.communication.response.ODataResponse; -@SuppressWarnings("unchecked") public interface AsyncRequestFactory { AsyncRequestWrapper getAsyncRequestWrapper(final ODataRequest odataRequest); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java index 8002845d1..f51285da3 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java @@ -30,7 +30,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.CommonODataEntitySet; @@ -62,11 +62,11 @@ public class ODataEntitySetIterator cached; + private ResWrap cached; private ES entitySet; - private final ByteArrayOutputStream osFeed; + private final ByteArrayOutputStream osEntitySet; private final String namespaces; @@ -85,21 +85,21 @@ public class ODataEntitySetIterator= 0) { + if (consume(stream, "\"value\":", osEntitySet, true) >= 0) { int c = 0; while (c != '[' && (c = stream.read()) >= 0) { - osFeed.write(c); + osEntitySet.write(c); } } } catch (IOException e) { - LOG.error("Error parsing feed", e); + LOG.error("Error parsing entity set", e); throw new IllegalStateException(e); } } @@ -113,15 +113,15 @@ public class ODataEntitySetIterator nextJsonEntryFromFeed(final InputStream input, final OutputStream osFeed) { - final ByteArrayOutputStream entry = new ByteArrayOutputStream(); + private ResWrap nextJSONEntityFromEntitySet(final InputStream input, final OutputStream osEntitySet) { + final ByteArrayOutputStream entity = new ByteArrayOutputStream(); - ResWrap jsonEntry = null; + ResWrap jsonEntity = null; try { int c; @@ -184,12 +184,12 @@ public class ODataEntitySetIterator= 0); @@ -205,55 +205,48 @@ public class ODataEntitySetIterator= 0) { - jsonEntry = odataClient.getDeserializer().toEntry( - new ByteArrayInputStream(entry.toByteArray()), ODataPubFormat.JSON); + jsonEntity = odataClient.getDeserializer().toEntity( + new ByteArrayInputStream(entity.toByteArray()), ODataPubFormat.JSON); } } else { while ((c = input.read()) >= 0) { - osFeed.write(c); + osEntitySet.write(c); } } } catch (Exception e) { LOG.error("Error retrieving entities from EntitySet", e); } - return jsonEntry; + return jsonEntity; } - /** - * De-Serializes a stream into an OData entity set. - * - * @param input stream to de-serialize. - * @param format de-serialize as AtomFeed or JSONFeed - * @return de-serialized entity set. - */ - private ResWrap nextAtomEntryFromFeed( - final InputStream input, final OutputStream osFeed, final String namespaces) { + private ResWrap nextAtomEntityFromEntitySet( + final InputStream input, final OutputStream osEntitySet, final String namespaces) { - final ByteArrayOutputStream entry = new ByteArrayOutputStream(); + final ByteArrayOutputStream entity = new ByteArrayOutputStream(); - ResWrap atomEntry = null; + ResWrap atomEntity = null; try { - if (consume(input, "", osFeed, false) >= 0) { - entry.write("".getBytes(Constants.UTF8)); + if (consume(input, "", osEntitySet, false) >= 0) { + entity.write("".getBytes(Constants.UTF8)); - if (consume(input, "", entry, true) >= 0) { - atomEntry = odataClient.getDeserializer(). - toEntry(new ByteArrayInputStream(entry.toByteArray()), ODataPubFormat.ATOM); + if (consume(input, "", entity, true) >= 0) { + atomEntity = odataClient.getDeserializer(). + toEntity(new ByteArrayInputStream(entity.toByteArray()), ODataPubFormat.ATOM); } } } catch (Exception e) { LOG.error("Error retrieving entities from EntitySet", e); } - return atomEntry; + return atomEntity; } private String getAllElementAttributes(final InputStream input, final String name, final OutputStream os) { diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java index acb08aebc..08ee08dc5 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java @@ -19,8 +19,8 @@ package org.apache.olingo.client.api.op; import java.io.Serializable; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +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.Property; import org.apache.olingo.client.api.data.ServiceDocument; @@ -34,22 +34,22 @@ import org.apache.olingo.commons.api.domain.ODataServiceDocument; public interface CommonODataBinder extends Serializable { /** - * Gets a Feed from the given OData entity set. + * Gets a EntitySet from the given OData entity set. * - * @param feed OData entity set. + * @param entitySet OData entity set. * @param reference reference class. - * @return Feed object. + * @return {@link EntitySet} object. */ - Feed getFeed(CommonODataEntitySet feed, Class reference); + EntitySet getEntitySet(CommonODataEntitySet entitySet, Class reference); /** - * Gets an Entry from the given OData entity. + * Gets an Entity from the given OData entity. * * @param entity OData entity. * @param reference reference class. - * @return Entry object. + * @return {@link Entity} object. */ - Entry getEntry(CommonODataEntity entity, Class reference); + Entity getEntity(CommonODataEntity entity, Class reference); /** * Gets a Link from the given OData link. @@ -67,7 +67,7 @@ public interface CommonODataBinder extends Serializable { * @param reference reference class. * @return Property object. */ - Property getProperty(CommonODataProperty property, Class reference); + Property getProperty(CommonODataProperty property, Class reference); /** * Adds the given property to the given entity. @@ -87,20 +87,20 @@ public interface CommonODataBinder extends Serializable { ODataServiceDocument getODataServiceDocument(ServiceDocument resource); /** - * Gets ODataEntitySet from the given feed resource. + * Gets ODataEntitySet from the given entity set resource. * - * @param resource feed resource. + * @param resource entity set resource. * @return {@link CommonODataEntitySet} object. */ - CommonODataEntitySet getODataEntitySet(ResWrap resource); + CommonODataEntitySet getODataEntitySet(ResWrap resource); /** - * Gets ODataEntity from the given entry resource. + * Gets ODataEntity from the given entity resource. * - * @param resource entry resource. + * @param resource entity resource. * @return {@link CommonODataEntity} object. */ - CommonODataEntity getODataEntity(ResWrap resource); + CommonODataEntity getODataEntity(ResWrap resource); /** * Gets an ODataProperty from the given property resource. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java index 0f1335a6a..eea1567e8 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java @@ -37,7 +37,7 @@ import org.apache.olingo.commons.api.format.ODataPubFormat; *
* Use this class to de-serialize an OData response body. *
- * This class provides method helpers to de-serialize an entire feed, a set of entities and a single entity as well. + * This class provides method helpers to de-serialize an entire entity set, a set of entities or a single entity. */ public interface CommonODataReader extends Serializable { @@ -71,7 +71,7 @@ public interface CommonODataReader extends Serializable { * De-Serializes a stream into an OData entity set. * * @param input stream to de-serialize. - * @param format de-serialize as AtomFeed or JSONFeed + * @param format de-serialize format * @return de-serialized entity set. */ CommonODataEntitySet readEntitySet(InputStream input, ODataPubFormat format); @@ -80,7 +80,7 @@ public interface CommonODataReader extends Serializable { * Parses a stream taking care to de-serializes the first OData entity found. * * @param input stream to de-serialize. - * @param format de-serialize as AtomEntry or JSONEntry + * @param format de-serialize format * @return entity de-serialized. */ CommonODataEntity readEntity(InputStream input, ODataPubFormat format); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataBinder.java index 92d3061cf..88e3224a1 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataBinder.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataBinder.java @@ -21,8 +21,8 @@ package org.apache.olingo.client.api.op.v3; import org.apache.olingo.commons.api.data.v3.LinkCollection; import org.apache.olingo.client.api.domain.v3.ODataLinkCollection; import org.apache.olingo.client.api.op.CommonODataBinder; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.v3.ODataEntity; @@ -32,10 +32,10 @@ import org.apache.olingo.commons.api.domain.v3.ODataProperty; public interface ODataBinder extends CommonODataBinder { @Override - ODataEntitySet getODataEntitySet(ResWrap resource); + ODataEntitySet getODataEntitySet(ResWrap resource); @Override - ODataEntity getODataEntity(ResWrap resource); + ODataEntity getODataEntity(ResWrap resource); @Override ODataProperty getODataProperty(ResWrap resource); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java index 9c84a8c2c..c6c53b3b9 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataBinder.java @@ -19,8 +19,8 @@ package org.apache.olingo.client.api.op.v4; import org.apache.olingo.client.api.op.CommonODataBinder; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.v4.ODataEntity; @@ -30,10 +30,10 @@ import org.apache.olingo.commons.api.domain.v4.ODataProperty; public interface ODataBinder extends CommonODataBinder { @Override - ODataEntitySet getODataEntitySet(ResWrap resource); + ODataEntitySet getODataEntitySet(ResWrap resource); @Override - ODataEntity getODataEntity(ResWrap resource); + ODataEntity getODataEntity(ResWrap resource); @Override ODataProperty getODataProperty(ResWrap resource); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java index 8b0e0b7f5..199e98fc4 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java @@ -22,10 +22,21 @@ import java.io.InputStream; import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata; import org.apache.olingo.client.api.op.ClientODataDeserializer; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.ResWrap; +import org.apache.olingo.commons.api.format.ODataPubFormat; public interface ODataDeserializer extends ClientODataDeserializer { @Override XMLMetadata toMetadata(InputStream input); + /** + * Gets a delta object from the given InputStream. + * + * @param input stream to be de-serialized. + * @param format Atom or JSON + * @return {@link Delta} instance. + */ + ResWrap toDelta(InputStream input, ODataPubFormat format); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java index 19ed949af..2822d82f4 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java @@ -34,7 +34,7 @@ import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; /** * This class implements an OData create request. @@ -119,8 +119,8 @@ public class ODataEntityCreateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(). - toEntry(getRawResponse(), ODataPubFormat.fromString(getAccept())); + final ResWrap resource = odataClient.getDeserializer(). + toEntity(getRawResponse(), ODataPubFormat.fromString(getAccept())); entity = (E) odataClient.getBinder().getODataEntity(resource); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java index 1134d7920..c3b835954 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java @@ -34,7 +34,7 @@ import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; /** * This class implements an OData update request. @@ -124,8 +124,8 @@ public class ODataEntityUpdateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(). - toEntry(getRawResponse(), ODataPubFormat.fromString(getAccept())); + final ResWrap resource = odataClient.getDeserializer(). + toEntity(getRawResponse(), ODataPubFormat.fromString(getAccept())); entity = (E) odataClient.getBinder().getODataEntity(resource); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java index c51bcdcb4..8652086f5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java @@ -25,7 +25,7 @@ import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.format.ODataPubFormat; @@ -81,8 +81,8 @@ public class ODataEntityRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(). - toEntry(getRawResponse(), ODataPubFormat.fromString(getContentType())); + final ResWrap resource = odataClient.getDeserializer(). + toEntity(getRawResponse(), ODataPubFormat.fromString(getContentType())); entity = (E) odataClient.getBinder().getODataEntity(resource); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java index b2e3b5777..cca50537b 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java @@ -36,7 +36,7 @@ public class ODataEntitySetIteratorRequestImpl, ODataPubFormat> implements ODataEntitySetIteratorRequest { - private ODataEntitySetIterator feedIterator = null; + private ODataEntitySetIterator entitySetIterator = null; /** * Private constructor. @@ -44,7 +44,7 @@ public class ODataEntitySetIteratorRequestImpl odataClient, final URI query) { super(odataClient, ODataPubFormat.class, query); } @@ -78,11 +78,11 @@ public class ODataEntitySetIteratorRequestImpl getBody() { - if (feedIterator == null) { - feedIterator = new ODataEntitySetIterator( + if (entitySetIterator == null) { + entitySetIterator = new ODataEntitySetIterator( odataClient, getRawResponse(), ODataPubFormat.fromString(getContentType())); } - return feedIterator; + return entitySetIterator; } } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java index a14b4a8a4..17837892e 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java @@ -25,7 +25,7 @@ import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.domain.CommonODataEntitySet; import org.apache.olingo.commons.api.format.ODataPubFormat; @@ -90,8 +90,8 @@ public class ODataEntitySetRequestImpl public ES getBody() { if (entitySet == null) { try { - final ResWrap resource = odataClient.getDeserializer(). - toFeed(getRawResponse(), ODataPubFormat.fromString(getContentType())); + final ResWrap resource = odataClient.getDeserializer(). + toEntitySet(getRawResponse(), ODataPubFormat.fromString(getContentType())); entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java index 0eb503743..89b0da07b 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java @@ -32,7 +32,7 @@ import org.apache.olingo.client.api.http.HttpMethod; import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; /** * This class implements an OData Media Entity create request. Get instance by using ODataStreamedRequestFactory. @@ -123,7 +123,7 @@ public class ODataMediaEntityCreateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer().toEntry(getRawResponse(), getFormat()); + final ResWrap resource = odataClient.getDeserializer().toEntity(getRawResponse(), getFormat()); entity = (E) odataClient.getBinder().getODataEntity(resource); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java index 476fb8dd0..bd9fa820c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java @@ -32,7 +32,7 @@ import org.apache.olingo.client.api.http.HttpMethod; import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; /** * This class implements an OData Media Entity create request. Get instance by using ODataStreamedRequestFactory. @@ -122,7 +122,7 @@ public class ODataMediaEntityUpdateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer().toEntry(getRawResponse(), getFormat()); + final ResWrap resource = odataClient.getDeserializer().toEntity(getRawResponse(), getFormat()); entity = (E) odataClient.getBinder().getODataEntity(resource); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestFactoryImpl.java index d5331bcd5..afd08f08c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestFactoryImpl.java @@ -26,12 +26,11 @@ import org.apache.olingo.client.api.communication.request.v4.AsyncRequestWrapper import org.apache.olingo.client.api.communication.response.ODataResponse; import org.apache.olingo.client.api.v4.ODataClient; -@SuppressWarnings("unchecked") public class AsyncRequestFactoryImpl implements AsyncRequestFactory { private static final long serialVersionUID = 546577958047902917L; - protected final ODataClient client; + private final ODataClient client; public AsyncRequestFactoryImpl(final ODataClient client) { this.client = client; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java index 95efa7cf8..3107e8e4d 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java @@ -30,8 +30,8 @@ import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ContextURL; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +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; @@ -105,33 +105,33 @@ public abstract class AbstractODataBinder implements CommonODataBinder { } @Override - public Feed getFeed(final CommonODataEntitySet entitySet, final Class reference) { - final Feed feed = ResourceFactory.newFeed(reference); + public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet, final Class reference) { + final EntitySet entitySet = ResourceFactory.newEntitySet(reference); - feed.setCount(entitySet.getCount()); + entitySet.setCount(odataEntitySet.getCount()); - final URI next = entitySet.getNext(); + final URI next = odataEntitySet.getNext(); if (next != null) { - feed.setNext(next); + entitySet.setNext(next); } - for (CommonODataEntity entity : entitySet.getEntities()) { - feed.getEntries().add(getEntry(entity, ResourceFactory.entryClassForFeed(reference))); + for (CommonODataEntity entity : odataEntitySet.getEntities()) { + entitySet.getEntities().add(getEntity(entity, ResourceFactory.entityClassForEntitySet(reference))); } - return feed; + return entitySet; } - protected void links(final ODataLinked odataLinked, final Linked linked, final Class reference) { + protected void links(final ODataLinked odataLinked, final Linked linked, final Class reference) { // ------------------------------------------------------------- - // Append navigation links (handling inline entry / feed as well) + // Append navigation links (handling inline entity / entity set as well) // ------------------------------------------------------------- // handle navigation links for (ODataLink link : odataLinked.getNavigationLinks()) { // append link LOG.debug("Append navigation link\n{}", link); linked.getNavigationLinks().add(getLink(link, - ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); + ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- @@ -141,61 +141,61 @@ public abstract class AbstractODataBinder implements CommonODataBinder { for (ODataLink link : odataLinked.getAssociationLinks()) { LOG.debug("Append association link\n{}", link); linked.getAssociationLinks().add(getLink(link, - ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); + ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- } @Override - public Entry getEntry(final CommonODataEntity entity, final Class reference) { - final Entry entry = ResourceFactory.newEntry(reference); + public Entity getEntity(final CommonODataEntity odataEntity, final Class reference) { + final Entity entity = ResourceFactory.newEntity(reference); - entry.setType(entity.getTypeName() == null ? null : entity.getTypeName().toString()); + entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString()); // ------------------------------------------------------------- // Add edit and self link // ------------------------------------------------------------- - final URI editLink = entity.getEditLink(); - if (editLink != null) { - final LinkImpl entryEditLink = new LinkImpl(); - entryEditLink.setTitle(entry.getType()); - entryEditLink.setHref(editLink.toASCIIString()); - entryEditLink.setRel(Constants.EDIT_LINK_REL); - entry.setEditLink(entryEditLink); + final URI odataEditLink = odataEntity.getEditLink(); + if (odataEditLink != null) { + final LinkImpl editLink = new LinkImpl(); + editLink.setTitle(entity.getType()); + editLink.setHref(odataEditLink.toASCIIString()); + editLink.setRel(Constants.EDIT_LINK_REL); + entity.setEditLink(editLink); } - if (entity.isReadOnly()) { - final LinkImpl entrySelfLink = new LinkImpl(); - entrySelfLink.setTitle(entry.getType()); - entrySelfLink.setHref(entity.getLink().toASCIIString()); - entrySelfLink.setRel(Constants.SELF_LINK_REL); - entry.setSelfLink(entrySelfLink); + if (odataEntity.isReadOnly()) { + final LinkImpl selfLink = new LinkImpl(); + selfLink.setTitle(entity.getType()); + selfLink.setHref(odataEntity.getLink().toASCIIString()); + selfLink.setRel(Constants.SELF_LINK_REL); + entity.setSelfLink(selfLink); } // ------------------------------------------------------------- - links(entity, entry, reference); + links(odataEntity, entity, reference); // ------------------------------------------------------------- // Append edit-media links // ------------------------------------------------------------- - for (ODataLink link : entity.getEditMediaLinks()) { + for (ODataLink link : odataEntity.getEditMediaLinks()) { LOG.debug("Append edit-media link\n{}", link); - entry.getMediaEditLinks().add(getLink(link, - ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM)); + entity.getMediaEditLinks().add(getLink(link, + ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM)); } // ------------------------------------------------------------- - if (entity.isMediaEntity()) { - entry.setMediaContentSource(entity.getMediaContentSource()); - entry.setMediaContentType(entity.getMediaContentType()); - entry.setMediaETag(entity.getMediaETag()); + if (odataEntity.isMediaEntity()) { + entity.setMediaContentSource(odataEntity.getMediaContentSource()); + entity.setMediaContentType(odataEntity.getMediaContentType()); + entity.setMediaETag(odataEntity.getMediaETag()); } - for (CommonODataProperty property : entity.getProperties()) { - entry.getProperties().add(getProperty(property, reference)); + for (CommonODataProperty property : odataEntity.getProperties()) { + entity.getProperties().add(getProperty(property, reference)); } - return entry; + return entity; } @Override @@ -212,19 +212,19 @@ public abstract class AbstractODataBinder implements CommonODataBinder { final CommonODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity(); LOG.debug("Append in-line entity\n{}", inlineEntity); - linkResource.setInlineEntry(getEntry(inlineEntity, ResourceFactory.entryClassForFormat(isXML))); + linkResource.setInlineEntity(getEntity(inlineEntity, ResourceFactory.entityClassForFormat(isXML))); } else if (link instanceof ODataInlineEntitySet) { - // append inline feed - final CommonODataEntitySet InlineFeed = ((ODataInlineEntitySet) link).getEntitySet(); - LOG.debug("Append in-line feed\n{}", InlineFeed); + // append inline entity set + final CommonODataEntitySet InlineEntitySet = ((ODataInlineEntitySet) link).getEntitySet(); + LOG.debug("Append in-line entity set\n{}", InlineEntitySet); - linkResource.setInlineFeed(getFeed(InlineFeed, ResourceFactory.feedClassForFormat(isXML))); + linkResource.setInlineEntitySet(getEntitySet(InlineEntitySet, ResourceFactory.entitySetClassForFormat(isXML))); } return linkResource; } - protected Value getValue(final ODataValue value, final Class reference) { + protected Value getValue(final ODataValue value, final Class reference) { Value valueResource = null; if (value == null) { @@ -255,12 +255,12 @@ public abstract class AbstractODataBinder implements CommonODataBinder { protected abstract boolean add(CommonODataEntitySet entitySet, CommonODataEntity entity); @Override - public CommonODataEntitySet getODataEntitySet(final ResWrap resource) { + public CommonODataEntitySet getODataEntitySet(final ResWrap resource) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); - client.getSerializer().feed(resource.getPayload(), writer); + client.getSerializer().entitySet(resource.getPayload(), writer); writer.flush(); - LOG.debug("Feed -> ODataEntitySet:\n{}", writer.toString()); + LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString()); } final URI base = resource.getContextURL() == null @@ -276,9 +276,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder { entitySet.setCount(resource.getPayload().getCount()); } - for (Entry entryResource : resource.getPayload().getEntries()) { + for (Entity entityResource : resource.getPayload().getEntities()) { add(entitySet, getODataEntity( - new ResWrap(resource.getContextURL(), resource.getMetadataETag(), entryResource))); + new ResWrap(resource.getContextURL(), resource.getMetadataETag(), entityResource))); } return entitySet; @@ -288,10 +288,10 @@ public abstract class AbstractODataBinder implements CommonODataBinder { final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) { for (Link link : linked.getNavigationLinks()) { - final Entry inlineEntry = link.getInlineEntry(); - final Feed inlineFeed = link.getInlineFeed(); + final Entity inlineEntity = link.getInlineEntity(); + final EntitySet inlineEntitySet = link.getInlineEntitySet(); - if (inlineEntry == null && inlineFeed == null) { + if (inlineEntity == null && inlineEntitySet == null) { ODataLinkType linkType = null; if (edmType != null) { final EdmNavigationProperty navProp = edmType.getNavigationProperty(link.getTitle()); @@ -312,20 +312,20 @@ public abstract class AbstractODataBinder implements CommonODataBinder { newEntityNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())) : client.getObjectFactory(). newEntitySetNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref()))); - } else if (inlineEntry != null) { + } else if (inlineEntity != null) { odataLinked.addLink(new ODataInlineEntity(client.getServiceVersion(), URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_NAVIGATION, link.getTitle(), - getODataEntity(new ResWrap( - inlineEntry.getBaseURI() == null ? base : inlineEntry.getBaseURI(), + getODataEntity(new ResWrap( + inlineEntity.getBaseURI() == null ? base : inlineEntity.getBaseURI(), metadataETag, - inlineEntry)))); + inlineEntity)))); } else { odataLinked.addLink(new ODataInlineEntitySet(client.getServiceVersion(), URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_SET_NAVIGATION, link.getTitle(), - getODataEntitySet(new ResWrap( - inlineFeed.getBaseURI() == null ? base : inlineFeed.getBaseURI(), + getODataEntitySet(new ResWrap( + inlineEntitySet.getBaseURI() == null ? base : inlineEntitySet.getBaseURI(), metadataETag, - inlineFeed)))); + inlineEntitySet)))); } } } @@ -374,12 +374,12 @@ public abstract class AbstractODataBinder implements CommonODataBinder { } @Override - public CommonODataEntity getODataEntity(final ResWrap resource) { + public CommonODataEntity getODataEntity(final ResWrap resource) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); - client.getSerializer().entry(resource.getPayload(), writer); + client.getSerializer().entity(resource.getPayload(), writer); writer.flush(); - LOG.debug("EntryResource -> ODataEntity:\n{}", writer.toString()); + LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString()); } final URI base = resource.getContextURL() == null @@ -428,7 +428,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder { entity.getOperations().add(operation); } - if (resource.getPayload().isMediaEntry()) { + if (resource.getPayload().isMediaEntity()) { entity.setMediaEntity(true); entity.setMediaContentSource(resource.getPayload().getMediaContentSource()); entity.setMediaContentType(resource.getPayload().getMediaContentType()); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java index 0df51a5ae..9cc9548d6 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java @@ -37,8 +37,8 @@ import org.apache.olingo.client.api.edm.xml.XMLMetadata; import org.apache.olingo.client.api.op.CommonODataReader; import org.apache.olingo.client.core.edm.EdmClientImpl; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataPubFormat; @@ -96,13 +96,14 @@ public abstract class AbstractODataReader implements CommonODataReader { reference.cast(new ODataEntitySetIterator( client, src, ODataPubFormat.fromString(format)))); } else if (CommonODataEntitySet.class.isAssignableFrom(reference)) { - final ResWrap resource = client.getDeserializer().toFeed(src, ODataPubFormat.fromString(format)); + final ResWrap resource = client.getDeserializer(). + toEntitySet(src, ODataPubFormat.fromString(format)); res = new ResWrap( resource.getContextURL(), resource.getMetadataETag(), reference.cast(client.getBinder().getODataEntitySet(resource))); } else if (CommonODataEntity.class.isAssignableFrom(reference)) { - final ResWrap container = client.getDeserializer().toEntry(src, ODataPubFormat.fromString(format)); + final ResWrap container = client.getDeserializer().toEntity(src, ODataPubFormat.fromString(format)); res = new ResWrap( container.getContextURL(), container.getMetadataETag(), diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java index 723070410..a1c7e5e12 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java @@ -48,8 +48,8 @@ public class ODataWriterImpl implements ODataWriter { final ByteArrayOutputStream output = new ByteArrayOutputStream(); try { for (CommonODataEntity entity : entities) { - client.getSerializer().entry(client.getBinder().getEntry( - entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)), output); + client.getSerializer().entity(client.getBinder().getEntity( + entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), output); } return new ByteArrayInputStream(output.toByteArray()); @@ -68,7 +68,7 @@ public class ODataWriterImpl implements ODataWriter { final ByteArrayOutputStream output = new ByteArrayOutputStream(); try { client.getSerializer().property(client.getBinder().getProperty( - property, ResourceFactory.entryClassForFormat(format == ODataFormat.XML)), output); + property, ResourceFactory.entityClassForFormat(format == ODataFormat.XML)), output); return new ByteArrayInputStream(output.toByteArray()); } finally { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java index 75d3eaac8..c42917776 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java @@ -22,8 +22,8 @@ import org.apache.olingo.client.api.domain.v3.ODataLinkCollection; import org.apache.olingo.client.api.op.v3.ODataBinder; import org.apache.olingo.client.core.op.AbstractODataBinder; import org.apache.olingo.client.core.v3.ODataClientImpl; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.data.v3.LinkCollection; @@ -55,7 +55,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override - public Property getProperty(final CommonODataProperty property, final Class reference) { + public Property getProperty(final CommonODataProperty property, final Class reference) { final Property propertyResource = ResourceFactory.newProperty(reference); propertyResource.setName(property.getName()); propertyResource.setValue(getValue(property.getValue(), reference)); @@ -72,12 +72,12 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override - public ODataEntitySet getODataEntitySet(final ResWrap resource) { + public ODataEntitySet getODataEntitySet(final ResWrap resource) { return (ODataEntitySet) super.getODataEntitySet(resource); } @Override - public ODataEntity getODataEntity(final ResWrap resource) { + public ODataEntity getODataEntity(final ResWrap resource) { return (ODataEntity) super.getODataEntity(resource); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java index 2b8bc5d78..c64d5c897 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java @@ -42,12 +42,12 @@ public class ODataReaderImpl extends AbstractODataReader implements ODataReader @Override public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) { - return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer().toFeed(input, format)); + return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer().toEntitySet(input, format)); } @Override public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) { - return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer().toEntry(input, format)); + return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer().toEntity(input, format)); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java index 407ab1b52..cbdd7735e 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java @@ -25,8 +25,8 @@ import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.op.AbstractODataBinder; import org.apache.olingo.client.core.uri.URIUtils; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.LinkedComplexValue; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ResWrap; @@ -89,14 +89,14 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override - public Entry getEntry(final CommonODataEntity entity, final Class reference) { - final Entry entry = super.getEntry(entity, reference); - entry.setId(((ODataEntity) entity).getReference()); - return entry; + public Entity getEntity(final CommonODataEntity odataEntity, final Class reference) { + final Entity entity = super.getEntity(odataEntity, reference); + entity.setId(((ODataEntity) odataEntity).getReference()); + return entity; } @Override - public Property getProperty(final CommonODataProperty property, final Class reference) { + public Property getProperty(final CommonODataProperty property, final Class reference) { final ODataProperty _property = (ODataProperty) property; final Property propertyResource = ResourceFactory.newProperty(reference); @@ -117,7 +117,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override - protected Value getValue(final ODataValue value, final Class reference) { + protected Value getValue(final ODataValue value, final Class reference) { Value valueResource; if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue && ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isEnum()) { @@ -144,12 +144,12 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override - public ODataEntitySet getODataEntitySet(final ResWrap resource) { + public ODataEntitySet getODataEntitySet(final ResWrap resource) { return (ODataEntitySet) super.getODataEntitySet(resource); } @Override - public ODataEntity getODataEntity(final ResWrap resource) { + public ODataEntity getODataEntity(final ResWrap resource) { final ODataEntity entity = (ODataEntity) super.getODataEntity(resource); entity.setReference(resource.getPayload().getId()); return entity; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java index 9bb6727f3..ae7d5cd43 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java @@ -28,9 +28,13 @@ import org.apache.olingo.client.core.data.v4.JSONServiceDocumentImpl; import org.apache.olingo.client.core.data.v4.XMLServiceDocumentImpl; import org.apache.olingo.client.core.edm.xml.v4.EdmxImpl; import org.apache.olingo.client.core.edm.xml.v4.XMLMetadataImpl; +import org.apache.olingo.commons.api.data.Delta; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.core.op.AbstractODataDeserializer; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.olingo.commons.api.format.ODataPubFormat; +import org.apache.olingo.commons.core.data.AtomDeltaImpl; +import org.apache.olingo.commons.core.data.JSONDeltaImpl; public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer { @@ -56,4 +60,12 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer implements : this.json(input, JSONServiceDocumentImpl.class); } + + @Override + public ResWrap toDelta(final InputStream input, final ODataPubFormat format) { + return format == ODataPubFormat.ATOM + ? this.atom(input, AtomDeltaImpl.class) + : this.json(input, JSONDeltaImpl.class); + } + } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java index eb446d1d8..71c22444a 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java @@ -38,12 +38,12 @@ public class ODataReaderImpl extends AbstractODataReader implements ODataReader @Override public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) { - return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer().toFeed(input, format)); + return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer().toEntitySet(input, format)); } @Override public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) { - return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer().toEntry(input, format)); + return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer().toEntity(input, format)); } @Override diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java index fc1e91d4f..33c27a66a 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java @@ -23,13 +23,13 @@ import java.io.InputStream; import java.io.StringWriter; import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.CommonODataClient; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.ODataValue; -import org.apache.olingo.commons.core.data.AtomEntryImpl; -import org.apache.olingo.commons.core.data.JSONEntryImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,19 +43,19 @@ public abstract class AbstractBaseTestITCase { @SuppressWarnings("rawtypes") protected abstract CommonODataClient getClient(); - protected void debugEntry(final Entry entry, final String message) { + protected void debugEntity(final Entity entity, final String message) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); - getClient().getSerializer().entry(entry, writer); + getClient().getSerializer().entity(entity, writer); writer.flush(); LOG.debug(message + "\n{}", writer.toString()); } } - protected void debugFeed(final Feed feed, final String message) { + protected void debugEntitySet(final EntitySet entitySet, final String message) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); - getClient().getSerializer().feed(feed, writer); + getClient().getSerializer().entitySet(entitySet, writer); writer.flush(); LOG.debug(message + "\n{}", writer.toString()); } @@ -72,12 +72,12 @@ public abstract class AbstractBaseTestITCase { protected void debugODataEntity(final CommonODataEntity entity, final String message) { if (LOG.isDebugEnabled()) { StringWriter writer = new StringWriter(); - getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, AtomEntryImpl.class), writer); + getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, AtomEntityImpl.class), writer); writer.flush(); LOG.debug(message + " (Atom)\n{}", writer.toString()); writer = new StringWriter(); - getClient().getSerializer().entry(getClient().getBinder().getEntry(entity, JSONEntryImpl.class), writer); + getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, JSONEntityImpl.class), writer); writer.flush(); LOG.debug(message + " (JSON)\n{}", writer.toString()); } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java index 2693fb2c2..de51167c2 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java @@ -78,8 +78,8 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity(); assertNotNull(inline); - debugEntry(client.getBinder().getEntry( - inline, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)), "Just read"); + debugEntity(client.getBinder().getEntity( + inline, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), "Just read"); final List properties = inline.getProperties(); assertEquals(2, properties.size()); @@ -125,7 +125,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase { final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet(); assertNotNull(inline); - debugFeed(client.getBinder().getFeed(inline, ResourceFactory.feedClassForFormat( + debugEntitySet(client.getBinder().getEntitySet(inline, ResourceFactory.entitySetClassForFormat( format == ODataPubFormat.ATOM)), "Just read"); found = true; diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java index abf0964e5..077a6b17d 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java @@ -111,7 +111,7 @@ public class EntitySetTestITCase extends AbstractTestITCase { assertNotNull(feed); - debugFeed(client.getBinder().getFeed(feed, ResourceFactory.feedClassForFormat( + debugEntitySet(client.getBinder().getEntitySet(feed, ResourceFactory.entitySetClassForFormat( ODataPubFormat.ATOM == format)), "Just retrieved feed"); assertEquals(2, feed.getEntities().size()); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java index 827ad2afe..a00f057f9 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java @@ -30,13 +30,13 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySe import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.uri.v3.URIBuilder; import org.apache.olingo.client.api.uri.v3.URIBuilder.InlineCount; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.domain.ODataInlineEntitySet; import org.apache.olingo.commons.api.domain.v3.ODataEntity; import org.apache.olingo.commons.api.domain.v3.ODataEntitySet; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.format.ODataPubFormat; -import org.apache.olingo.commons.core.data.AtomEntryImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; import org.junit.Test; /** @@ -194,9 +194,9 @@ public class QueryOptionsTestITCase extends AbstractTestITCase { req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()); req.setFormat(ODataPubFormat.ATOM); - final Entry atomEntry = - client.getDeserializer().toEntry(req.execute().getRawResponse(), ODataPubFormat.ATOM).getPayload(); + final Entity atomEntry = + client.getDeserializer().toEntity(req.execute().getRawResponse(), ODataPubFormat.ATOM).getPayload(); assertEquals("remotingdestructorprinterswitcheschannelssatellitelanguageresolve", - ((AtomEntryImpl) atomEntry).getSummary()); + ((AtomEntityImpl) atomEntry).getSummary()); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java index 1e6df49ed..1b047a84a 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java @@ -67,37 +67,37 @@ public class AtomTest extends AbstractTest { assertTrue(diff.similar()); } - protected void feed(final String filename, final ODataPubFormat format) throws Exception { + protected void entitySet(final String filename, final ODataPubFormat format) throws Exception { final StringWriter writer = new StringWriter(); - getClient().getSerializer().feed(getClient().getDeserializer().toFeed( + getClient().getSerializer().entitySet(getClient().getDeserializer().toEntitySet( getClass().getResourceAsStream("Customer." + getSuffix(format)), format).getPayload(), writer); assertSimilar("Customer." + getSuffix(format), writer.toString()); } @Test - public void feeds() throws Exception { - feed("Customer", getODataPubFormat()); + public void entitySets() throws Exception { + entitySet("Customer", getODataPubFormat()); } - protected void entry(final String filename, final ODataPubFormat format) throws Exception { + protected void entity(final String filename, final ODataPubFormat format) throws Exception { final StringWriter writer = new StringWriter(); - getClient().getSerializer().entry(getClient().getDeserializer().toEntry( + getClient().getSerializer().entity(getClient().getDeserializer().toEntity( getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer); assertSimilar(filename + "." + getSuffix(format), writer.toString()); } @Test - public void entries() throws Exception { - entry("AllGeoTypesSet_-5", getODataPubFormat()); - entry("AllGeoTypesSet_-8", getODataPubFormat()); - entry("Car_16", getODataPubFormat()); - entry("ComputerDetail_-10", getODataPubFormat()); - entry("Customer_-10", getODataPubFormat()); - entry("Products_1", getODataPubFormat()); - entry("PersonDetails_0_Person", getODataPubFormat()); - entry("Products_0_Categories", getODataPubFormat()); + public void entities() throws Exception { + entity("AllGeoTypesSet_-5", getODataPubFormat()); + entity("AllGeoTypesSet_-8", getODataPubFormat()); + entity("Car_16", getODataPubFormat()); + entity("ComputerDetail_-10", getODataPubFormat()); + entity("Customer_-10", getODataPubFormat()); + entity("Products_1", getODataPubFormat()); + entity("PersonDetails_0_Person", getODataPubFormat()); + entity("Products_0_Categories", getODataPubFormat()); } protected void property(final String filename, final ODataFormat format) throws Exception { diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java index f01a7f516..46a6995dd 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java @@ -27,7 +27,7 @@ import java.net.URI; import org.apache.olingo.client.api.v3.ODataClient; import org.apache.olingo.commons.api.format.ODataPubFormat; import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.v3.ODataEntitySet; import org.apache.olingo.commons.core.op.ResourceFactory; @@ -43,15 +43,15 @@ public class EntitySetTest extends AbstractTest { private void read(final ODataPubFormat format) throws IOException { final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format)); final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet( - getClient().getDeserializer().toFeed(input, format)); + getClient().getDeserializer().toEntitySet(input, format)); assertNotNull(entitySet); assertEquals(2, entitySet.getEntities().size()); assertNotNull(entitySet.getNext()); - final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap((URI) null, null, - getClient().getBinder().getFeed( - entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap((URI) null, null, + getClient().getBinder().getEntitySet( + entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entitySet, written); } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java index cbc804119..20f7536d8 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java @@ -28,7 +28,7 @@ import org.apache.olingo.client.api.v3.ODataClient; import org.apache.olingo.commons.api.domain.ODataLink; import org.apache.olingo.commons.api.format.ODataPubFormat; import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.v3.ODataEntity; import org.apache.olingo.commons.api.domain.v3.ODataProperty; @@ -49,7 +49,7 @@ public class EntityTest extends AbstractTest { private void readAndWrite(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getTypeName().toString()); @@ -67,8 +67,9 @@ public class EntityTest extends AbstractTest { assertTrue(check); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -85,7 +86,7 @@ public class EntityTest extends AbstractTest { private void readGeospatial(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-8." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); boolean found = false; @@ -98,8 +99,9 @@ public class EntityTest extends AbstractTest { } assertTrue(found); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -117,14 +119,15 @@ public class EntityTest extends AbstractTest { private void withActions(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("ComputerDetail_-10." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); assertEquals(1, entity.getOperations().size()); assertEquals("ResetComputerDetailsSpecifications", entity.getOperations().get(0).getTitle()); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); entity.getOperations().clear(); assertEquals(entity, written); } @@ -143,14 +146,15 @@ public class EntityTest extends AbstractTest { private void mediaEntity(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("Car_16." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); assertTrue(entity.isMediaEntity()); assertNotNull(entity.getMediaContentSource()); assertNotNull(entity.getMediaContentType()); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -167,7 +171,7 @@ public class EntityTest extends AbstractTest { private void issue128(final ODataPubFormat format) throws EdmPrimitiveTypeException { final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-5." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); final ODataProperty geogCollection = entity.getProperty("GeogCollection"); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java index fad3624a0..75d4bb1e9 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/AtomTest.java @@ -68,7 +68,7 @@ public class AtomTest extends JSONTest { } @Override - public void additionalEntries() throws Exception { + public void additionalEntities() throws Exception { // no test } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java index 88a0f07f3..e213a54a5 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java @@ -27,7 +27,7 @@ import java.io.InputStream; import java.net.URI; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.v4.ODataEntity; import org.apache.olingo.commons.api.domain.v4.ODataEntitySet; @@ -45,15 +45,15 @@ public class EntitySetTest extends AbstractTest { private void read(final ODataPubFormat format) throws IOException { final InputStream input = getClass().getResourceAsStream("Customers." + getSuffix(format)); final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet( - getClient().getDeserializer().toFeed(input, format)); + getClient().getDeserializer().toEntitySet(input, format)); assertNotNull(entitySet); assertEquals(2, entitySet.getEntities().size()); assertNull(entitySet.getNext()); - final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap((URI) null, null, - getClient().getBinder().getFeed( - entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap((URI) null, null, + getClient().getBinder().getEntitySet( + entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entitySet, written); } @@ -70,7 +70,7 @@ public class EntitySetTest extends AbstractTest { private void ref(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(format)); final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet( - getClient().getDeserializer().toFeed(input, format)); + getClient().getDeserializer().toEntitySet(input, format)); assertNotNull(entitySet); for (ODataEntity entity : entitySet.getEntities()) { @@ -78,9 +78,9 @@ public class EntitySetTest extends AbstractTest { } entitySet.setCount(entitySet.getEntities().size()); - final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap((URI) null, null, - getClient().getBinder().getFeed( - entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap((URI) null, null, + getClient().getBinder().getEntitySet( + entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entitySet, written); } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java index 317f9160e..212c52766 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java @@ -28,7 +28,7 @@ import java.net.URI; import java.util.Iterator; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.AbstractTest; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.domain.ODataInlineEntitySet; import org.apache.olingo.commons.api.domain.ODataLink; @@ -53,7 +53,7 @@ public class EntityTest extends AbstractTest { private void singleton(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("VipCustomer." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString()); @@ -93,8 +93,9 @@ public class EntityTest extends AbstractTest { // operations won't get serialized entity.getOperations().clear(); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -111,7 +112,7 @@ public class EntityTest extends AbstractTest { private void withEnums(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("Products_5." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); final ODataProperty skinColor = entity.getProperty("SkinColor"); @@ -128,8 +129,9 @@ public class EntityTest extends AbstractTest { // operations won't get serialized entity.getOperations().clear(); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -147,7 +149,7 @@ public class EntityTest extends AbstractTest { final InputStream input = getClass().getResourceAsStream( "Accounts_101_expand_MyPaymentInstruments." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); final ODataLink instruments = entity.getNavigationLink("MyPaymentInstruments"); @@ -162,8 +164,9 @@ public class EntityTest extends AbstractTest { inline.getEntitySet().setCount(3); // operations won't get serialized entity.getOperations().clear(); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -181,15 +184,16 @@ public class EntityTest extends AbstractTest { final InputStream input = getClass().getResourceAsStream( "Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); assertTrue(entity.isMediaEntity()); assertNotNull(entity.getMediaContentSource()); assertEquals("\"8zOOKKvgOtptr4gt8IrnapX3jds=\"", entity.getMediaETag()); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -206,7 +210,7 @@ public class EntityTest extends AbstractTest { private void withStream(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); assertFalse(entity.isMediaEntity()); @@ -214,8 +218,9 @@ public class EntityTest extends AbstractTest { final ODataLink editMedia = entity.getEditMediaLink("Photo"); assertNotNull(editMedia); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -232,13 +237,14 @@ public class EntityTest extends AbstractTest { private void ref(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); assertNotNull(entity.getReference()); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } @@ -255,7 +261,7 @@ public class EntityTest extends AbstractTest { private void complexNavigationProperties(final ODataPubFormat format) { final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(format)); final ODataEntity entity = getClient().getBinder().getODataEntity( - getClient().getDeserializer().toEntry(input, format)); + getClient().getDeserializer().toEntity(input, format)); assertNotNull(entity); final ODataLinkedComplexValue addressValue = entity.getProperty("Address").getLinkedComplexValue(); @@ -264,8 +270,9 @@ public class EntityTest extends AbstractTest { // ETag is not serialized entity.setETag(null); - final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap((URI) null, null, getClient(). - getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)))); + final ODataEntity written = getClient().getBinder().getODataEntity( + new ResWrap((URI) null, null, getClient(). + getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)))); assertEquals(entity, written); } 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 904e35ec4..663cff11a 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 @@ -18,11 +18,16 @@ */ package org.apache.olingo.client.core.v4; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.ByteArrayInputStream; import java.io.StringWriter; +import java.net.URI; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -31,10 +36,11 @@ import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.AbstractTest; import org.apache.olingo.commons.api.Constants; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataPubFormat; -import static org.junit.Assert.assertEquals; import org.junit.Test; public class JSONTest extends AbstractTest { @@ -79,21 +85,24 @@ public class JSONTest extends AbstractTest { if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))) { node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE)); } + if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_COUNT))) { + node.remove(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_COUNT)); + } final List toRemove = new ArrayList(); for (final Iterator> itor = node.fields(); itor.hasNext();) { final Map.Entry field = itor.next(); if (field.getKey().charAt(0) == '#' || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)) + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE)) || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)) + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK)) || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE)) + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE)) || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK)) + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK)) || field.getKey().endsWith( - getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) { + getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) { toRemove.add(field.getKey()); } else if (field.getValue().isObject()) { @@ -113,51 +122,51 @@ 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().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK), - Constants.JSON_BIND_LINK_SUFFIX)); + Constants.JSON_BIND_LINK_SUFFIX)); cleanup((ObjectNode) expected); final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())); cleanup(actualNode); assertEquals(expected, actualNode); } - protected void feed(final String filename, final ODataPubFormat format) throws Exception { + protected void entitySet(final String filename, final ODataPubFormat format) throws Exception { final StringWriter writer = new StringWriter(); - getClient().getSerializer().feed(getClient().getDeserializer().toFeed( + getClient().getSerializer().entitySet(getClient().getDeserializer().toEntitySet( getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer); assertSimilar(filename + "." + getSuffix(format), writer.toString()); } @Test - public void feeds() throws Exception { - feed("Customers", getODataPubFormat()); - feed("collectionOfEntityReferences", getODataPubFormat()); + public void entitySets() throws Exception { + entitySet("Customers", getODataPubFormat()); + entitySet("collectionOfEntityReferences", getODataPubFormat()); } - protected void entry(final String filename, final ODataPubFormat format) throws Exception { + protected void entity(final String filename, final ODataPubFormat format) throws Exception { final StringWriter writer = new StringWriter(); - getClient().getSerializer().entry(getClient().getDeserializer().toEntry( + getClient().getSerializer().entity(getClient().getDeserializer().toEntity( getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer); assertSimilar(filename + "." + getSuffix(format), writer.toString()); } @Test - public void additionalEntries() throws Exception { - entry("entity.minimal", getODataPubFormat()); - entry("entity.primitive", getODataPubFormat()); - entry("entity.complex", getODataPubFormat()); - entry("entity.collection.primitive", getODataPubFormat()); - entry("entity.collection.complex", getODataPubFormat()); + public void additionalEntities() throws Exception { + entity("entity.minimal", getODataPubFormat()); + entity("entity.primitive", getODataPubFormat()); + entity("entity.complex", getODataPubFormat()); + entity("entity.collection.primitive", getODataPubFormat()); + entity("entity.collection.complex", getODataPubFormat()); } @Test - public void entries() throws Exception { - entry("Products_5", getODataPubFormat()); - entry("VipCustomer", getODataPubFormat()); - entry("Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7", getODataPubFormat()); - entry("entityReference", getODataPubFormat()); - entry("entity.withcomplexnavigation", getODataPubFormat()); + public void entities() throws Exception { + entity("Products_5", getODataPubFormat()); + entity("VipCustomer", getODataPubFormat()); + entity("Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7", getODataPubFormat()); + entity("entityReference", getODataPubFormat()); + entity("entity.withcomplexnavigation", getODataPubFormat()); } protected void property(final String filename, final ODataFormat format) throws Exception { @@ -179,7 +188,39 @@ public class JSONTest extends AbstractTest { @Test public void crossjoin() throws Exception { - getClient().getDeserializer().toFeed( - getClass().getResourceAsStream("crossjoin.json"), ODataPubFormat.JSON_FULL_METADATA); + assertNotNull(getClient().getDeserializer().toEntitySet( + getClass().getResourceAsStream("crossjoin.json"), ODataPubFormat.JSON_FULL_METADATA)); + } + + protected void delta(final String filename, final ODataPubFormat format) throws Exception { + final Delta delta = getClient().getDeserializer().toDelta( + getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(); + assertNotNull(delta); + assertNotNull(delta.getDeltaLink()); + assertEquals(5, delta.getCount(), 0); + + assertEquals(1, delta.getDeletedEntities().size()); + assertTrue(delta.getDeletedEntities().get(0).getId().endsWith("Customers('ANTON')")); + + assertEquals(1, delta.getAddedLinks().size()); + assertTrue(delta.getAddedLinks().get(0).getSource().toASCIIString().endsWith("Customers('BOTTM')")); + assertEquals("Orders", delta.getAddedLinks().get(0).getRelationship()); + + assertEquals(1, delta.getDeletedLinks().size()); + assertTrue(delta.getDeletedLinks().get(0).getSource().toASCIIString().endsWith("Customers('ALFKI')")); + assertEquals("Orders", delta.getDeletedLinks().get(0).getRelationship()); + + assertEquals(2, delta.getEntities().size()); + Property property = delta.getEntities().get(0).getProperty("ContactName"); + assertNotNull(property); + assertTrue(property.getValue().isPrimitive()); + property = delta.getEntities().get(1).getProperty("ShippingAddress"); + assertNotNull(property); + assertTrue(property.getValue().isComplex()); + } + + @Test + public void deltas() throws Exception { + delta("delta", getODataPubFormat()); } } diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Customers.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Customers.json index c8e2cdfc5..c37d5a54e 100644 --- a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Customers.json +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/Customers.json @@ -1,6 +1,6 @@ { "@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Customers", - "odata.count": 2, + "@odata.count": 2, "value": [{ "@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)", "@odata.editLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)", diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/delta.json b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/delta.json new file mode 100644 index 000000000..d8e8f549c --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/delta.json @@ -0,0 +1,39 @@ +{ + "@odata.context": "http://host/service/$metadata#Customers/$delta", + "@odata.count": 5, + "value": + [ + { + "@odata.id": "Customers('BOTTM')'", + "ContactName": "Susan Halvenstern" + }, + { + "@odata.context": "#Customers/$deletedLink", + "source": "Customers('ALFKI')", + "relationship": "Orders", + "target": "Orders(10643)" + }, + { + "@odata.context": "#Customers/$link", + "source": "Customers('BOTTM')", + "relationship": "Orders", + "target": "Orders(10645)" + }, + { + "@odata.context": "#Orders/$entity", + "@odata.id": "Orders(10643)", + "ShippingAddress": { + "Street": "23 Tsawassen Blvd.", + "City": " Tsawassen ", + "Region": "BC", + "PostalCode": "T2F 8M4" + } + }, + { + "@odata.context": "#Customers/$deletedEntity", + "id": "Customers('ANTON')", + "reason": "deleted" + } + ], + "@odata.deltaLink": "Customers?$expand=Orders&$deltatoken=8015" +} diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/delta.xml b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/delta.xml new file mode 100644 index 000000000..df65b499d --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/v4/delta.xml @@ -0,0 +1,87 @@ + + + + Customers + http://host/service/Customers + 2012-11-27T15:38:25Z + 5 + + http://host/service/Customers('BOTTM') + + <updated>2012-11-17T15:38:22Z</updated> + <author> + <name /> + </author> + <link rel="edit" title="Customer" href="Customers('BOTTM')"/> + <category term="#Model.Customer" + scheme="http://docs.oasis-open.org/odata/ns/scheme"/> + <content type="application/xml"> + <metadata:properties> + <data:ContactName>Susan Halvenstern</data:ContactName> + </metadata:properties> + </content> + </entry> + <metadata:deleted-link + metadata:context="$metadata#Customers/$deleted-link" + source="http://host/service/Customers('ALFKI')" + relationship="Orders" + target="http://host/service/Orders(10643)"/> + <metadata:link + metadata:context="$metadata#Customers/$link" + source="http://host/service/Customers('BOTTM')" + relationship="Orders" + target="http://host/service/Orders(10645)"/> + <entry metadata:context="$metadata#Orders/$entity"> + <id>http://host/service/Orders(10643)</id> + <title type="text" /> + <updated>2012-11-27T15:38:24Z</updated> + <author> + <name/> + </author> + <link rel="edit" title="Order" href="Orders(10643)" /> + <category term="#Model.Order" + scheme="http://docs.oasis-open.org/odata/ns/scheme" /> + <content type="application/xml"> + <metadata:properties> + <data:ShippingAddress> + <data:Street>23 Tsawassen Blvd.</data:Street> + <data:City>Tsawassen</data:City> + <data:Region>BC</data:Region> + <data:PostalCode>T2F 8M4</data:PostalCode> + </data:ShippingAddress> + </metadata:properties> + </content> + </entry> + <at:deleted-entry + metadata:context="$metadata#Customers/$deleted-entry" + ref="http://host/service/Customers('ANTON')" + when="2012-11-27T15:38:25Z" + metadata:reason="deleted"/> + <link + rel="http://docs.oasis-open.org/odata/ns/delta" + href="http://host/service/Customers?$expand=Orders&$deltatoken=8015"/> +</feed> 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 882c81132..770f81cb7 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 @@ -42,6 +42,8 @@ public interface Constants { public static final String NS_GML = "http://www.opengis.net/gml"; + public static final String NS_ATOM_TOMBSTONE = "http://purl.org/atompub/tombstones/1.0"; + public static final String PREFIX_DATASERVICES = "d"; public static final String PREFIX_METADATA = "m"; @@ -61,6 +63,8 @@ public interface Constants { public static final String NEXT_LINK_REL = "next"; + public static final String DELTA_LINK_REL = "http://docs.oasis-open.org/odata/ns/delta"; + // XML elements and attributes public static final String PROPERTIES = "properties"; @@ -84,6 +88,8 @@ public interface Constants { public static final String ATTR_HREF = "href"; + public static final String ATTR_REF = "ref"; + public static final String ATTR_TARGET = "target"; public static final String ATTR_SRSNAME = "srsName"; @@ -138,6 +144,14 @@ public interface Constants { public static final String ELEM_URI = "uri"; + public final static String ELEM_REASON = "reason"; + + public static final String ELEM_DELETED_LINK = "deleted-link"; + + public static final String ATTR_SOURCE = "source"; + + public static final String ATTR_RELATIONSHIP = "relationship"; + // JSON stuff public final static String JSON_METADATA = "odata.metadata"; @@ -159,10 +173,6 @@ public interface Constants { public final static String JSON_CRS = "crs"; - public final static String JSON_COUNT = "odata.count"; - - public final static String JSON_NEXT_LINK = "odata.nextLink"; - public final static String JSON_NAME = "name"; // Atom stuff @@ -224,7 +234,9 @@ public interface Constants { public static final String ATOM_ATTR_METADATAETAG = "metadata-etag"; - // error stuff + public static final String ATOM_ELEM_DELETED_ENTRY = "deleted-entry"; + +// error stuff public static final String ERROR_CODE = "code"; public static final String ERROR_MESSAGE = "message"; diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java index c2d503e2c..4fa13503b 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ContextURL.java @@ -42,14 +42,38 @@ public class ContextURL { private String navOrPropertyPath; + private boolean entity; + + private boolean delta; + + private boolean deltaDeletedEntity; + + private boolean deltaLink; + + private boolean deltaDeletedLink; + public static ContextURL getInstance(final URI contextURL) { final ContextURL instance = new ContextURL(); instance.uri = contextURL; - final String contextURLasString = instance.uri.toASCIIString(). - replace("/$entity", StringUtils.EMPTY). - replace("/@Element", StringUtils.EMPTY); - + String contextURLasString = instance.uri.toASCIIString(); + + instance.entity = contextURLasString.endsWith("/$entity") || contextURLasString.endsWith("/@Element"); + contextURLasString = contextURLasString. + replace("/$entity", StringUtils.EMPTY).replace("/@Element", StringUtils.EMPTY); + + instance.delta = contextURLasString.endsWith("/$delta"); + contextURLasString = contextURLasString.replace("/$delta", StringUtils.EMPTY); + + instance.deltaDeletedEntity = contextURLasString.endsWith("/$deletedEntity"); + contextURLasString = contextURLasString.replace("/$deletedEntity", StringUtils.EMPTY); + + instance.deltaLink = contextURLasString.endsWith("/$link"); + contextURLasString = contextURLasString.replace("/$link", StringUtils.EMPTY); + + instance.deltaDeletedLink = contextURLasString.endsWith("$deletedLink"); + contextURLasString = contextURLasString.replace("$deletedLink", StringUtils.EMPTY); + instance.serviceRoot = URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA)); final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#"); @@ -124,6 +148,26 @@ public class ContextURL { return navOrPropertyPath; } + public boolean isEntity() { + return entity; + } + + public boolean isDelta() { + return delta; + } + + public boolean isDeltaDeletedEntity() { + return deltaDeletedEntity; + } + + public boolean isDeltaLink() { + return deltaLink; + } + + public boolean isDeltaDeletedLink() { + return deltaDeletedLink; + } + @Override public boolean equals(final Object obj) { if (obj == null) { diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java new file mode 100644 index 000000000..98f2a89b9 --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeletedEntity.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.commons.api.data; + +public interface DeletedEntity { + + String getId(); + + String getReason(); + +} diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Delta.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Delta.java new file mode 100644 index 000000000..066033af9 --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Delta.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.commons.api.data; + +import java.net.URI; +import java.util.List; + +public interface Delta extends EntitySet { + + List<DeletedEntity> getDeletedEntities(); + + List<DeltaLink> getAddedLinks(); + + List<DeltaLink> getDeletedLinks(); + + /** + * Gets delta link if exists. + * + * @return delta link if exists; null otherwise. + */ + URI getDeltaLink(); + + /** + * Sets delta link. + * + * @param deltaLink delta link. + */ + void setDeltaLink(URI deltaLink); +} diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeltaLink.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeltaLink.java new file mode 100644 index 000000000..a28016537 --- /dev/null +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/DeltaLink.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.commons.api.data; + +import java.net.URI; + +public interface DeltaLink { + + URI getSource(); + + void setSource(URI source); + + String getRelationship(); + + void setRelationship(String relationship); + + URI getTarget(); + + void setTarget(URI target); +} diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entry.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entity.java similarity index 85% rename from lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entry.java rename to lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entity.java index d82005eb6..ed0ad157b 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entry.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Entity.java @@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.domain.ODataOperation; import java.net.URI; import java.util.List; -public interface Entry extends Linked { +public interface Entity extends Linked { /** * Gets ETag. @@ -39,56 +39,56 @@ public interface Entry extends Linked { URI getBaseURI(); /** - * Gets entry type. + * Gets entity type. * - * @return entry type. + * @return entity type. */ String getType(); /** - * Sets entry type. + * Sets entity type. * - * @param type entry type. + * @param type entity type. */ void setType(String type); /** - * Gets entry ID. + * Gets entity ID. * - * @return entry ID. + * @return entity ID. */ String getId(); /** - * Sets entry ID. + * Sets entity ID. * - * @param id entry ID. + * @param id entity ID. */ void setId(String id); /** - * Gets entry self link. + * Gets entity self link. * * @return self link. */ Link getSelfLink(); /** - * Sets entry self link. + * Sets entity self link. * * @param selfLink self link. */ void setSelfLink(Link selfLink); /** - * Gets entry edit link. + * Gets entity edit link. * * @return edit link. */ Link getEditLink(); /** - * Sets entry edit link. + * Sets entity edit link. * * @param editLink edit link. */ @@ -166,9 +166,9 @@ public interface Entry extends Linked { void setMediaETag(String eTag); /** - * Checks if the current entry is a media entry. + * Checks if the current entity is a media entity. * - * @return 'TRUE' if is a media entry; 'FALSE' otherwise. + * @return 'TRUE' if is a media entity; 'FALSE' otherwise. */ - boolean isMediaEntry(); + boolean isMediaEntity(); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Feed.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntitySet.java similarity index 90% rename from lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Feed.java rename to lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntitySet.java index 4f6a54235..0812acf71 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Feed.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntitySet.java @@ -21,7 +21,7 @@ package org.apache.olingo.commons.api.data; import java.net.URI; import java.util.List; -public interface Feed { +public interface EntitySet { /** * Gets base URI. @@ -40,23 +40,23 @@ public interface Feed { /** * Gets number of entries - if it was required. * - * @return number of entries into the feed. + * @return number of entries into the entity set. */ Integer getCount(); /** - * Gest feed ID. + * Gest ID. * - * @return feed ID. + * @return ID. */ String getId(); /** - * Gets entries. + * Gets entities. * * @return entries. */ - List<Entry> getEntries(); + List<Entity> getEntities(); /** * Gets next link if exists. 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 f0a35a57f..63c953a77 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 @@ -91,31 +91,31 @@ public interface Link { void setMediaETag(String etag); /** - * Gets in-line entry. + * Gets in-line entity. * - * @return in-line entry. + * @return in-line entity. */ - Entry getInlineEntry(); + Entity getInlineEntity(); /** - * Sets in-line entry. + * Sets in-line entity. * - * @param entry entry. + * @param entity entity. */ - void setInlineEntry(Entry entry); + void setInlineEntity(Entity entity); /** - * Gets in-line feed. + * Gets in-line entity set. * - * @return in-line feed. + * @return in-line entity set. */ - Feed getInlineFeed(); + EntitySet getInlineEntitySet(); /** - * Sets in-line feed. + * Sets in-line entity set. * - * @param feed feed. + * @param entitySet entity set. */ - void setInlineFeed(Feed feed); + void setInlineEntitySet(EntitySet entitySet); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java index 39677487c..e33055fd2 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/CommonODataEntitySet.java @@ -36,7 +36,7 @@ public interface CommonODataEntitySet extends ODataInvokeResult { /** * Gets contained entities. * - * @return feed entries. + * @return entity set's entities. */ List<? extends CommonODataEntity> getEntities(); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinked.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinked.java index 0dd546255..4e3852cda 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinked.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinked.java @@ -62,7 +62,7 @@ public interface ODataLinked { ODataLink getNavigationLink(String name); /** - * Returns all entity navigation links (including inline entities / feeds). + * Returns all entity navigation links (including inline entities / entity sets). * * @return OData entity links. */ 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 c6354ecbe..8e6b145f5 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 @@ -69,6 +69,13 @@ public enum ODataServiceVersion { public static final String JSON_ASSOCIATION_LINK = "jsonAssociationLink"; public static final String JSON_NAVIGATION_LINK = "jsonNavigationLink"; + + public final static String JSON_COUNT = "jsonCount"; + + public final static String JSON_NEXT_LINK = "jsonNextLink"; + + public final static String JSON_DELTA_LINK = "jsonDeltaLink"; + public static final String JSON_ERROR = "jsonError"; private static final Map<String, String> V30_NAMESPACES = Collections.unmodifiableMap(new HashMap<String, String>() { @@ -101,6 +108,8 @@ public enum ODataServiceVersion { put(JSON_MEDIA_ETAG, "odata.mediaEtag"); put(JSON_ASSOCIATION_LINK, "@odata.associationLinkUrl"); put(JSON_NAVIGATION_LINK, "@odata.navigationLinkUrl"); + put(JSON_COUNT, "odata.count"); + put(JSON_NEXT_LINK, "odata.nextLink"); put(JSON_ERROR, "odata.error"); } }); @@ -135,6 +144,9 @@ public enum ODataServiceVersion { put(JSON_MEDIA_ETAG, "@odata.mediaEtag"); put(JSON_ASSOCIATION_LINK, "@odata.associationLink"); put(JSON_NAVIGATION_LINK, "@odata.navigationLink"); + put(JSON_COUNT, "@odata.count"); + put(JSON_NEXT_LINK, "@odata.nextLink"); + put(JSON_DELTA_LINK, "@odata.deltaLink"); put(JSON_ERROR, "error"); } }); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java index 52b010362..a0d9a87a4 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java @@ -21,35 +21,35 @@ package org.apache.olingo.commons.api.op; import java.io.InputStream; import java.io.Serializable; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataPubFormat; /** - * Interface for serialization. + * Interface for de-serialization. */ public interface CommonODataDeserializer extends Serializable { /** - * Gets a feed object from the given InputStream. + * Gets an entity set object from the given InputStream. * * @param input stream to be de-serialized. * @param format Atom or JSON - * @return Feed instance. + * @return {@link EntitySet} instance. */ - ResWrap<Feed> toFeed(InputStream input, ODataPubFormat format); + ResWrap<EntitySet> toEntitySet(InputStream input, ODataPubFormat format); /** - * Gets an entry object from the given InputStream. + * Gets an entity object from the given InputStream. * * @param input stream to be de-serialized. * @param format Atom or JSON - * @return Entry instance. + * @return {@link Entity} instance. */ - ResWrap<Entry> toEntry(InputStream input, ODataPubFormat format); + ResWrap<Entity> toEntity(InputStream input, ODataPubFormat format); /** * Gets a property object from the given InputStream. diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java index 2a7befff2..c8a02cf79 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java @@ -21,8 +21,8 @@ package org.apache.olingo.commons.api.op; import java.io.OutputStream; import java.io.Serializable; import java.io.Writer; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +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.Property; import org.apache.olingo.commons.api.format.ODataFormat; @@ -33,36 +33,36 @@ import org.apache.olingo.commons.api.format.ODataFormat; public interface ODataSerializer extends Serializable { /** - * Writes Feed object onto the given stream. + * Writes entity set object onto the given stream. * * @param obj object to be streamed. * @param out output stream. */ - void feed(Feed obj, OutputStream out); + void entitySet(EntitySet obj, OutputStream out); /** - * Writes Feed object by the given writer. + * Writes entity set object by the given writer. * * @param obj object to be streamed. * @param writer writer. */ - void feed(Feed obj, Writer writer); + void entitySet(EntitySet obj, Writer writer); /** - * Writes theEntry object onto the given stream. + * Writes entity object onto the given stream. * * @param obj object to be streamed. * @param out output stream. */ - void entry(Entry obj, OutputStream out); + void entity(Entity obj, OutputStream out); /** - * Writes the Entry object by the given writer. + * Writes entity object by the given writer. * * @param obj object to be streamed. * @param writer writer. */ - void entry(Entry obj, Writer writer); + void entity(Entity obj, Writer writer); /** * Writes the property object onto the given stream. diff --git a/lib/commons-api/src/test/java/org/apache/olingo/commons/api/data/ContextURLTest.java b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/data/ContextURLTest.java index df7e6496f..14d42e22c 100644 --- a/lib/commons-api/src/test/java/org/apache/olingo/commons/api/data/ContextURLTest.java +++ b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/data/ContextURLTest.java @@ -19,7 +19,9 @@ package org.apache.olingo.commons.api.data; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.net.URI; import org.junit.Test; @@ -35,6 +37,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Orders(4711)/Items")); @@ -42,6 +45,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertEquals("Items", contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -52,6 +56,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertTrue(contextURL.isEntity()); contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Orders(4711)/Items/$entity")); @@ -59,6 +64,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertEquals("Items", contextURL.getNavOrPropertyPath()); + assertTrue(contextURL.isEntity()); // v3 contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Products/@Element")); @@ -67,6 +73,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertTrue(contextURL.isEntity()); } @Test @@ -77,6 +84,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -88,6 +96,7 @@ public class ContextURLTest { assertEquals("Model.VipCustomer", contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -99,6 +108,7 @@ public class ContextURLTest { assertEquals("Model.VipCustomer", contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertTrue(contextURL.isEntity()); } @Test @@ -110,6 +120,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertEquals("Address,Orders", contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -121,6 +132,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertEquals("Name,Rating", contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertTrue(contextURL.isEntity()); contextURL = ContextURL.getInstance( URI.create("http://host/service/$metadata#Customers(Name,Address/Country)")); @@ -129,6 +141,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertEquals("Name,Address/Country", contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -141,6 +154,7 @@ public class ContextURLTest { assertEquals("Sales.Manager", contextURL.getDerivedEntity()); assertEquals("DirectReports,DirectReports+(FirstName,LastName)", contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -152,6 +166,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertEquals("Addresses", contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -163,6 +178,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); } @Test @@ -173,6 +189,7 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#ODataDemo.Address")); @@ -180,5 +197,21 @@ public class ContextURLTest { assertNull(contextURL.getDerivedEntity()); assertNull(contextURL.getSelectList()); assertNull(contextURL.getNavOrPropertyPath()); + assertFalse(contextURL.isEntity()); + } + + @Test + public void delta() { + ContextURL contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Customers/$delta")); + assertTrue(contextURL.isDelta()); + + contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Customers/$deletedLink")); + assertTrue(contextURL.isDeltaDeletedLink()); + + contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Customers/$link")); + assertTrue(contextURL.isDeltaLink()); + + contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Customers/$deletedEntity")); + assertTrue(contextURL.isDeltaDeletedEntity()); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java index f571c66a5..2f3ebb3ae 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAtomDealer.java @@ -58,7 +58,15 @@ abstract class AbstractAtomDealer { protected final QName entryRefQName; - protected final QName v4PropertyValueQName; + protected final QName propertyValueQName; + + protected final QName deletedEntryQName; + + protected final QName reasonQName; + + protected final QName linkQName; + + protected final QName deletedLinkQName; protected final QName errorCodeQName; @@ -94,9 +102,17 @@ abstract class AbstractAtomDealer { new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.CONTEXT); this.entryRefQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ENTRY_REF); - this.v4PropertyValueQName = + this.propertyValueQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.VALUE); + this.deletedEntryQName = new QName(Constants.NS_ATOM_TOMBSTONE, Constants.ATOM_ELEM_DELETED_ENTRY); + this.reasonQName = + new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ELEM_REASON); + this.linkQName = + new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_LINK); + this.deletedLinkQName = + new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ELEM_DELETED_LINK); + this.errorCodeQName = new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ERROR_CODE); this.errorMessageQName = diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractDelta.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractDelta.java new file mode 100644 index 000000000..73a65b7c0 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractDelta.java @@ -0,0 +1,65 @@ +/* + * 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.net.URI; +import java.util.ArrayList; +import java.util.List; +import org.apache.olingo.commons.api.data.DeletedEntity; +import org.apache.olingo.commons.api.data.Delta; +import org.apache.olingo.commons.api.data.DeltaLink; + +public abstract class AbstractDelta extends AbstractEntitySet implements Delta { + + private static final long serialVersionUID = 4576771708961553195L; + + private final List<DeletedEntity> deletedEntities = new ArrayList<DeletedEntity>(); + + private final List<DeltaLink> addedLinks = new ArrayList<DeltaLink>(); + + private final List<DeltaLink> deletedLinks = new ArrayList<DeltaLink>(); + + private URI deltaLink; + + @Override + public List<DeletedEntity> getDeletedEntities() { + return deletedEntities; + } + + @Override + public List<DeltaLink> getAddedLinks() { + return addedLinks; + } + + @Override + public List<DeltaLink> getDeletedLinks() { + return deletedLinks; + } + + @Override + public URI getDeltaLink() { + return deltaLink; + } + + @Override + public void setDeltaLink(final URI deltaLink) { + this.deltaLink = deltaLink; + } + +} 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/AbstractEntity.java similarity index 93% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntry.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java index 4c0f3468a..fc895047f 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/AbstractEntity.java @@ -21,15 +21,15 @@ package org.apache.olingo.commons.core.data; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.data.Entry; +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; /** - * Abstract base for classes implementing an OData entry in Atom and JSON. + * Abstract base for classes implementing an OData entity in Atom and JSON. */ -public abstract class AbstractEntry extends AbstractODataObject implements Entry { +public abstract class AbstractEntity extends AbstractODataObject implements Entity { private static final long serialVersionUID = 2127764552600969783L; @@ -165,7 +165,7 @@ public abstract class AbstractEntry extends AbstractODataObject implements Entry } @Override - public boolean isMediaEntry() { + public boolean isMediaEntity() { return StringUtils.isNotBlank(this.mediaContentSource); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomFeedImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntitySet.java similarity index 75% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomFeedImpl.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntitySet.java index 09dfdcfe1..b640812fb 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomFeedImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntitySet.java @@ -21,21 +21,16 @@ 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.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; -/** - * List of entries, represented via Atom. - * - * @see AtomEntry - */ -public class AtomFeedImpl extends AbstractODataObject implements Feed { +public abstract class AbstractEntitySet extends AbstractODataObject implements EntitySet { - private static final long serialVersionUID = 5466590540021319153L; + private static final long serialVersionUID = -9159884750819150969L; private Integer count; - private final List<Entry> entries = new ArrayList<Entry>(); + private final List<Entity> entities = new ArrayList<Entity>(); private URI next; @@ -50,8 +45,8 @@ public class AtomFeedImpl extends AbstractODataObject implements Feed { } @Override - public List<Entry> getEntries() { - return entries; + public List<Entity> getEntities() { + return entities; } @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java index 97be4eb66..82f8ae05c 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java @@ -60,33 +60,33 @@ abstract class AbstractJsonDeserializer<T> extends ODataJacksonDeserializer<ResW protected String setInline(final String name, final String suffix, final JsonNode tree, final ObjectCodec codec, final LinkImpl link) throws IOException { - final String entryNamePrefix = name.substring(0, name.indexOf(suffix)); - if (tree.has(entryNamePrefix)) { - final JsonNode inline = tree.path(entryNamePrefix); + final String entityNamePrefix = name.substring(0, name.indexOf(suffix)); + if (tree.has(entityNamePrefix)) { + final JsonNode inline = tree.path(entityNamePrefix); if (inline instanceof ObjectNode) { link.setType(ODataLinkType.ENTITY_NAVIGATION.toString()); - link.setInlineEntry(inline.traverse(codec).<ResWrap<JSONEntryImpl>>readValueAs( - new TypeReference<JSONEntryImpl>() { + link.setInlineEntity(inline.traverse(codec).<ResWrap<JSONEntityImpl>>readValueAs( + new TypeReference<JSONEntityImpl>() { }).getPayload()); } if (inline instanceof ArrayNode) { link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString()); - final JSONFeedImpl feed = new JSONFeedImpl(); + final JSONEntitySetImpl entitySet = new JSONEntitySetImpl(); final Iterator<JsonNode> entries = ((ArrayNode) inline).elements(); while (entries.hasNext()) { - feed.getEntries().add(entries.next().traverse(codec).<ResWrap<JSONEntryImpl>>readValuesAs( - new TypeReference<JSONEntryImpl>() { + entitySet.getEntities().add(entries.next().traverse(codec).<ResWrap<JSONEntityImpl>>readValuesAs( + new TypeReference<JSONEntityImpl>() { }).next().getPayload()); } - link.setInlineFeed(feed); + link.setInlineEntitySet(entitySet); } } - return entryNamePrefix; + return entityNamePrefix; } protected void links(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove, diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java index 06e0e5e19..9efc67cae 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java @@ -30,7 +30,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.CollectionValue; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Linked; import org.apache.olingo.commons.api.data.PrimitiveValue; @@ -86,11 +86,11 @@ abstract class AbstractJsonSerializer<T> extends ODataJacksonSerializer<T> { } } - if (link.getInlineEntry() != null) { - jgen.writeObjectField(link.getTitle(), link.getInlineEntry()); - } else if (link.getInlineFeed() != null) { + if (link.getInlineEntity() != null) { + jgen.writeObjectField(link.getTitle(), link.getInlineEntity()); + } else if (link.getInlineEntitySet() != null) { jgen.writeArrayFieldStart(link.getTitle()); - for (Entry subEntry : link.getInlineFeed().getEntries()) { + for (Entity subEntry : link.getInlineEntitySet().getEntities()) { jgen.writeObject(subEntry); } jgen.writeEndArray(); @@ -123,11 +123,11 @@ abstract class AbstractJsonSerializer<T> extends ODataJacksonSerializer<T> { link.getHref()); } - if (link.getInlineEntry() != null) { - jgen.writeObjectField(link.getTitle(), link.getInlineEntry()); - } else if (link.getInlineFeed() != null) { + if (link.getInlineEntity() != null) { + jgen.writeObjectField(link.getTitle(), link.getInlineEntity()); + } else if (link.getInlineEntitySet() != null) { jgen.writeArrayFieldStart(link.getTitle()); - for (Entry subEntry : link.getInlineFeed().getEntries()) { + for (Entity subEntry : link.getInlineEntitySet().getEntities()) { jgen.writeObject(subEntry); } jgen.writeEndArray(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeltaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeltaImpl.java new file mode 100644 index 000000000..165299bb6 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeltaImpl.java @@ -0,0 +1,25 @@ +/* + * 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; + +public class AtomDeltaImpl extends AbstractDelta { + + private static final long serialVersionUID = -730729098008847535L; + +} 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 72d8d76c4..080b4aab3 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 @@ -18,7 +18,6 @@ */ package org.apache.olingo.commons.core.data; -import org.apache.olingo.commons.api.data.ResWrap; import java.io.InputStream; import java.net.URI; import java.text.ParseException; @@ -32,6 +31,8 @@ import javax.xml.stream.events.XMLEvent; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.CollectionValue; +import org.apache.olingo.commons.api.data.EntitySet; +import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.data.Value; import org.apache.olingo.commons.api.domain.ODataOperation; import org.apache.olingo.commons.api.domain.ODataPropertyType; @@ -228,7 +229,7 @@ public class AtomDeserializer extends AbstractAtomDealer { final AtomPropertyImpl property = new AtomPropertyImpl(); - if (ODataServiceVersion.V40 == version && v4PropertyValueQName.equals(start.getName())) { + if (ODataServiceVersion.V40 == version && propertyValueQName.equals(start.getName())) { // retrieve name from context final Attribute context = start.getAttributeByName(contextQName); if (context != null) { @@ -352,10 +353,10 @@ public class AtomDeserializer extends AbstractAtomDealer { } if (inline != null) { if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(inline.getName())) { - link.setInlineEntry(entry(reader, inline)); + link.setInlineEntity(entity(reader, inline)); } if (Constants.QNAME_ATOM_ELEM_FEED.equals(inline.getName())) { - link.setInlineFeed(feed(reader, inline)); + link.setInlineEntitySet(entitySet(reader, inline)); } } } @@ -366,6 +367,102 @@ public class AtomDeserializer extends AbstractAtomDealer { } } + private ResWrap<AtomDeltaImpl> delta(final InputStream input) throws XMLStreamException { + final XMLEventReader reader = getReader(input); + final StartElement start = skipBeforeFirstStartElement(reader); + return getContainer(start, delta(reader, start)); + } + + private AtomDeltaImpl delta(final XMLEventReader reader, final StartElement start) throws XMLStreamException { + if (!Constants.QNAME_ATOM_ELEM_FEED.equals(start.getName())) { + return null; + } + final AtomDeltaImpl delta = new AtomDeltaImpl(); + final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE); + if (xmlBase != null) { + delta.setBaseURI(xmlBase.getValue()); + } + + boolean foundEndFeed = false; + while (reader.hasNext() && !foundEndFeed) { + final XMLEvent event = reader.nextEvent(); + if (event.isStartElement()) { + if (countQName.equals(event.asStartElement().getName())) { + count(reader, event.asStartElement(), delta); + } else if (Constants.QNAME_ATOM_ELEM_ID.equals(event.asStartElement().getName())) { + common(reader, event.asStartElement(), delta, "id"); + } else if (Constants.QNAME_ATOM_ELEM_TITLE.equals(event.asStartElement().getName())) { + common(reader, event.asStartElement(), delta, "title"); + } else if (Constants.QNAME_ATOM_ELEM_SUMMARY.equals(event.asStartElement().getName())) { + common(reader, event.asStartElement(), delta, "summary"); + } else if (Constants.QNAME_ATOM_ELEM_UPDATED.equals(event.asStartElement().getName())) { + common(reader, event.asStartElement(), delta, "updated"); + } else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) { + final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL)); + if (rel != null) { + if (Constants.NEXT_LINK_REL.equals(rel.getValue())) { + final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF)); + if (href != null) { + delta.setNext(URI.create(href.getValue())); + } + } + if (Constants.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())); + } + } + } + } else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(event.asStartElement().getName())) { + delta.getEntities().add(entity(reader, event.asStartElement())); + } else if (deletedEntryQName.equals(event.asStartElement().getName())) { + final DeletedEntityImpl deletedEntity = new DeletedEntityImpl(); + + final Attribute ref = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REF)); + if (ref != null) { + deletedEntity.setId(ref.getValue()); + } + final Attribute reason = event.asStartElement().getAttributeByName(reasonQName); + if (reason != null) { + deletedEntity.setReason(reason.getValue()); + } + + delta.getDeletedEntities().add(deletedEntity); + } else if (linkQName.equals(event.asStartElement().getName()) + || deletedLinkQName.equals(event.asStartElement().getName())) { + + final DeltaLinkImpl link = new DeltaLinkImpl(); + + final Attribute source = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_SOURCE)); + if (source != null) { + link.setSource(URI.create(source.getValue())); + } + final Attribute relationship = + event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_RELATIONSHIP)); + if (relationship != null) { + link.setRelationship(relationship.getValue()); + } + final Attribute target = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TARGET)); + if (target != null) { + link.setTarget(URI.create(target.getValue())); + } + + if (linkQName.equals(event.asStartElement().getName())) { + delta.getAddedLinks().add(link); + } else { + delta.getDeletedLinks().add(link); + } + } + } + + if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { + foundEndFeed = true; + } + } + + return delta; + } + private ResWrap<XMLLinkCollectionImpl> linkCollection(final InputStream input) throws XMLStreamException { final XMLEventReader reader = getReader(input); final StartElement start = skipBeforeFirstStartElement(reader); @@ -400,14 +497,14 @@ public class AtomDeserializer extends AbstractAtomDealer { return linkCollection; } - private void properties(final XMLEventReader reader, final StartElement start, final AtomEntryImpl entry) + private void properties(final XMLEventReader reader, final StartElement start, final AtomEntityImpl entity) throws XMLStreamException { boolean foundEndProperties = false; while (reader.hasNext() && !foundEndProperties) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { - entry.getProperties().add(property(reader, event.asStartElement())); + entity.getProperties().add(property(reader, event.asStartElement())); } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { @@ -416,31 +513,31 @@ public class AtomDeserializer extends AbstractAtomDealer { } } - private AtomEntryImpl entryRef(final StartElement start) throws XMLStreamException { - final AtomEntryImpl entry = new AtomEntryImpl(); + private AtomEntityImpl entityRef(final StartElement start) throws XMLStreamException { + final AtomEntityImpl entity = new AtomEntityImpl(); - final Attribute entryRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID); - if (entryRefId != null) { - entry.setId(entryRefId.getValue()); + final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID); + if (entityRefId != null) { + entity.setId(entityRefId.getValue()); } - return entry; + return entity; } - private AtomEntryImpl entry(final XMLEventReader reader, final StartElement start) throws XMLStreamException { - final AtomEntryImpl entry; + private AtomEntityImpl entity(final XMLEventReader reader, final StartElement start) throws XMLStreamException { + final AtomEntityImpl entity; if (entryRefQName.equals(start.getName())) { - entry = entryRef(start); + entity = entityRef(start); } else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) { - entry = new AtomEntryImpl(); + entity = new AtomEntityImpl(); final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE); if (xmlBase != null) { - entry.setBaseURI(xmlBase.getValue()); + entity.setBaseURI(xmlBase.getValue()); } final Attribute etag = start.getAttributeByName(etagQName); if (etag != null) { - entry.setETag(etag.getValue()); + entity.setETag(etag.getValue()); } boolean foundEndEntry = false; @@ -449,17 +546,17 @@ public class AtomDeserializer extends AbstractAtomDealer { if (event.isStartElement()) { if (Constants.QNAME_ATOM_ELEM_ID.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), entry, "id"); + common(reader, event.asStartElement(), entity, "id"); } else if (Constants.QNAME_ATOM_ELEM_TITLE.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), entry, "title"); + common(reader, event.asStartElement(), entity, "title"); } else if (Constants.QNAME_ATOM_ELEM_SUMMARY.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), entry, "summary"); + common(reader, event.asStartElement(), entity, "summary"); } else if (Constants.QNAME_ATOM_ELEM_UPDATED.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), entry, "updated"); + common(reader, event.asStartElement(), entity, "updated"); } else if (Constants.QNAME_ATOM_ELEM_CATEGORY.equals(event.asStartElement().getName())) { final Attribute term = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_TERM)); if (term != null) { - entry.setType(new EdmTypeInfo.Builder().setTypeExpression(term.getValue()).build().internal()); + entity.setType(new EdmTypeInfo.Builder().setTypeExpression(term.getValue()).build().internal()); } } else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) { final LinkImpl link = new LinkImpl(); @@ -481,22 +578,22 @@ public class AtomDeserializer extends AbstractAtomDealer { } if (Constants.SELF_LINK_REL.equals(link.getRel())) { - entry.setSelfLink(link); + entity.setSelfLink(link); } else if (Constants.EDIT_LINK_REL.equals(link.getRel())) { - entry.setEditLink(link); + entity.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()); + entity.setMediaETag(mediaETag.getValue()); } } else if (link.getRel().startsWith( version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) { - entry.getNavigationLinks().add(link); + entity.getNavigationLinks().add(link); inline(reader, event.asStartElement(), link); } else if (link.getRel().startsWith( version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) { - entry.getAssociationLinks().add(link); + entity.getAssociationLinks().add(link); } else if (link.getRel().startsWith( version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) { @@ -504,7 +601,7 @@ public class AtomDeserializer extends AbstractAtomDealer { if (metag != null) { link.setMediaETag(metag.getValue()); } - entry.getMediaEditLinks().add(link); + entity.getMediaEditLinks().add(link); } } else if (actionQName.equals(event.asStartElement().getName())) { final ODataOperation operation = new ODataOperation(); @@ -522,20 +619,20 @@ public class AtomDeserializer extends AbstractAtomDealer { operation.setTarget(URI.create(target.getValue())); } - entry.getOperations().add(operation); + entity.getOperations().add(operation); } else if (Constants.QNAME_ATOM_ELEM_CONTENT.equals(event.asStartElement().getName())) { final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE)); if (type == null || ContentType.APPLICATION_XML.equals(type.getValue())) { - properties(reader, skipBeforeFirstStartElement(reader), entry); + properties(reader, skipBeforeFirstStartElement(reader), entity); } else { - entry.setMediaContentType(type.getValue()); + entity.setMediaContentType(type.getValue()); final Attribute src = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_SRC)); if (src != null) { - entry.setMediaContentSource(src.getValue()); + entity.setMediaContentSource(src.getValue()); } } } else if (propertiesQName.equals(event.asStartElement().getName())) { - properties(reader, event.asStartElement(), entry); + properties(reader, event.asStartElement(), entity); } } @@ -544,21 +641,21 @@ public class AtomDeserializer extends AbstractAtomDealer { } } - return entry; + return entity; } else { - entry = null; + entity = null; } - return entry; + return entity; } - private ResWrap<AtomEntryImpl> entry(final InputStream input) throws XMLStreamException { + private ResWrap<AtomEntityImpl> entity(final InputStream input) throws XMLStreamException { final XMLEventReader reader = getReader(input); final StartElement start = skipBeforeFirstStartElement(reader); - return getContainer(start, entry(reader, start)); + return getContainer(start, entity(reader, start)); } - private void count(final XMLEventReader reader, final StartElement start, final AtomFeedImpl feed) + private void count(final XMLEventReader reader, final StartElement start, final EntitySet entitySet) throws XMLStreamException { boolean foundEndElement = false; @@ -566,7 +663,7 @@ public class AtomDeserializer extends AbstractAtomDealer { final XMLEvent event = reader.nextEvent(); if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) { - feed.setCount(Integer.valueOf(event.asCharacters().getData())); + entitySet.setCount(Integer.valueOf(event.asCharacters().getData())); } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { @@ -575,14 +672,14 @@ public class AtomDeserializer extends AbstractAtomDealer { } } - private AtomFeedImpl feed(final XMLEventReader reader, final StartElement start) throws XMLStreamException { + private AtomEntitySetImpl entitySet(final XMLEventReader reader, final StartElement start) throws XMLStreamException { if (!Constants.QNAME_ATOM_ELEM_FEED.equals(start.getName())) { return null; } - final AtomFeedImpl feed = new AtomFeedImpl(); + final AtomEntitySetImpl entitySet = new AtomEntitySetImpl(); final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE); if (xmlBase != null) { - feed.setBaseURI(xmlBase.getValue()); + entitySet.setBaseURI(xmlBase.getValue()); } boolean foundEndFeed = false; @@ -590,27 +687,27 @@ public class AtomDeserializer extends AbstractAtomDealer { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { if (countQName.equals(event.asStartElement().getName())) { - count(reader, event.asStartElement(), feed); + count(reader, event.asStartElement(), entitySet); } else if (Constants.QNAME_ATOM_ELEM_ID.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), feed, "id"); + common(reader, event.asStartElement(), entitySet, "id"); } else if (Constants.QNAME_ATOM_ELEM_TITLE.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), feed, "title"); + common(reader, event.asStartElement(), entitySet, "title"); } else if (Constants.QNAME_ATOM_ELEM_SUMMARY.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), feed, "summary"); + common(reader, event.asStartElement(), entitySet, "summary"); } else if (Constants.QNAME_ATOM_ELEM_UPDATED.equals(event.asStartElement().getName())) { - common(reader, event.asStartElement(), feed, "updated"); + common(reader, event.asStartElement(), entitySet, "updated"); } else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) { final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL)); if (rel != null && Constants.NEXT_LINK_REL.equals(rel.getValue())) { final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF)); if (href != null) { - feed.setNext(URI.create(href.getValue())); + entitySet.setNext(URI.create(href.getValue())); } } } else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(event.asStartElement().getName())) { - feed.getEntries().add(entry(reader, event.asStartElement())); + entitySet.getEntities().add(entity(reader, event.asStartElement())); } else if (entryRefQName.equals(event.asStartElement().getName())) { - feed.getEntries().add(entryRef(event.asStartElement())); + entitySet.getEntities().add(entityRef(event.asStartElement())); } } @@ -619,13 +716,13 @@ public class AtomDeserializer extends AbstractAtomDealer { } } - return feed; + return entitySet; } - private ResWrap<AtomFeedImpl> feed(final InputStream input) throws XMLStreamException { + private ResWrap<AtomEntitySetImpl> entitySet(final InputStream input) throws XMLStreamException { final XMLEventReader reader = getReader(input); final StartElement start = skipBeforeFirstStartElement(reader); - return getContainer(start, feed(reader, start)); + return getContainer(start, entitySet(reader, start)); } private XMLODataErrorImpl error(final XMLEventReader reader, final StartElement start) throws XMLStreamException { @@ -700,14 +797,16 @@ public class AtomDeserializer extends AbstractAtomDealer { if (XMLODataErrorImpl.class.equals(reference)) { return (ResWrap<T>) error(input); - } else if (AtomFeedImpl.class.equals(reference)) { - return (ResWrap<T>) feed(input); - } else if (AtomEntryImpl.class.equals(reference)) { - return (ResWrap<T>) entry(input); + } else if (AtomEntitySetImpl.class.equals(reference)) { + return (ResWrap<T>) entitySet(input); + } else if (AtomEntityImpl.class.equals(reference)) { + return (ResWrap<T>) entity(input); } else if (AtomPropertyImpl.class.equals(reference)) { return (ResWrap<T>) property(input); } else if (XMLLinkCollectionImpl.class.equals(reference)) { return (ResWrap<T>) linkCollection(input); + } else if (AtomDeltaImpl.class.equals(reference)) { + return (ResWrap<T>) delta(input); } return null; } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntryImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntityImpl.java similarity index 94% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntryImpl.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntityImpl.java index 8eef97aef..6c7fb13ad 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntryImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntityImpl.java @@ -18,7 +18,7 @@ */ package org.apache.olingo.commons.core.data; -public class AtomEntryImpl extends AbstractEntry { +public class AtomEntityImpl extends AbstractEntity { private static final long serialVersionUID = 6973729343868293279L; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntitySetImpl.java new file mode 100644 index 000000000..397b18e99 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntitySetImpl.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * List of entries, represented via Atom. + */ +public class AtomEntitySetImpl extends AbstractEntitySet { + + private static final long serialVersionUID = 5466590540021319153L; + +} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java index aba3d16d2..279e3fe44 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java @@ -29,8 +29,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.CollectionValue; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +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.Property; import org.apache.olingo.commons.api.data.Value; @@ -166,18 +166,18 @@ public class AtomSerializer extends AbstractAtomDealer { writer.writeAttribute(Constants.ATTR_TYPE, link.getType()); } - if (link.getInlineEntry() != null || link.getInlineFeed() != null) { + if (link.getInlineEntity() != null || link.getInlineEntitySet() != null) { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); - if (link.getInlineEntry() != null) { + if (link.getInlineEntity() != null) { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY); - entry(writer, link.getInlineEntry()); + entity(writer, link.getInlineEntity()); writer.writeEndElement(); } - if (link.getInlineFeed() != null) { + if (link.getInlineEntitySet() != null) { writer.writeStartElement(Constants.ATOM_ELEM_FEED); - feed(writer, link.getInlineFeed()); + entitySet(writer, link.getInlineEntitySet()); writer.writeEndElement(); } @@ -210,51 +210,51 @@ public class AtomSerializer extends AbstractAtomDealer { } } - private void entry(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException { - if (entry.getBaseURI() != null) { - writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entry.getBaseURI().toASCIIString()); + private void entity(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException { + if (entity.getBaseURI() != null) { + writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entity.getBaseURI().toASCIIString()); } - if (serverMode && StringUtils.isNotBlank(entry.getETag())) { + if (serverMode && StringUtils.isNotBlank(entity.getETag())) { writer.writeAttribute( version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), - Constants.ATOM_ATTR_ETAG, entry.getETag()); + Constants.ATOM_ATTR_ETAG, entity.getETag()); } - if (StringUtils.isNotBlank(entry.getId())) { + if (StringUtils.isNotBlank(entity.getId())) { writer.writeStartElement(Constants.ATOM_ELEM_ID); - writer.writeCharacters(entry.getId()); + writer.writeCharacters(entity.getId()); writer.writeEndElement(); } writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY); writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME)); - if (StringUtils.isNotBlank(entry.getType())) { + if (StringUtils.isNotBlank(entity.getType())) { writer.writeAttribute(Constants.ATOM_ATTR_TERM, - new EdmTypeInfo.Builder().setTypeExpression(entry.getType()).build().external(version)); + new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); } writer.writeEndElement(); - if (entry instanceof AbstractODataObject) { - common(writer, (AbstractODataObject) entry); + if (entity instanceof AbstractODataObject) { + common(writer, (AbstractODataObject) entity); } if (serverMode) { - if (entry.getEditLink() != null) { - links(writer, Collections.singletonList(entry.getEditLink())); + if (entity.getEditLink() != null) { + links(writer, Collections.singletonList(entity.getEditLink())); } - if (entry.getSelfLink() != null) { - links(writer, Collections.singletonList(entry.getSelfLink())); + if (entity.getSelfLink() != null) { + links(writer, Collections.singletonList(entity.getSelfLink())); } } - links(writer, entry.getAssociationLinks()); - links(writer, entry.getNavigationLinks()); - links(writer, entry.getMediaEditLinks()); + links(writer, entity.getAssociationLinks()); + links(writer, entity.getNavigationLinks()); + links(writer, entity.getMediaEditLinks()); if (serverMode) { - for (ODataOperation operation : entry.getOperations()) { + for (ODataOperation operation : entity.getOperations()) { writer.writeStartElement( version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION); writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor()); @@ -265,51 +265,51 @@ public class AtomSerializer extends AbstractAtomDealer { } writer.writeStartElement(Constants.ATOM_ELEM_CONTENT); - if (entry.isMediaEntry()) { - if (StringUtils.isNotBlank(entry.getMediaContentType())) { - writer.writeAttribute(Constants.ATTR_TYPE, entry.getMediaContentType()); + if (entity.isMediaEntity()) { + if (StringUtils.isNotBlank(entity.getMediaContentType())) { + writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType()); } - if (StringUtils.isNotBlank(entry.getMediaContentSource())) { - writer.writeAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource()); + if (StringUtils.isNotBlank(entity.getMediaContentSource())) { + writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource()); } writer.writeEndElement(); writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); - properties(writer, entry.getProperties()); + properties(writer, entity.getProperties()); } else { writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML); writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES); - properties(writer, entry.getProperties()); + properties(writer, entity.getProperties()); writer.writeEndElement(); } writer.writeEndElement(); } - private void entryRef(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException { + private void entityRef(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); - writer.writeAttribute(Constants.ATOM_ATTR_ID, entry.getId()); + writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId()); } - private void entryRef(final XMLStreamWriter writer, final ResWrap<Entry> container) throws XMLStreamException { + private void entityRef(final XMLStreamWriter writer, final ResWrap<Entity> container) throws XMLStreamException { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF); writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); addContextInfo(writer, container); writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId()); } - private void entry(final Writer outWriter, final Entry entry) throws XMLStreamException { + private void entity(final Writer outWriter, final Entity entity) throws XMLStreamException { final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); - if (entry.getType() == null && entry.getProperties().isEmpty()) { + if (entity.getType() == null && entity.getProperties().isEmpty()) { writer.writeStartDocument(); writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); - entryRef(writer, entry); + entityRef(writer, entity); } else { startDocument(writer, Constants.ATOM_ELEM_ENTRY); - entry(writer, entry); + entity(writer, entity); } writer.writeEndElement(); @@ -317,22 +317,22 @@ public class AtomSerializer extends AbstractAtomDealer { writer.flush(); } - private void entry(final Writer outWriter, final ResWrap<Entry> container) throws XMLStreamException { - final Entry entry = container.getPayload(); + private void entity(final Writer outWriter, final ResWrap<Entity> container) throws XMLStreamException { + final Entity entity = container.getPayload(); final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); - if (entry.getType() == null && entry.getProperties().isEmpty()) { + if (entity.getType() == null && entity.getProperties().isEmpty()) { writer.writeStartDocument(); writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA)); - entryRef(writer, container); + entityRef(writer, container); } else { startDocument(writer, Constants.ATOM_ELEM_ENTRY); addContextInfo(writer, container); - entry(writer, entry); + entity(writer, entity); } writer.writeEndElement(); @@ -340,68 +340,68 @@ public class AtomSerializer extends AbstractAtomDealer { writer.flush(); } - private void feed(final XMLStreamWriter writer, final Feed feed) throws XMLStreamException { - if (feed.getBaseURI() != null) { - writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, feed.getBaseURI().toASCIIString()); + private void entitySet(final XMLStreamWriter writer, final EntitySet entitySet) throws XMLStreamException { + if (entitySet.getBaseURI() != null) { + writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entitySet.getBaseURI().toASCIIString()); } - if (feed.getCount() != null) { + if (entitySet.getCount() != null) { writer.writeStartElement( version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT); - writer.writeCharacters(Integer.toString(feed.getCount())); + writer.writeCharacters(Integer.toString(entitySet.getCount())); writer.writeEndElement(); } - if (StringUtils.isNotBlank(feed.getId())) { + if (StringUtils.isNotBlank(entitySet.getId())) { writer.writeStartElement(Constants.ATOM_ELEM_ID); - writer.writeCharacters(feed.getId()); + writer.writeCharacters(entitySet.getId()); writer.writeEndElement(); } - if (feed instanceof AbstractODataObject) { - common(writer, (AbstractODataObject) feed); + if (entitySet instanceof AbstractODataObject) { + common(writer, (AbstractODataObject) entitySet); } - for (Entry entry : feed.getEntries()) { - if (entry.getType() == null && entry.getProperties().isEmpty()) { - entryRef(writer, entry); + for (Entity entity : entitySet.getEntities()) { + if (entity.getType() == null && entity.getProperties().isEmpty()) { + entityRef(writer, entity); writer.writeEndElement(); } else { writer.writeStartElement(Constants.ATOM_ELEM_ENTRY); - entry(writer, entry); + entity(writer, entity); writer.writeEndElement(); } } - if (feed.getNext() != null) { + if (entitySet.getNext() != null) { final LinkImpl next = new LinkImpl(); next.setRel(Constants.NEXT_LINK_REL); - next.setHref(feed.getNext().toASCIIString()); + next.setHref(entitySet.getNext().toASCIIString()); links(writer, Collections.<Link>singletonList(next)); } } - private void feed(final Writer outWriter, final Feed feed) throws XMLStreamException { + private void entitySet(final Writer outWriter, final EntitySet entitySet) throws XMLStreamException { final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); startDocument(writer, Constants.ATOM_ELEM_FEED); - feed(writer, feed); + entitySet(writer, entitySet); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } - private void feed(final Writer outWriter, final ResWrap<Feed> feed) throws XMLStreamException { + private void entitySet(final Writer outWriter, final ResWrap<EntitySet> entitySet) throws XMLStreamException { final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); startDocument(writer, Constants.ATOM_ELEM_FEED); - addContextInfo(writer, feed); + addContextInfo(writer, entitySet); - feed(writer, feed.getPayload()); + entitySet(writer, entitySet.getPayload()); writer.writeEndElement(); writer.writeEndDocument(); @@ -427,10 +427,10 @@ public class AtomSerializer extends AbstractAtomDealer { } public <T> void write(final Writer writer, final T obj) throws XMLStreamException { - if (obj instanceof Feed) { - feed(writer, (Feed) obj); - } else if (obj instanceof Entry) { - entry(writer, (Entry) obj); + if (obj instanceof EntitySet) { + entitySet(writer, (EntitySet) obj); + } else if (obj instanceof Entity) { + entity(writer, (Entity) obj); } else if (obj instanceof Property) { property(writer, (Property) obj); } else if (obj instanceof Link) { @@ -442,10 +442,10 @@ public class AtomSerializer extends AbstractAtomDealer { public <T> void write(final Writer writer, final ResWrap<T> container) throws XMLStreamException { final T obj = container == null ? null : container.getPayload(); - if (obj instanceof Feed) { - this.feed(writer, (ResWrap<Feed>) container); - } else if (obj instanceof Entry) { - entry(writer, (ResWrap<Entry>) container); + if (obj instanceof EntitySet) { + this.entitySet(writer, (ResWrap<EntitySet>) container); + } else if (obj instanceof Entity) { + entity(writer, (ResWrap<Entity>) container); } else if (obj instanceof Property) { property(writer, (Property) obj); } else if (obj instanceof Link) { @@ -458,11 +458,11 @@ public class AtomSerializer extends AbstractAtomDealer { if (container.getContextURL() != null) { String base = container.getContextURL().getServiceRoot().toASCIIString(); - if (container.getPayload() instanceof AtomFeedImpl) { - ((AtomFeedImpl) container.getPayload()).setBaseURI(base); + if (container.getPayload() instanceof AtomEntitySetImpl) { + ((AtomEntitySetImpl) container.getPayload()).setBaseURI(base); } - if (container.getPayload() instanceof AtomEntryImpl) { - ((AtomEntryImpl) container.getPayload()).setBaseURI(base); + if (container.getPayload() instanceof AtomEntityImpl) { + ((AtomEntityImpl) container.getPayload()).setBaseURI(base); } writer.writeAttribute( diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java new file mode 100644 index 000000000..0c97e9a05 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java @@ -0,0 +1,49 @@ +/* + * 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 org.apache.olingo.commons.api.data.DeletedEntity; + +public class DeletedEntityImpl extends AbstractPayloadObject implements DeletedEntity { + + private static final long serialVersionUID = -3841730551749114664L; + + private String id; + + private String reason; + + @Override + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + @Override + public String getReason() { + return reason; + } + + public void setReason(final String reason) { + this.reason = reason; + } + +} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeltaLinkImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeltaLinkImpl.java new file mode 100644 index 000000000..972c6c64f --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeltaLinkImpl.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.commons.core.data; + +import java.net.URI; +import org.apache.olingo.commons.api.data.DeltaLink; + +public class DeltaLinkImpl extends AbstractPayloadObject implements DeltaLink { + + private static final long serialVersionUID = -6686550836508873044L; + + private URI source; + + private String relationship; + + private URI target; + + @Override + public URI getSource() { + return source; + } + + @Override + public void setSource(final URI source) { + this.source = source; + } + + @Override + public String getRelationship() { + return relationship; + } + + @Override + public void setRelationship(String relationship) { + this.relationship = relationship; + } + + @Override + public URI getTarget() { + return target; + } + + @Override + public void setTarget(URI target) { + this.target = target; + } + +} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java new file mode 100644 index 000000000..a1411112b --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java @@ -0,0 +1,93 @@ +/* + * 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 com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +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 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.ResWrap; + +public class JSONDeltaDeserializer extends AbstractJsonDeserializer<JSONDeltaImpl> { + + @Override + protected ResWrap<JSONDeltaImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt) + throws IOException, JsonProcessingException { + + final ObjectNode tree = parser.getCodec().readTree(parser); + + final JSONDeltaImpl delta = new JSONDeltaImpl(); + + final URI contextURL; + if (tree.hasNonNull(Constants.JSON_CONTEXT)) { + contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue()); + } else { + contextURL = null; + } + if (contextURL != null) { + delta.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); + } + + if (tree.hasNonNull(jsonCount)) { + delta.setCount(tree.get(jsonCount).asInt()); + } + if (tree.hasNonNull(jsonNextLink)) { + delta.setNext(URI.create(tree.get(jsonNextLink).textValue())); + } + if (tree.hasNonNull(jsonDeltaLink)) { + delta.setDeltaLink(URI.create(tree.get(jsonDeltaLink).textValue())); + } + + if (tree.hasNonNull(Constants.VALUE)) { + for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).iterator(); itor.hasNext();) { + final ObjectNode item = (ObjectNode) itor.next(); + final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT) + ? ContextURL.getInstance(URI.create(item.get(Constants.JSON_CONTEXT).textValue())) : null; + item.remove(Constants.JSON_CONTEXT); + + if (itemContextURL == null || itemContextURL.isEntity()) { + final ResWrap<JSONEntityImpl> entity = item.traverse(parser.getCodec()). + readValueAs(new TypeReference<JSONEntityImpl>() { + }); + delta.getEntities().add(entity.getPayload()); + } else if (itemContextURL.isDeltaDeletedEntity()) { + delta.getDeletedEntities(). + add(parser.getCodec().treeToValue(item, DeletedEntityImpl.class)); + } else if (itemContextURL.isDeltaLink()) { + delta.getAddedLinks(). + add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class)); + } else if (itemContextURL.isDeltaDeletedLink()) { + delta.getDeletedLinks(). + add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class)); + } + } + } + + return new ResWrap<JSONDeltaImpl>(contextURL, null, delta); + } + +} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaImpl.java new file mode 100644 index 000000000..d68406954 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaImpl.java @@ -0,0 +1,28 @@ +/* + * 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 com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = JSONDeltaDeserializer.class) +public class JSONDeltaImpl extends AbstractDelta { + + private static final long serialVersionUID = -7948494801560470246L; + +} 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/JSONEntityDeserializer.java similarity index 82% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryDeserializer.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java index dce4b7407..4fd7ace9e 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/JSONEntityDeserializer.java @@ -40,14 +40,14 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.EdmTypeInfo; /** - * Reads JSON string into an entry. + * Reads JSON string into an entity. * <br/> - * If metadata information is available, the corresponding entry fields and content will be populated. + * If metadata information is available, the corresponding entity fields and content will be populated. */ -public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImpl> { +public class JSONEntityDeserializer extends AbstractJsonDeserializer<JSONEntityImpl> { @Override - protected ResWrap<JSONEntryImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt) + protected ResWrap<JSONEntityImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final ObjectNode tree = parser.getCodec().readTree(parser); @@ -56,7 +56,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation()); } - final JSONEntryImpl entry = new JSONEntryImpl(); + final JSONEntityImpl entity = new JSONEntityImpl(); final URI contextURL; if (tree.hasNonNull(Constants.JSON_CONTEXT)) { @@ -69,7 +69,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp contextURL = null; } if (contextURL != null) { - entry.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); + entity.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); } final String metadataETag; @@ -81,17 +81,17 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp } if (tree.hasNonNull(jsonETag)) { - entry.setETag(tree.get(jsonETag).textValue()); + entity.setETag(tree.get(jsonETag).textValue()); tree.remove(jsonETag); } if (tree.hasNonNull(jsonType)) { - entry.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal()); + entity.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal()); tree.remove(jsonType); } if (tree.hasNonNull(jsonId)) { - entry.setId(tree.get(jsonId).textValue()); + entity.setId(tree.get(jsonId).textValue()); tree.remove(jsonId); } @@ -99,7 +99,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp final LinkImpl link = new LinkImpl(); link.setRel(Constants.SELF_LINK_REL); link.setHref(tree.get(jsonReadLink).textValue()); - entry.setSelfLink(link); + entity.setSelfLink(link); tree.remove(jsonReadLink); } @@ -111,25 +111,25 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp link.setRel(Constants.EDIT_LINK_REL); } link.setHref(tree.get(jsonEditLink).textValue()); - entry.setEditLink(link); + entity.setEditLink(link); tree.remove(jsonEditLink); } if (tree.hasNonNull(jsonMediaReadLink)) { - entry.setMediaContentSource(tree.get(jsonMediaReadLink).textValue()); + entity.setMediaContentSource(tree.get(jsonMediaReadLink).textValue()); tree.remove(jsonMediaReadLink); } if (tree.hasNonNull(jsonMediaEditLink)) { - entry.setMediaContentSource(tree.get(jsonMediaEditLink).textValue()); + entity.setMediaContentSource(tree.get(jsonMediaEditLink).textValue()); tree.remove(jsonMediaEditLink); } if (tree.hasNonNull(jsonMediaContentType)) { - entry.setMediaContentType(tree.get(jsonMediaContentType).textValue()); + entity.setMediaContentType(tree.get(jsonMediaContentType).textValue()); tree.remove(jsonMediaContentType); } if (tree.hasNonNull(jsonMediaETag)) { - entry.setMediaETag(tree.get(jsonMediaETag).textValue()); + entity.setMediaETag(tree.get(jsonMediaETag).textValue()); tree.remove(jsonMediaETag); } @@ -137,14 +137,14 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) { final Map.Entry<String, JsonNode> field = itor.next(); - links(field, entry, toRemove, tree, parser.getCodec()); + links(field, entity, toRemove, tree, parser.getCodec()); if (field.getKey().endsWith(getJSONAnnotation(jsonMediaEditLink))) { final LinkImpl link = new LinkImpl(); link.setTitle(getTitle(field)); link.setRel(version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL) + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.MEDIA_EDIT.toString()); - entry.getMediaEditLinks().add(link); + entity.getMediaEditLinks().add(link); if (tree.has(link.getTitle() + getJSONAnnotation(jsonMediaETag))) { link.setMediaETag(tree.get(link.getTitle() + getJSONAnnotation(jsonMediaETag)).asText()); @@ -155,7 +155,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree, parser.getCodec(), link)); } else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) { final String linkTitle = getTitle(field); - for (Link link : entry.getMediaEditLinks()) { + for (Link link : entity.getMediaEditLinks()) { if (linkTitle.equals(link.getTitle())) { ((LinkImpl) link).setType(field.getValue().asText()); } @@ -169,7 +169,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp operation.setTitle(opNode.get(Constants.ATTR_TITLE).asText()); operation.setTarget(URI.create(opNode.get(Constants.ATTR_TARGET).asText())); - entry.getOperations().add(operation); + entity.getOperations().add(operation); toRemove.add(field.getKey()); } @@ -191,10 +191,10 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp type = null; value(property, field.getValue(), parser.getCodec()); - entry.getProperties().add(property); + entity.getProperties().add(property); } } - - return new ResWrap<JSONEntryImpl>(contextURL, metadataETag, entry); + + return new ResWrap<JSONEntityImpl>(contextURL, metadataETag, entity); } } 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/JSONEntityImpl.java similarity index 84% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntryImpl.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityImpl.java index edf4366a9..57db80565 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/JSONEntityImpl.java @@ -22,11 +22,11 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; /** - * A single entry, represented via JSON. + * A single entity, represented via JSON. */ -@JsonSerialize(using = JSONEntrySerializer.class) -@JsonDeserialize(using = JSONEntryDeserializer.class) -public class JSONEntryImpl extends AbstractEntry { +@JsonSerialize(using = JSONEntitySerializer.class) +@JsonDeserialize(using = JSONEntityDeserializer.class) +public class JSONEntityImpl extends AbstractEntity { private static final long serialVersionUID = -5275365545400797758L; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java similarity index 69% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java index a5c2c3361..043978344 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java @@ -26,7 +26,7 @@ import java.net.URI; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +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; @@ -34,23 +34,23 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.EdmTypeInfo; /** - * Writes out JSON string from an entry. + * Writes out JSON string from an entity. */ -public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> { +public class JSONEntitySerializer extends AbstractJsonSerializer<JSONEntityImpl> { @Override - protected void doSerialize(final JSONEntryImpl entry, final JsonGenerator jgen, final SerializerProvider provider) + protected void doSerialize(final JSONEntityImpl entity, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { - doContainerSerialize(new ResWrap<JSONEntryImpl>((URI) null, null, entry), jgen, provider); + doContainerSerialize(new ResWrap<JSONEntityImpl>((URI) null, null, entity), jgen, provider); } @Override protected void doContainerSerialize( - final ResWrap<JSONEntryImpl> container, final JsonGenerator jgen, final SerializerProvider provider) + final ResWrap<JSONEntityImpl> container, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { - final Entry entry = container.getPayload(); + final Entity entity = container.getPayload(); jgen.writeStartObject(); @@ -64,45 +64,45 @@ public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> { jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag()); } - if (StringUtils.isNotBlank(entry.getETag())) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ETAG), entry.getETag()); + if (StringUtils.isNotBlank(entity.getETag())) { + jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ETAG), entity.getETag()); } } - if (StringUtils.isNotBlank(entry.getType())) { + if (StringUtils.isNotBlank(entity.getType())) { jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), - new EdmTypeInfo.Builder().setTypeExpression(entry.getType()).build().external(version)); + new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version)); } - if (entry.getId() != null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entry.getId()); + if (entity.getId() != null) { + jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entity.getId()); } - for (Property property : entry.getProperties()) { + for (Property property : entity.getProperties()) { property(jgen, property, property.getName()); } - if (serverMode && entry.getEditLink() != null && StringUtils.isNotBlank(entry.getEditLink().getHref())) { - final URI link = URI.create(entry.getEditLink().getHref()); + if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) { + final URI link = URI.create(entity.getEditLink().getHref()); final String editLink = link.isAbsolute() ? link.toASCIIString() - : URI.create(entry.getBaseURI() + "/" + link.toASCIIString()).normalize().toASCIIString(); + : URI.create(entity.getBaseURI() + "/" + link.toASCIIString()).normalize().toASCIIString(); jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK), editLink); } - links(entry, jgen); + links(entity, jgen); - for (Link link : entry.getMediaEditLinks()) { + for (Link link : entity.getMediaEditLinks()) { if (link.getTitle() == null) { jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), link.getHref()); } - if (link.getInlineEntry() != null) { - jgen.writeObjectField(link.getTitle(), link.getInlineEntry()); + if (link.getInlineEntity() != null) { + jgen.writeObjectField(link.getTitle(), link.getInlineEntity()); } - if (link.getInlineFeed() != null) { + if (link.getInlineEntitySet() != null) { jgen.writeArrayFieldStart(link.getTitle()); - for (Entry subEntry : link.getInlineFeed().getEntries()) { + for (Entity subEntry : link.getInlineEntitySet().getEntities()) { jgen.writeObject(subEntry); } jgen.writeEndArray(); @@ -110,7 +110,7 @@ public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> { } if (serverMode) { - for (ODataOperation operation : entry.getOperations()) { + for (ODataOperation operation : entity.getOperations()) { jgen.writeObjectFieldStart("#" + StringUtils.substringAfterLast(operation.getMetadataAnchor(), "#")); jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle()); jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java similarity index 71% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedDeserializer.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java index a9f80c446..044e26905 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java @@ -27,18 +27,19 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; import java.net.URI; import java.util.Iterator; +import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ResWrap; /** - * Reads JSON string into a feed. + * Reads JSON string into an entity set. * <br/> - * If metadata information is available, the corresponding entry fields and content will be populated. + * If metadata information is available, the corresponding entity fields and content will be populated. */ -public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl> { +public class JSONEntitySetDeserializer extends AbstractJsonDeserializer<JSONEntitySetImpl> { @Override - protected ResWrap<JSONFeedImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt) + protected ResWrap<JSONEntitySetImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser); @@ -47,7 +48,7 @@ public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl> return null; } - final JSONFeedImpl feed = new JSONFeedImpl(); + final JSONEntitySetImpl entitySet = new JSONEntitySetImpl(); final URI contextURL; if (tree.hasNonNull(Constants.JSON_CONTEXT)) { @@ -59,7 +60,9 @@ public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl> } else { contextURL = null; } - feed.setMetadataContextURL(contextURL); + if (contextURL != null) { + entitySet.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); + } final String metadataETag; if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) { @@ -69,22 +72,22 @@ public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl> metadataETag = null; } - if (tree.hasNonNull(Constants.JSON_COUNT)) { - feed.setCount(tree.get(Constants.JSON_COUNT).asInt()); + if (tree.hasNonNull(jsonCount)) { + entitySet.setCount(tree.get(jsonCount).asInt()); } - if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) { - feed.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue())); + if (tree.hasNonNull(jsonNextLink)) { + entitySet.setNext(URI.create(tree.get(jsonNextLink).textValue())); } if (tree.hasNonNull(Constants.VALUE)) { for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).iterator(); itor.hasNext();) { - feed.getEntries().add( - itor.next().traverse(parser.getCodec()).<ResWrap<JSONEntryImpl>>readValueAs( - new TypeReference<JSONEntryImpl>() { + entitySet.getEntities().add( + itor.next().traverse(parser.getCodec()).<ResWrap<JSONEntityImpl>>readValueAs( + new TypeReference<JSONEntityImpl>() { }).getPayload()); } } - return new ResWrap<JSONFeedImpl>(contextURL, metadataETag, feed); + return new ResWrap<JSONEntitySetImpl>(contextURL, metadataETag, entitySet); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetImpl.java new file mode 100644 index 000000000..dac67cdeb --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetImpl.java @@ -0,0 +1,35 @@ +/* + * 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 com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +/** + * List of entries, represented via JSON. + * + * @see JSONEntry + */ +@JsonDeserialize(using = JSONEntitySetDeserializer.class) +@JsonSerialize(using = JSONEntitySetSerializer.class) +public class JSONEntitySetImpl extends AbstractEntitySet { + + private static final long serialVersionUID = -3576372289800799417L; + +} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java similarity index 68% rename from lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedSerializer.java rename to lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java index 457b34c98..1e16fa8aa 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java @@ -26,25 +26,25 @@ import java.net.URI; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.commons.api.Constants; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; -public class JSONFeedSerializer extends AbstractJsonSerializer<JSONFeedImpl> { +public class JSONEntitySetSerializer extends AbstractJsonSerializer<JSONEntitySetImpl> { @Override protected void doSerialize( - final JSONFeedImpl feed, final JsonGenerator jgen, final SerializerProvider provider) + final JSONEntitySetImpl entitySet, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { - - doContainerSerialize(new ResWrap<JSONFeedImpl>((URI) null, null, feed), jgen, provider); + + doContainerSerialize(new ResWrap<JSONEntitySetImpl>((URI) null, null, entitySet), jgen, provider); } @Override protected void doContainerSerialize( - final ResWrap<JSONFeedImpl> container, final JsonGenerator jgen, final SerializerProvider provider) + final ResWrap<JSONEntitySetImpl> container, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { - final JSONFeedImpl feed = container.getPayload(); + final JSONEntitySetImpl entitySet = container.getPayload(); jgen.writeStartObject(); @@ -62,19 +62,19 @@ public class JSONFeedSerializer extends AbstractJsonSerializer<JSONFeedImpl> { } } - if (feed.getId() != null) { - jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), feed.getId()); + if (entitySet.getId() != null) { + jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entitySet.getId()); } - if (feed.getCount() != null) { - jgen.writeNumberField(Constants.JSON_COUNT, feed.getCount()); - } - if (feed.getNext() != null) { - jgen.writeStringField(Constants.JSON_NEXT_LINK, feed.getNext().toASCIIString()); + jgen.writeNumberField(version.getJSONMap().get(ODataServiceVersion.JSON_COUNT), + entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount()); + if (entitySet.getNext() != null) { + jgen.writeStringField( + version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK), entitySet.getNext().toASCIIString()); } jgen.writeArrayFieldStart(Constants.VALUE); - for (Entry entry : feed.getEntries()) { - jgen.writeObject(entry); + for (Entity entity : entitySet.getEntities()) { + jgen.writeObject(entity); } jgen.writeEndArray(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedImpl.java deleted file mode 100644 index 02ce871c8..000000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONFeedImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.commons.core.data; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; -import org.apache.olingo.commons.api.Constants; - -/** - * List of entries, represented via JSON. - * - * @see JSONEntry - */ -@JsonDeserialize(using = JSONFeedDeserializer.class) -@JsonSerialize(using = JSONFeedSerializer.class) -public class JSONFeedImpl extends AbstractPayloadObject implements Feed { - - private static final long serialVersionUID = -3576372289800799417L; - - private URI metadataContextURL; - - private String id; - - private Integer count; - - private final List<Entry> entries = new ArrayList<Entry>(); - - private String next; - - @Override - public URI getBaseURI() { - URI baseURI = null; - if (metadataContextURL != null) { - final String metadataURI = metadataContextURL.toASCIIString(); - baseURI = URI.create(metadataURI.substring(0, metadataURI.indexOf(Constants.METADATA))); - } - - return baseURI; - } - - public void setMetadataContextURL(final URI metadataContextURL) { - this.metadataContextURL = metadataContextURL; - } - - @Override - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - @Override - public Integer getCount() { - return count; - } - - @Override - public void setCount(final Integer count) { - this.count = count; - } - - @Override - public List<Entry> getEntries() { - return entries; - } - - @Override - public void setNext(final URI next) { - this.next = next == null ? null : next.toASCIIString(); - } - - @Override - public URI getNext() { - return next == null ? null : URI.create(next); - } -} 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 85fabdc31..bb865d1a9 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 @@ -18,8 +18,8 @@ */ package org.apache.olingo.commons.core.data; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +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 AbstractPayloadObject implements Link { @@ -36,9 +36,9 @@ public class LinkImpl extends AbstractPayloadObject implements Link { private String mediaETag; - private Entry entry; + private Entity entity; - private Feed feed; + private EntitySet entitySet; @Override public String getTitle() { @@ -91,22 +91,22 @@ public class LinkImpl extends AbstractPayloadObject implements Link { } @Override - public Entry getInlineEntry() { - return entry; + public Entity getInlineEntity() { + return entity; } @Override - public void setInlineEntry(final Entry entry) { - this.entry = entry; + public void setInlineEntity(final Entity entity) { + this.entity = entity; } @Override - public Feed getInlineFeed() { - return feed; + public EntitySet getInlineEntitySet() { + return entitySet; } @Override - public void setInlineFeed(final Feed feed) { - this.feed = feed; + public void setInlineEntitySet(final EntitySet entitySet) { + this.entitySet = entitySet; } } 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 8651b4b57..a6a75b8c0 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 @@ -55,6 +55,12 @@ public abstract class ODataJacksonDeserializer<T> extends JsonDeserializer<T> { protected String jsonNavigationLink; + protected String jsonCount; + + protected String jsonNextLink; + + protected String jsonDeltaLink; + protected String jsonError; protected abstract T doDeserialize(JsonParser jp, DeserializationContext ctxt) @@ -82,6 +88,9 @@ public abstract class ODataJacksonDeserializer<T> extends JsonDeserializer<T> { jsonMediaETag = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG); jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK); jsonNavigationLink = version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK); + jsonCount = version.getJSONMap().get(ODataServiceVersion.JSON_COUNT); + jsonNextLink = version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK); + jsonDeltaLink = version.getJSONMap().get(ODataServiceVersion.JSON_DELTA_LINK); jsonError = version.getJSONMap().get(ODataServiceVersion.JSON_ERROR); return doDeserialize(jp, ctxt); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java index b0bd6e095..edf871b2f 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java @@ -27,7 +27,7 @@ import org.apache.olingo.commons.api.data.v3.LinkCollection; import org.apache.olingo.commons.core.data.AbstractPayloadObject; /** - * Link from an entry, represented via JSON. + * Link from an entity, represented via JSON. */ public class JSONLinkCollectionImpl extends AbstractPayloadObject implements LinkCollection { 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 253b1a163..3152b3de8 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 @@ -69,7 +69,7 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement private URI editLink; /** - * Navigation links (might contain in-line entities or feeds). + * Navigation links (might contain in-line entities or entity sets). */ private final List<ODataLink> navigationLinks = new ArrayList<ODataLink>(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java index b2f7dc8bb..1396bcedb 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/AbstractODataEntitySet.java @@ -32,8 +32,9 @@ public abstract class AbstractODataEntitySet extends AbstractODataPayload implem private URI next; /** - * Number of ODataEntities contained in this feed. If <tt>$inlinecount</tt> was requested, this value comes from - * there. + * Number of ODataEntities contained in this entity set. + * <br/> + * If <tt>$inlinecount</tt> was requested, this value comes from there. */ private Integer count; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java index 9eed8c57b..07ae0da5d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/domain/v4/ODataComplexValueImpl.java @@ -34,7 +34,7 @@ public class ODataComplexValueImpl extends AbstractODataComplexValue<ODataProper private static final long serialVersionUID = 1143925901934898802L; /** - * Navigation links (might contain in-line entities or feeds). + * Navigation links (might contain in-line entities or entity sets). */ private final List<ODataLink> navigationLinks = new ArrayList<ODataLink>(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java index e14879e2f..2e398f565 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java @@ -23,7 +23,6 @@ import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmException; import org.apache.olingo.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.commons.api.edm.EdmStructuredType; -import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.FullQualifiedName; public abstract class AbstractEdmNavigationProperty extends EdmElementImpl implements EdmNavigationProperty { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java index 29eed4a15..f5848682d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java @@ -22,9 +22,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import java.io.InputStream; import java.lang.reflect.Type; import java.net.URI; -import org.apache.olingo.commons.api.data.Entry; +import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.domain.ODataError; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataPubFormat; @@ -32,11 +32,11 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.op.CommonODataDeserializer; import org.apache.olingo.commons.core.data.AtomDeserializer; import org.apache.olingo.commons.api.data.ResWrap; -import org.apache.olingo.commons.core.data.AtomEntryImpl; -import org.apache.olingo.commons.core.data.AtomFeedImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; +import org.apache.olingo.commons.core.data.AtomEntitySetImpl; import org.apache.olingo.commons.core.data.AtomPropertyImpl; -import org.apache.olingo.commons.core.data.JSONEntryImpl; -import org.apache.olingo.commons.core.data.JSONFeedImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; +import org.apache.olingo.commons.core.data.JSONEntitySetImpl; import org.apache.olingo.commons.core.data.JSONODataErrorImpl; import org.apache.olingo.commons.core.data.JSONPropertyImpl; import org.apache.olingo.commons.core.data.XMLODataErrorImpl; @@ -54,17 +54,17 @@ public abstract class AbstractODataDeserializer extends AbstractJacksonTool impl } @Override - public ResWrap<Feed> toFeed(final InputStream input, final ODataPubFormat format) { + public ResWrap<EntitySet> toEntitySet(final InputStream input, final ODataPubFormat format) { return format == ODataPubFormat.ATOM - ? this.<Feed, AtomFeedImpl>atom(input, AtomFeedImpl.class) - : this.<Feed, JSONFeedImpl>json(input, JSONFeedImpl.class); + ? this.<EntitySet, AtomEntitySetImpl>atom(input, AtomEntitySetImpl.class) + : this.<EntitySet, JSONEntitySetImpl>json(input, JSONEntitySetImpl.class); } @Override - public ResWrap<Entry> toEntry(final InputStream input, final ODataPubFormat format) { + public ResWrap<Entity> toEntity(final InputStream input, final ODataPubFormat format) { return format == ODataPubFormat.ATOM - ? this.<Entry, AtomEntryImpl>atom(input, AtomEntryImpl.class) - : this.<Entry, JSONEntryImpl>json(input, JSONEntryImpl.class); + ? this.<Entity, AtomEntityImpl>atom(input, AtomEntityImpl.class) + : this.<Entity, JSONEntityImpl>json(input, JSONEntityImpl.class); } @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java index 6ce1fbfa0..32b9e993e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java @@ -25,19 +25,19 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import org.apache.olingo.commons.api.Constants; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +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.Property; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.op.ODataSerializer; -import org.apache.olingo.commons.core.data.AtomEntryImpl; -import org.apache.olingo.commons.core.data.AtomFeedImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; +import org.apache.olingo.commons.core.data.AtomEntitySetImpl; import org.apache.olingo.commons.core.data.AtomPropertyImpl; import org.apache.olingo.commons.core.data.AtomSerializer; -import org.apache.olingo.commons.core.data.JSONEntryImpl; -import org.apache.olingo.commons.core.data.JSONFeedImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; +import org.apache.olingo.commons.core.data.JSONEntitySetImpl; import org.apache.olingo.commons.core.data.JSONPropertyImpl; public abstract class AbstractODataSerializer extends AbstractJacksonTool implements ODataSerializer { @@ -53,30 +53,30 @@ public abstract class AbstractODataSerializer extends AbstractJacksonTool implem } @Override - public void feed(final Feed obj, final OutputStream out) { - feed(obj, new OutputStreamWriter(out)); + public void entitySet(final EntitySet obj, final OutputStream out) { + entitySet(obj, new OutputStreamWriter(out)); } @Override - public void feed(final Feed obj, final Writer writer) { - if (obj instanceof AtomFeedImpl) { - atom((AtomFeedImpl) obj, writer); + public void entitySet(final EntitySet obj, final Writer writer) { + if (obj instanceof AtomEntitySetImpl) { + atom((AtomEntitySetImpl) obj, writer); } else { - json((JSONFeedImpl) obj, writer); + json((JSONEntitySetImpl) obj, writer); } } @Override - public void entry(final Entry obj, final OutputStream out) { - entry(obj, new OutputStreamWriter(out)); + public void entity(final Entity obj, final OutputStream out) { + entity(obj, new OutputStreamWriter(out)); } @Override - public void entry(final Entry obj, final Writer writer) { - if (obj instanceof AtomEntryImpl) { - atom((AtomEntryImpl) obj, writer); + public void entity(final Entity obj, final Writer writer) { + if (obj instanceof AtomEntityImpl) { + atom((AtomEntityImpl) obj, writer); } else { - json((JSONEntryImpl) obj, writer); + json((JSONEntityImpl) obj, writer); } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java index e585b2d20..a2efe34b9 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java @@ -18,62 +18,62 @@ */ package org.apache.olingo.commons.core.op; -import org.apache.olingo.commons.api.data.Entry; -import org.apache.olingo.commons.api.data.Feed; +import org.apache.olingo.commons.api.data.Entity; +import org.apache.olingo.commons.api.data.EntitySet; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.format.ODataPubFormat; -import org.apache.olingo.commons.core.data.AtomEntryImpl; -import org.apache.olingo.commons.core.data.AtomFeedImpl; +import org.apache.olingo.commons.core.data.AtomEntityImpl; +import org.apache.olingo.commons.core.data.AtomEntitySetImpl; import org.apache.olingo.commons.core.data.AtomPropertyImpl; -import org.apache.olingo.commons.core.data.JSONEntryImpl; -import org.apache.olingo.commons.core.data.JSONFeedImpl; +import org.apache.olingo.commons.core.data.JSONEntityImpl; +import org.apache.olingo.commons.core.data.JSONEntitySetImpl; import org.apache.olingo.commons.core.data.JSONPropertyImpl; public class ResourceFactory { /** - * Gets a new instance of <tt>Feed</tt>. + * Gets a new instance of <tt>EntitySet</tt>. * * @param resourceClass reference class. - * @return <tt>Feed</tt> object. + * @return {@link EntitySet} object. */ - public static Feed newFeed(final Class<? extends Feed> resourceClass) { - Feed result = null; + public static EntitySet newEntitySet(final Class<? extends EntitySet> resourceClass) { + EntitySet result = null; - if (AtomFeedImpl.class.equals(resourceClass)) { - result = new AtomFeedImpl(); + if (AtomEntitySetImpl.class.equals(resourceClass)) { + result = new AtomEntitySetImpl(); } - if (JSONFeedImpl.class.equals(resourceClass)) { - result = new JSONFeedImpl(); + if (JSONEntitySetImpl.class.equals(resourceClass)) { + result = new JSONEntitySetImpl(); } return result; } /** - * Gets a new instance of <tt>Entry</tt>. + * Gets a new instance of <tt>Entity</tt>. * * @param resourceClass reference class. - * @return <tt>Entry</tt> object. + * @return {@link Entity} object. */ - public static Entry newEntry(final Class<? extends Entry> resourceClass) { - Entry result = null; - if (AtomEntryImpl.class.equals(resourceClass)) { - result = new AtomEntryImpl(); + public static Entity newEntity(final Class<? extends Entity> resourceClass) { + Entity result = null; + if (AtomEntityImpl.class.equals(resourceClass)) { + result = new AtomEntityImpl(); } - if (JSONEntryImpl.class.equals(resourceClass)) { - result = new JSONEntryImpl(); + if (JSONEntityImpl.class.equals(resourceClass)) { + result = new JSONEntityImpl(); } return result; } - public static Property newProperty(final Class<? extends Entry> resourceClass) { + public static Property newProperty(final Class<? extends Entity> resourceClass) { Property result = null; - if (AtomEntryImpl.class.equals(resourceClass)) { + if (AtomEntityImpl.class.equals(resourceClass)) { result = new AtomPropertyImpl(); } - if (JSONEntryImpl.class.equals(resourceClass)) { + if (JSONEntityImpl.class.equals(resourceClass)) { result = new JSONPropertyImpl(); } @@ -81,45 +81,45 @@ public class ResourceFactory { } /** - * Gets feed reference class from the given format. + * Gets entity set reference class from the given format. * * @param isXML whether it is JSON or XML / Atom * @return resource reference class. */ - public static Class<? extends Feed> feedClassForFormat(final boolean isXML) { - return isXML ? AtomFeedImpl.class : JSONFeedImpl.class; + public static Class<? extends EntitySet> entitySetClassForFormat(final boolean isXML) { + return isXML ? AtomEntitySetImpl.class : JSONEntitySetImpl.class; } /** - * Gets entry reference class from the given format. + * Gets entity reference class from the given format. * * @param isXML whether it is JSON or XML / Atom * @return resource reference class. */ - public static Class<? extends Entry> entryClassForFormat(final boolean isXML) { - return isXML ? AtomEntryImpl.class : JSONEntryImpl.class; + public static Class<? extends Entity> entityClassForFormat(final boolean isXML) { + return isXML ? AtomEntityImpl.class : JSONEntityImpl.class; } /** - * Gets <tt>Entry</tt> object from feed resource. + * Gets <tt>Entity</tt> object from entity set resource. * - * @param resourceClass feed reference class. - * @return <tt>Entry</tt> object. + * @param resourceClass entity set reference class. + * @return {@link Entity} object. */ - public static Class<? extends Entry> entryClassForFeed(final Class<? extends Feed> resourceClass) { - Class<? extends Entry> result = null; + public static Class<? extends Entity> entityClassForEntitySet(final Class<? extends EntitySet> resourceClass) { + Class<? extends Entity> result = null; - if (AtomFeedImpl.class.equals(resourceClass)) { - result = AtomEntryImpl.class; + if (AtomEntitySetImpl.class.equals(resourceClass)) { + result = AtomEntityImpl.class; } - if (JSONFeedImpl.class.equals(resourceClass)) { - result = JSONEntryImpl.class; + if (JSONEntitySetImpl.class.equals(resourceClass)) { + result = JSONEntityImpl.class; } return result; } - public static ODataPubFormat formatForEntryClass(final Class<? extends Entry> reference) { - return reference.equals(AtomEntryImpl.class) ? ODataPubFormat.ATOM : ODataPubFormat.JSON; + public static ODataPubFormat formatForEntityClass(final Class<? extends Entity> reference) { + return reference.equals(AtomEntityImpl.class) ? ODataPubFormat.ATOM : ODataPubFormat.JSON; } }