[OLINGO-259] Delta response content parsing (including new domain objects)
This commit is contained in:
parent
0b05798cd9
commit
118b779bc4
|
@ -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.Multipart;
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
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.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.AtomPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomSerializer;
|
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.NullValueImpl;
|
||||||
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
|
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.EntityType;
|
||||||
import org.apache.olingo.fit.metadata.NavigationProperty;
|
import org.apache.olingo.fit.metadata.NavigationProperty;
|
||||||
import org.apache.olingo.fit.methods.MERGE;
|
import org.apache.olingo.fit.methods.MERGE;
|
||||||
|
@ -401,22 +400,22 @@ public abstract class AbstractServices {
|
||||||
|
|
||||||
final Accept contentTypeValue = Accept.parse(contentType, version);
|
final Accept contentTypeValue = Accept.parse(contentType, version);
|
||||||
|
|
||||||
final AtomEntryImpl entryChanges;
|
final AtomEntityImpl entryChanges;
|
||||||
|
|
||||||
if (contentTypeValue == Accept.XML || contentTypeValue == Accept.TEXT) {
|
if (contentTypeValue == Accept.XML || contentTypeValue == Accept.TEXT) {
|
||||||
throw new UnsupportedMediaTypeException("Unsupported media type");
|
throw new UnsupportedMediaTypeException("Unsupported media type");
|
||||||
} else if (contentTypeValue == Accept.ATOM) {
|
} else if (contentTypeValue == Accept.ATOM) {
|
||||||
entryChanges = atomDeserializer.<AtomEntryImpl, AtomEntryImpl>read(
|
entryChanges = atomDeserializer.<AtomEntityImpl, AtomEntityImpl>read(
|
||||||
IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntryImpl.class).getPayload();
|
IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntityImpl.class).getPayload();
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<JSONEntryImpl> jcont = mapper.readValue(IOUtils.toInputStream(changes, Constants.ENCODING),
|
final ResWrap<JSONEntityImpl> jcont = mapper.readValue(IOUtils.toInputStream(changes, Constants.ENCODING),
|
||||||
new TypeReference<JSONEntryImpl>() {
|
new TypeReference<JSONEntityImpl>() {
|
||||||
});
|
});
|
||||||
|
|
||||||
entryChanges = dataBinder.toAtomEntry(jcont.getPayload());
|
entryChanges = dataBinder.toAtomEntity(jcont.getPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
final ResWrap<AtomEntryImpl> container = atomDeserializer.read(entityInfo.getValue(), AtomEntryImpl.class);
|
final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entityInfo.getValue(), AtomEntityImpl.class);
|
||||||
|
|
||||||
for (Property property : entryChanges.getProperties()) {
|
for (Property property : entryChanges.getProperties()) {
|
||||||
container.getPayload().getProperty(property.getName()).setValue(property.getValue());
|
container.getPayload().getProperty(property.getName()).setValue(property.getValue());
|
||||||
|
@ -435,7 +434,7 @@ public abstract class AbstractServices {
|
||||||
final InputStream res = xml.addOrReplaceEntity(
|
final InputStream res = xml.addOrReplaceEntity(
|
||||||
entityId, entitySetName, new ByteArrayInputStream(content.toByteArray()), container.getPayload());
|
entityId, entitySetName, new ByteArrayInputStream(content.toByteArray()), container.getPayload());
|
||||||
|
|
||||||
final ResWrap<AtomEntryImpl> cres = atomDeserializer.read(res, AtomEntryImpl.class);
|
final ResWrap<AtomEntityImpl> cres = atomDeserializer.read(res, AtomEntityImpl.class);
|
||||||
|
|
||||||
normalizeAtomEntry(cres.getPayload(), entitySetName, entityId);
|
normalizeAtomEntry(cres.getPayload(), entitySetName, entityId);
|
||||||
|
|
||||||
|
@ -492,14 +491,14 @@ public abstract class AbstractServices {
|
||||||
IOUtils.toInputStream(entity, Constants.ENCODING),
|
IOUtils.toInputStream(entity, Constants.ENCODING),
|
||||||
xml.readEntry(acceptType, IOUtils.toInputStream(entity, Constants.ENCODING)));
|
xml.readEntry(acceptType, IOUtils.toInputStream(entity, Constants.ENCODING)));
|
||||||
|
|
||||||
final ResWrap<AtomEntryImpl> cres;
|
final ResWrap<AtomEntityImpl> cres;
|
||||||
if (acceptType == Accept.ATOM) {
|
if (acceptType == Accept.ATOM) {
|
||||||
cres = atomDeserializer.read(res, AtomEntryImpl.class);
|
cres = atomDeserializer.read(res, AtomEntityImpl.class);
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<JSONEntryImpl> jcont = mapper.readValue(res, new TypeReference<JSONEntryImpl>() {
|
final ResWrap<JSONEntityImpl> jcont = mapper.readValue(res, new TypeReference<JSONEntityImpl>() {
|
||||||
});
|
});
|
||||||
cres = new ResWrap<AtomEntryImpl>(jcont.getContextURL(), jcont.getMetadataETag(),
|
cres = new ResWrap<AtomEntityImpl>(jcont.getContextURL(), jcont.getMetadataETag(),
|
||||||
dataBinder.toAtomEntry(jcont.getPayload()));
|
dataBinder.toAtomEntity(jcont.getPayload()));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String path = Commons.getEntityBasePath(entitySetName, entityId);
|
final String path = Commons.getEntityBasePath(entitySetName, entityId);
|
||||||
|
@ -552,14 +551,14 @@ public abstract class AbstractServices {
|
||||||
throw new UnsupportedMediaTypeException("Unsupported media type");
|
throw new UnsupportedMediaTypeException("Unsupported media type");
|
||||||
}
|
}
|
||||||
|
|
||||||
final ResWrap<AtomEntryImpl> container;
|
final ResWrap<AtomEntityImpl> 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;
|
final String entityKey;
|
||||||
if (xml.isMediaContent(entitySetName)) {
|
if (xml.isMediaContent(entitySetName)) {
|
||||||
entry = new AtomEntryImpl();
|
entry = new AtomEntityImpl();
|
||||||
entry.setMediaContentType(ContentType.WILDCARD);
|
entry.setMediaContentType(ContentType.WILDCARD);
|
||||||
entry.setType(entitySet.getType());
|
entry.setType(entitySet.getType());
|
||||||
|
|
||||||
|
@ -584,21 +583,21 @@ public abstract class AbstractServices {
|
||||||
|
|
||||||
entry.setMediaContentSource(editLink.getHref() + "/$value");
|
entry.setMediaContentSource(editLink.getHref() + "/$value");
|
||||||
|
|
||||||
container = new ResWrap<AtomEntryImpl>((URI) null, null, entry);
|
container = new ResWrap<AtomEntityImpl>((URI) null, null, entry);
|
||||||
} else {
|
} else {
|
||||||
final Accept contentTypeValue = Accept.parse(contentType, version);
|
final Accept contentTypeValue = Accept.parse(contentType, version);
|
||||||
if (Accept.ATOM == contentTypeValue) {
|
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();
|
entry = container.getPayload();
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<JSONEntryImpl> jcontainer =
|
final ResWrap<JSONEntityImpl> jcontainer =
|
||||||
mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING),
|
mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING),
|
||||||
new TypeReference<JSONEntryImpl>() {
|
new TypeReference<JSONEntityImpl>() {
|
||||||
});
|
});
|
||||||
|
|
||||||
entry = dataBinder.toAtomEntry(jcontainer.getPayload());
|
entry = dataBinder.toAtomEntity(jcontainer.getPayload());
|
||||||
|
|
||||||
container = new ResWrap<AtomEntryImpl>(
|
container = new ResWrap<AtomEntityImpl>(
|
||||||
jcontainer.getContextURL(),
|
jcontainer.getContextURL(),
|
||||||
jcontainer.getMetadataETag(),
|
jcontainer.getMetadataETag(),
|
||||||
entry);
|
entry);
|
||||||
|
@ -618,8 +617,8 @@ public abstract class AbstractServices {
|
||||||
final InputStream serialization =
|
final InputStream serialization =
|
||||||
xml.addOrReplaceEntity(null, entitySetName, new ByteArrayInputStream(content.toByteArray()), entry);
|
xml.addOrReplaceEntity(null, entitySetName, new ByteArrayInputStream(content.toByteArray()), entry);
|
||||||
|
|
||||||
ResWrap<AtomEntryImpl> result = atomDeserializer.read(serialization, AtomEntryImpl.class);
|
ResWrap<AtomEntityImpl> result = atomDeserializer.read(serialization, AtomEntityImpl.class);
|
||||||
result = new ResWrap<AtomEntryImpl>(
|
result = new ResWrap<AtomEntityImpl>(
|
||||||
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
|
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
|
||||||
+ entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)),
|
+ entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)),
|
||||||
null, result.getPayload());
|
null, result.getPayload());
|
||||||
|
@ -862,7 +861,7 @@ public abstract class AbstractServices {
|
||||||
|
|
||||||
final InputStream feed = FSManager.instance(version).readFile(builder.toString(), Accept.ATOM);
|
final InputStream feed = FSManager.instance(version).readFile(builder.toString(), Accept.ATOM);
|
||||||
|
|
||||||
final ResWrap<AtomFeedImpl> container = atomDeserializer.read(feed, AtomFeedImpl.class);
|
final ResWrap<AtomEntitySetImpl> container = atomDeserializer.read(feed, AtomEntitySetImpl.class);
|
||||||
|
|
||||||
setInlineCount(container.getPayload(), count);
|
setInlineCount(container.getPayload(), count);
|
||||||
|
|
||||||
|
@ -872,7 +871,7 @@ public abstract class AbstractServices {
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
// Evaluate $skip and $top
|
// Evaluate $skip and $top
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
List<Entry> entries = new ArrayList<Entry>(container.getPayload().getEntries());
|
List<Entity> entries = new ArrayList<Entity>(container.getPayload().getEntities());
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(skip)) {
|
if (StringUtils.isNotBlank(skip)) {
|
||||||
entries = entries.subList(Integer.valueOf(skip), entries.size());
|
entries = entries.subList(Integer.valueOf(skip), entries.size());
|
||||||
|
@ -882,8 +881,8 @@ public abstract class AbstractServices {
|
||||||
entries = entries.subList(0, Integer.valueOf(top));
|
entries = entries.subList(0, Integer.valueOf(top));
|
||||||
}
|
}
|
||||||
|
|
||||||
container.getPayload().getEntries().clear();
|
container.getPayload().getEntities().clear();
|
||||||
container.getPayload().getEntries().addAll(entries);
|
container.getPayload().getEntities().addAll(entries);
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
|
|
||||||
if (acceptType == Accept.ATOM) {
|
if (acceptType == Accept.ATOM) {
|
||||||
|
@ -893,7 +892,7 @@ public abstract class AbstractServices {
|
||||||
} else {
|
} else {
|
||||||
mapper.writeValue(
|
mapper.writeValue(
|
||||||
writer, new JSONFeedContainer(container.getContextURL(), container.getMetadataETag(),
|
writer, new JSONFeedContainer(container.getContextURL(), container.getMetadataETag(),
|
||||||
dataBinder.toJSONFeed(container.getPayload())));
|
dataBinder.toJSONEntitySet(container.getPayload())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return xml.createResponse(
|
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.
|
* Retrieve entity with key as segment.
|
||||||
|
@ -1000,13 +999,13 @@ public abstract class AbstractServices {
|
||||||
|
|
||||||
final InputStream entity = entityInfo.getValue();
|
final InputStream entity = entityInfo.getValue();
|
||||||
|
|
||||||
ResWrap<AtomEntryImpl> container = atomDeserializer.read(entity, AtomEntryImpl.class);
|
ResWrap<AtomEntityImpl> container = atomDeserializer.read(entity, AtomEntityImpl.class);
|
||||||
if (container.getContextURL() == null) {
|
if (container.getContextURL() == null) {
|
||||||
container = new ResWrap<AtomEntryImpl>(URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
|
container = new ResWrap<AtomEntityImpl>(URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
|
||||||
+ entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)),
|
+ entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)),
|
||||||
container.getMetadataETag(), container.getPayload());
|
container.getMetadataETag(), container.getPayload());
|
||||||
}
|
}
|
||||||
final Entry entry = container.getPayload();
|
final Entity entry = container.getPayload();
|
||||||
|
|
||||||
if (keyAsSegment) {
|
if (keyAsSegment) {
|
||||||
final Link editLink = new LinkImpl();
|
final Link editLink = new LinkImpl();
|
||||||
|
@ -1055,16 +1054,16 @@ public abstract class AbstractServices {
|
||||||
rep.setType(link.getType());
|
rep.setType(link.getType());
|
||||||
if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_ENTRY))) {
|
if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_ENTRY))) {
|
||||||
// inline entry
|
// inline entry
|
||||||
final Entry inline = atomDeserializer.<Entry, AtomEntryImpl>read(
|
final Entity inline = atomDeserializer.<Entity, AtomEntityImpl>read(
|
||||||
xml.expandEntity(entitySetName, entityId, link.getTitle()),
|
xml.expandEntity(entitySetName, entityId, link.getTitle()),
|
||||||
AtomEntryImpl.class).getPayload();
|
AtomEntityImpl.class).getPayload();
|
||||||
rep.setInlineEntry(inline);
|
rep.setInlineEntity(inline);
|
||||||
} else if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_FEED))) {
|
} else if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_FEED))) {
|
||||||
// inline feed
|
// inline feed
|
||||||
final Feed inline = atomDeserializer.<Feed, AtomFeedImpl>read(
|
final EntitySet inline = atomDeserializer.<EntitySet, AtomEntitySetImpl>read(
|
||||||
xml.expandEntity(entitySetName, entityId, link.getTitle()),
|
xml.expandEntity(entitySetName, entityId, link.getTitle()),
|
||||||
AtomFeedImpl.class).getPayload();
|
AtomEntitySetImpl.class).getPayload();
|
||||||
rep.setInlineFeed(inline);
|
rep.setInlineEntitySet(inline);
|
||||||
}
|
}
|
||||||
replace.put(link, rep);
|
replace.put(link, rep);
|
||||||
}
|
}
|
||||||
|
@ -1508,7 +1507,8 @@ public abstract class AbstractServices {
|
||||||
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
|
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
|
||||||
|
|
||||||
if (linkInfo.isFeed()) {
|
if (linkInfo.isFeed()) {
|
||||||
final ResWrap<Feed> container = atomDeserializer.<Feed, AtomFeedImpl>read(stream, AtomFeedImpl.class);
|
final ResWrap<EntitySet> container =
|
||||||
|
atomDeserializer.<EntitySet, AtomEntitySetImpl>read(stream, AtomEntitySetImpl.class);
|
||||||
|
|
||||||
if (acceptType == Accept.ATOM) {
|
if (acceptType == Accept.ATOM) {
|
||||||
atomSerializer.write(writer, container);
|
atomSerializer.write(writer, container);
|
||||||
|
@ -1519,10 +1519,11 @@ public abstract class AbstractServices {
|
||||||
writer,
|
writer,
|
||||||
new JSONFeedContainer(container.getContextURL(),
|
new JSONFeedContainer(container.getContextURL(),
|
||||||
container.getMetadataETag(),
|
container.getMetadataETag(),
|
||||||
dataBinder.toJSONFeed((AtomFeedImpl) container.getPayload())));
|
dataBinder.toJSONEntitySet((AtomEntitySetImpl) container.getPayload())));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<Entry> container = atomDeserializer.<Entry, AtomEntryImpl>read(stream, AtomEntryImpl.class);
|
final ResWrap<Entity> container =
|
||||||
|
atomDeserializer.<Entity, AtomEntityImpl>read(stream, AtomEntityImpl.class);
|
||||||
if (acceptType == Accept.ATOM) {
|
if (acceptType == Accept.ATOM) {
|
||||||
atomSerializer.write(writer, container);
|
atomSerializer.write(writer, container);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
@ -1532,7 +1533,7 @@ public abstract class AbstractServices {
|
||||||
writer,
|
writer,
|
||||||
new JSONEntryContainer(container.getContextURL(),
|
new JSONEntryContainer(container.getContextURL(),
|
||||||
container.getMetadataETag(),
|
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 InputStream entity = entityInfo.getValue();
|
||||||
|
|
||||||
final ResWrap<AtomEntryImpl> entryContainer = atomDeserializer.read(entity, AtomEntryImpl.class);
|
final ResWrap<AtomEntityImpl> entryContainer = atomDeserializer.read(entity, AtomEntityImpl.class);
|
||||||
|
|
||||||
final String[] pathElems = StringUtils.split(path, "/");
|
final String[] pathElems = StringUtils.split(path, "/");
|
||||||
AtomPropertyImpl property = (AtomPropertyImpl) entryContainer.getPayload().getProperty(pathElems[0]);
|
AtomPropertyImpl property = (AtomPropertyImpl) entryContainer.getPayload().getProperty(pathElems[0]);
|
||||||
|
@ -1676,8 +1677,8 @@ public abstract class AbstractServices {
|
||||||
return utils;
|
return utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void normalizeAtomEntry(final AtomEntryImpl entry, final String entitySetName, final String entityKey) {
|
protected void normalizeAtomEntry(final AtomEntityImpl entry, final String entitySetName, final String entityKey) {
|
||||||
final EntitySet entitySet = getMetadataObj().getEntitySet(entitySetName);
|
final org.apache.olingo.fit.metadata.EntitySet entitySet = getMetadataObj().getEntitySet(entitySetName);
|
||||||
final EntityType entityType = getMetadataObj().getEntityType(entitySet.getType());
|
final EntityType entityType = getMetadataObj().getEntityType(entitySet.getType());
|
||||||
for (Map.Entry<String, org.apache.olingo.fit.metadata.Property> property
|
for (Map.Entry<String, org.apache.olingo.fit.metadata.Property> property
|
||||||
: entityType.getPropertyMap().entrySet()) {
|
: entityType.getPropertyMap().entrySet()) {
|
||||||
|
@ -1700,7 +1701,7 @@ public abstract class AbstractServices {
|
||||||
if (!found) {
|
if (!found) {
|
||||||
final LinkImpl link = new LinkImpl();
|
final LinkImpl link = new LinkImpl();
|
||||||
link.setTitle(property.getKey());
|
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_FEED)
|
||||||
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY));
|
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY));
|
||||||
link.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getKey());
|
link.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getKey());
|
||||||
|
|
|
@ -40,7 +40,7 @@ import javax.ws.rs.core.UriInfo;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
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.commons.api.edm.constants.ODataServiceVersion;
|
||||||
import static org.apache.olingo.fit.AbstractServices.LOG;
|
import static org.apache.olingo.fit.AbstractServices.LOG;
|
||||||
import org.apache.olingo.fit.utils.AbstractUtilities;
|
import org.apache.olingo.fit.utils.AbstractUtilities;
|
||||||
|
@ -206,7 +206,7 @@ public class V3ActionOverloading extends AbstractServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setInlineCount(Feed feed, String count) {
|
protected void setInlineCount(EntitySet feed, String count) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.cxf.interceptor.InInterceptors;
|
import org.apache.cxf.interceptor.InInterceptors;
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
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.commons.api.edm.constants.ODataServiceVersion;
|
||||||
import org.apache.olingo.fit.methods.MERGE;
|
import org.apache.olingo.fit.methods.MERGE;
|
||||||
import org.apache.olingo.fit.methods.PATCH;
|
import org.apache.olingo.fit.methods.PATCH;
|
||||||
|
@ -109,9 +109,9 @@ public class V3Services extends AbstractServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setInlineCount(final Feed feed, final String count) {
|
protected void setInlineCount(final EntitySet feed, final String count) {
|
||||||
if ("allpages".equals(count)) {
|
if ("allpages".equals(count)) {
|
||||||
feed.setCount(feed.getEntries().size());
|
feed.setCount(feed.getEntities().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,17 +55,17 @@ import org.apache.cxf.jaxrs.ext.multipart.Multipart;
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
||||||
import org.apache.olingo.commons.api.data.CollectionValue;
|
import org.apache.olingo.commons.api.data.CollectionValue;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.core.data.AtomEntryImpl;
|
import org.apache.olingo.commons.core.data.AtomEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomFeedImpl;
|
import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.CollectionValueImpl;
|
import org.apache.olingo.commons.core.data.CollectionValueImpl;
|
||||||
import org.apache.olingo.commons.core.data.EnumValueImpl;
|
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.JSONPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
|
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
|
||||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||||
|
@ -192,7 +192,7 @@ public class V4Services extends AbstractServices {
|
||||||
|
|
||||||
final UUID uuid = UUID.randomUUID();
|
final UUID uuid = UUID.randomUUID();
|
||||||
providedAsync.put(uuid.toString(), bos.toString(Constants.ENCODING.toString()));
|
providedAsync.put(uuid.toString(), bos.toString(Constants.ENCODING.toString()));
|
||||||
|
|
||||||
bos.flush();
|
bos.flush();
|
||||||
bos.close();
|
bos.close();
|
||||||
|
|
||||||
|
@ -242,9 +242,9 @@ public class V4Services extends AbstractServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setInlineCount(final Feed feed, final String count) {
|
protected void setInlineCount(final EntitySet feed, final String count) {
|
||||||
if ("true".equals(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 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(
|
return xml.createResponse(
|
||||||
null,
|
null,
|
||||||
|
@ -419,7 +419,7 @@ public class V4Services extends AbstractServices {
|
||||||
acceptType = Accept.parse(accept, version);
|
acceptType = Accept.parse(accept, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
final AtomEntryImpl entry = new AtomEntryImpl();
|
final AtomEntityImpl entry = new AtomEntityImpl();
|
||||||
entry.setType("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail");
|
entry.setType("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail");
|
||||||
final Property productId = new AtomPropertyImpl();
|
final Property productId = new AtomPropertyImpl();
|
||||||
productId.setName("ProductID");
|
productId.setName("ProductID");
|
||||||
|
@ -432,10 +432,10 @@ public class V4Services extends AbstractServices {
|
||||||
productDetailId.setValue(new PrimitiveValueImpl("2"));
|
productDetailId.setValue(new PrimitiveValueImpl("2"));
|
||||||
entry.getProperties().add(productDetailId);
|
entry.getProperties().add(productDetailId);
|
||||||
|
|
||||||
final AtomFeedImpl feed = new AtomFeedImpl();
|
final AtomEntitySetImpl feed = new AtomEntitySetImpl();
|
||||||
feed.getEntries().add(entry);
|
feed.getEntities().add(entry);
|
||||||
|
|
||||||
final ResWrap<AtomFeedImpl> container = new ResWrap<AtomFeedImpl>(
|
final ResWrap<AtomEntitySetImpl> container = new ResWrap<AtomEntitySetImpl>(
|
||||||
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + "ProductDetail"), null,
|
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + "ProductDetail"), null,
|
||||||
feed);
|
feed);
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ public class V4Services extends AbstractServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
final Accept contentTypeValue = Accept.parse(contentType, version);
|
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 1 == entry.getProperties().size();
|
||||||
assert entry.getProperty("accessRight") != null;
|
assert entry.getProperty("accessRight") != null;
|
||||||
|
@ -495,7 +495,7 @@ public class V4Services extends AbstractServices {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Accept contentTypeValue = Accept.parse(contentType, version);
|
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 2 == entry.getProperties().size();
|
||||||
assert entry.getProperty("addresses") != null;
|
assert entry.getProperty("addresses") != null;
|
||||||
|
@ -532,7 +532,7 @@ public class V4Services extends AbstractServices {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Accept contentTypeValue = Accept.parse(contentType, version);
|
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 1 == entry.getProperties().size();
|
||||||
assert entry.getProperty("newDate") != null;
|
assert entry.getProperty("newDate") != null;
|
||||||
|
@ -619,7 +619,7 @@ public class V4Services extends AbstractServices {
|
||||||
|
|
||||||
return utils.getValue().createResponse(
|
return utils.getValue().createResponse(
|
||||||
FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF)
|
FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF)
|
||||||
+ File.separatorChar + filename, utils.getKey()),
|
+ File.separatorChar + filename, utils.getKey()),
|
||||||
null,
|
null,
|
||||||
utils.getKey());
|
utils.getKey());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -641,7 +641,7 @@ public class V4Services extends AbstractServices {
|
||||||
|
|
||||||
final Response response =
|
final Response response =
|
||||||
getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
|
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
|
return response.getStatus() >= 400
|
||||||
? postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes)
|
? postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes)
|
||||||
: super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, 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 InputStream entry = FSManager.instance(version).readFile(containedPath.toString(), Accept.ATOM);
|
||||||
|
|
||||||
final ResWrap<AtomEntryImpl> container = atomDeserializer.read(entry, AtomEntryImpl.class);
|
final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entry, AtomEntityImpl.class);
|
||||||
|
|
||||||
return xml.createResponse(
|
return xml.createResponse(
|
||||||
null,
|
null,
|
||||||
|
@ -730,21 +730,21 @@ public class V4Services extends AbstractServices {
|
||||||
final AbstractUtilities utils = getUtilities(acceptType);
|
final AbstractUtilities utils = getUtilities(acceptType);
|
||||||
|
|
||||||
// 1. parse the entry (from Atom or JSON) into AtomEntryImpl
|
// 1. parse the entry (from Atom or JSON) into AtomEntryImpl
|
||||||
final ResWrap<AtomEntryImpl> entryContainer;
|
final ResWrap<AtomEntityImpl> entryContainer;
|
||||||
final AtomEntryImpl entry;
|
final AtomEntityImpl entry;
|
||||||
final Accept contentTypeValue = Accept.parse(contentType, version);
|
final Accept contentTypeValue = Accept.parse(contentType, version);
|
||||||
if (Accept.ATOM == contentTypeValue) {
|
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();
|
entry = entryContainer.getPayload();
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<JSONEntryImpl> jcontainer =
|
final ResWrap<JSONEntityImpl> jcontainer =
|
||||||
mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING),
|
mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING),
|
||||||
new TypeReference<JSONEntryImpl>() {
|
new TypeReference<JSONEntityImpl>() {
|
||||||
});
|
});
|
||||||
|
|
||||||
entry = dataBinder.toAtomEntry(jcontainer.getPayload());
|
entry = dataBinder.toAtomEntity(jcontainer.getPayload());
|
||||||
|
|
||||||
entryContainer = new ResWrap<AtomEntryImpl>(
|
entryContainer = new ResWrap<AtomEntityImpl>(
|
||||||
jcontainer.getContextURL(),
|
jcontainer.getContextURL(),
|
||||||
jcontainer.getMetadataETag(),
|
jcontainer.getMetadataETag(),
|
||||||
entry);
|
entry);
|
||||||
|
@ -765,8 +765,8 @@ public class V4Services extends AbstractServices {
|
||||||
// 3. Update the contained entity set
|
// 3. Update the contained entity set
|
||||||
final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString();
|
final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString();
|
||||||
final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM);
|
final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM);
|
||||||
final ResWrap<AtomFeedImpl> feedContainer = atomDeserializer.read(feedIS, AtomFeedImpl.class);
|
final ResWrap<AtomEntitySetImpl> feedContainer = atomDeserializer.read(feedIS, AtomEntitySetImpl.class);
|
||||||
feedContainer.getPayload().getEntries().add(entry);
|
feedContainer.getPayload().getEntities().add(entry);
|
||||||
|
|
||||||
final ByteArrayOutputStream content = new ByteArrayOutputStream();
|
final ByteArrayOutputStream content = new ByteArrayOutputStream();
|
||||||
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
|
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
|
||||||
|
@ -823,12 +823,12 @@ public class V4Services extends AbstractServices {
|
||||||
final LinkInfo links = xml.readLinks(
|
final LinkInfo links = xml.readLinks(
|
||||||
entitySetName, entityId, containedEntitySetName + "(" + containedEntityId + ")", Accept.ATOM);
|
entitySetName, entityId, containedEntitySetName + "(" + containedEntityId + ")", Accept.ATOM);
|
||||||
|
|
||||||
ResWrap<AtomEntryImpl> container = atomDeserializer.read(links.getLinks(), AtomEntryImpl.class);
|
ResWrap<AtomEntityImpl> container = atomDeserializer.read(links.getLinks(), AtomEntityImpl.class);
|
||||||
final AtomEntryImpl original = container.getPayload();
|
final AtomEntityImpl original = container.getPayload();
|
||||||
|
|
||||||
final AtomEntryImpl entryChanges;
|
final AtomEntityImpl entryChanges;
|
||||||
if (Accept.ATOM == contentTypeValue) {
|
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();
|
entryChanges = container.getPayload();
|
||||||
} else {
|
} else {
|
||||||
final String entityType = getMetadataObj().getEntitySet(entitySetName).getType();
|
final String entityType = getMetadataObj().getEntitySet(entitySetName).getType();
|
||||||
|
@ -836,11 +836,11 @@ public class V4Services extends AbstractServices {
|
||||||
getNavigationProperty(containedEntitySetName).getType();
|
getNavigationProperty(containedEntitySetName).getType();
|
||||||
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(containedType).build();
|
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(containedType).build();
|
||||||
|
|
||||||
final ResWrap<JSONEntryImpl> jsonContainer = mapper.readValue(
|
final ResWrap<JSONEntityImpl> jsonContainer = mapper.readValue(
|
||||||
IOUtils.toInputStream(changes, Constants.ENCODING), new TypeReference<JSONEntryImpl>() {
|
IOUtils.toInputStream(changes, Constants.ENCODING), new TypeReference<JSONEntityImpl>() {
|
||||||
});
|
});
|
||||||
jsonContainer.getPayload().setType(typeInfo.getFullQualifiedName().toString());
|
jsonContainer.getPayload().setType(typeInfo.getFullQualifiedName().toString());
|
||||||
entryChanges = dataBinder.toAtomEntry(jsonContainer.getPayload());
|
entryChanges = dataBinder.toAtomEntity(jsonContainer.getPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Property property : entryChanges.getProperties()) {
|
for (Property property : entryChanges.getProperties()) {
|
||||||
|
@ -851,7 +851,7 @@ public class V4Services extends AbstractServices {
|
||||||
original.getProperties().add(property);
|
original.getProperties().add(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
FSManager.instance(version).putInMemory(new ResWrap<AtomEntryImpl>((URI) null, null, original),
|
FSManager.instance(version).putInMemory(new ResWrap<AtomEntityImpl>((URI) null, null, original),
|
||||||
xml.getLinksBasePath(entitySetName, entityId) + containedEntitySetName + "(" + containedEntityId + ")");
|
xml.getLinksBasePath(entitySetName, entityId) + containedEntitySetName + "(" + containedEntityId + ")");
|
||||||
|
|
||||||
return xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT);
|
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
|
// 1. Fetch the contained entity to be removed
|
||||||
final InputStream entry = FSManager.instance(version).
|
final InputStream entry = FSManager.instance(version).
|
||||||
readFile(containedPath(entityId, containedEntitySetName).
|
readFile(containedPath(entityId, containedEntitySetName).
|
||||||
append('(').append(containedEntityId).append(')').toString(), Accept.ATOM);
|
append('(').append(containedEntityId).append(')').toString(), Accept.ATOM);
|
||||||
final ResWrap<AtomEntryImpl> container = atomDeserializer.read(entry, AtomEntryImpl.class);
|
final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entry, AtomEntityImpl.class);
|
||||||
|
|
||||||
// 2. Remove the contained entity
|
// 2. Remove the contained entity
|
||||||
final String atomEntryRelativePath = containedPath(entityId, containedEntitySetName).
|
final String atomEntryRelativePath = containedPath(entityId, containedEntitySetName).
|
||||||
|
@ -882,8 +882,8 @@ public class V4Services extends AbstractServices {
|
||||||
// 3. Update the contained entity set
|
// 3. Update the contained entity set
|
||||||
final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString();
|
final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString();
|
||||||
final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM);
|
final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM);
|
||||||
final ResWrap<AtomFeedImpl> feedContainer = atomDeserializer.read(feedIS, AtomFeedImpl.class);
|
final ResWrap<AtomEntitySetImpl> feedContainer = atomDeserializer.read(feedIS, AtomEntitySetImpl.class);
|
||||||
feedContainer.getPayload().getEntries().remove(container.getPayload());
|
feedContainer.getPayload().getEntities().remove(container.getPayload());
|
||||||
|
|
||||||
final ByteArrayOutputStream content = new ByteArrayOutputStream();
|
final ByteArrayOutputStream content = new ByteArrayOutputStream();
|
||||||
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
|
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
|
||||||
|
@ -927,7 +927,7 @@ public class V4Services extends AbstractServices {
|
||||||
final InputStream feed = FSManager.instance(version).
|
final InputStream feed = FSManager.instance(version).
|
||||||
readFile(containedPath(entityId, containedEntitySetName).toString(), Accept.ATOM);
|
readFile(containedPath(entityId, containedEntitySetName).toString(), Accept.ATOM);
|
||||||
|
|
||||||
final ResWrap<AtomFeedImpl> container = atomDeserializer.read(feed, AtomFeedImpl.class);
|
final ResWrap<AtomEntitySetImpl> container = atomDeserializer.read(feed, AtomEntitySetImpl.class);
|
||||||
|
|
||||||
return xml.createResponse(
|
return xml.createResponse(
|
||||||
null,
|
null,
|
||||||
|
@ -1100,8 +1100,8 @@ public class V4Services extends AbstractServices {
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<JSONPropertyImpl> paramContainer =
|
final ResWrap<JSONPropertyImpl> paramContainer =
|
||||||
mapper.readValue(IOUtils.toInputStream(param, Constants.ENCODING),
|
mapper.readValue(IOUtils.toInputStream(param, Constants.ENCODING),
|
||||||
new TypeReference<JSONPropertyImpl>() {
|
new TypeReference<JSONPropertyImpl>() {
|
||||||
});
|
});
|
||||||
property = paramContainer.getPayload();
|
property = paramContainer.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1142,8 +1142,8 @@ public class V4Services extends AbstractServices {
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<JSONPropertyImpl> paramContainer =
|
final ResWrap<JSONPropertyImpl> paramContainer =
|
||||||
mapper.readValue(IOUtils.toInputStream(param, Constants.ENCODING),
|
mapper.readValue(IOUtils.toInputStream(param, Constants.ENCODING),
|
||||||
new TypeReference<JSONPropertyImpl>() {
|
new TypeReference<JSONPropertyImpl>() {
|
||||||
});
|
});
|
||||||
property = paramContainer.getPayload();
|
property = paramContainer.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1177,7 +1177,7 @@ public class V4Services extends AbstractServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
final Accept contentTypeValue = Accept.parse(contentType, version);
|
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 1 == entry.getProperties().size();
|
||||||
assert "Collection(Edm.String)".equals(entry.getProperty("emails").getType());
|
assert "Collection(Edm.String)".equals(entry.getProperty("emails").getType());
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class Metadata extends AbstractMetadataElement {
|
||||||
property.getReleationship().replaceAll(schemaEntry.getKey() + "\\.", ""));
|
property.getReleationship().replaceAll(schemaEntry.getKey() + "\\.", ""));
|
||||||
final Association.Role role = association.getRole(property.getToRole());
|
final Association.Role role = association.getRole(property.getToRole());
|
||||||
property.setFeed(role.getMultiplicity().equals("*"));
|
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
|
// let me assume that it will be just a single container
|
||||||
final AssociationSet associationSet = schemaEntry.getValue().getContainers().iterator().next().
|
final AssociationSet associationSet = schemaEntry.getValue().getContainers().iterator().next().
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class NavigationProperty extends AbstractMetadataElement {
|
||||||
|
|
||||||
private String target;
|
private String target;
|
||||||
|
|
||||||
private boolean feed;
|
private boolean entitySet;
|
||||||
|
|
||||||
public NavigationProperty(final String name) {
|
public NavigationProperty(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -76,11 +76,11 @@ public class NavigationProperty extends AbstractMetadataElement {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFeed() {
|
public boolean isEntitySet() {
|
||||||
return feed;
|
return entitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFeed(boolean feed) {
|
public void setFeed(boolean entitySet) {
|
||||||
this.feed = feed;
|
this.entitySet = entitySet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,15 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import org.apache.olingo.commons.api.data.ContextURL;
|
import org.apache.olingo.commons.api.data.ContextURL;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
import org.apache.olingo.commons.core.data.JSONEntryDeserializer;
|
import org.apache.olingo.commons.core.data.JSONEntityDeserializer;
|
||||||
import org.apache.olingo.commons.core.data.JSONEntryImpl;
|
import org.apache.olingo.commons.core.data.JSONEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONEntrySerializer;
|
import org.apache.olingo.commons.core.data.JSONEntitySerializer;
|
||||||
|
|
||||||
@JsonDeserialize(using = JSONEntryDeserializer.class)
|
@JsonDeserialize(using = JSONEntityDeserializer.class)
|
||||||
@JsonSerialize(using = JSONEntrySerializer.class)
|
@JsonSerialize(using = JSONEntitySerializer.class)
|
||||||
public class JSONEntryContainer extends ResWrap<JSONEntryImpl> {
|
public class JSONEntryContainer extends ResWrap<JSONEntityImpl> {
|
||||||
|
|
||||||
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);
|
super(contextURL, metadataETag, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,15 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import org.apache.olingo.commons.api.data.ContextURL;
|
import org.apache.olingo.commons.api.data.ContextURL;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
import org.apache.olingo.commons.core.data.JSONFeedDeserializer;
|
import org.apache.olingo.commons.core.data.JSONEntitySetDeserializer;
|
||||||
import org.apache.olingo.commons.core.data.JSONFeedImpl;
|
import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONFeedSerializer;
|
import org.apache.olingo.commons.core.data.JSONEntitySetSerializer;
|
||||||
|
|
||||||
@JsonDeserialize(using = JSONFeedDeserializer.class)
|
@JsonDeserialize(using = JSONEntitySetDeserializer.class)
|
||||||
@JsonSerialize(using = JSONFeedSerializer.class)
|
@JsonSerialize(using = JSONEntitySetSerializer.class)
|
||||||
public class JSONFeedContainer extends ResWrap<JSONFeedImpl> {
|
public class JSONFeedContainer extends ResWrap<JSONEntitySetImpl> {
|
||||||
|
|
||||||
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);
|
super(contextURL, metadataETag, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,16 +43,16 @@ import javax.xml.stream.XMLStreamException;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.vfs2.FileObject;
|
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
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.AtomFeedImpl;
|
import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomSerializer;
|
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.commons.core.data.JSONPropertyImpl;
|
||||||
import org.apache.olingo.fit.UnsupportedMediaTypeException;
|
import org.apache.olingo.fit.UnsupportedMediaTypeException;
|
||||||
import org.apache.olingo.fit.metadata.Metadata;
|
import org.apache.olingo.fit.metadata.Metadata;
|
||||||
|
@ -199,7 +199,7 @@ public abstract class AbstractUtilities {
|
||||||
return fo.getContent().getInputStream();
|
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();
|
final StringWriter writer = new StringWriter();
|
||||||
atomSerializer.write(writer, entry);
|
atomSerializer.write(writer, entry);
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ public abstract class AbstractUtilities {
|
||||||
final String key,
|
final String key,
|
||||||
final String entitySetName,
|
final String entitySetName,
|
||||||
final InputStream is,
|
final InputStream is,
|
||||||
final AtomEntryImpl entry) throws Exception {
|
final AtomEntityImpl entry) throws Exception {
|
||||||
|
|
||||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
IOUtils.copy(is, bos);
|
IOUtils.copy(is, bos);
|
||||||
|
@ -297,27 +297,27 @@ public abstract class AbstractUtilities {
|
||||||
navigationProperties == null ? null : navigationProperties.get(link.getTitle());
|
navigationProperties == null ? null : navigationProperties.get(link.getTitle());
|
||||||
if (navProp != null) {
|
if (navProp != null) {
|
||||||
final String inlineEntitySetName = navProp.getTarget();
|
final String inlineEntitySetName = navProp.getTarget();
|
||||||
if (link.getInlineEntry() != null) {
|
if (link.getInlineEntity() != null) {
|
||||||
final String inlineEntryKey = getDefaultEntryKey(
|
final String inlineEntryKey = getDefaultEntryKey(
|
||||||
inlineEntitySetName, (AtomEntryImpl) link.getInlineEntry());
|
inlineEntitySetName, (AtomEntityImpl) link.getInlineEntity());
|
||||||
|
|
||||||
addOrReplaceEntity(
|
addOrReplaceEntity(
|
||||||
inlineEntryKey,
|
inlineEntryKey,
|
||||||
inlineEntitySetName,
|
inlineEntitySetName,
|
||||||
toInputStream((AtomEntryImpl) link.getInlineEntry()),
|
toInputStream((AtomEntityImpl) link.getInlineEntity()),
|
||||||
(AtomEntryImpl) link.getInlineEntry());
|
(AtomEntityImpl) link.getInlineEntity());
|
||||||
|
|
||||||
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
|
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
|
||||||
} else if (link.getInlineFeed() != null) {
|
} else if (link.getInlineEntitySet() != null) {
|
||||||
for (Entry subentry : link.getInlineFeed().getEntries()) {
|
for (Entity subentry : link.getInlineEntitySet().getEntities()) {
|
||||||
final String inlineEntryKey = getDefaultEntryKey(
|
final String inlineEntryKey = getDefaultEntryKey(
|
||||||
inlineEntitySetName, (AtomEntryImpl) subentry);
|
inlineEntitySetName, (AtomEntityImpl) subentry);
|
||||||
|
|
||||||
addOrReplaceEntity(
|
addOrReplaceEntity(
|
||||||
inlineEntryKey,
|
inlineEntryKey,
|
||||||
inlineEntitySetName,
|
inlineEntitySetName,
|
||||||
toInputStream((AtomEntryImpl) subentry),
|
toInputStream((AtomEntityImpl) subentry),
|
||||||
(AtomEntryImpl) subentry);
|
(AtomEntityImpl) subentry);
|
||||||
|
|
||||||
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
|
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ public abstract class AbstractUtilities {
|
||||||
final Metadata metadata = Commons.getMetadata(version);
|
final Metadata metadata = Commons.getMetadata(version);
|
||||||
final Map<String, NavigationProperty> navigationProperties = metadata.getNavigationProperties(entitySetName);
|
final Map<String, NavigationProperty> navigationProperties = metadata.getNavigationProperties(entitySetName);
|
||||||
|
|
||||||
if (navigationProperties.get(linkName).isFeed()) {
|
if (navigationProperties.get(linkName).isEntitySet()) {
|
||||||
try {
|
try {
|
||||||
final Map.Entry<String, List<String>> currents = extractLinkURIs(entitySetName, entityKey, linkName);
|
final Map.Entry<String, List<String>> currents = extractLinkURIs(entitySetName, entityKey, linkName);
|
||||||
uris.addAll(currents.getValue());
|
uris.addAll(currents.getValue());
|
||||||
|
@ -540,7 +540,7 @@ public abstract class AbstractUtilities {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream writeFeed(final Accept accept, final ResWrap<AtomFeedImpl> container)
|
public InputStream writeFeed(final Accept accept, final ResWrap<AtomEntitySetImpl> container)
|
||||||
throws XMLStreamException, IOException {
|
throws XMLStreamException, IOException {
|
||||||
|
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
|
@ -551,31 +551,31 @@ public abstract class AbstractUtilities {
|
||||||
} else {
|
} else {
|
||||||
mapper.writeValue(
|
mapper.writeValue(
|
||||||
writer, new JSONFeedContainer(container.getContextURL(),
|
writer, new JSONFeedContainer(container.getContextURL(),
|
||||||
container.getMetadataETag(), dataBinder.toJSONFeed(container.getPayload())));
|
container.getMetadataETag(), dataBinder.toJSONEntitySet(container.getPayload())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
|
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 {
|
throws XMLStreamException, IOException {
|
||||||
|
|
||||||
final AtomEntryImpl entry;
|
final AtomEntityImpl entry;
|
||||||
|
|
||||||
if (accept == Accept.ATOM || accept == Accept.XML) {
|
if (accept == Accept.ATOM || accept == Accept.XML) {
|
||||||
final ResWrap<AtomEntryImpl> container = atomDeserializer.read(entity, AtomEntryImpl.class);
|
final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entity, AtomEntityImpl.class);
|
||||||
entry = container.getPayload();
|
entry = container.getPayload();
|
||||||
} else {
|
} else {
|
||||||
final ResWrap<JSONEntryImpl> container =
|
final ResWrap<JSONEntityImpl> container =
|
||||||
mapper.readValue(entity, new TypeReference<JSONEntryImpl>() {
|
mapper.readValue(entity, new TypeReference<JSONEntityImpl>() {
|
||||||
});
|
});
|
||||||
entry = dataBinder.toAtomEntry(container.getPayload());
|
entry = dataBinder.toAtomEntity(container.getPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream writeEntry(final Accept accept, final ResWrap<AtomEntryImpl> container)
|
public InputStream writeEntry(final Accept accept, final ResWrap<AtomEntityImpl> container)
|
||||||
throws XMLStreamException, IOException {
|
throws XMLStreamException, IOException {
|
||||||
|
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
|
@ -584,7 +584,7 @@ public abstract class AbstractUtilities {
|
||||||
} else {
|
} else {
|
||||||
mapper.writeValue(
|
mapper.writeValue(
|
||||||
writer, new JSONEntryContainer(container.getContextURL(), container.getMetadataETag(),
|
writer, new JSONEntryContainer(container.getContextURL(), container.getMetadataETag(),
|
||||||
dataBinder.toJSONEntry(container.getPayload())));
|
dataBinder.toJSONEntityType(container.getPayload())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
|
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
|
||||||
|
@ -620,7 +620,7 @@ public abstract class AbstractUtilities {
|
||||||
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
|
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 {
|
throws Exception {
|
||||||
|
|
||||||
String res;
|
String res;
|
||||||
|
@ -638,7 +638,7 @@ public abstract class AbstractUtilities {
|
||||||
return res;
|
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 {
|
try {
|
||||||
String res;
|
String res;
|
||||||
|
|
||||||
|
@ -734,7 +734,7 @@ public abstract class AbstractUtilities {
|
||||||
final Metadata metadata = Commons.getMetadata(version);
|
final Metadata metadata = Commons.getMetadata(version);
|
||||||
final Map<String, NavigationProperty> navigationProperties = metadata.getNavigationProperties(entitySetName);
|
final Map<String, NavigationProperty> navigationProperties = metadata.getNavigationProperties(entitySetName);
|
||||||
|
|
||||||
linkInfo.setFeed(navigationProperties.get(linkName.replaceAll("\\(.*\\)", "")).isFeed());
|
linkInfo.setFeed(navigationProperties.get(linkName.replaceAll("\\(.*\\)", "")).isEntitySet());
|
||||||
|
|
||||||
return linkInfo;
|
return linkInfo;
|
||||||
}
|
}
|
||||||
|
@ -800,7 +800,7 @@ public abstract class AbstractUtilities {
|
||||||
links.getValue(),
|
links.getValue(),
|
||||||
linkName,
|
linkName,
|
||||||
links.getKey(),
|
links.getKey(),
|
||||||
navigationProperties.get(linkName).isFeed());
|
navigationProperties.get(linkName).isEntitySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream expandEntity(
|
public InputStream expandEntity(
|
||||||
|
@ -832,8 +832,8 @@ public abstract class AbstractUtilities {
|
||||||
InputStream stream = fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType);
|
InputStream stream = fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType);
|
||||||
stream = replaceProperty(stream, changes, path, justValue);
|
stream = replaceProperty(stream, changes, path, justValue);
|
||||||
|
|
||||||
final AtomEntryImpl entry = readEntry(acceptType, stream);
|
final AtomEntityImpl entry = readEntry(acceptType, stream);
|
||||||
final ResWrap<AtomEntryImpl> container = new ResWrap<AtomEntryImpl>((URI) null, null, entry);
|
final ResWrap<AtomEntityImpl> container = new ResWrap<AtomEntityImpl>((URI) null, null, entry);
|
||||||
|
|
||||||
fsManager.putInMemory(writeEntry(Accept.ATOM, container),
|
fsManager.putInMemory(writeEntry(Accept.ATOM, container),
|
||||||
fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), Accept.ATOM));
|
fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), Accept.ATOM));
|
||||||
|
|
|
@ -18,25 +18,24 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.fit.utils;
|
package org.apache.olingo.fit.utils;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
import org.apache.olingo.commons.api.data.Link;
|
import org.apache.olingo.commons.api.data.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.Value;
|
import org.apache.olingo.commons.api.data.Value;
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
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.AtomFeedImpl;
|
import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.CollectionValueImpl;
|
import org.apache.olingo.commons.core.data.CollectionValueImpl;
|
||||||
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
import org.apache.olingo.commons.core.data.ComplexValueImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONEntryImpl;
|
import org.apache.olingo.commons.core.data.JSONEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONFeedImpl;
|
import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.LinkImpl;
|
import org.apache.olingo.commons.core.data.LinkImpl;
|
||||||
import org.apache.olingo.fit.metadata.EntityType;
|
import org.apache.olingo.fit.metadata.EntityType;
|
||||||
|
@ -52,157 +51,157 @@ public class DataBinder {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONFeedImpl toJSONFeed(final AtomFeedImpl atomfeed) {
|
public JSONEntitySetImpl toJSONEntitySet(final AtomEntitySetImpl atomEntitySet) {
|
||||||
final JSONFeedImpl jsonfeed = new JSONFeedImpl();
|
final JSONEntitySetImpl jsonEntitySet = new JSONEntitySetImpl();
|
||||||
|
|
||||||
BeanUtils.copyProperties(atomfeed, jsonfeed, "baseURI", "metadataContextURL");
|
BeanUtils.copyProperties(atomEntitySet, jsonEntitySet, "baseURI", "metadataContextURL");
|
||||||
jsonfeed.setMetadataContextURL(atomfeed.getBaseURI() == null
|
jsonEntitySet.setBaseURI(atomEntitySet.getBaseURI() == null
|
||||||
? null
|
? null
|
||||||
: URI.create(atomfeed.getBaseURI().toASCIIString() + "/$metadata").normalize());
|
: atomEntitySet.getBaseURI().toASCIIString() + "/$metadata");
|
||||||
|
|
||||||
final Collection<Entry> entries = jsonfeed.getEntries();
|
final Collection<Entity> entries = jsonEntitySet.getEntities();
|
||||||
for (Entry entry : atomfeed.getEntries()) {
|
for (Entity entity : atomEntitySet.getEntities()) {
|
||||||
entries.add(toJSONEntry((AtomEntryImpl) entry));
|
entries.add(toJSONEntityType((AtomEntityImpl) entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonfeed;
|
return jsonEntitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AtomFeedImpl toAtomFeed(final JSONFeedImpl jsonfeed) {
|
public AtomEntitySetImpl toAtomEntitySet(final JSONEntitySetImpl jsonEntitySet) {
|
||||||
final AtomFeedImpl atomfeed = new AtomFeedImpl();
|
final AtomEntitySetImpl atomEntitySet = new AtomEntitySetImpl();
|
||||||
|
|
||||||
BeanUtils.copyProperties(jsonfeed, atomfeed, "baseURI", "metadataContextURL");
|
BeanUtils.copyProperties(jsonEntitySet, atomEntitySet, "baseURI", "metadataContextURL");
|
||||||
atomfeed.setBaseURI(jsonfeed.getBaseURI() == null
|
atomEntitySet.setBaseURI(jsonEntitySet.getBaseURI() == null
|
||||||
? null
|
? null
|
||||||
: jsonfeed.getBaseURI().toASCIIString() + "/$metadata");
|
: jsonEntitySet.getBaseURI().toASCIIString() + "/$metadata");
|
||||||
|
|
||||||
final Collection<Entry> entries = atomfeed.getEntries();
|
final Collection<Entity> entries = atomEntitySet.getEntities();
|
||||||
for (Entry entry : jsonfeed.getEntries()) {
|
for (Entity entity : jsonEntitySet.getEntities()) {
|
||||||
entries.add(toAtomEntry((JSONEntryImpl) entry));
|
entries.add(toAtomEntity((JSONEntityImpl) entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
return atomfeed;
|
return atomEntitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONEntryImpl toJSONEntry(final AtomEntryImpl atomentry) {
|
public JSONEntityImpl toJSONEntityType(final AtomEntityImpl atomEntity) {
|
||||||
final JSONEntryImpl jsonentry = new JSONEntryImpl();
|
final JSONEntityImpl jsonEntity = new JSONEntityImpl();
|
||||||
|
|
||||||
BeanUtils.copyProperties(atomentry, jsonentry, "baseURI", "properties", "links");
|
BeanUtils.copyProperties(atomEntity, jsonEntity, "baseURI", "properties", "links");
|
||||||
jsonentry.setBaseURI(atomentry.getBaseURI() == null ? null : atomentry.getBaseURI().toASCIIString());
|
jsonEntity.setBaseURI(atomEntity.getBaseURI() == null ? null : atomEntity.getBaseURI().toASCIIString());
|
||||||
jsonentry.getOperations().addAll(atomentry.getOperations());
|
jsonEntity.getOperations().addAll(atomEntity.getOperations());
|
||||||
|
|
||||||
for (Link link : atomentry.getNavigationLinks()) {
|
for (Link link : atomEntity.getNavigationLinks()) {
|
||||||
final Link jlink = new LinkImpl();
|
final Link jlink = new LinkImpl();
|
||||||
jlink.setHref(link.getHref());
|
jlink.setHref(link.getHref());
|
||||||
jlink.setTitle(link.getTitle());
|
jlink.setTitle(link.getTitle());
|
||||||
jlink.setType(link.getType());
|
jlink.setType(link.getType());
|
||||||
jlink.setRel(link.getRel());
|
jlink.setRel(link.getRel());
|
||||||
|
|
||||||
if (link.getInlineEntry() instanceof AtomEntryImpl) {
|
if (link.getInlineEntity() instanceof AtomEntityImpl) {
|
||||||
final Entry inlineEntry = link.getInlineEntry();
|
final Entity inlineEntity = link.getInlineEntity();
|
||||||
if (inlineEntry instanceof AtomEntryImpl) {
|
if (inlineEntity instanceof AtomEntityImpl) {
|
||||||
jlink.setInlineEntry(toJSONEntry((AtomEntryImpl) link.getInlineEntry()));
|
jlink.setInlineEntity(toJSONEntityType((AtomEntityImpl) link.getInlineEntity()));
|
||||||
}
|
}
|
||||||
} else if (link.getInlineFeed() instanceof AtomFeedImpl) {
|
} else if (link.getInlineEntitySet() instanceof AtomEntitySetImpl) {
|
||||||
final Feed inlineFeed = link.getInlineFeed();
|
final EntitySet inlineEntitySet = link.getInlineEntitySet();
|
||||||
if (inlineFeed instanceof AtomFeedImpl) {
|
if (inlineEntitySet instanceof AtomEntitySetImpl) {
|
||||||
jlink.setInlineFeed(toJSONFeed((AtomFeedImpl) link.getInlineFeed()));
|
jlink.setInlineEntitySet(toJSONEntitySet((AtomEntitySetImpl) link.getInlineEntitySet()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonentry.getNavigationLinks().add(jlink);
|
jsonEntity.getNavigationLinks().add(jlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Collection<Property> properties = jsonentry.getProperties();
|
final Collection<Property> properties = jsonEntity.getProperties();
|
||||||
for (Property property : atomentry.getProperties()) {
|
for (Property property : atomEntity.getProperties()) {
|
||||||
properties.add(toJSONProperty((AtomPropertyImpl) property));
|
properties.add(toJSONProperty((AtomPropertyImpl) property));
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonentry;
|
return jsonEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AtomEntryImpl toAtomEntry(final JSONEntryImpl jsonentry) {
|
public AtomEntityImpl toAtomEntity(final JSONEntityImpl jsonEntity) {
|
||||||
final AtomEntryImpl atomentry = new AtomEntryImpl();
|
final AtomEntityImpl atomEntity = new AtomEntityImpl();
|
||||||
|
|
||||||
final Metadata metadata = Commons.getMetadata(version);
|
final Metadata metadata = Commons.getMetadata(version);
|
||||||
|
|
||||||
BeanUtils.copyProperties(jsonentry, atomentry, "baseURI", "properties", "links");
|
BeanUtils.copyProperties(jsonEntity, atomEntity, "baseURI", "properties", "links");
|
||||||
atomentry.setBaseURI(jsonentry.getBaseURI() == null ? null : jsonentry.getBaseURI().toASCIIString());
|
atomEntity.setBaseURI(jsonEntity.getBaseURI() == null ? null : jsonEntity.getBaseURI().toASCIIString());
|
||||||
|
|
||||||
for (Link link : jsonentry.getNavigationLinks()) {
|
for (Link link : jsonEntity.getNavigationLinks()) {
|
||||||
final Link alink = new LinkImpl();
|
final Link alink = new LinkImpl();
|
||||||
alink.setHref(link.getHref());
|
alink.setHref(link.getHref());
|
||||||
alink.setTitle(link.getTitle());
|
alink.setTitle(link.getTitle());
|
||||||
|
|
||||||
final NavigationProperty navPropDetails =
|
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));
|
? Constants.get(ConstantKey.ATOM_LINK_FEED) : Constants.get(ConstantKey.ATOM_LINK_ENTRY));
|
||||||
alink.setRel(link.getRel());
|
alink.setRel(link.getRel());
|
||||||
|
|
||||||
if (link.getInlineEntry() instanceof JSONEntryImpl) {
|
if (link.getInlineEntity() instanceof JSONEntityImpl) {
|
||||||
final Entry inlineEntry = link.getInlineEntry();
|
final Entity inlineEntity = link.getInlineEntity();
|
||||||
if (inlineEntry instanceof JSONEntryImpl) {
|
if (inlineEntity instanceof JSONEntityImpl) {
|
||||||
alink.setInlineEntry(toAtomEntry((JSONEntryImpl) link.getInlineEntry()));
|
alink.setInlineEntity(toAtomEntity((JSONEntityImpl) link.getInlineEntity()));
|
||||||
}
|
}
|
||||||
} else if (link.getInlineFeed() instanceof JSONFeedImpl) {
|
} else if (link.getInlineEntitySet() instanceof JSONEntitySetImpl) {
|
||||||
final Feed inlineFeed = link.getInlineFeed();
|
final EntitySet inlineEntitySet = link.getInlineEntitySet();
|
||||||
if (inlineFeed instanceof JSONFeedImpl) {
|
if (inlineEntitySet instanceof JSONEntitySetImpl) {
|
||||||
alink.setInlineFeed(toAtomFeed((JSONFeedImpl) link.getInlineFeed()));
|
alink.setInlineEntitySet(toAtomEntitySet((JSONEntitySetImpl) link.getInlineEntitySet()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
atomentry.getNavigationLinks().add(alink);
|
atomEntity.getNavigationLinks().add(alink);
|
||||||
}
|
}
|
||||||
|
|
||||||
final EntityType entityType = StringUtils.isBlank(jsonentry.getType())
|
final EntityType entityType = StringUtils.isBlank(jsonEntity.getType())
|
||||||
? null : metadata.getEntityType(jsonentry.getType());
|
? null : metadata.getEntityType(jsonEntity.getType());
|
||||||
final Map<String, NavigationProperty> navProperties = entityType == null
|
final Map<String, NavigationProperty> navProperties = entityType == null
|
||||||
? Collections.<String, NavigationProperty>emptyMap() : entityType.getNavigationPropertyMap();
|
? Collections.<String, NavigationProperty>emptyMap() : entityType.getNavigationPropertyMap();
|
||||||
|
|
||||||
final List<Property> properties = atomentry.getProperties();
|
final List<Property> properties = atomEntity.getProperties();
|
||||||
|
|
||||||
for (Property property : jsonentry.getProperties()) {
|
for (Property property : jsonEntity.getProperties()) {
|
||||||
if (navProperties.containsKey(property.getName())) {
|
if (navProperties.containsKey(property.getName())) {
|
||||||
final Link alink = new LinkImpl();
|
final Link alink = new LinkImpl();
|
||||||
alink.setTitle(property.getName());
|
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_FEED)
|
||||||
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY));
|
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY));
|
||||||
|
|
||||||
alink.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getName());
|
alink.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getName());
|
||||||
|
|
||||||
if (property.getValue().isComplex()) {
|
if (property.getValue().isComplex()) {
|
||||||
final Entry inline = new AtomEntryImpl();
|
final Entity inline = new AtomEntityImpl();
|
||||||
inline.setType(navProperties.get(property.getName()).getType());
|
inline.setType(navProperties.get(property.getName()).getType());
|
||||||
for (Property prop : property.getValue().asComplex().get()) {
|
for (Property prop : property.getValue().asComplex().get()) {
|
||||||
inline.getProperties().add(prop);
|
inline.getProperties().add(prop);
|
||||||
}
|
}
|
||||||
alink.setInlineEntry(inline);
|
alink.setInlineEntity(inline);
|
||||||
|
|
||||||
} else if (property.getValue().isCollection()) {
|
} else if (property.getValue().isCollection()) {
|
||||||
final Feed inline = new AtomFeedImpl();
|
final EntitySet inline = new AtomEntitySetImpl();
|
||||||
for (Value entry : property.getValue().asCollection().get()) {
|
for (Value value : property.getValue().asCollection().get()) {
|
||||||
final Entry inlineEntry = new AtomEntryImpl();
|
final Entity inlineEntity = new AtomEntityImpl();
|
||||||
inlineEntry.setType(navProperties.get(property.getName()).getType());
|
inlineEntity.setType(navProperties.get(property.getName()).getType());
|
||||||
for (Property prop : entry.asComplex().get()) {
|
for (Property prop : value.asComplex().get()) {
|
||||||
inlineEntry.getProperties().add(toAtomProperty((JSONPropertyImpl) prop, inlineEntry.getType()));
|
inlineEntity.getProperties().add(toAtomProperty((JSONPropertyImpl) prop, inlineEntity.getType()));
|
||||||
}
|
}
|
||||||
inline.getEntries().add(inlineEntry);
|
inline.getEntities().add(inlineEntity);
|
||||||
}
|
}
|
||||||
alink.setInlineFeed(inline);
|
alink.setInlineEntitySet(inline);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Invalid navigation property " + property);
|
throw new IllegalStateException("Invalid navigation property " + property);
|
||||||
}
|
}
|
||||||
atomentry.getNavigationLinks().add(alink);
|
atomEntity.getNavigationLinks().add(alink);
|
||||||
} else {
|
} 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) {
|
public JSONPropertyImpl toJSONProperty(final AtomPropertyImpl atomproperty) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.commons.vfs2.FileSystemManager;
|
||||||
import org.apache.commons.vfs2.VFS;
|
import org.apache.commons.vfs2.VFS;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
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.commons.core.data.AtomSerializer;
|
||||||
import org.apache.olingo.fit.serializer.JSONEntryContainer;
|
import org.apache.olingo.fit.serializer.JSONEntryContainer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -98,7 +98,7 @@ public class FSManager {
|
||||||
return memObject;
|
return memObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putInMemory(final ResWrap<AtomEntryImpl> container, final String relativePath)
|
public void putInMemory(final ResWrap<AtomEntityImpl> container, final String relativePath)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
|
final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
|
||||||
|
@ -117,7 +117,7 @@ public class FSManager {
|
||||||
writer, new JSONEntryContainer(
|
writer, new JSONEntryContainer(
|
||||||
container.getContextURL(),
|
container.getContextURL(),
|
||||||
container.getMetadataETag(),
|
container.getMetadataETag(),
|
||||||
new DataBinder(version).toJSONEntry(container.getPayload())));
|
new DataBinder(version).toJSONEntityType(container.getPayload())));
|
||||||
|
|
||||||
putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.JSON_FULLMETA));
|
putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.JSON_FULLMETA));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class XMLUtilities extends AbstractUtilities {
|
||||||
attributes.add(eventFactory.createAttribute(new QName("rel"),
|
attributes.add(eventFactory.createAttribute(new QName("rel"),
|
||||||
Constants.get(version, ConstantKey.ATOM_LINK_REL) + link));
|
Constants.get(version, ConstantKey.ATOM_LINK_REL) + link));
|
||||||
attributes.add(eventFactory.createAttribute(new QName("type"),
|
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_FEED)
|
||||||
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY)));
|
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY)));
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.client.api;
|
package org.apache.olingo.client.api;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
|
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
|
|
||||||
|
|
|
@ -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.request.batch.v4.ODataBatchRequest;
|
||||||
import org.apache.olingo.client.api.communication.response.ODataResponse;
|
import org.apache.olingo.client.api.communication.response.ODataResponse;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public interface AsyncRequestFactory {
|
public interface AsyncRequestFactory {
|
||||||
|
|
||||||
<R extends ODataResponse> AsyncRequestWrapper<R> getAsyncRequestWrapper(final ODataRequest odataRequest);
|
<R extends ODataResponse> AsyncRequestWrapper<R> getAsyncRequestWrapper(final ODataRequest odataRequest);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.olingo.client.api.CommonODataClient;
|
import org.apache.olingo.client.api.CommonODataClient;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
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.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||||
|
@ -62,11 +62,11 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
|
||||||
|
|
||||||
private final ODataPubFormat format;
|
private final ODataPubFormat format;
|
||||||
|
|
||||||
private ResWrap<Entry> cached;
|
private ResWrap<Entity> cached;
|
||||||
|
|
||||||
private ES entitySet;
|
private ES entitySet;
|
||||||
|
|
||||||
private final ByteArrayOutputStream osFeed;
|
private final ByteArrayOutputStream osEntitySet;
|
||||||
|
|
||||||
private final String namespaces;
|
private final String namespaces;
|
||||||
|
|
||||||
|
@ -85,21 +85,21 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
|
||||||
this.odataClient = odataClient;
|
this.odataClient = odataClient;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.osFeed = new ByteArrayOutputStream();
|
this.osEntitySet = new ByteArrayOutputStream();
|
||||||
|
|
||||||
if (format == ODataPubFormat.ATOM) {
|
if (format == ODataPubFormat.ATOM) {
|
||||||
namespaces = getAllElementAttributes(stream, "feed", osFeed);
|
namespaces = getAllElementAttributes(stream, "feed", osEntitySet);
|
||||||
} else {
|
} else {
|
||||||
namespaces = null;
|
namespaces = null;
|
||||||
try {
|
try {
|
||||||
if (consume(stream, "\"value\":", osFeed, true) >= 0) {
|
if (consume(stream, "\"value\":", osEntitySet, true) >= 0) {
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while (c != '[' && (c = stream.read()) >= 0) {
|
while (c != '[' && (c = stream.read()) >= 0) {
|
||||||
osFeed.write(c);
|
osEntitySet.write(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Error parsing feed", e);
|
LOG.error("Error parsing entity set", e);
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,15 +113,15 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
if (available && cached == null) {
|
if (available && cached == null) {
|
||||||
if (format == ODataPubFormat.ATOM) {
|
if (format == ODataPubFormat.ATOM) {
|
||||||
cached = nextAtomEntryFromFeed(stream, osFeed, namespaces);
|
cached = nextAtomEntityFromEntitySet(stream, osEntitySet, namespaces);
|
||||||
} else {
|
} else {
|
||||||
cached = nextJsonEntryFromFeed(stream, osFeed);
|
cached = nextJSONEntityFromEntitySet(stream, osEntitySet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cached == null) {
|
if (cached == null) {
|
||||||
available = false;
|
available = false;
|
||||||
entitySet = (ES) odataClient.getReader().
|
entitySet = (ES) odataClient.getReader().
|
||||||
readEntitySet(new ByteArrayInputStream(osFeed.toByteArray()), format);
|
readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), format);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
IOUtils.closeQuietly(stream);
|
IOUtils.closeQuietly(stream);
|
||||||
IOUtils.closeQuietly(osFeed);
|
IOUtils.closeQuietly(osEntitySet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,10 +172,10 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
|
||||||
return entitySet.getNext();
|
return entitySet.getNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResWrap<Entry> nextJsonEntryFromFeed(final InputStream input, final OutputStream osFeed) {
|
private ResWrap<Entity> nextJSONEntityFromEntitySet(final InputStream input, final OutputStream osEntitySet) {
|
||||||
final ByteArrayOutputStream entry = new ByteArrayOutputStream();
|
final ByteArrayOutputStream entity = new ByteArrayOutputStream();
|
||||||
|
|
||||||
ResWrap<Entry> jsonEntry = null;
|
ResWrap<Entity> jsonEntity = null;
|
||||||
try {
|
try {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
@ -184,12 +184,12 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
|
||||||
do {
|
do {
|
||||||
c = input.read();
|
c = input.read();
|
||||||
if (c == '{') {
|
if (c == '{') {
|
||||||
entry.write(c);
|
entity.write(c);
|
||||||
c = -1;
|
c = -1;
|
||||||
foundNewOne = true;
|
foundNewOne = true;
|
||||||
}
|
}
|
||||||
if (c == ']') {
|
if (c == ']') {
|
||||||
osFeed.write(c);
|
osEntitySet.write(c);
|
||||||
c = -1;
|
c = -1;
|
||||||
}
|
}
|
||||||
} while (c >= 0);
|
} while (c >= 0);
|
||||||
|
@ -205,55 +205,48 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
|
||||||
} else if (c == '}') {
|
} else if (c == '}') {
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
entry.write(c);
|
entity.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c >= 0) {
|
if (c >= 0) {
|
||||||
jsonEntry = odataClient.getDeserializer().toEntry(
|
jsonEntity = odataClient.getDeserializer().toEntity(
|
||||||
new ByteArrayInputStream(entry.toByteArray()), ODataPubFormat.JSON);
|
new ByteArrayInputStream(entity.toByteArray()), ODataPubFormat.JSON);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while ((c = input.read()) >= 0) {
|
while ((c = input.read()) >= 0) {
|
||||||
osFeed.write(c);
|
osEntitySet.write(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error retrieving entities from EntitySet", e);
|
LOG.error("Error retrieving entities from EntitySet", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonEntry;
|
return jsonEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private ResWrap<Entity> nextAtomEntityFromEntitySet(
|
||||||
* De-Serializes a stream into an OData entity set.
|
final InputStream input, final OutputStream osEntitySet, final String namespaces) {
|
||||||
*
|
|
||||||
* @param input stream to de-serialize.
|
|
||||||
* @param format de-serialize as AtomFeed or JSONFeed
|
|
||||||
* @return de-serialized entity set.
|
|
||||||
*/
|
|
||||||
private ResWrap<Entry> nextAtomEntryFromFeed(
|
|
||||||
final InputStream input, final OutputStream osFeed, final String namespaces) {
|
|
||||||
|
|
||||||
final ByteArrayOutputStream entry = new ByteArrayOutputStream();
|
final ByteArrayOutputStream entity = new ByteArrayOutputStream();
|
||||||
|
|
||||||
ResWrap<Entry> atomEntry = null;
|
ResWrap<Entity> atomEntity = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (consume(input, "<entry>", osFeed, false) >= 0) {
|
if (consume(input, "<entry>", osEntitySet, false) >= 0) {
|
||||||
entry.write("<entry ".getBytes(Constants.UTF8));
|
entity.write("<entry ".getBytes(Constants.UTF8));
|
||||||
entry.write(namespaces.getBytes(Constants.UTF8));
|
entity.write(namespaces.getBytes(Constants.UTF8));
|
||||||
entry.write(">".getBytes(Constants.UTF8));
|
entity.write(">".getBytes(Constants.UTF8));
|
||||||
|
|
||||||
if (consume(input, "</entry>", entry, true) >= 0) {
|
if (consume(input, "</entry>", entity, true) >= 0) {
|
||||||
atomEntry = odataClient.getDeserializer().
|
atomEntity = odataClient.getDeserializer().
|
||||||
toEntry(new ByteArrayInputStream(entry.toByteArray()), ODataPubFormat.ATOM);
|
toEntity(new ByteArrayInputStream(entity.toByteArray()), ODataPubFormat.ATOM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error retrieving entities from EntitySet", 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) {
|
private String getAllElementAttributes(final InputStream input, final String name, final OutputStream os) {
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
package org.apache.olingo.client.api.op;
|
package org.apache.olingo.client.api.op;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.client.api.data.ServiceDocument;
|
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 {
|
public interface CommonODataBinder extends Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a <tt>Feed</tt> from the given OData entity set.
|
* Gets a <tt>EntitySet</tt> from the given OData entity set.
|
||||||
*
|
*
|
||||||
* @param feed OData entity set.
|
* @param entitySet OData entity set.
|
||||||
* @param reference reference class.
|
* @param reference reference class.
|
||||||
* @return <tt>Feed</tt> object.
|
* @return {@link EntitySet} object.
|
||||||
*/
|
*/
|
||||||
Feed getFeed(CommonODataEntitySet feed, Class<? extends Feed> reference);
|
EntitySet getEntitySet(CommonODataEntitySet entitySet, Class<? extends EntitySet> reference);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an <tt>Entry</tt> from the given OData entity.
|
* Gets an <tt>Entity</tt> from the given OData entity.
|
||||||
*
|
*
|
||||||
* @param entity OData entity.
|
* @param entity OData entity.
|
||||||
* @param reference reference class.
|
* @param reference reference class.
|
||||||
* @return <tt>Entry</tt> object.
|
* @return {@link Entity} object.
|
||||||
*/
|
*/
|
||||||
Entry getEntry(CommonODataEntity entity, Class<? extends Entry> reference);
|
Entity getEntity(CommonODataEntity entity, Class<? extends Entity> reference);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a <tt>Link</tt> from the given OData link.
|
* Gets a <tt>Link</tt> from the given OData link.
|
||||||
|
@ -67,7 +67,7 @@ public interface CommonODataBinder extends Serializable {
|
||||||
* @param reference reference class.
|
* @param reference reference class.
|
||||||
* @return <tt>Property</tt> object.
|
* @return <tt>Property</tt> object.
|
||||||
*/
|
*/
|
||||||
Property getProperty(CommonODataProperty property, Class<? extends Entry> reference);
|
Property getProperty(CommonODataProperty property, Class<? extends Entity> reference);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given property to the given entity.
|
* Adds the given property to the given entity.
|
||||||
|
@ -87,20 +87,20 @@ public interface CommonODataBinder extends Serializable {
|
||||||
ODataServiceDocument getODataServiceDocument(ServiceDocument resource);
|
ODataServiceDocument getODataServiceDocument(ServiceDocument resource);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets <tt>ODataEntitySet</tt> from the given feed resource.
|
* Gets <tt>ODataEntitySet</tt> from the given entity set resource.
|
||||||
*
|
*
|
||||||
* @param resource feed resource.
|
* @param resource entity set resource.
|
||||||
* @return {@link CommonODataEntitySet} object.
|
* @return {@link CommonODataEntitySet} object.
|
||||||
*/
|
*/
|
||||||
CommonODataEntitySet getODataEntitySet(ResWrap<Feed> resource);
|
CommonODataEntitySet getODataEntitySet(ResWrap<EntitySet> resource);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets <tt>ODataEntity</tt> from the given entry resource.
|
* Gets <tt>ODataEntity</tt> from the given entity resource.
|
||||||
*
|
*
|
||||||
* @param resource entry resource.
|
* @param resource entity resource.
|
||||||
* @return {@link CommonODataEntity} object.
|
* @return {@link CommonODataEntity} object.
|
||||||
*/
|
*/
|
||||||
CommonODataEntity getODataEntity(ResWrap<Entry> resource);
|
CommonODataEntity getODataEntity(ResWrap<Entity> resource);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an <tt>ODataProperty</tt> from the given property resource.
|
* Gets an <tt>ODataProperty</tt> from the given property resource.
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
* <br/>
|
* <br/>
|
||||||
* Use this class to de-serialize an OData response body.
|
* Use this class to de-serialize an OData response body.
|
||||||
* <br/>
|
* <br/>
|
||||||
* 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 {
|
public interface CommonODataReader extends Serializable {
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public interface CommonODataReader extends Serializable {
|
||||||
* De-Serializes a stream into an OData entity set.
|
* De-Serializes a stream into an OData entity set.
|
||||||
*
|
*
|
||||||
* @param input stream to de-serialize.
|
* @param input stream to de-serialize.
|
||||||
* @param format de-serialize as AtomFeed or JSONFeed
|
* @param format de-serialize format
|
||||||
* @return de-serialized entity set.
|
* @return de-serialized entity set.
|
||||||
*/
|
*/
|
||||||
CommonODataEntitySet readEntitySet(InputStream input, ODataPubFormat format);
|
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.
|
* Parses a stream taking care to de-serializes the first OData entity found.
|
||||||
*
|
*
|
||||||
* @param input stream to de-serialize.
|
* @param input stream to de-serialize.
|
||||||
* @param format de-serialize as AtomEntry or JSONEntry
|
* @param format de-serialize format
|
||||||
* @return entity de-serialized.
|
* @return entity de-serialized.
|
||||||
*/
|
*/
|
||||||
CommonODataEntity readEntity(InputStream input, ODataPubFormat format);
|
CommonODataEntity readEntity(InputStream input, ODataPubFormat format);
|
||||||
|
|
|
@ -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.commons.api.data.v3.LinkCollection;
|
||||||
import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
|
import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
|
||||||
import org.apache.olingo.client.api.op.CommonODataBinder;
|
import org.apache.olingo.client.api.op.CommonODataBinder;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.ODataEntity;
|
||||||
|
@ -32,10 +32,10 @@ import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||||
public interface ODataBinder extends CommonODataBinder {
|
public interface ODataBinder extends CommonODataBinder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ODataEntitySet getODataEntitySet(ResWrap<Feed> resource);
|
ODataEntitySet getODataEntitySet(ResWrap<EntitySet> resource);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ODataEntity getODataEntity(ResWrap<Entry> resource);
|
ODataEntity getODataEntity(ResWrap<Entity> resource);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ODataProperty getODataProperty(ResWrap<Property> resource);
|
ODataProperty getODataProperty(ResWrap<Property> resource);
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
package org.apache.olingo.client.api.op.v4;
|
package org.apache.olingo.client.api.op.v4;
|
||||||
|
|
||||||
import org.apache.olingo.client.api.op.CommonODataBinder;
|
import org.apache.olingo.client.api.op.CommonODataBinder;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.ODataEntity;
|
||||||
|
@ -30,10 +30,10 @@ import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||||
public interface ODataBinder extends CommonODataBinder {
|
public interface ODataBinder extends CommonODataBinder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ODataEntitySet getODataEntitySet(ResWrap<Feed> resource);
|
ODataEntitySet getODataEntitySet(ResWrap<EntitySet> resource);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ODataEntity getODataEntity(ResWrap<Entry> resource);
|
ODataEntity getODataEntity(ResWrap<Entity> resource);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ODataProperty getODataProperty(ResWrap<Property> resource);
|
ODataProperty getODataProperty(ResWrap<Property> resource);
|
||||||
|
|
|
@ -22,10 +22,21 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata;
|
import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata;
|
||||||
import org.apache.olingo.client.api.op.ClientODataDeserializer;
|
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 {
|
public interface ODataDeserializer extends ClientODataDeserializer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
XMLMetadata toMetadata(InputStream input);
|
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<Delta> toDelta(InputStream input, ODataPubFormat format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.request.AbstractODataBasicRequest;
|
||||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.
|
* This class implements an OData create request.
|
||||||
|
@ -119,8 +119,8 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
|
||||||
public E getBody() {
|
public E getBody() {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
try {
|
try {
|
||||||
final ResWrap<Entry> resource = odataClient.getDeserializer().
|
final ResWrap<Entity> resource = odataClient.getDeserializer().
|
||||||
toEntry(getRawResponse(), ODataPubFormat.fromString(getAccept()));
|
toEntity(getRawResponse(), ODataPubFormat.fromString(getAccept()));
|
||||||
|
|
||||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -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.request.AbstractODataBasicRequest;
|
||||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.
|
* This class implements an OData update request.
|
||||||
|
@ -124,8 +124,8 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
|
||||||
public E getBody() {
|
public E getBody() {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
try {
|
try {
|
||||||
final ResWrap<Entry> resource = odataClient.getDeserializer().
|
final ResWrap<Entity> resource = odataClient.getDeserializer().
|
||||||
toEntry(getRawResponse(), ODataPubFormat.fromString(getAccept()));
|
toEntity(getRawResponse(), ODataPubFormat.fromString(getAccept()));
|
||||||
|
|
||||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -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.request.retrieve.ODataEntityRequest;
|
||||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.domain.CommonODataEntity;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
|
|
||||||
|
@ -81,8 +81,8 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
|
||||||
public E getBody() {
|
public E getBody() {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
try {
|
try {
|
||||||
final ResWrap<Entry> resource = odataClient.getDeserializer().
|
final ResWrap<Entity> resource = odataClient.getDeserializer().
|
||||||
toEntry(getRawResponse(), ODataPubFormat.fromString(getContentType()));
|
toEntity(getRawResponse(), ODataPubFormat.fromString(getContentType()));
|
||||||
|
|
||||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class ODataEntitySetIteratorRequestImpl<ES extends CommonODataEntitySet,
|
||||||
extends AbstractODataRetrieveRequest<ODataEntitySetIterator<ES, E>, ODataPubFormat>
|
extends AbstractODataRetrieveRequest<ODataEntitySetIterator<ES, E>, ODataPubFormat>
|
||||||
implements ODataEntitySetIteratorRequest<ES, E> {
|
implements ODataEntitySetIteratorRequest<ES, E> {
|
||||||
|
|
||||||
private ODataEntitySetIterator feedIterator = null;
|
private ODataEntitySetIterator entitySetIterator = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private constructor.
|
* Private constructor.
|
||||||
|
@ -44,7 +44,7 @@ public class ODataEntitySetIteratorRequestImpl<ES extends CommonODataEntitySet,
|
||||||
* @param odataClient client instance getting this request
|
* @param odataClient client instance getting this request
|
||||||
* @param query query to be executed.
|
* @param query query to be executed.
|
||||||
*/
|
*/
|
||||||
public ODataEntitySetIteratorRequestImpl(final CommonODataClient odataClient, final URI query) {
|
public ODataEntitySetIteratorRequestImpl(final CommonODataClient<?> odataClient, final URI query) {
|
||||||
super(odataClient, ODataPubFormat.class, query);
|
super(odataClient, ODataPubFormat.class, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +78,11 @@ public class ODataEntitySetIteratorRequestImpl<ES extends CommonODataEntitySet,
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public ODataEntitySetIterator<ES, E> getBody() {
|
public ODataEntitySetIterator<ES, E> getBody() {
|
||||||
if (feedIterator == null) {
|
if (entitySetIterator == null) {
|
||||||
feedIterator = new ODataEntitySetIterator<ES, E>(
|
entitySetIterator = new ODataEntitySetIterator<ES, E>(
|
||||||
odataClient, getRawResponse(), ODataPubFormat.fromString(getContentType()));
|
odataClient, getRawResponse(), ODataPubFormat.fromString(getContentType()));
|
||||||
}
|
}
|
||||||
return feedIterator;
|
return entitySetIterator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.request.retrieve.ODataEntitySetRequest;
|
||||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.domain.CommonODataEntitySet;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
|
||||||
public ES getBody() {
|
public ES getBody() {
|
||||||
if (entitySet == null) {
|
if (entitySet == null) {
|
||||||
try {
|
try {
|
||||||
final ResWrap<Feed> resource = odataClient.getDeserializer().
|
final ResWrap<EntitySet> resource = odataClient.getDeserializer().
|
||||||
toFeed(getRawResponse(), ODataPubFormat.fromString(getContentType()));
|
toEntitySet(getRawResponse(), ODataPubFormat.fromString(getContentType()));
|
||||||
|
|
||||||
entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);
|
entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -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.request.AbstractODataStreamManager;
|
||||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.
|
* This class implements an OData Media Entity create request. Get instance by using ODataStreamedRequestFactory.
|
||||||
|
@ -123,7 +123,7 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
|
||||||
public E getBody() {
|
public E getBody() {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
try {
|
try {
|
||||||
final ResWrap<Entry> resource = odataClient.getDeserializer().toEntry(getRawResponse(), getFormat());
|
final ResWrap<Entity> resource = odataClient.getDeserializer().toEntity(getRawResponse(), getFormat());
|
||||||
|
|
||||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -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.request.AbstractODataStreamManager;
|
||||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.
|
* This class implements an OData Media Entity create request. Get instance by using ODataStreamedRequestFactory.
|
||||||
|
@ -122,7 +122,7 @@ public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
|
||||||
public E getBody() {
|
public E getBody() {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
try {
|
try {
|
||||||
final ResWrap<Entry> resource = odataClient.getDeserializer().toEntry(getRawResponse(), getFormat());
|
final ResWrap<Entity> resource = odataClient.getDeserializer().toEntity(getRawResponse(), getFormat());
|
||||||
|
|
||||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -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.communication.response.ODataResponse;
|
||||||
import org.apache.olingo.client.api.v4.ODataClient;
|
import org.apache.olingo.client.api.v4.ODataClient;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public class AsyncRequestFactoryImpl implements AsyncRequestFactory {
|
public class AsyncRequestFactoryImpl implements AsyncRequestFactory {
|
||||||
|
|
||||||
private static final long serialVersionUID = 546577958047902917L;
|
private static final long serialVersionUID = 546577958047902917L;
|
||||||
|
|
||||||
protected final ODataClient client;
|
private final ODataClient client;
|
||||||
|
|
||||||
public AsyncRequestFactoryImpl(final ODataClient client) {
|
public AsyncRequestFactoryImpl(final ODataClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
|
@ -30,8 +30,8 @@ import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
|
||||||
import org.apache.olingo.client.core.uri.URIUtils;
|
import org.apache.olingo.client.core.uri.URIUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.ContextURL;
|
import org.apache.olingo.commons.api.data.ContextURL;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Linked;
|
import org.apache.olingo.commons.api.data.Linked;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
|
@ -105,33 +105,33 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Feed getFeed(final CommonODataEntitySet entitySet, final Class<? extends Feed> reference) {
|
public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet, final Class<? extends EntitySet> reference) {
|
||||||
final Feed feed = ResourceFactory.newFeed(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) {
|
if (next != null) {
|
||||||
feed.setNext(next);
|
entitySet.setNext(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CommonODataEntity entity : entitySet.getEntities()) {
|
for (CommonODataEntity entity : odataEntitySet.getEntities()) {
|
||||||
feed.getEntries().add(getEntry(entity, ResourceFactory.entryClassForFeed(reference)));
|
entitySet.getEntities().add(getEntity(entity, ResourceFactory.entityClassForEntitySet(reference)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return feed;
|
return entitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void links(final ODataLinked odataLinked, final Linked linked, final Class<? extends Entry> reference) {
|
protected void links(final ODataLinked odataLinked, final Linked linked, final Class<? extends Entity> reference) {
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// Append navigation links (handling inline entry / feed as well)
|
// Append navigation links (handling inline entity / entity set as well)
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// handle navigation links
|
// handle navigation links
|
||||||
for (ODataLink link : odataLinked.getNavigationLinks()) {
|
for (ODataLink link : odataLinked.getNavigationLinks()) {
|
||||||
// append link
|
// append link
|
||||||
LOG.debug("Append navigation link\n{}", link);
|
LOG.debug("Append navigation link\n{}", link);
|
||||||
linked.getNavigationLinks().add(getLink(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()) {
|
for (ODataLink link : odataLinked.getAssociationLinks()) {
|
||||||
LOG.debug("Append association link\n{}", link);
|
LOG.debug("Append association link\n{}", link);
|
||||||
linked.getAssociationLinks().add(getLink(link,
|
linked.getAssociationLinks().add(getLink(link,
|
||||||
ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
|
ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM));
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entry getEntry(final CommonODataEntity entity, final Class<? extends Entry> reference) {
|
public Entity getEntity(final CommonODataEntity odataEntity, final Class<? extends Entity> reference) {
|
||||||
final Entry entry = ResourceFactory.newEntry(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
|
// Add edit and self link
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
final URI editLink = entity.getEditLink();
|
final URI odataEditLink = odataEntity.getEditLink();
|
||||||
if (editLink != null) {
|
if (odataEditLink != null) {
|
||||||
final LinkImpl entryEditLink = new LinkImpl();
|
final LinkImpl editLink = new LinkImpl();
|
||||||
entryEditLink.setTitle(entry.getType());
|
editLink.setTitle(entity.getType());
|
||||||
entryEditLink.setHref(editLink.toASCIIString());
|
editLink.setHref(odataEditLink.toASCIIString());
|
||||||
entryEditLink.setRel(Constants.EDIT_LINK_REL);
|
editLink.setRel(Constants.EDIT_LINK_REL);
|
||||||
entry.setEditLink(entryEditLink);
|
entity.setEditLink(editLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.isReadOnly()) {
|
if (odataEntity.isReadOnly()) {
|
||||||
final LinkImpl entrySelfLink = new LinkImpl();
|
final LinkImpl selfLink = new LinkImpl();
|
||||||
entrySelfLink.setTitle(entry.getType());
|
selfLink.setTitle(entity.getType());
|
||||||
entrySelfLink.setHref(entity.getLink().toASCIIString());
|
selfLink.setHref(odataEntity.getLink().toASCIIString());
|
||||||
entrySelfLink.setRel(Constants.SELF_LINK_REL);
|
selfLink.setRel(Constants.SELF_LINK_REL);
|
||||||
entry.setSelfLink(entrySelfLink);
|
entity.setSelfLink(selfLink);
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
links(entity, entry, reference);
|
links(odataEntity, entity, reference);
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// Append edit-media links
|
// Append edit-media links
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
for (ODataLink link : entity.getEditMediaLinks()) {
|
for (ODataLink link : odataEntity.getEditMediaLinks()) {
|
||||||
LOG.debug("Append edit-media link\n{}", link);
|
LOG.debug("Append edit-media link\n{}", link);
|
||||||
entry.getMediaEditLinks().add(getLink(link,
|
entity.getMediaEditLinks().add(getLink(link,
|
||||||
ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
|
ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM));
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
if (entity.isMediaEntity()) {
|
if (odataEntity.isMediaEntity()) {
|
||||||
entry.setMediaContentSource(entity.getMediaContentSource());
|
entity.setMediaContentSource(odataEntity.getMediaContentSource());
|
||||||
entry.setMediaContentType(entity.getMediaContentType());
|
entity.setMediaContentType(odataEntity.getMediaContentType());
|
||||||
entry.setMediaETag(entity.getMediaETag());
|
entity.setMediaETag(odataEntity.getMediaETag());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CommonODataProperty property : entity.getProperties()) {
|
for (CommonODataProperty property : odataEntity.getProperties()) {
|
||||||
entry.getProperties().add(getProperty(property, reference));
|
entity.getProperties().add(getProperty(property, reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -212,19 +212,19 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||||
final CommonODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
|
final CommonODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
|
||||||
LOG.debug("Append in-line entity\n{}", inlineEntity);
|
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) {
|
} else if (link instanceof ODataInlineEntitySet) {
|
||||||
// append inline feed
|
// append inline entity set
|
||||||
final CommonODataEntitySet InlineFeed = ((ODataInlineEntitySet) link).getEntitySet();
|
final CommonODataEntitySet InlineEntitySet = ((ODataInlineEntitySet) link).getEntitySet();
|
||||||
LOG.debug("Append in-line feed\n{}", InlineFeed);
|
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;
|
return linkResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Value getValue(final ODataValue value, final Class<? extends Entry> reference) {
|
protected Value getValue(final ODataValue value, final Class<? extends Entity> reference) {
|
||||||
Value valueResource = null;
|
Value valueResource = null;
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
@ -255,12 +255,12 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||||
protected abstract boolean add(CommonODataEntitySet entitySet, CommonODataEntity entity);
|
protected abstract boolean add(CommonODataEntitySet entitySet, CommonODataEntity entity);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonODataEntitySet getODataEntitySet(final ResWrap<Feed> resource) {
|
public CommonODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
client.getSerializer().feed(resource.getPayload(), writer);
|
client.getSerializer().entitySet(resource.getPayload(), writer);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
LOG.debug("Feed -> ODataEntitySet:\n{}", writer.toString());
|
LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
final URI base = resource.getContextURL() == null
|
final URI base = resource.getContextURL() == null
|
||||||
|
@ -276,9 +276,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||||
entitySet.setCount(resource.getPayload().getCount());
|
entitySet.setCount(resource.getPayload().getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry entryResource : resource.getPayload().getEntries()) {
|
for (Entity entityResource : resource.getPayload().getEntities()) {
|
||||||
add(entitySet, getODataEntity(
|
add(entitySet, getODataEntity(
|
||||||
new ResWrap<Entry>(resource.getContextURL(), resource.getMetadataETag(), entryResource)));
|
new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return entitySet;
|
return entitySet;
|
||||||
|
@ -288,10 +288,10 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||||
final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) {
|
final Linked linked, final ODataLinked odataLinked, final String metadataETag, final URI base) {
|
||||||
|
|
||||||
for (Link link : linked.getNavigationLinks()) {
|
for (Link link : linked.getNavigationLinks()) {
|
||||||
final Entry inlineEntry = link.getInlineEntry();
|
final Entity inlineEntity = link.getInlineEntity();
|
||||||
final Feed inlineFeed = link.getInlineFeed();
|
final EntitySet inlineEntitySet = link.getInlineEntitySet();
|
||||||
|
|
||||||
if (inlineEntry == null && inlineFeed == null) {
|
if (inlineEntity == null && inlineEntitySet == null) {
|
||||||
ODataLinkType linkType = null;
|
ODataLinkType linkType = null;
|
||||||
if (edmType != null) {
|
if (edmType != null) {
|
||||||
final EdmNavigationProperty navProp = edmType.getNavigationProperty(link.getTitle());
|
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()))
|
newEntityNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref()))
|
||||||
: client.getObjectFactory().
|
: client.getObjectFactory().
|
||||||
newEntitySetNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
|
newEntitySetNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
|
||||||
} else if (inlineEntry != null) {
|
} else if (inlineEntity != null) {
|
||||||
odataLinked.addLink(new ODataInlineEntity(client.getServiceVersion(),
|
odataLinked.addLink(new ODataInlineEntity(client.getServiceVersion(),
|
||||||
URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_NAVIGATION, link.getTitle(),
|
URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_NAVIGATION, link.getTitle(),
|
||||||
getODataEntity(new ResWrap<Entry>(
|
getODataEntity(new ResWrap<Entity>(
|
||||||
inlineEntry.getBaseURI() == null ? base : inlineEntry.getBaseURI(),
|
inlineEntity.getBaseURI() == null ? base : inlineEntity.getBaseURI(),
|
||||||
metadataETag,
|
metadataETag,
|
||||||
inlineEntry))));
|
inlineEntity))));
|
||||||
} else {
|
} else {
|
||||||
odataLinked.addLink(new ODataInlineEntitySet(client.getServiceVersion(),
|
odataLinked.addLink(new ODataInlineEntitySet(client.getServiceVersion(),
|
||||||
URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_SET_NAVIGATION, link.getTitle(),
|
URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_SET_NAVIGATION, link.getTitle(),
|
||||||
getODataEntitySet(new ResWrap<Feed>(
|
getODataEntitySet(new ResWrap<EntitySet>(
|
||||||
inlineFeed.getBaseURI() == null ? base : inlineFeed.getBaseURI(),
|
inlineEntitySet.getBaseURI() == null ? base : inlineEntitySet.getBaseURI(),
|
||||||
metadataETag,
|
metadataETag,
|
||||||
inlineFeed))));
|
inlineEntitySet))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,12 +374,12 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonODataEntity getODataEntity(final ResWrap<Entry> resource) {
|
public CommonODataEntity getODataEntity(final ResWrap<Entity> resource) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
client.getSerializer().entry(resource.getPayload(), writer);
|
client.getSerializer().entity(resource.getPayload(), writer);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
LOG.debug("EntryResource -> ODataEntity:\n{}", writer.toString());
|
LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
final URI base = resource.getContextURL() == null
|
final URI base = resource.getContextURL() == null
|
||||||
|
@ -428,7 +428,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
|
||||||
entity.getOperations().add(operation);
|
entity.getOperations().add(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resource.getPayload().isMediaEntry()) {
|
if (resource.getPayload().isMediaEntity()) {
|
||||||
entity.setMediaEntity(true);
|
entity.setMediaEntity(true);
|
||||||
entity.setMediaContentSource(resource.getPayload().getMediaContentSource());
|
entity.setMediaContentSource(resource.getPayload().getMediaContentSource());
|
||||||
entity.setMediaContentType(resource.getPayload().getMediaContentType());
|
entity.setMediaContentType(resource.getPayload().getMediaContentType());
|
||||||
|
|
|
@ -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.api.op.CommonODataReader;
|
||||||
import org.apache.olingo.client.core.edm.EdmClientImpl;
|
import org.apache.olingo.client.core.edm.EdmClientImpl;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
|
@ -96,13 +96,14 @@ public abstract class AbstractODataReader implements CommonODataReader {
|
||||||
reference.cast(new ODataEntitySetIterator<CommonODataEntitySet, CommonODataEntity>(
|
reference.cast(new ODataEntitySetIterator<CommonODataEntitySet, CommonODataEntity>(
|
||||||
client, src, ODataPubFormat.fromString(format))));
|
client, src, ODataPubFormat.fromString(format))));
|
||||||
} else if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
|
} else if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
|
||||||
final ResWrap<Feed> resource = client.getDeserializer().toFeed(src, ODataPubFormat.fromString(format));
|
final ResWrap<EntitySet> resource = client.getDeserializer().
|
||||||
|
toEntitySet(src, ODataPubFormat.fromString(format));
|
||||||
res = new ResWrap<T>(
|
res = new ResWrap<T>(
|
||||||
resource.getContextURL(),
|
resource.getContextURL(),
|
||||||
resource.getMetadataETag(),
|
resource.getMetadataETag(),
|
||||||
reference.cast(client.getBinder().getODataEntitySet(resource)));
|
reference.cast(client.getBinder().getODataEntitySet(resource)));
|
||||||
} else if (CommonODataEntity.class.isAssignableFrom(reference)) {
|
} else if (CommonODataEntity.class.isAssignableFrom(reference)) {
|
||||||
final ResWrap<Entry> container = client.getDeserializer().toEntry(src, ODataPubFormat.fromString(format));
|
final ResWrap<Entity> container = client.getDeserializer().toEntity(src, ODataPubFormat.fromString(format));
|
||||||
res = new ResWrap<T>(
|
res = new ResWrap<T>(
|
||||||
container.getContextURL(),
|
container.getContextURL(),
|
||||||
container.getMetadataETag(),
|
container.getMetadataETag(),
|
||||||
|
|
|
@ -48,8 +48,8 @@ public class ODataWriterImpl implements ODataWriter {
|
||||||
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
for (CommonODataEntity entity : entities) {
|
for (CommonODataEntity entity : entities) {
|
||||||
client.getSerializer().entry(client.getBinder().getEntry(
|
client.getSerializer().entity(client.getBinder().getEntity(
|
||||||
entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)), output);
|
entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ByteArrayInputStream(output.toByteArray());
|
return new ByteArrayInputStream(output.toByteArray());
|
||||||
|
@ -68,7 +68,7 @@ public class ODataWriterImpl implements ODataWriter {
|
||||||
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
final ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
client.getSerializer().property(client.getBinder().getProperty(
|
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());
|
return new ByteArrayInputStream(output.toByteArray());
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -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.api.op.v3.ODataBinder;
|
||||||
import org.apache.olingo.client.core.op.AbstractODataBinder;
|
import org.apache.olingo.client.core.op.AbstractODataBinder;
|
||||||
import org.apache.olingo.client.core.v3.ODataClientImpl;
|
import org.apache.olingo.client.core.v3.ODataClientImpl;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.data.v3.LinkCollection;
|
import org.apache.olingo.commons.api.data.v3.LinkCollection;
|
||||||
|
@ -55,7 +55,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Property getProperty(final CommonODataProperty property, final Class<? extends Entry> reference) {
|
public Property getProperty(final CommonODataProperty property, final Class<? extends Entity> reference) {
|
||||||
final Property propertyResource = ResourceFactory.newProperty(reference);
|
final Property propertyResource = ResourceFactory.newProperty(reference);
|
||||||
propertyResource.setName(property.getName());
|
propertyResource.setName(property.getName());
|
||||||
propertyResource.setValue(getValue(property.getValue(), reference));
|
propertyResource.setValue(getValue(property.getValue(), reference));
|
||||||
|
@ -72,12 +72,12 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataEntitySet getODataEntitySet(final ResWrap<Feed> resource) {
|
public ODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
|
||||||
return (ODataEntitySet) super.getODataEntitySet(resource);
|
return (ODataEntitySet) super.getODataEntitySet(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataEntity getODataEntity(final ResWrap<Entry> resource) {
|
public ODataEntity getODataEntity(final ResWrap<Entity> resource) {
|
||||||
return (ODataEntity) super.getODataEntity(resource);
|
return (ODataEntity) super.getODataEntity(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,12 @@ public class ODataReaderImpl extends AbstractODataReader implements ODataReader
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
|
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
|
@Override
|
||||||
public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
|
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
|
@Override
|
||||||
|
|
|
@ -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.api.v4.ODataClient;
|
||||||
import org.apache.olingo.client.core.op.AbstractODataBinder;
|
import org.apache.olingo.client.core.op.AbstractODataBinder;
|
||||||
import org.apache.olingo.client.core.uri.URIUtils;
|
import org.apache.olingo.client.core.uri.URIUtils;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
|
@ -89,14 +89,14 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entry getEntry(final CommonODataEntity entity, final Class<? extends Entry> reference) {
|
public Entity getEntity(final CommonODataEntity odataEntity, final Class<? extends Entity> reference) {
|
||||||
final Entry entry = super.getEntry(entity, reference);
|
final Entity entity = super.getEntity(odataEntity, reference);
|
||||||
entry.setId(((ODataEntity) entity).getReference());
|
entity.setId(((ODataEntity) odataEntity).getReference());
|
||||||
return entry;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Property getProperty(final CommonODataProperty property, final Class<? extends Entry> reference) {
|
public Property getProperty(final CommonODataProperty property, final Class<? extends Entity> reference) {
|
||||||
final ODataProperty _property = (ODataProperty) property;
|
final ODataProperty _property = (ODataProperty) property;
|
||||||
|
|
||||||
final Property propertyResource = ResourceFactory.newProperty(reference);
|
final Property propertyResource = ResourceFactory.newProperty(reference);
|
||||||
|
@ -117,7 +117,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Value getValue(final ODataValue value, final Class<? extends Entry> reference) {
|
protected Value getValue(final ODataValue value, final Class<? extends Entity> reference) {
|
||||||
Value valueResource;
|
Value valueResource;
|
||||||
if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue
|
if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue
|
||||||
&& ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isEnum()) {
|
&& ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isEnum()) {
|
||||||
|
@ -144,12 +144,12 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataEntitySet getODataEntitySet(final ResWrap<Feed> resource) {
|
public ODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
|
||||||
return (ODataEntitySet) super.getODataEntitySet(resource);
|
return (ODataEntitySet) super.getODataEntitySet(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataEntity getODataEntity(final ResWrap<Entry> resource) {
|
public ODataEntity getODataEntity(final ResWrap<Entity> resource) {
|
||||||
final ODataEntity entity = (ODataEntity) super.getODataEntity(resource);
|
final ODataEntity entity = (ODataEntity) super.getODataEntity(resource);
|
||||||
entity.setReference(resource.getPayload().getId());
|
entity.setReference(resource.getPayload().getId());
|
||||||
return entity;
|
return entity;
|
||||||
|
|
|
@ -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.data.v4.XMLServiceDocumentImpl;
|
||||||
import org.apache.olingo.client.core.edm.xml.v4.EdmxImpl;
|
import org.apache.olingo.client.core.edm.xml.v4.EdmxImpl;
|
||||||
import org.apache.olingo.client.core.edm.xml.v4.XMLMetadataImpl;
|
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.api.data.ResWrap;
|
||||||
import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
|
import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
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 {
|
public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer {
|
||||||
|
|
||||||
|
@ -56,4 +60,12 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer implements
|
||||||
: this.<ServiceDocument, JSONServiceDocumentImpl>json(input, JSONServiceDocumentImpl.class);
|
: this.<ServiceDocument, JSONServiceDocumentImpl>json(input, JSONServiceDocumentImpl.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResWrap<Delta> toDelta(final InputStream input, final ODataPubFormat format) {
|
||||||
|
return format == ODataPubFormat.ATOM
|
||||||
|
? this.<Delta, AtomDeltaImpl>atom(input, AtomDeltaImpl.class)
|
||||||
|
: this.<Delta, JSONDeltaImpl>json(input, JSONDeltaImpl.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,12 +38,12 @@ public class ODataReaderImpl extends AbstractODataReader implements ODataReader
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
|
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
|
@Override
|
||||||
public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
|
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
|
@Override
|
||||||
|
|
|
@ -23,13 +23,13 @@ import java.io.InputStream;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.olingo.client.api.CommonODataClient;
|
import org.apache.olingo.client.api.CommonODataClient;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||||
import org.apache.olingo.commons.api.domain.ODataValue;
|
import org.apache.olingo.commons.api.domain.ODataValue;
|
||||||
import org.apache.olingo.commons.core.data.AtomEntryImpl;
|
import org.apache.olingo.commons.core.data.AtomEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONEntryImpl;
|
import org.apache.olingo.commons.core.data.JSONEntityImpl;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -43,19 +43,19 @@ public abstract class AbstractBaseTestITCase {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
protected abstract CommonODataClient getClient();
|
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()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
getClient().getSerializer().entry(entry, writer);
|
getClient().getSerializer().entity(entity, writer);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
LOG.debug(message + "\n{}", writer.toString());
|
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()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
getClient().getSerializer().feed(feed, writer);
|
getClient().getSerializer().entitySet(entitySet, writer);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
LOG.debug(message + "\n{}", writer.toString());
|
LOG.debug(message + "\n{}", writer.toString());
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ public abstract class AbstractBaseTestITCase {
|
||||||
protected void debugODataEntity(final CommonODataEntity entity, final String message) {
|
protected void debugODataEntity(final CommonODataEntity entity, final String message) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
StringWriter writer = new StringWriter();
|
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();
|
writer.flush();
|
||||||
LOG.debug(message + " (Atom)\n{}", writer.toString());
|
LOG.debug(message + " (Atom)\n{}", writer.toString());
|
||||||
|
|
||||||
writer = new StringWriter();
|
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();
|
writer.flush();
|
||||||
LOG.debug(message + " (JSON)\n{}", writer.toString());
|
LOG.debug(message + " (JSON)\n{}", writer.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,8 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
||||||
final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
|
final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
|
||||||
assertNotNull(inline);
|
assertNotNull(inline);
|
||||||
|
|
||||||
debugEntry(client.getBinder().getEntry(
|
debugEntity(client.getBinder().getEntity(
|
||||||
inline, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)), "Just read");
|
inline, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), "Just read");
|
||||||
|
|
||||||
final List<? extends CommonODataProperty> properties = inline.getProperties();
|
final List<? extends CommonODataProperty> properties = inline.getProperties();
|
||||||
assertEquals(2, properties.size());
|
assertEquals(2, properties.size());
|
||||||
|
@ -125,7 +125,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
|
||||||
final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
|
final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
|
||||||
assertNotNull(inline);
|
assertNotNull(inline);
|
||||||
|
|
||||||
debugFeed(client.getBinder().getFeed(inline, ResourceFactory.feedClassForFormat(
|
debugEntitySet(client.getBinder().getEntitySet(inline, ResourceFactory.entitySetClassForFormat(
|
||||||
format == ODataPubFormat.ATOM)), "Just read");
|
format == ODataPubFormat.ATOM)), "Just read");
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
|
||||||
|
|
||||||
assertNotNull(feed);
|
assertNotNull(feed);
|
||||||
|
|
||||||
debugFeed(client.getBinder().getFeed(feed, ResourceFactory.feedClassForFormat(
|
debugEntitySet(client.getBinder().getEntitySet(feed, ResourceFactory.entitySetClassForFormat(
|
||||||
ODataPubFormat.ATOM == format)), "Just retrieved feed");
|
ODataPubFormat.ATOM == format)), "Just retrieved feed");
|
||||||
|
|
||||||
assertEquals(2, feed.getEntities().size());
|
assertEquals(2, feed.getEntities().size());
|
||||||
|
|
|
@ -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.communication.response.ODataRetrieveResponse;
|
||||||
import org.apache.olingo.client.api.uri.v3.URIBuilder;
|
import org.apache.olingo.client.api.uri.v3.URIBuilder;
|
||||||
import org.apache.olingo.client.api.uri.v3.URIBuilder.InlineCount;
|
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.ODataInlineEntitySet;
|
||||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
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;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,9 +194,9 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
||||||
req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||||
req.setFormat(ODataPubFormat.ATOM);
|
req.setFormat(ODataPubFormat.ATOM);
|
||||||
|
|
||||||
final Entry atomEntry =
|
final Entity atomEntry =
|
||||||
client.getDeserializer().toEntry(req.execute().getRawResponse(), ODataPubFormat.ATOM).getPayload();
|
client.getDeserializer().toEntity(req.execute().getRawResponse(), ODataPubFormat.ATOM).getPayload();
|
||||||
assertEquals("remotingdestructorprinterswitcheschannelssatellitelanguageresolve",
|
assertEquals("remotingdestructorprinterswitcheschannelssatellitelanguageresolve",
|
||||||
((AtomEntryImpl) atomEntry).getSummary());
|
((AtomEntityImpl) atomEntry).getSummary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,37 +67,37 @@ public class AtomTest extends AbstractTest {
|
||||||
assertTrue(diff.similar());
|
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();
|
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);
|
getClass().getResourceAsStream("Customer." + getSuffix(format)), format).getPayload(), writer);
|
||||||
|
|
||||||
assertSimilar("Customer." + getSuffix(format), writer.toString());
|
assertSimilar("Customer." + getSuffix(format), writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void feeds() throws Exception {
|
public void entitySets() throws Exception {
|
||||||
feed("Customer", getODataPubFormat());
|
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();
|
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);
|
getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer);
|
||||||
|
|
||||||
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entries() throws Exception {
|
public void entities() throws Exception {
|
||||||
entry("AllGeoTypesSet_-5", getODataPubFormat());
|
entity("AllGeoTypesSet_-5", getODataPubFormat());
|
||||||
entry("AllGeoTypesSet_-8", getODataPubFormat());
|
entity("AllGeoTypesSet_-8", getODataPubFormat());
|
||||||
entry("Car_16", getODataPubFormat());
|
entity("Car_16", getODataPubFormat());
|
||||||
entry("ComputerDetail_-10", getODataPubFormat());
|
entity("ComputerDetail_-10", getODataPubFormat());
|
||||||
entry("Customer_-10", getODataPubFormat());
|
entity("Customer_-10", getODataPubFormat());
|
||||||
entry("Products_1", getODataPubFormat());
|
entity("Products_1", getODataPubFormat());
|
||||||
entry("PersonDetails_0_Person", getODataPubFormat());
|
entity("PersonDetails_0_Person", getODataPubFormat());
|
||||||
entry("Products_0_Categories", getODataPubFormat());
|
entity("Products_0_Categories", getODataPubFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void property(final String filename, final ODataFormat format) throws Exception {
|
protected void property(final String filename, final ODataFormat format) throws Exception {
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.net.URI;
|
||||||
import org.apache.olingo.client.api.v3.ODataClient;
|
import org.apache.olingo.client.api.v3.ODataClient;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
import org.apache.olingo.client.core.AbstractTest;
|
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.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
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 {
|
private void read(final ODataPubFormat format) throws IOException {
|
||||||
final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format));
|
||||||
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
|
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
|
||||||
getClient().getDeserializer().toFeed(input, format));
|
getClient().getDeserializer().toEntitySet(input, format));
|
||||||
assertNotNull(entitySet);
|
assertNotNull(entitySet);
|
||||||
|
|
||||||
assertEquals(2, entitySet.getEntities().size());
|
assertEquals(2, entitySet.getEntities().size());
|
||||||
assertNotNull(entitySet.getNext());
|
assertNotNull(entitySet.getNext());
|
||||||
|
|
||||||
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<Feed>((URI) null, null,
|
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<EntitySet>((URI) null, null,
|
||||||
getClient().getBinder().getFeed(
|
getClient().getBinder().getEntitySet(
|
||||||
entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM))));
|
entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entitySet, written);
|
assertEquals(entitySet, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.domain.ODataLink;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
import org.apache.olingo.client.core.AbstractTest;
|
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.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||||
|
@ -49,7 +49,7 @@ public class EntityTest extends AbstractTest {
|
||||||
private void readAndWrite(final ODataPubFormat format) {
|
private void readAndWrite(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getTypeName().toString());
|
assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getTypeName().toString());
|
||||||
|
@ -67,8 +67,9 @@ public class EntityTest extends AbstractTest {
|
||||||
|
|
||||||
assertTrue(check);
|
assertTrue(check);
|
||||||
|
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ public class EntityTest extends AbstractTest {
|
||||||
private void readGeospatial(final ODataPubFormat format) {
|
private void readGeospatial(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-8." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-8." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
@ -98,8 +99,9 @@ public class EntityTest extends AbstractTest {
|
||||||
}
|
}
|
||||||
assertTrue(found);
|
assertTrue(found);
|
||||||
|
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,14 +119,15 @@ public class EntityTest extends AbstractTest {
|
||||||
private void withActions(final ODataPubFormat format) {
|
private void withActions(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("ComputerDetail_-10." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("ComputerDetail_-10." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
assertEquals(1, entity.getOperations().size());
|
assertEquals(1, entity.getOperations().size());
|
||||||
assertEquals("ResetComputerDetailsSpecifications", entity.getOperations().get(0).getTitle());
|
assertEquals("ResetComputerDetailsSpecifications", entity.getOperations().get(0).getTitle());
|
||||||
|
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
entity.getOperations().clear();
|
entity.getOperations().clear();
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
@ -143,14 +146,15 @@ public class EntityTest extends AbstractTest {
|
||||||
private void mediaEntity(final ODataPubFormat format) {
|
private void mediaEntity(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("Car_16." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("Car_16." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
assertTrue(entity.isMediaEntity());
|
assertTrue(entity.isMediaEntity());
|
||||||
assertNotNull(entity.getMediaContentSource());
|
assertNotNull(entity.getMediaContentSource());
|
||||||
assertNotNull(entity.getMediaContentType());
|
assertNotNull(entity.getMediaContentType());
|
||||||
|
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +171,7 @@ public class EntityTest extends AbstractTest {
|
||||||
private void issue128(final ODataPubFormat format) throws EdmPrimitiveTypeException {
|
private void issue128(final ODataPubFormat format) throws EdmPrimitiveTypeException {
|
||||||
final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-5." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-5." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
final ODataProperty geogCollection = entity.getProperty("GeogCollection");
|
final ODataProperty geogCollection = entity.getProperty("GeogCollection");
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class AtomTest extends JSONTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void additionalEntries() throws Exception {
|
public void additionalEntities() throws Exception {
|
||||||
// no test
|
// no test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import org.apache.olingo.client.api.v4.ODataClient;
|
import org.apache.olingo.client.api.v4.ODataClient;
|
||||||
import org.apache.olingo.client.core.AbstractTest;
|
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.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
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 {
|
private void read(final ODataPubFormat format) throws IOException {
|
||||||
final InputStream input = getClass().getResourceAsStream("Customers." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("Customers." + getSuffix(format));
|
||||||
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
|
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
|
||||||
getClient().getDeserializer().toFeed(input, format));
|
getClient().getDeserializer().toEntitySet(input, format));
|
||||||
assertNotNull(entitySet);
|
assertNotNull(entitySet);
|
||||||
|
|
||||||
assertEquals(2, entitySet.getEntities().size());
|
assertEquals(2, entitySet.getEntities().size());
|
||||||
assertNull(entitySet.getNext());
|
assertNull(entitySet.getNext());
|
||||||
|
|
||||||
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<Feed>((URI) null, null,
|
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<EntitySet>((URI) null, null,
|
||||||
getClient().getBinder().getFeed(
|
getClient().getBinder().getEntitySet(
|
||||||
entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM))));
|
entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entitySet, written);
|
assertEquals(entitySet, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class EntitySetTest extends AbstractTest {
|
||||||
private void ref(final ODataPubFormat format) {
|
private void ref(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(format));
|
||||||
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
|
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
|
||||||
getClient().getDeserializer().toFeed(input, format));
|
getClient().getDeserializer().toEntitySet(input, format));
|
||||||
assertNotNull(entitySet);
|
assertNotNull(entitySet);
|
||||||
|
|
||||||
for (ODataEntity entity : entitySet.getEntities()) {
|
for (ODataEntity entity : entitySet.getEntities()) {
|
||||||
|
@ -78,9 +78,9 @@ public class EntitySetTest extends AbstractTest {
|
||||||
}
|
}
|
||||||
entitySet.setCount(entitySet.getEntities().size());
|
entitySet.setCount(entitySet.getEntities().size());
|
||||||
|
|
||||||
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<Feed>((URI) null, null,
|
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<EntitySet>((URI) null, null,
|
||||||
getClient().getBinder().getFeed(
|
getClient().getBinder().getEntitySet(
|
||||||
entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM))));
|
entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entitySet, written);
|
assertEquals(entitySet, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.net.URI;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import org.apache.olingo.client.api.v4.ODataClient;
|
import org.apache.olingo.client.api.v4.ODataClient;
|
||||||
import org.apache.olingo.client.core.AbstractTest;
|
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.data.ResWrap;
|
||||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||||
|
@ -53,7 +53,7 @@ public class EntityTest extends AbstractTest {
|
||||||
private void singleton(final ODataPubFormat format) {
|
private void singleton(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("VipCustomer." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("VipCustomer." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
|
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
|
||||||
|
@ -93,8 +93,9 @@ public class EntityTest extends AbstractTest {
|
||||||
|
|
||||||
// operations won't get serialized
|
// operations won't get serialized
|
||||||
entity.getOperations().clear();
|
entity.getOperations().clear();
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ public class EntityTest extends AbstractTest {
|
||||||
private void withEnums(final ODataPubFormat format) {
|
private void withEnums(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("Products_5." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("Products_5." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
final ODataProperty skinColor = entity.getProperty("SkinColor");
|
final ODataProperty skinColor = entity.getProperty("SkinColor");
|
||||||
|
@ -128,8 +129,9 @@ public class EntityTest extends AbstractTest {
|
||||||
|
|
||||||
// operations won't get serialized
|
// operations won't get serialized
|
||||||
entity.getOperations().clear();
|
entity.getOperations().clear();
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +149,7 @@ public class EntityTest extends AbstractTest {
|
||||||
final InputStream input = getClass().getResourceAsStream(
|
final InputStream input = getClass().getResourceAsStream(
|
||||||
"Accounts_101_expand_MyPaymentInstruments." + getSuffix(format));
|
"Accounts_101_expand_MyPaymentInstruments." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
final ODataLink instruments = entity.getNavigationLink("MyPaymentInstruments");
|
final ODataLink instruments = entity.getNavigationLink("MyPaymentInstruments");
|
||||||
|
@ -162,8 +164,9 @@ public class EntityTest extends AbstractTest {
|
||||||
inline.getEntitySet().setCount(3);
|
inline.getEntitySet().setCount(3);
|
||||||
// operations won't get serialized
|
// operations won't get serialized
|
||||||
entity.getOperations().clear();
|
entity.getOperations().clear();
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,15 +184,16 @@ public class EntityTest extends AbstractTest {
|
||||||
final InputStream input = getClass().getResourceAsStream(
|
final InputStream input = getClass().getResourceAsStream(
|
||||||
"Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(format));
|
"Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
assertTrue(entity.isMediaEntity());
|
assertTrue(entity.isMediaEntity());
|
||||||
assertNotNull(entity.getMediaContentSource());
|
assertNotNull(entity.getMediaContentSource());
|
||||||
assertEquals("\"8zOOKKvgOtptr4gt8IrnapX3jds=\"", entity.getMediaETag());
|
assertEquals("\"8zOOKKvgOtptr4gt8IrnapX3jds=\"", entity.getMediaETag());
|
||||||
|
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +210,7 @@ public class EntityTest extends AbstractTest {
|
||||||
private void withStream(final ODataPubFormat format) {
|
private void withStream(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
assertFalse(entity.isMediaEntity());
|
assertFalse(entity.isMediaEntity());
|
||||||
|
@ -214,8 +218,9 @@ public class EntityTest extends AbstractTest {
|
||||||
final ODataLink editMedia = entity.getEditMediaLink("Photo");
|
final ODataLink editMedia = entity.getEditMediaLink("Photo");
|
||||||
assertNotNull(editMedia);
|
assertNotNull(editMedia);
|
||||||
|
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,13 +237,14 @@ public class EntityTest extends AbstractTest {
|
||||||
private void ref(final ODataPubFormat format) {
|
private void ref(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
assertNotNull(entity.getReference());
|
assertNotNull(entity.getReference());
|
||||||
|
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +261,7 @@ public class EntityTest extends AbstractTest {
|
||||||
private void complexNavigationProperties(final ODataPubFormat format) {
|
private void complexNavigationProperties(final ODataPubFormat format) {
|
||||||
final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(format));
|
final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(format));
|
||||||
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
getClient().getDeserializer().toEntry(input, format));
|
getClient().getDeserializer().toEntity(input, format));
|
||||||
assertNotNull(entity);
|
assertNotNull(entity);
|
||||||
|
|
||||||
final ODataLinkedComplexValue addressValue = entity.getProperty("Address").getLinkedComplexValue();
|
final ODataLinkedComplexValue addressValue = entity.getProperty("Address").getLinkedComplexValue();
|
||||||
|
@ -264,8 +270,9 @@ public class EntityTest extends AbstractTest {
|
||||||
|
|
||||||
// ETag is not serialized
|
// ETag is not serialized
|
||||||
entity.setETag(null);
|
entity.setETag(null);
|
||||||
final ODataEntity written = getClient().getBinder().getODataEntity(new ResWrap<Entry>((URI) null, null, getClient().
|
final ODataEntity written = getClient().getBinder().getODataEntity(
|
||||||
getBinder().getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM))));
|
new ResWrap<Entity>((URI) null, null, getClient().
|
||||||
|
getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
|
||||||
assertEquals(entity, written);
|
assertEquals(entity, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,16 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.client.core.v4;
|
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.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
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.api.v4.ODataClient;
|
||||||
import org.apache.olingo.client.core.AbstractTest;
|
import org.apache.olingo.client.core.AbstractTest;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
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.edm.constants.ODataServiceVersion;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class JSONTest extends AbstractTest {
|
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))) {
|
if (node.has(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))) {
|
||||||
node.remove(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<String> toRemove = new ArrayList<String>();
|
final List<String> toRemove = new ArrayList<String>();
|
||||||
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
|
for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
|
||||||
final Map.Entry<String, JsonNode> field = itor.next();
|
final Map.Entry<String, JsonNode> field = itor.next();
|
||||||
|
|
||||||
if (field.getKey().charAt(0) == '#'
|
if (field.getKey().charAt(0) == '#'
|
||||||
|| field.getKey().endsWith(
|
|| field.getKey().endsWith(
|
||||||
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))
|
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))
|
||||||
|| field.getKey().endsWith(
|
|| field.getKey().endsWith(
|
||||||
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))
|
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))
|
||||||
|| field.getKey().endsWith(
|
|| field.getKey().endsWith(
|
||||||
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))
|
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))
|
||||||
|| field.getKey().endsWith(
|
|| field.getKey().endsWith(
|
||||||
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK))
|
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK))
|
||||||
|| field.getKey().endsWith(
|
|| field.getKey().endsWith(
|
||||||
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) {
|
getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) {
|
||||||
|
|
||||||
toRemove.add(field.getKey());
|
toRemove.add(field.getKey());
|
||||||
} else if (field.getValue().isObject()) {
|
} 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 {
|
protected void assertSimilar(final String filename, final String actual) throws Exception {
|
||||||
final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)).
|
final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)).
|
||||||
replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK),
|
replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK),
|
||||||
Constants.JSON_BIND_LINK_SUFFIX));
|
Constants.JSON_BIND_LINK_SUFFIX));
|
||||||
cleanup((ObjectNode) expected);
|
cleanup((ObjectNode) expected);
|
||||||
final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes()));
|
final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes()));
|
||||||
cleanup(actualNode);
|
cleanup(actualNode);
|
||||||
assertEquals(expected, 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();
|
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);
|
getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer);
|
||||||
|
|
||||||
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void feeds() throws Exception {
|
public void entitySets() throws Exception {
|
||||||
feed("Customers", getODataPubFormat());
|
entitySet("Customers", getODataPubFormat());
|
||||||
feed("collectionOfEntityReferences", 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();
|
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);
|
getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer);
|
||||||
|
|
||||||
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void additionalEntries() throws Exception {
|
public void additionalEntities() throws Exception {
|
||||||
entry("entity.minimal", getODataPubFormat());
|
entity("entity.minimal", getODataPubFormat());
|
||||||
entry("entity.primitive", getODataPubFormat());
|
entity("entity.primitive", getODataPubFormat());
|
||||||
entry("entity.complex", getODataPubFormat());
|
entity("entity.complex", getODataPubFormat());
|
||||||
entry("entity.collection.primitive", getODataPubFormat());
|
entity("entity.collection.primitive", getODataPubFormat());
|
||||||
entry("entity.collection.complex", getODataPubFormat());
|
entity("entity.collection.complex", getODataPubFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entries() throws Exception {
|
public void entities() throws Exception {
|
||||||
entry("Products_5", getODataPubFormat());
|
entity("Products_5", getODataPubFormat());
|
||||||
entry("VipCustomer", getODataPubFormat());
|
entity("VipCustomer", getODataPubFormat());
|
||||||
entry("Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7", getODataPubFormat());
|
entity("Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7", getODataPubFormat());
|
||||||
entry("entityReference", getODataPubFormat());
|
entity("entityReference", getODataPubFormat());
|
||||||
entry("entity.withcomplexnavigation", getODataPubFormat());
|
entity("entity.withcomplexnavigation", getODataPubFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void property(final String filename, final ODataFormat format) throws Exception {
|
protected void property(final String filename, final ODataFormat format) throws Exception {
|
||||||
|
@ -179,7 +188,39 @@ public class JSONTest extends AbstractTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void crossjoin() throws Exception {
|
public void crossjoin() throws Exception {
|
||||||
getClient().getDeserializer().toFeed(
|
assertNotNull(getClient().getDeserializer().toEntitySet(
|
||||||
getClass().getResourceAsStream("crossjoin.json"), ODataPubFormat.JSON_FULL_METADATA);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Customers",
|
"@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Customers",
|
||||||
"odata.count": 2,
|
"@odata.count": 2,
|
||||||
"value": [{
|
"value": [{
|
||||||
"@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)",
|
"@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)",
|
||||||
"@odata.editLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)",
|
"@odata.editLink": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)",
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<feed xml:base="http://host/service/"
|
||||||
|
xmlns:data="http://docs.oasis-open.org/odata/ns/data"
|
||||||
|
xmlns:metadata="http://docs.oasis-open.org/odata/ns/metadata"
|
||||||
|
xmlns="http://www.w3.org/2005/Atom"
|
||||||
|
xmlns:at="http://purl.org/atompub/tombstones/1.0"
|
||||||
|
metadata:context="$metadata#Customers/$delta">
|
||||||
|
<title type="text">Customers</title>
|
||||||
|
<id>http://host/service/Customers</id>
|
||||||
|
<updated>2012-11-27T15:38:25Z</updated>
|
||||||
|
<metadata:count>5</metadata:count>
|
||||||
|
<entry>
|
||||||
|
<id>http://host/service/Customers('BOTTM')</id>
|
||||||
|
<title type="text" />
|
||||||
|
<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>
|
|
@ -42,6 +42,8 @@ public interface Constants {
|
||||||
|
|
||||||
public static final String NS_GML = "http://www.opengis.net/gml";
|
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_DATASERVICES = "d";
|
||||||
|
|
||||||
public static final String PREFIX_METADATA = "m";
|
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 NEXT_LINK_REL = "next";
|
||||||
|
|
||||||
|
public static final String DELTA_LINK_REL = "http://docs.oasis-open.org/odata/ns/delta";
|
||||||
|
|
||||||
// XML elements and attributes
|
// XML elements and attributes
|
||||||
public static final String PROPERTIES = "properties";
|
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_HREF = "href";
|
||||||
|
|
||||||
|
public static final String ATTR_REF = "ref";
|
||||||
|
|
||||||
public static final String ATTR_TARGET = "target";
|
public static final String ATTR_TARGET = "target";
|
||||||
|
|
||||||
public static final String ATTR_SRSNAME = "srsName";
|
public static final String ATTR_SRSNAME = "srsName";
|
||||||
|
@ -138,6 +144,14 @@ public interface Constants {
|
||||||
|
|
||||||
public static final String ELEM_URI = "uri";
|
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
|
// JSON stuff
|
||||||
public final static String JSON_METADATA = "odata.metadata";
|
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_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";
|
public final static String JSON_NAME = "name";
|
||||||
|
|
||||||
// Atom stuff
|
// Atom stuff
|
||||||
|
@ -224,7 +234,9 @@ public interface Constants {
|
||||||
|
|
||||||
public static final String ATOM_ATTR_METADATAETAG = "metadata-etag";
|
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_CODE = "code";
|
||||||
|
|
||||||
public static final String ERROR_MESSAGE = "message";
|
public static final String ERROR_MESSAGE = "message";
|
||||||
|
|
|
@ -42,14 +42,38 @@ public class ContextURL {
|
||||||
|
|
||||||
private String navOrPropertyPath;
|
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) {
|
public static ContextURL getInstance(final URI contextURL) {
|
||||||
final ContextURL instance = new ContextURL();
|
final ContextURL instance = new ContextURL();
|
||||||
instance.uri = contextURL;
|
instance.uri = contextURL;
|
||||||
|
|
||||||
final String contextURLasString = instance.uri.toASCIIString().
|
String contextURLasString = instance.uri.toASCIIString();
|
||||||
replace("/$entity", StringUtils.EMPTY).
|
|
||||||
replace("/@Element", StringUtils.EMPTY);
|
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));
|
instance.serviceRoot = URI.create(StringUtils.substringBefore(contextURLasString, Constants.METADATA));
|
||||||
|
|
||||||
final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#");
|
final String rest = StringUtils.substringAfter(contextURLasString, Constants.METADATA + "#");
|
||||||
|
@ -124,6 +148,26 @@ public class ContextURL {
|
||||||
return navOrPropertyPath;
|
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
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface Entry extends Linked {
|
public interface Entity extends Linked {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets ETag.
|
* Gets ETag.
|
||||||
|
@ -39,56 +39,56 @@ public interface Entry extends Linked {
|
||||||
URI getBaseURI();
|
URI getBaseURI();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets entry type.
|
* Gets entity type.
|
||||||
*
|
*
|
||||||
* @return entry type.
|
* @return entity type.
|
||||||
*/
|
*/
|
||||||
String getType();
|
String getType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets entry type.
|
* Sets entity type.
|
||||||
*
|
*
|
||||||
* @param type entry type.
|
* @param type entity type.
|
||||||
*/
|
*/
|
||||||
void setType(String type);
|
void setType(String type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets entry ID.
|
* Gets entity ID.
|
||||||
*
|
*
|
||||||
* @return entry ID.
|
* @return entity ID.
|
||||||
*/
|
*/
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets entry ID.
|
* Sets entity ID.
|
||||||
*
|
*
|
||||||
* @param id entry ID.
|
* @param id entity ID.
|
||||||
*/
|
*/
|
||||||
void setId(String id);
|
void setId(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets entry self link.
|
* Gets entity self link.
|
||||||
*
|
*
|
||||||
* @return self link.
|
* @return self link.
|
||||||
*/
|
*/
|
||||||
Link getSelfLink();
|
Link getSelfLink();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets entry self link.
|
* Sets entity self link.
|
||||||
*
|
*
|
||||||
* @param selfLink self link.
|
* @param selfLink self link.
|
||||||
*/
|
*/
|
||||||
void setSelfLink(Link selfLink);
|
void setSelfLink(Link selfLink);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets entry edit link.
|
* Gets entity edit link.
|
||||||
*
|
*
|
||||||
* @return edit link.
|
* @return edit link.
|
||||||
*/
|
*/
|
||||||
Link getEditLink();
|
Link getEditLink();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets entry edit link.
|
* Sets entity edit link.
|
||||||
*
|
*
|
||||||
* @param editLink edit link.
|
* @param editLink edit link.
|
||||||
*/
|
*/
|
||||||
|
@ -166,9 +166,9 @@ public interface Entry extends Linked {
|
||||||
void setMediaETag(String eTag);
|
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();
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ package org.apache.olingo.commons.api.data;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface Feed {
|
public interface EntitySet {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets base URI.
|
* Gets base URI.
|
||||||
|
@ -40,23 +40,23 @@ public interface Feed {
|
||||||
/**
|
/**
|
||||||
* Gets number of entries - if it was required.
|
* 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();
|
Integer getCount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gest feed ID.
|
* Gest ID.
|
||||||
*
|
*
|
||||||
* @return feed ID.
|
* @return ID.
|
||||||
*/
|
*/
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets entries.
|
* Gets entities.
|
||||||
*
|
*
|
||||||
* @return entries.
|
* @return entries.
|
||||||
*/
|
*/
|
||||||
List<Entry> getEntries();
|
List<Entity> getEntities();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets next link if exists.
|
* Gets next link if exists.
|
|
@ -91,31 +91,31 @@ public interface Link {
|
||||||
void setMediaETag(String etag);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public interface CommonODataEntitySet extends ODataInvokeResult {
|
||||||
/**
|
/**
|
||||||
* Gets contained entities.
|
* Gets contained entities.
|
||||||
*
|
*
|
||||||
* @return feed entries.
|
* @return entity set's entities.
|
||||||
*/
|
*/
|
||||||
List<? extends CommonODataEntity> getEntities();
|
List<? extends CommonODataEntity> getEntities();
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ public interface ODataLinked {
|
||||||
ODataLink getNavigationLink(String name);
|
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.
|
* @return OData entity links.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -69,6 +69,13 @@ public enum ODataServiceVersion {
|
||||||
public static final String JSON_ASSOCIATION_LINK = "jsonAssociationLink";
|
public static final String JSON_ASSOCIATION_LINK = "jsonAssociationLink";
|
||||||
|
|
||||||
public static final String JSON_NAVIGATION_LINK = "jsonNavigationLink";
|
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";
|
public static final String JSON_ERROR = "jsonError";
|
||||||
|
|
||||||
private static final Map<String, String> V30_NAMESPACES = Collections.unmodifiableMap(new HashMap<String, String>() {
|
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_MEDIA_ETAG, "odata.mediaEtag");
|
||||||
put(JSON_ASSOCIATION_LINK, "@odata.associationLinkUrl");
|
put(JSON_ASSOCIATION_LINK, "@odata.associationLinkUrl");
|
||||||
put(JSON_NAVIGATION_LINK, "@odata.navigationLinkUrl");
|
put(JSON_NAVIGATION_LINK, "@odata.navigationLinkUrl");
|
||||||
|
put(JSON_COUNT, "odata.count");
|
||||||
|
put(JSON_NEXT_LINK, "odata.nextLink");
|
||||||
put(JSON_ERROR, "odata.error");
|
put(JSON_ERROR, "odata.error");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -135,6 +144,9 @@ public enum ODataServiceVersion {
|
||||||
put(JSON_MEDIA_ETAG, "@odata.mediaEtag");
|
put(JSON_MEDIA_ETAG, "@odata.mediaEtag");
|
||||||
put(JSON_ASSOCIATION_LINK, "@odata.associationLink");
|
put(JSON_ASSOCIATION_LINK, "@odata.associationLink");
|
||||||
put(JSON_NAVIGATION_LINK, "@odata.navigationLink");
|
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");
|
put(JSON_ERROR, "error");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,35 +21,35 @@ package org.apache.olingo.commons.api.op;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.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.data.Property;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for serialization.
|
* Interface for de-serialization.
|
||||||
*/
|
*/
|
||||||
public interface CommonODataDeserializer extends Serializable {
|
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 input stream to be de-serialized.
|
||||||
* @param format Atom or JSON
|
* @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 input stream to be de-serialized.
|
||||||
* @param format Atom or JSON
|
* @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.
|
* Gets a property object from the given InputStream.
|
||||||
|
|
|
@ -21,8 +21,8 @@ package org.apache.olingo.commons.api.op;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
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 {
|
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 obj object to be streamed.
|
||||||
* @param out output stream.
|
* @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 obj object to be streamed.
|
||||||
* @param writer writer.
|
* @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 obj object to be streamed.
|
||||||
* @param out output stream.
|
* @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 obj object to be streamed.
|
||||||
* @param writer writer.
|
* @param writer writer.
|
||||||
*/
|
*/
|
||||||
void entry(Entry obj, Writer writer);
|
void entity(Entity obj, Writer writer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the property object onto the given stream.
|
* Writes the property object onto the given stream.
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
package org.apache.olingo.commons.api.data;
|
package org.apache.olingo.commons.api.data;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -35,6 +37,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
|
|
||||||
contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Orders(4711)/Items"));
|
contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Orders(4711)/Items"));
|
||||||
|
|
||||||
|
@ -42,6 +45,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertEquals("Items", contextURL.getNavOrPropertyPath());
|
assertEquals("Items", contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,6 +56,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertTrue(contextURL.isEntity());
|
||||||
|
|
||||||
contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Orders(4711)/Items/$entity"));
|
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.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertEquals("Items", contextURL.getNavOrPropertyPath());
|
assertEquals("Items", contextURL.getNavOrPropertyPath());
|
||||||
|
assertTrue(contextURL.isEntity());
|
||||||
|
|
||||||
// v3
|
// v3
|
||||||
contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Products/@Element"));
|
contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#Products/@Element"));
|
||||||
|
@ -67,6 +73,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertTrue(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -77,6 +84,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -88,6 +96,7 @@ public class ContextURLTest {
|
||||||
assertEquals("Model.VipCustomer", contextURL.getDerivedEntity());
|
assertEquals("Model.VipCustomer", contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -99,6 +108,7 @@ public class ContextURLTest {
|
||||||
assertEquals("Model.VipCustomer", contextURL.getDerivedEntity());
|
assertEquals("Model.VipCustomer", contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertTrue(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -110,6 +120,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertEquals("Address,Orders", contextURL.getSelectList());
|
assertEquals("Address,Orders", contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -121,6 +132,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertEquals("Name,Rating", contextURL.getSelectList());
|
assertEquals("Name,Rating", contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertTrue(contextURL.isEntity());
|
||||||
|
|
||||||
contextURL = ContextURL.getInstance(
|
contextURL = ContextURL.getInstance(
|
||||||
URI.create("http://host/service/$metadata#Customers(Name,Address/Country)"));
|
URI.create("http://host/service/$metadata#Customers(Name,Address/Country)"));
|
||||||
|
@ -129,6 +141,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertEquals("Name,Address/Country", contextURL.getSelectList());
|
assertEquals("Name,Address/Country", contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -141,6 +154,7 @@ public class ContextURLTest {
|
||||||
assertEquals("Sales.Manager", contextURL.getDerivedEntity());
|
assertEquals("Sales.Manager", contextURL.getDerivedEntity());
|
||||||
assertEquals("DirectReports,DirectReports+(FirstName,LastName)", contextURL.getSelectList());
|
assertEquals("DirectReports,DirectReports+(FirstName,LastName)", contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -152,6 +166,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertEquals("Addresses", contextURL.getNavOrPropertyPath());
|
assertEquals("Addresses", contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -163,6 +178,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -173,6 +189,7 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
assertNull(contextURL.getNavOrPropertyPath());
|
||||||
|
assertFalse(contextURL.isEntity());
|
||||||
|
|
||||||
contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#ODataDemo.Address"));
|
contextURL = ContextURL.getInstance(URI.create("http://host/service/$metadata#ODataDemo.Address"));
|
||||||
|
|
||||||
|
@ -180,5 +197,21 @@ public class ContextURLTest {
|
||||||
assertNull(contextURL.getDerivedEntity());
|
assertNull(contextURL.getDerivedEntity());
|
||||||
assertNull(contextURL.getSelectList());
|
assertNull(contextURL.getSelectList());
|
||||||
assertNull(contextURL.getNavOrPropertyPath());
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,15 @@ abstract class AbstractAtomDealer {
|
||||||
|
|
||||||
protected final QName entryRefQName;
|
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;
|
protected final QName errorCodeQName;
|
||||||
|
|
||||||
|
@ -94,9 +102,17 @@ abstract class AbstractAtomDealer {
|
||||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.CONTEXT);
|
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.CONTEXT);
|
||||||
this.entryRefQName =
|
this.entryRefQName =
|
||||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ENTRY_REF);
|
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);
|
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 =
|
this.errorCodeQName =
|
||||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ERROR_CODE);
|
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ERROR_CODE);
|
||||||
this.errorMessageQName =
|
this.errorMessageQName =
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,15 +21,15 @@ package org.apache.olingo.commons.core.data;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
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;
|
private static final long serialVersionUID = 2127764552600969783L;
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public abstract class AbstractEntry extends AbstractODataObject implements Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMediaEntry() {
|
public boolean isMediaEntity() {
|
||||||
return StringUtils.isNotBlank(this.mediaContentSource);
|
return StringUtils.isNotBlank(this.mediaContentSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,21 +21,16 @@ package org.apache.olingo.commons.core.data;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
|
|
||||||
/**
|
public abstract class AbstractEntitySet extends AbstractODataObject implements EntitySet {
|
||||||
* List of entries, represented via Atom.
|
|
||||||
*
|
|
||||||
* @see AtomEntry
|
|
||||||
*/
|
|
||||||
public class AtomFeedImpl extends AbstractODataObject implements Feed {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 5466590540021319153L;
|
private static final long serialVersionUID = -9159884750819150969L;
|
||||||
|
|
||||||
private Integer count;
|
private Integer count;
|
||||||
|
|
||||||
private final List<Entry> entries = new ArrayList<Entry>();
|
private final List<Entity> entities = new ArrayList<Entity>();
|
||||||
|
|
||||||
private URI next;
|
private URI next;
|
||||||
|
|
||||||
|
@ -50,8 +45,8 @@ public class AtomFeedImpl extends AbstractODataObject implements Feed {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Entry> getEntries() {
|
public List<Entity> getEntities() {
|
||||||
return entries;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -60,33 +60,33 @@ abstract class AbstractJsonDeserializer<T> extends ODataJacksonDeserializer<ResW
|
||||||
protected String setInline(final String name, final String suffix, final JsonNode tree,
|
protected String setInline(final String name, final String suffix, final JsonNode tree,
|
||||||
final ObjectCodec codec, final LinkImpl link) throws IOException {
|
final ObjectCodec codec, final LinkImpl link) throws IOException {
|
||||||
|
|
||||||
final String entryNamePrefix = name.substring(0, name.indexOf(suffix));
|
final String entityNamePrefix = name.substring(0, name.indexOf(suffix));
|
||||||
if (tree.has(entryNamePrefix)) {
|
if (tree.has(entityNamePrefix)) {
|
||||||
final JsonNode inline = tree.path(entryNamePrefix);
|
final JsonNode inline = tree.path(entityNamePrefix);
|
||||||
|
|
||||||
if (inline instanceof ObjectNode) {
|
if (inline instanceof ObjectNode) {
|
||||||
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
|
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
|
||||||
|
|
||||||
link.setInlineEntry(inline.traverse(codec).<ResWrap<JSONEntryImpl>>readValueAs(
|
link.setInlineEntity(inline.traverse(codec).<ResWrap<JSONEntityImpl>>readValueAs(
|
||||||
new TypeReference<JSONEntryImpl>() {
|
new TypeReference<JSONEntityImpl>() {
|
||||||
}).getPayload());
|
}).getPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inline instanceof ArrayNode) {
|
if (inline instanceof ArrayNode) {
|
||||||
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
|
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
|
||||||
|
|
||||||
final JSONFeedImpl feed = new JSONFeedImpl();
|
final JSONEntitySetImpl entitySet = new JSONEntitySetImpl();
|
||||||
final Iterator<JsonNode> entries = ((ArrayNode) inline).elements();
|
final Iterator<JsonNode> entries = ((ArrayNode) inline).elements();
|
||||||
while (entries.hasNext()) {
|
while (entries.hasNext()) {
|
||||||
feed.getEntries().add(entries.next().traverse(codec).<ResWrap<JSONEntryImpl>>readValuesAs(
|
entitySet.getEntities().add(entries.next().traverse(codec).<ResWrap<JSONEntityImpl>>readValuesAs(
|
||||||
new TypeReference<JSONEntryImpl>() {
|
new TypeReference<JSONEntityImpl>() {
|
||||||
}).next().getPayload());
|
}).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,
|
protected void links(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.CollectionValue;
|
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Linked;
|
import org.apache.olingo.commons.api.data.Linked;
|
||||||
import org.apache.olingo.commons.api.data.PrimitiveValue;
|
import org.apache.olingo.commons.api.data.PrimitiveValue;
|
||||||
|
@ -86,11 +86,11 @@ abstract class AbstractJsonSerializer<T> extends ODataJacksonSerializer<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (link.getInlineEntry() != null) {
|
if (link.getInlineEntity() != null) {
|
||||||
jgen.writeObjectField(link.getTitle(), link.getInlineEntry());
|
jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
|
||||||
} else if (link.getInlineFeed() != null) {
|
} else if (link.getInlineEntitySet() != null) {
|
||||||
jgen.writeArrayFieldStart(link.getTitle());
|
jgen.writeArrayFieldStart(link.getTitle());
|
||||||
for (Entry subEntry : link.getInlineFeed().getEntries()) {
|
for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
|
||||||
jgen.writeObject(subEntry);
|
jgen.writeObject(subEntry);
|
||||||
}
|
}
|
||||||
jgen.writeEndArray();
|
jgen.writeEndArray();
|
||||||
|
@ -123,11 +123,11 @@ abstract class AbstractJsonSerializer<T> extends ODataJacksonSerializer<T> {
|
||||||
link.getHref());
|
link.getHref());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (link.getInlineEntry() != null) {
|
if (link.getInlineEntity() != null) {
|
||||||
jgen.writeObjectField(link.getTitle(), link.getInlineEntry());
|
jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
|
||||||
} else if (link.getInlineFeed() != null) {
|
} else if (link.getInlineEntitySet() != null) {
|
||||||
jgen.writeArrayFieldStart(link.getTitle());
|
jgen.writeArrayFieldStart(link.getTitle());
|
||||||
for (Entry subEntry : link.getInlineFeed().getEntries()) {
|
for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
|
||||||
jgen.writeObject(subEntry);
|
jgen.writeObject(subEntry);
|
||||||
}
|
}
|
||||||
jgen.writeEndArray();
|
jgen.writeEndArray();
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.commons.core.data;
|
package org.apache.olingo.commons.core.data;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -32,6 +31,8 @@ import javax.xml.stream.events.XMLEvent;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.CollectionValue;
|
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.data.Value;
|
||||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||||
import org.apache.olingo.commons.api.domain.ODataPropertyType;
|
import org.apache.olingo.commons.api.domain.ODataPropertyType;
|
||||||
|
@ -228,7 +229,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
|
|
||||||
final AtomPropertyImpl property = new AtomPropertyImpl();
|
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
|
// retrieve name from context
|
||||||
final Attribute context = start.getAttributeByName(contextQName);
|
final Attribute context = start.getAttributeByName(contextQName);
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
|
@ -352,10 +353,10 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
if (inline != null) {
|
if (inline != null) {
|
||||||
if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(inline.getName())) {
|
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())) {
|
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 {
|
private ResWrap<XMLLinkCollectionImpl> linkCollection(final InputStream input) throws XMLStreamException {
|
||||||
final XMLEventReader reader = getReader(input);
|
final XMLEventReader reader = getReader(input);
|
||||||
final StartElement start = skipBeforeFirstStartElement(reader);
|
final StartElement start = skipBeforeFirstStartElement(reader);
|
||||||
|
@ -400,14 +497,14 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
return linkCollection;
|
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 {
|
throws XMLStreamException {
|
||||||
boolean foundEndProperties = false;
|
boolean foundEndProperties = false;
|
||||||
while (reader.hasNext() && !foundEndProperties) {
|
while (reader.hasNext() && !foundEndProperties) {
|
||||||
final XMLEvent event = reader.nextEvent();
|
final XMLEvent event = reader.nextEvent();
|
||||||
|
|
||||||
if (event.isStartElement()) {
|
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())) {
|
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 {
|
private AtomEntityImpl entityRef(final StartElement start) throws XMLStreamException {
|
||||||
final AtomEntryImpl entry = new AtomEntryImpl();
|
final AtomEntityImpl entity = new AtomEntityImpl();
|
||||||
|
|
||||||
final Attribute entryRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
|
final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
|
||||||
if (entryRefId != null) {
|
if (entityRefId != null) {
|
||||||
entry.setId(entryRefId.getValue());
|
entity.setId(entityRefId.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AtomEntryImpl entry(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
|
private AtomEntityImpl entity(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
|
||||||
final AtomEntryImpl entry;
|
final AtomEntityImpl entity;
|
||||||
if (entryRefQName.equals(start.getName())) {
|
if (entryRefQName.equals(start.getName())) {
|
||||||
entry = entryRef(start);
|
entity = entityRef(start);
|
||||||
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) {
|
} 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);
|
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
|
||||||
if (xmlBase != null) {
|
if (xmlBase != null) {
|
||||||
entry.setBaseURI(xmlBase.getValue());
|
entity.setBaseURI(xmlBase.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
final Attribute etag = start.getAttributeByName(etagQName);
|
final Attribute etag = start.getAttributeByName(etagQName);
|
||||||
if (etag != null) {
|
if (etag != null) {
|
||||||
entry.setETag(etag.getValue());
|
entity.setETag(etag.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean foundEndEntry = false;
|
boolean foundEndEntry = false;
|
||||||
|
@ -449,17 +546,17 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
|
|
||||||
if (event.isStartElement()) {
|
if (event.isStartElement()) {
|
||||||
if (Constants.QNAME_ATOM_ELEM_ID.equals(event.asStartElement().getName())) {
|
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())) {
|
} 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())) {
|
} 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())) {
|
} 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())) {
|
} else if (Constants.QNAME_ATOM_ELEM_CATEGORY.equals(event.asStartElement().getName())) {
|
||||||
final Attribute term = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_TERM));
|
final Attribute term = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_TERM));
|
||||||
if (term != null) {
|
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())) {
|
} else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
|
||||||
final LinkImpl link = new LinkImpl();
|
final LinkImpl link = new LinkImpl();
|
||||||
|
@ -481,22 +578,22 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Constants.SELF_LINK_REL.equals(link.getRel())) {
|
if (Constants.SELF_LINK_REL.equals(link.getRel())) {
|
||||||
entry.setSelfLink(link);
|
entity.setSelfLink(link);
|
||||||
} else if (Constants.EDIT_LINK_REL.equals(link.getRel())) {
|
} else if (Constants.EDIT_LINK_REL.equals(link.getRel())) {
|
||||||
entry.setEditLink(link);
|
entity.setEditLink(link);
|
||||||
} else if (Constants.EDITMEDIA_LINK_REL.equals(link.getRel())) {
|
} else if (Constants.EDITMEDIA_LINK_REL.equals(link.getRel())) {
|
||||||
final Attribute mediaETag = event.asStartElement().getAttributeByName(etagQName);
|
final Attribute mediaETag = event.asStartElement().getAttributeByName(etagQName);
|
||||||
if (mediaETag != null) {
|
if (mediaETag != null) {
|
||||||
entry.setMediaETag(mediaETag.getValue());
|
entity.setMediaETag(mediaETag.getValue());
|
||||||
}
|
}
|
||||||
} else if (link.getRel().startsWith(
|
} else if (link.getRel().startsWith(
|
||||||
version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
|
version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
|
||||||
entry.getNavigationLinks().add(link);
|
entity.getNavigationLinks().add(link);
|
||||||
inline(reader, event.asStartElement(), link);
|
inline(reader, event.asStartElement(), link);
|
||||||
} else if (link.getRel().startsWith(
|
} else if (link.getRel().startsWith(
|
||||||
version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
|
version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
|
||||||
|
|
||||||
entry.getAssociationLinks().add(link);
|
entity.getAssociationLinks().add(link);
|
||||||
} else if (link.getRel().startsWith(
|
} else if (link.getRel().startsWith(
|
||||||
version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) {
|
version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) {
|
||||||
|
|
||||||
|
@ -504,7 +601,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
if (metag != null) {
|
if (metag != null) {
|
||||||
link.setMediaETag(metag.getValue());
|
link.setMediaETag(metag.getValue());
|
||||||
}
|
}
|
||||||
entry.getMediaEditLinks().add(link);
|
entity.getMediaEditLinks().add(link);
|
||||||
}
|
}
|
||||||
} else if (actionQName.equals(event.asStartElement().getName())) {
|
} else if (actionQName.equals(event.asStartElement().getName())) {
|
||||||
final ODataOperation operation = new ODataOperation();
|
final ODataOperation operation = new ODataOperation();
|
||||||
|
@ -522,20 +619,20 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
operation.setTarget(URI.create(target.getValue()));
|
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())) {
|
} else if (Constants.QNAME_ATOM_ELEM_CONTENT.equals(event.asStartElement().getName())) {
|
||||||
final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE));
|
final Attribute type = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_TYPE));
|
||||||
if (type == null || ContentType.APPLICATION_XML.equals(type.getValue())) {
|
if (type == null || ContentType.APPLICATION_XML.equals(type.getValue())) {
|
||||||
properties(reader, skipBeforeFirstStartElement(reader), entry);
|
properties(reader, skipBeforeFirstStartElement(reader), entity);
|
||||||
} else {
|
} else {
|
||||||
entry.setMediaContentType(type.getValue());
|
entity.setMediaContentType(type.getValue());
|
||||||
final Attribute src = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_SRC));
|
final Attribute src = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATOM_ATTR_SRC));
|
||||||
if (src != null) {
|
if (src != null) {
|
||||||
entry.setMediaContentSource(src.getValue());
|
entity.setMediaContentSource(src.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (propertiesQName.equals(event.asStartElement().getName())) {
|
} 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 {
|
} 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 XMLEventReader reader = getReader(input);
|
||||||
final StartElement start = skipBeforeFirstStartElement(reader);
|
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 {
|
throws XMLStreamException {
|
||||||
|
|
||||||
boolean foundEndElement = false;
|
boolean foundEndElement = false;
|
||||||
|
@ -566,7 +663,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
final XMLEvent event = reader.nextEvent();
|
final XMLEvent event = reader.nextEvent();
|
||||||
|
|
||||||
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
|
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())) {
|
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())) {
|
if (!Constants.QNAME_ATOM_ELEM_FEED.equals(start.getName())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final AtomFeedImpl feed = new AtomFeedImpl();
|
final AtomEntitySetImpl entitySet = new AtomEntitySetImpl();
|
||||||
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
|
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
|
||||||
if (xmlBase != null) {
|
if (xmlBase != null) {
|
||||||
feed.setBaseURI(xmlBase.getValue());
|
entitySet.setBaseURI(xmlBase.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean foundEndFeed = false;
|
boolean foundEndFeed = false;
|
||||||
|
@ -590,27 +687,27 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
final XMLEvent event = reader.nextEvent();
|
final XMLEvent event = reader.nextEvent();
|
||||||
if (event.isStartElement()) {
|
if (event.isStartElement()) {
|
||||||
if (countQName.equals(event.asStartElement().getName())) {
|
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())) {
|
} 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())) {
|
} 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())) {
|
} 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())) {
|
} 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())) {
|
} else if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
|
||||||
final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL));
|
final Attribute rel = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_REL));
|
||||||
if (rel != null && Constants.NEXT_LINK_REL.equals(rel.getValue())) {
|
if (rel != null && Constants.NEXT_LINK_REL.equals(rel.getValue())) {
|
||||||
final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF));
|
final Attribute href = event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_HREF));
|
||||||
if (href != null) {
|
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())) {
|
} 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())) {
|
} 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 XMLEventReader reader = getReader(input);
|
||||||
final StartElement start = skipBeforeFirstStartElement(reader);
|
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 {
|
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)) {
|
if (XMLODataErrorImpl.class.equals(reference)) {
|
||||||
return (ResWrap<T>) error(input);
|
return (ResWrap<T>) error(input);
|
||||||
} else if (AtomFeedImpl.class.equals(reference)) {
|
} else if (AtomEntitySetImpl.class.equals(reference)) {
|
||||||
return (ResWrap<T>) feed(input);
|
return (ResWrap<T>) entitySet(input);
|
||||||
} else if (AtomEntryImpl.class.equals(reference)) {
|
} else if (AtomEntityImpl.class.equals(reference)) {
|
||||||
return (ResWrap<T>) entry(input);
|
return (ResWrap<T>) entity(input);
|
||||||
} else if (AtomPropertyImpl.class.equals(reference)) {
|
} else if (AtomPropertyImpl.class.equals(reference)) {
|
||||||
return (ResWrap<T>) property(input);
|
return (ResWrap<T>) property(input);
|
||||||
} else if (XMLLinkCollectionImpl.class.equals(reference)) {
|
} else if (XMLLinkCollectionImpl.class.equals(reference)) {
|
||||||
return (ResWrap<T>) linkCollection(input);
|
return (ResWrap<T>) linkCollection(input);
|
||||||
|
} else if (AtomDeltaImpl.class.equals(reference)) {
|
||||||
|
return (ResWrap<T>) delta(input);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.commons.core.data;
|
package org.apache.olingo.commons.core.data;
|
||||||
|
|
||||||
public class AtomEntryImpl extends AbstractEntry {
|
public class AtomEntityImpl extends AbstractEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = 6973729343868293279L;
|
private static final long serialVersionUID = 6973729343868293279L;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -29,8 +29,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.CollectionValue;
|
import org.apache.olingo.commons.api.data.CollectionValue;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
import org.apache.olingo.commons.api.data.Link;
|
import org.apache.olingo.commons.api.data.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.Value;
|
import org.apache.olingo.commons.api.data.Value;
|
||||||
|
@ -166,18 +166,18 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
|
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,
|
writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE,
|
||||||
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
||||||
|
|
||||||
if (link.getInlineEntry() != null) {
|
if (link.getInlineEntity() != null) {
|
||||||
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
|
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
|
||||||
entry(writer, link.getInlineEntry());
|
entity(writer, link.getInlineEntity());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
if (link.getInlineFeed() != null) {
|
if (link.getInlineEntitySet() != null) {
|
||||||
writer.writeStartElement(Constants.ATOM_ELEM_FEED);
|
writer.writeStartElement(Constants.ATOM_ELEM_FEED);
|
||||||
feed(writer, link.getInlineFeed());
|
entitySet(writer, link.getInlineEntitySet());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,51 +210,51 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void entry(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException {
|
private void entity(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException {
|
||||||
if (entry.getBaseURI() != null) {
|
if (entity.getBaseURI() != null) {
|
||||||
writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entry.getBaseURI().toASCIIString());
|
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(
|
writer.writeAttribute(
|
||||||
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
|
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.writeStartElement(Constants.ATOM_ELEM_ID);
|
||||||
writer.writeCharacters(entry.getId());
|
writer.writeCharacters(entity.getId());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
|
writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
|
||||||
writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
|
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,
|
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();
|
writer.writeEndElement();
|
||||||
|
|
||||||
if (entry instanceof AbstractODataObject) {
|
if (entity instanceof AbstractODataObject) {
|
||||||
common(writer, (AbstractODataObject) entry);
|
common(writer, (AbstractODataObject) entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverMode) {
|
if (serverMode) {
|
||||||
if (entry.getEditLink() != null) {
|
if (entity.getEditLink() != null) {
|
||||||
links(writer, Collections.singletonList(entry.getEditLink()));
|
links(writer, Collections.singletonList(entity.getEditLink()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.getSelfLink() != null) {
|
if (entity.getSelfLink() != null) {
|
||||||
links(writer, Collections.singletonList(entry.getSelfLink()));
|
links(writer, Collections.singletonList(entity.getSelfLink()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
links(writer, entry.getAssociationLinks());
|
links(writer, entity.getAssociationLinks());
|
||||||
links(writer, entry.getNavigationLinks());
|
links(writer, entity.getNavigationLinks());
|
||||||
links(writer, entry.getMediaEditLinks());
|
links(writer, entity.getMediaEditLinks());
|
||||||
|
|
||||||
if (serverMode) {
|
if (serverMode) {
|
||||||
for (ODataOperation operation : entry.getOperations()) {
|
for (ODataOperation operation : entity.getOperations()) {
|
||||||
writer.writeStartElement(
|
writer.writeStartElement(
|
||||||
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION);
|
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION);
|
||||||
writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor());
|
writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor());
|
||||||
|
@ -265,51 +265,51 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
|
writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
|
||||||
if (entry.isMediaEntry()) {
|
if (entity.isMediaEntity()) {
|
||||||
if (StringUtils.isNotBlank(entry.getMediaContentType())) {
|
if (StringUtils.isNotBlank(entity.getMediaContentType())) {
|
||||||
writer.writeAttribute(Constants.ATTR_TYPE, entry.getMediaContentType());
|
writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(entry.getMediaContentSource())) {
|
if (StringUtils.isNotBlank(entity.getMediaContentSource())) {
|
||||||
writer.writeAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource());
|
writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource());
|
||||||
}
|
}
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
|
||||||
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
|
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
|
||||||
properties(writer, entry.getProperties());
|
properties(writer, entity.getProperties());
|
||||||
} else {
|
} else {
|
||||||
writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML);
|
writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML);
|
||||||
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
|
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.PROPERTIES);
|
||||||
properties(writer, entry.getProperties());
|
properties(writer, entity.getProperties());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
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.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
|
||||||
writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
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.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
|
||||||
writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
||||||
addContextInfo(writer, container);
|
addContextInfo(writer, container);
|
||||||
writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId());
|
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);
|
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
||||||
|
|
||||||
if (entry.getType() == null && entry.getProperties().isEmpty()) {
|
if (entity.getType() == null && entity.getProperties().isEmpty()) {
|
||||||
writer.writeStartDocument();
|
writer.writeStartDocument();
|
||||||
writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
||||||
|
|
||||||
entryRef(writer, entry);
|
entityRef(writer, entity);
|
||||||
} else {
|
} else {
|
||||||
startDocument(writer, Constants.ATOM_ELEM_ENTRY);
|
startDocument(writer, Constants.ATOM_ELEM_ENTRY);
|
||||||
|
|
||||||
entry(writer, entry);
|
entity(writer, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
@ -317,22 +317,22 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void entry(final Writer outWriter, final ResWrap<Entry> container) throws XMLStreamException {
|
private void entity(final Writer outWriter, final ResWrap<Entity> container) throws XMLStreamException {
|
||||||
final Entry entry = container.getPayload();
|
final Entity entity = container.getPayload();
|
||||||
|
|
||||||
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
||||||
|
|
||||||
if (entry.getType() == null && entry.getProperties().isEmpty()) {
|
if (entity.getType() == null && entity.getProperties().isEmpty()) {
|
||||||
writer.writeStartDocument();
|
writer.writeStartDocument();
|
||||||
writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
||||||
|
|
||||||
entryRef(writer, container);
|
entityRef(writer, container);
|
||||||
} else {
|
} else {
|
||||||
startDocument(writer, Constants.ATOM_ELEM_ENTRY);
|
startDocument(writer, Constants.ATOM_ELEM_ENTRY);
|
||||||
|
|
||||||
addContextInfo(writer, container);
|
addContextInfo(writer, container);
|
||||||
|
|
||||||
entry(writer, entry);
|
entity(writer, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
@ -340,68 +340,68 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void feed(final XMLStreamWriter writer, final Feed feed) throws XMLStreamException {
|
private void entitySet(final XMLStreamWriter writer, final EntitySet entitySet) throws XMLStreamException {
|
||||||
if (feed.getBaseURI() != null) {
|
if (entitySet.getBaseURI() != null) {
|
||||||
writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, feed.getBaseURI().toASCIIString());
|
writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entitySet.getBaseURI().toASCIIString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feed.getCount() != null) {
|
if (entitySet.getCount() != null) {
|
||||||
writer.writeStartElement(
|
writer.writeStartElement(
|
||||||
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
|
version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
|
||||||
writer.writeCharacters(Integer.toString(feed.getCount()));
|
writer.writeCharacters(Integer.toString(entitySet.getCount()));
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(feed.getId())) {
|
if (StringUtils.isNotBlank(entitySet.getId())) {
|
||||||
writer.writeStartElement(Constants.ATOM_ELEM_ID);
|
writer.writeStartElement(Constants.ATOM_ELEM_ID);
|
||||||
writer.writeCharacters(feed.getId());
|
writer.writeCharacters(entitySet.getId());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feed instanceof AbstractODataObject) {
|
if (entitySet instanceof AbstractODataObject) {
|
||||||
common(writer, (AbstractODataObject) feed);
|
common(writer, (AbstractODataObject) entitySet);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry entry : feed.getEntries()) {
|
for (Entity entity : entitySet.getEntities()) {
|
||||||
if (entry.getType() == null && entry.getProperties().isEmpty()) {
|
if (entity.getType() == null && entity.getProperties().isEmpty()) {
|
||||||
entryRef(writer, entry);
|
entityRef(writer, entity);
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
} else {
|
} else {
|
||||||
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
|
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
|
||||||
entry(writer, entry);
|
entity(writer, entity);
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feed.getNext() != null) {
|
if (entitySet.getNext() != null) {
|
||||||
final LinkImpl next = new LinkImpl();
|
final LinkImpl next = new LinkImpl();
|
||||||
next.setRel(Constants.NEXT_LINK_REL);
|
next.setRel(Constants.NEXT_LINK_REL);
|
||||||
next.setHref(feed.getNext().toASCIIString());
|
next.setHref(entitySet.getNext().toASCIIString());
|
||||||
|
|
||||||
links(writer, Collections.<Link>singletonList(next));
|
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);
|
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
||||||
|
|
||||||
startDocument(writer, Constants.ATOM_ELEM_FEED);
|
startDocument(writer, Constants.ATOM_ELEM_FEED);
|
||||||
|
|
||||||
feed(writer, feed);
|
entitySet(writer, entitySet);
|
||||||
|
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
writer.writeEndDocument();
|
writer.writeEndDocument();
|
||||||
writer.flush();
|
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);
|
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
||||||
|
|
||||||
startDocument(writer, Constants.ATOM_ELEM_FEED);
|
startDocument(writer, Constants.ATOM_ELEM_FEED);
|
||||||
|
|
||||||
addContextInfo(writer, feed);
|
addContextInfo(writer, entitySet);
|
||||||
|
|
||||||
feed(writer, feed.getPayload());
|
entitySet(writer, entitySet.getPayload());
|
||||||
|
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
writer.writeEndDocument();
|
writer.writeEndDocument();
|
||||||
|
@ -427,10 +427,10 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void write(final Writer writer, final T obj) throws XMLStreamException {
|
public <T> void write(final Writer writer, final T obj) throws XMLStreamException {
|
||||||
if (obj instanceof Feed) {
|
if (obj instanceof EntitySet) {
|
||||||
feed(writer, (Feed) obj);
|
entitySet(writer, (EntitySet) obj);
|
||||||
} else if (obj instanceof Entry) {
|
} else if (obj instanceof Entity) {
|
||||||
entry(writer, (Entry) obj);
|
entity(writer, (Entity) obj);
|
||||||
} else if (obj instanceof Property) {
|
} else if (obj instanceof Property) {
|
||||||
property(writer, (Property) obj);
|
property(writer, (Property) obj);
|
||||||
} else if (obj instanceof Link) {
|
} 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 {
|
public <T> void write(final Writer writer, final ResWrap<T> container) throws XMLStreamException {
|
||||||
final T obj = container == null ? null : container.getPayload();
|
final T obj = container == null ? null : container.getPayload();
|
||||||
|
|
||||||
if (obj instanceof Feed) {
|
if (obj instanceof EntitySet) {
|
||||||
this.feed(writer, (ResWrap<Feed>) container);
|
this.entitySet(writer, (ResWrap<EntitySet>) container);
|
||||||
} else if (obj instanceof Entry) {
|
} else if (obj instanceof Entity) {
|
||||||
entry(writer, (ResWrap<Entry>) container);
|
entity(writer, (ResWrap<Entity>) container);
|
||||||
} else if (obj instanceof Property) {
|
} else if (obj instanceof Property) {
|
||||||
property(writer, (Property) obj);
|
property(writer, (Property) obj);
|
||||||
} else if (obj instanceof Link) {
|
} else if (obj instanceof Link) {
|
||||||
|
@ -458,11 +458,11 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
|
|
||||||
if (container.getContextURL() != null) {
|
if (container.getContextURL() != null) {
|
||||||
String base = container.getContextURL().getServiceRoot().toASCIIString();
|
String base = container.getContextURL().getServiceRoot().toASCIIString();
|
||||||
if (container.getPayload() instanceof AtomFeedImpl) {
|
if (container.getPayload() instanceof AtomEntitySetImpl) {
|
||||||
((AtomFeedImpl) container.getPayload()).setBaseURI(base);
|
((AtomEntitySetImpl) container.getPayload()).setBaseURI(base);
|
||||||
}
|
}
|
||||||
if (container.getPayload() instanceof AtomEntryImpl) {
|
if (container.getPayload() instanceof AtomEntityImpl) {
|
||||||
((AtomEntryImpl) container.getPayload()).setBaseURI(base);
|
((AtomEntityImpl) container.getPayload()).setBaseURI(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.writeAttribute(
|
writer.writeAttribute(
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -40,14 +40,14 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads JSON string into an entry.
|
* Reads JSON string into an entity.
|
||||||
* <br/>
|
* <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
|
@Override
|
||||||
protected ResWrap<JSONEntryImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
|
protected ResWrap<JSONEntityImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
|
||||||
throws IOException, JsonProcessingException {
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
final ObjectNode tree = parser.getCodec().readTree(parser);
|
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());
|
throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
final JSONEntryImpl entry = new JSONEntryImpl();
|
final JSONEntityImpl entity = new JSONEntityImpl();
|
||||||
|
|
||||||
final URI contextURL;
|
final URI contextURL;
|
||||||
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
|
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
|
||||||
|
@ -69,7 +69,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp
|
||||||
contextURL = null;
|
contextURL = null;
|
||||||
}
|
}
|
||||||
if (contextURL != null) {
|
if (contextURL != null) {
|
||||||
entry.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
|
entity.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String metadataETag;
|
final String metadataETag;
|
||||||
|
@ -81,17 +81,17 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree.hasNonNull(jsonETag)) {
|
if (tree.hasNonNull(jsonETag)) {
|
||||||
entry.setETag(tree.get(jsonETag).textValue());
|
entity.setETag(tree.get(jsonETag).textValue());
|
||||||
tree.remove(jsonETag);
|
tree.remove(jsonETag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree.hasNonNull(jsonType)) {
|
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);
|
tree.remove(jsonType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree.hasNonNull(jsonId)) {
|
if (tree.hasNonNull(jsonId)) {
|
||||||
entry.setId(tree.get(jsonId).textValue());
|
entity.setId(tree.get(jsonId).textValue());
|
||||||
tree.remove(jsonId);
|
tree.remove(jsonId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp
|
||||||
final LinkImpl link = new LinkImpl();
|
final LinkImpl link = new LinkImpl();
|
||||||
link.setRel(Constants.SELF_LINK_REL);
|
link.setRel(Constants.SELF_LINK_REL);
|
||||||
link.setHref(tree.get(jsonReadLink).textValue());
|
link.setHref(tree.get(jsonReadLink).textValue());
|
||||||
entry.setSelfLink(link);
|
entity.setSelfLink(link);
|
||||||
|
|
||||||
tree.remove(jsonReadLink);
|
tree.remove(jsonReadLink);
|
||||||
}
|
}
|
||||||
|
@ -111,25 +111,25 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp
|
||||||
link.setRel(Constants.EDIT_LINK_REL);
|
link.setRel(Constants.EDIT_LINK_REL);
|
||||||
}
|
}
|
||||||
link.setHref(tree.get(jsonEditLink).textValue());
|
link.setHref(tree.get(jsonEditLink).textValue());
|
||||||
entry.setEditLink(link);
|
entity.setEditLink(link);
|
||||||
|
|
||||||
tree.remove(jsonEditLink);
|
tree.remove(jsonEditLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree.hasNonNull(jsonMediaReadLink)) {
|
if (tree.hasNonNull(jsonMediaReadLink)) {
|
||||||
entry.setMediaContentSource(tree.get(jsonMediaReadLink).textValue());
|
entity.setMediaContentSource(tree.get(jsonMediaReadLink).textValue());
|
||||||
tree.remove(jsonMediaReadLink);
|
tree.remove(jsonMediaReadLink);
|
||||||
}
|
}
|
||||||
if (tree.hasNonNull(jsonMediaEditLink)) {
|
if (tree.hasNonNull(jsonMediaEditLink)) {
|
||||||
entry.setMediaContentSource(tree.get(jsonMediaEditLink).textValue());
|
entity.setMediaContentSource(tree.get(jsonMediaEditLink).textValue());
|
||||||
tree.remove(jsonMediaEditLink);
|
tree.remove(jsonMediaEditLink);
|
||||||
}
|
}
|
||||||
if (tree.hasNonNull(jsonMediaContentType)) {
|
if (tree.hasNonNull(jsonMediaContentType)) {
|
||||||
entry.setMediaContentType(tree.get(jsonMediaContentType).textValue());
|
entity.setMediaContentType(tree.get(jsonMediaContentType).textValue());
|
||||||
tree.remove(jsonMediaContentType);
|
tree.remove(jsonMediaContentType);
|
||||||
}
|
}
|
||||||
if (tree.hasNonNull(jsonMediaETag)) {
|
if (tree.hasNonNull(jsonMediaETag)) {
|
||||||
entry.setMediaETag(tree.get(jsonMediaETag).textValue());
|
entity.setMediaETag(tree.get(jsonMediaETag).textValue());
|
||||||
tree.remove(jsonMediaETag);
|
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();) {
|
for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
|
||||||
final Map.Entry<String, JsonNode> field = itor.next();
|
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))) {
|
if (field.getKey().endsWith(getJSONAnnotation(jsonMediaEditLink))) {
|
||||||
final LinkImpl link = new LinkImpl();
|
final LinkImpl link = new LinkImpl();
|
||||||
link.setTitle(getTitle(field));
|
link.setTitle(getTitle(field));
|
||||||
link.setRel(version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL) + getTitle(field));
|
link.setRel(version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL) + getTitle(field));
|
||||||
link.setHref(field.getValue().textValue());
|
link.setHref(field.getValue().textValue());
|
||||||
link.setType(ODataLinkType.MEDIA_EDIT.toString());
|
link.setType(ODataLinkType.MEDIA_EDIT.toString());
|
||||||
entry.getMediaEditLinks().add(link);
|
entity.getMediaEditLinks().add(link);
|
||||||
|
|
||||||
if (tree.has(link.getTitle() + getJSONAnnotation(jsonMediaETag))) {
|
if (tree.has(link.getTitle() + getJSONAnnotation(jsonMediaETag))) {
|
||||||
link.setMediaETag(tree.get(link.getTitle() + getJSONAnnotation(jsonMediaETag)).asText());
|
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));
|
toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree, parser.getCodec(), link));
|
||||||
} else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) {
|
} else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) {
|
||||||
final String linkTitle = getTitle(field);
|
final String linkTitle = getTitle(field);
|
||||||
for (Link link : entry.getMediaEditLinks()) {
|
for (Link link : entity.getMediaEditLinks()) {
|
||||||
if (linkTitle.equals(link.getTitle())) {
|
if (linkTitle.equals(link.getTitle())) {
|
||||||
((LinkImpl) link).setType(field.getValue().asText());
|
((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.setTitle(opNode.get(Constants.ATTR_TITLE).asText());
|
||||||
operation.setTarget(URI.create(opNode.get(Constants.ATTR_TARGET).asText()));
|
operation.setTarget(URI.create(opNode.get(Constants.ATTR_TARGET).asText()));
|
||||||
|
|
||||||
entry.getOperations().add(operation);
|
entity.getOperations().add(operation);
|
||||||
|
|
||||||
toRemove.add(field.getKey());
|
toRemove.add(field.getKey());
|
||||||
}
|
}
|
||||||
|
@ -191,10 +191,10 @@ public class JSONEntryDeserializer extends AbstractJsonDeserializer<JSONEntryImp
|
||||||
type = null;
|
type = null;
|
||||||
|
|
||||||
value(property, field.getValue(), parser.getCodec());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,11 +22,11 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A single entry, represented via JSON.
|
* A single entity, represented via JSON.
|
||||||
*/
|
*/
|
||||||
@JsonSerialize(using = JSONEntrySerializer.class)
|
@JsonSerialize(using = JSONEntitySerializer.class)
|
||||||
@JsonDeserialize(using = JSONEntryDeserializer.class)
|
@JsonDeserialize(using = JSONEntityDeserializer.class)
|
||||||
public class JSONEntryImpl extends AbstractEntry {
|
public class JSONEntityImpl extends AbstractEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = -5275365545400797758L;
|
private static final long serialVersionUID = -5275365545400797758L;
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.net.URI;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
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;
|
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
|
@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 {
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
doContainerSerialize(new ResWrap<JSONEntryImpl>((URI) null, null, entry), jgen, provider);
|
doContainerSerialize(new ResWrap<JSONEntityImpl>((URI) null, null, entity), jgen, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doContainerSerialize(
|
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 {
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
final Entry entry = container.getPayload();
|
final Entity entity = container.getPayload();
|
||||||
|
|
||||||
jgen.writeStartObject();
|
jgen.writeStartObject();
|
||||||
|
|
||||||
|
@ -64,45 +64,45 @@ public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> {
|
||||||
jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag());
|
jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(entry.getETag())) {
|
if (StringUtils.isNotBlank(entity.getETag())) {
|
||||||
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ETAG), entry.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),
|
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) {
|
if (entity.getId() != null) {
|
||||||
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entry.getId());
|
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());
|
property(jgen, property, property.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverMode && entry.getEditLink() != null && StringUtils.isNotBlank(entry.getEditLink().getHref())) {
|
if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) {
|
||||||
final URI link = URI.create(entry.getEditLink().getHref());
|
final URI link = URI.create(entity.getEditLink().getHref());
|
||||||
final String editLink = link.isAbsolute() ? link.toASCIIString()
|
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);
|
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) {
|
if (link.getTitle() == null) {
|
||||||
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), link.getHref());
|
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), link.getHref());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (link.getInlineEntry() != null) {
|
if (link.getInlineEntity() != null) {
|
||||||
jgen.writeObjectField(link.getTitle(), link.getInlineEntry());
|
jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
|
||||||
}
|
}
|
||||||
if (link.getInlineFeed() != null) {
|
if (link.getInlineEntitySet() != null) {
|
||||||
jgen.writeArrayFieldStart(link.getTitle());
|
jgen.writeArrayFieldStart(link.getTitle());
|
||||||
for (Entry subEntry : link.getInlineFeed().getEntries()) {
|
for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
|
||||||
jgen.writeObject(subEntry);
|
jgen.writeObject(subEntry);
|
||||||
}
|
}
|
||||||
jgen.writeEndArray();
|
jgen.writeEndArray();
|
||||||
|
@ -110,7 +110,7 @@ public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverMode) {
|
if (serverMode) {
|
||||||
for (ODataOperation operation : entry.getOperations()) {
|
for (ODataOperation operation : entity.getOperations()) {
|
||||||
jgen.writeObjectFieldStart("#" + StringUtils.substringAfterLast(operation.getMetadataAnchor(), "#"));
|
jgen.writeObjectFieldStart("#" + StringUtils.substringAfterLast(operation.getMetadataAnchor(), "#"));
|
||||||
jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle());
|
jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle());
|
||||||
jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
|
jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
|
|
@ -27,18 +27,19 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads JSON string into a feed.
|
* Reads JSON string into an entity set.
|
||||||
* <br/>
|
* <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
|
@Override
|
||||||
protected ResWrap<JSONFeedImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
|
protected ResWrap<JSONEntitySetImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
|
||||||
throws IOException, JsonProcessingException {
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
|
final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
|
||||||
|
@ -47,7 +48,7 @@ public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl>
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final JSONFeedImpl feed = new JSONFeedImpl();
|
final JSONEntitySetImpl entitySet = new JSONEntitySetImpl();
|
||||||
|
|
||||||
final URI contextURL;
|
final URI contextURL;
|
||||||
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
|
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
|
||||||
|
@ -59,7 +60,9 @@ public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl>
|
||||||
} else {
|
} else {
|
||||||
contextURL = null;
|
contextURL = null;
|
||||||
}
|
}
|
||||||
feed.setMetadataContextURL(contextURL);
|
if (contextURL != null) {
|
||||||
|
entitySet.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
|
||||||
|
}
|
||||||
|
|
||||||
final String metadataETag;
|
final String metadataETag;
|
||||||
if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
|
if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
|
||||||
|
@ -69,22 +72,22 @@ public class JSONFeedDeserializer extends AbstractJsonDeserializer<JSONFeedImpl>
|
||||||
metadataETag = null;
|
metadataETag = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree.hasNonNull(Constants.JSON_COUNT)) {
|
if (tree.hasNonNull(jsonCount)) {
|
||||||
feed.setCount(tree.get(Constants.JSON_COUNT).asInt());
|
entitySet.setCount(tree.get(jsonCount).asInt());
|
||||||
}
|
}
|
||||||
if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) {
|
if (tree.hasNonNull(jsonNextLink)) {
|
||||||
feed.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue()));
|
entitySet.setNext(URI.create(tree.get(jsonNextLink).textValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree.hasNonNull(Constants.VALUE)) {
|
if (tree.hasNonNull(Constants.VALUE)) {
|
||||||
for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).iterator(); itor.hasNext();) {
|
for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).iterator(); itor.hasNext();) {
|
||||||
feed.getEntries().add(
|
entitySet.getEntities().add(
|
||||||
itor.next().traverse(parser.getCodec()).<ResWrap<JSONEntryImpl>>readValueAs(
|
itor.next().traverse(parser.getCodec()).<ResWrap<JSONEntityImpl>>readValueAs(
|
||||||
new TypeReference<JSONEntryImpl>() {
|
new TypeReference<JSONEntityImpl>() {
|
||||||
}).getPayload());
|
}).getPayload());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResWrap<JSONFeedImpl>(contextURL, metadataETag, feed);
|
return new ResWrap<JSONEntitySetImpl>(contextURL, metadataETag, entitySet);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -26,25 +26,25 @@ import java.net.URI;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
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;
|
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||||
|
|
||||||
public class JSONFeedSerializer extends AbstractJsonSerializer<JSONFeedImpl> {
|
public class JSONEntitySetSerializer extends AbstractJsonSerializer<JSONEntitySetImpl> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doSerialize(
|
protected void doSerialize(
|
||||||
final JSONFeedImpl feed, final JsonGenerator jgen, final SerializerProvider provider)
|
final JSONEntitySetImpl entitySet, final JsonGenerator jgen, final SerializerProvider provider)
|
||||||
throws IOException, JsonProcessingException {
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
doContainerSerialize(new ResWrap<JSONFeedImpl>((URI) null, null, feed), jgen, provider);
|
doContainerSerialize(new ResWrap<JSONEntitySetImpl>((URI) null, null, entitySet), jgen, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doContainerSerialize(
|
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 {
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
final JSONFeedImpl feed = container.getPayload();
|
final JSONEntitySetImpl entitySet = container.getPayload();
|
||||||
|
|
||||||
jgen.writeStartObject();
|
jgen.writeStartObject();
|
||||||
|
|
||||||
|
@ -62,19 +62,19 @@ public class JSONFeedSerializer extends AbstractJsonSerializer<JSONFeedImpl> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feed.getId() != null) {
|
if (entitySet.getId() != null) {
|
||||||
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), feed.getId());
|
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entitySet.getId());
|
||||||
}
|
}
|
||||||
if (feed.getCount() != null) {
|
jgen.writeNumberField(version.getJSONMap().get(ODataServiceVersion.JSON_COUNT),
|
||||||
jgen.writeNumberField(Constants.JSON_COUNT, feed.getCount());
|
entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount());
|
||||||
}
|
if (entitySet.getNext() != null) {
|
||||||
if (feed.getNext() != null) {
|
jgen.writeStringField(
|
||||||
jgen.writeStringField(Constants.JSON_NEXT_LINK, feed.getNext().toASCIIString());
|
version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK), entitySet.getNext().toASCIIString());
|
||||||
}
|
}
|
||||||
|
|
||||||
jgen.writeArrayFieldStart(Constants.VALUE);
|
jgen.writeArrayFieldStart(Constants.VALUE);
|
||||||
for (Entry entry : feed.getEntries()) {
|
for (Entity entity : entitySet.getEntities()) {
|
||||||
jgen.writeObject(entry);
|
jgen.writeObject(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
jgen.writeEndArray();
|
jgen.writeEndArray();
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,8 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.commons.core.data;
|
package org.apache.olingo.commons.core.data;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.Link;
|
||||||
|
|
||||||
public class LinkImpl extends AbstractPayloadObject implements Link {
|
public class LinkImpl extends AbstractPayloadObject implements Link {
|
||||||
|
@ -36,9 +36,9 @@ public class LinkImpl extends AbstractPayloadObject implements Link {
|
||||||
|
|
||||||
private String mediaETag;
|
private String mediaETag;
|
||||||
|
|
||||||
private Entry entry;
|
private Entity entity;
|
||||||
|
|
||||||
private Feed feed;
|
private EntitySet entitySet;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
|
@ -91,22 +91,22 @@ public class LinkImpl extends AbstractPayloadObject implements Link {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entry getInlineEntry() {
|
public Entity getInlineEntity() {
|
||||||
return entry;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInlineEntry(final Entry entry) {
|
public void setInlineEntity(final Entity entity) {
|
||||||
this.entry = entry;
|
this.entity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Feed getInlineFeed() {
|
public EntitySet getInlineEntitySet() {
|
||||||
return feed;
|
return entitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInlineFeed(final Feed feed) {
|
public void setInlineEntitySet(final EntitySet entitySet) {
|
||||||
this.feed = feed;
|
this.entitySet = entitySet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,12 @@ public abstract class ODataJacksonDeserializer<T> extends JsonDeserializer<T> {
|
||||||
|
|
||||||
protected String jsonNavigationLink;
|
protected String jsonNavigationLink;
|
||||||
|
|
||||||
|
protected String jsonCount;
|
||||||
|
|
||||||
|
protected String jsonNextLink;
|
||||||
|
|
||||||
|
protected String jsonDeltaLink;
|
||||||
|
|
||||||
protected String jsonError;
|
protected String jsonError;
|
||||||
|
|
||||||
protected abstract T doDeserialize(JsonParser jp, DeserializationContext ctxt)
|
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);
|
jsonMediaETag = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG);
|
||||||
jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK);
|
jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK);
|
||||||
jsonNavigationLink = version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_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);
|
jsonError = version.getJSONMap().get(ODataServiceVersion.JSON_ERROR);
|
||||||
|
|
||||||
return doDeserialize(jp, ctxt);
|
return doDeserialize(jp, ctxt);
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.olingo.commons.api.data.v3.LinkCollection;
|
||||||
import org.apache.olingo.commons.core.data.AbstractPayloadObject;
|
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 {
|
public class JSONLinkCollectionImpl extends AbstractPayloadObject implements LinkCollection {
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public abstract class AbstractODataEntity extends AbstractODataPayload implement
|
||||||
private URI editLink;
|
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>();
|
private final List<ODataLink> navigationLinks = new ArrayList<ODataLink>();
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,9 @@ public abstract class AbstractODataEntitySet extends AbstractODataPayload implem
|
||||||
private URI next;
|
private URI next;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of ODataEntities contained in this feed. If <tt>$inlinecount</tt> was requested, this value comes from
|
* Number of ODataEntities contained in this entity set.
|
||||||
* there.
|
* <br/>
|
||||||
|
* If <tt>$inlinecount</tt> was requested, this value comes from there.
|
||||||
*/
|
*/
|
||||||
private Integer count;
|
private Integer count;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class ODataComplexValueImpl extends AbstractODataComplexValue<ODataProper
|
||||||
private static final long serialVersionUID = 1143925901934898802L;
|
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>();
|
private final List<ODataLink> navigationLinks = new ArrayList<ODataLink>();
|
||||||
|
|
||||||
|
|
|
@ -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.EdmException;
|
||||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmType;
|
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
|
||||||
public abstract class AbstractEdmNavigationProperty extends EdmElementImpl implements EdmNavigationProperty {
|
public abstract class AbstractEdmNavigationProperty extends EdmElementImpl implements EdmNavigationProperty {
|
||||||
|
|
|
@ -22,9 +22,9 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.net.URI;
|
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.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.data.Property;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
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.api.op.CommonODataDeserializer;
|
||||||
import org.apache.olingo.commons.core.data.AtomDeserializer;
|
import org.apache.olingo.commons.core.data.AtomDeserializer;
|
||||||
import org.apache.olingo.commons.api.data.ResWrap;
|
import org.apache.olingo.commons.api.data.ResWrap;
|
||||||
import org.apache.olingo.commons.core.data.AtomEntryImpl;
|
import org.apache.olingo.commons.core.data.AtomEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomFeedImpl;
|
import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONEntryImpl;
|
import org.apache.olingo.commons.core.data.JSONEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONFeedImpl;
|
import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONODataErrorImpl;
|
import org.apache.olingo.commons.core.data.JSONODataErrorImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.XMLODataErrorImpl;
|
import org.apache.olingo.commons.core.data.XMLODataErrorImpl;
|
||||||
|
@ -54,17 +54,17 @@ public abstract class AbstractODataDeserializer extends AbstractJacksonTool impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
return format == ODataPubFormat.ATOM
|
||||||
? this.<Feed, AtomFeedImpl>atom(input, AtomFeedImpl.class)
|
? this.<EntitySet, AtomEntitySetImpl>atom(input, AtomEntitySetImpl.class)
|
||||||
: this.<Feed, JSONFeedImpl>json(input, JSONFeedImpl.class);
|
: this.<EntitySet, JSONEntitySetImpl>json(input, JSONEntitySetImpl.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
return format == ODataPubFormat.ATOM
|
||||||
? this.<Entry, AtomEntryImpl>atom(input, AtomEntryImpl.class)
|
? this.<Entity, AtomEntityImpl>atom(input, AtomEntityImpl.class)
|
||||||
: this.<Entry, JSONEntryImpl>json(input, JSONEntryImpl.class);
|
: this.<Entity, JSONEntityImpl>json(input, JSONEntityImpl.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,19 +25,19 @@ import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import org.apache.olingo.commons.api.Constants;
|
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.Feed;
|
import org.apache.olingo.commons.api.data.EntitySet;
|
||||||
import org.apache.olingo.commons.api.data.Link;
|
import org.apache.olingo.commons.api.data.Link;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||||
import org.apache.olingo.commons.api.op.ODataSerializer;
|
import org.apache.olingo.commons.api.op.ODataSerializer;
|
||||||
import org.apache.olingo.commons.core.data.AtomEntryImpl;
|
import org.apache.olingo.commons.core.data.AtomEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomFeedImpl;
|
import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomSerializer;
|
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.JSONFeedImpl;
|
import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
||||||
|
|
||||||
public abstract class AbstractODataSerializer extends AbstractJacksonTool implements ODataSerializer {
|
public abstract class AbstractODataSerializer extends AbstractJacksonTool implements ODataSerializer {
|
||||||
|
@ -53,30 +53,30 @@ public abstract class AbstractODataSerializer extends AbstractJacksonTool implem
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void feed(final Feed obj, final OutputStream out) {
|
public void entitySet(final EntitySet obj, final OutputStream out) {
|
||||||
feed(obj, new OutputStreamWriter(out));
|
entitySet(obj, new OutputStreamWriter(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void feed(final Feed obj, final Writer writer) {
|
public void entitySet(final EntitySet obj, final Writer writer) {
|
||||||
if (obj instanceof AtomFeedImpl) {
|
if (obj instanceof AtomEntitySetImpl) {
|
||||||
atom((AtomFeedImpl) obj, writer);
|
atom((AtomEntitySetImpl) obj, writer);
|
||||||
} else {
|
} else {
|
||||||
json((JSONFeedImpl) obj, writer);
|
json((JSONEntitySetImpl) obj, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void entry(final Entry obj, final OutputStream out) {
|
public void entity(final Entity obj, final OutputStream out) {
|
||||||
entry(obj, new OutputStreamWriter(out));
|
entity(obj, new OutputStreamWriter(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void entry(final Entry obj, final Writer writer) {
|
public void entity(final Entity obj, final Writer writer) {
|
||||||
if (obj instanceof AtomEntryImpl) {
|
if (obj instanceof AtomEntityImpl) {
|
||||||
atom((AtomEntryImpl) obj, writer);
|
atom((AtomEntityImpl) obj, writer);
|
||||||
} else {
|
} else {
|
||||||
json((JSONEntryImpl) obj, writer);
|
json((JSONEntityImpl) obj, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,62 +18,62 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.commons.core.op;
|
package org.apache.olingo.commons.core.op;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.Entry;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
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.data.Property;
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
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.apache.olingo.commons.core.data.AtomFeedImpl;
|
import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
import org.apache.olingo.commons.core.data.AtomPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONEntryImpl;
|
import org.apache.olingo.commons.core.data.JSONEntityImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONFeedImpl;
|
import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
|
||||||
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
import org.apache.olingo.commons.core.data.JSONPropertyImpl;
|
||||||
|
|
||||||
public class ResourceFactory {
|
public class ResourceFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a new instance of <tt>Feed</tt>.
|
* Gets a new instance of <tt>EntitySet</tt>.
|
||||||
*
|
*
|
||||||
* @param resourceClass reference class.
|
* @param resourceClass reference class.
|
||||||
* @return <tt>Feed</tt> object.
|
* @return {@link EntitySet} object.
|
||||||
*/
|
*/
|
||||||
public static Feed newFeed(final Class<? extends Feed> resourceClass) {
|
public static EntitySet newEntitySet(final Class<? extends EntitySet> resourceClass) {
|
||||||
Feed result = null;
|
EntitySet result = null;
|
||||||
|
|
||||||
if (AtomFeedImpl.class.equals(resourceClass)) {
|
if (AtomEntitySetImpl.class.equals(resourceClass)) {
|
||||||
result = new AtomFeedImpl();
|
result = new AtomEntitySetImpl();
|
||||||
}
|
}
|
||||||
if (JSONFeedImpl.class.equals(resourceClass)) {
|
if (JSONEntitySetImpl.class.equals(resourceClass)) {
|
||||||
result = new JSONFeedImpl();
|
result = new JSONEntitySetImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a new instance of <tt>Entry</tt>.
|
* Gets a new instance of <tt>Entity</tt>.
|
||||||
*
|
*
|
||||||
* @param resourceClass reference class.
|
* @param resourceClass reference class.
|
||||||
* @return <tt>Entry</tt> object.
|
* @return {@link Entity} object.
|
||||||
*/
|
*/
|
||||||
public static Entry newEntry(final Class<? extends Entry> resourceClass) {
|
public static Entity newEntity(final Class<? extends Entity> resourceClass) {
|
||||||
Entry result = null;
|
Entity result = null;
|
||||||
if (AtomEntryImpl.class.equals(resourceClass)) {
|
if (AtomEntityImpl.class.equals(resourceClass)) {
|
||||||
result = new AtomEntryImpl();
|
result = new AtomEntityImpl();
|
||||||
}
|
}
|
||||||
if (JSONEntryImpl.class.equals(resourceClass)) {
|
if (JSONEntityImpl.class.equals(resourceClass)) {
|
||||||
result = new JSONEntryImpl();
|
result = new JSONEntityImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Property newProperty(final Class<? extends Entry> resourceClass) {
|
public static Property newProperty(final Class<? extends Entity> resourceClass) {
|
||||||
Property result = null;
|
Property result = null;
|
||||||
if (AtomEntryImpl.class.equals(resourceClass)) {
|
if (AtomEntityImpl.class.equals(resourceClass)) {
|
||||||
result = new AtomPropertyImpl();
|
result = new AtomPropertyImpl();
|
||||||
}
|
}
|
||||||
if (JSONEntryImpl.class.equals(resourceClass)) {
|
if (JSONEntityImpl.class.equals(resourceClass)) {
|
||||||
result = new JSONPropertyImpl();
|
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
|
* @param isXML whether it is JSON or XML / Atom
|
||||||
* @return resource reference class.
|
* @return resource reference class.
|
||||||
*/
|
*/
|
||||||
public static Class<? extends Feed> feedClassForFormat(final boolean isXML) {
|
public static Class<? extends EntitySet> entitySetClassForFormat(final boolean isXML) {
|
||||||
return isXML ? AtomFeedImpl.class : JSONFeedImpl.class;
|
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
|
* @param isXML whether it is JSON or XML / Atom
|
||||||
* @return resource reference class.
|
* @return resource reference class.
|
||||||
*/
|
*/
|
||||||
public static Class<? extends Entry> entryClassForFormat(final boolean isXML) {
|
public static Class<? extends Entity> entityClassForFormat(final boolean isXML) {
|
||||||
return isXML ? AtomEntryImpl.class : JSONEntryImpl.class;
|
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.
|
* @param resourceClass entity set reference class.
|
||||||
* @return <tt>Entry</tt> object.
|
* @return {@link Entity} object.
|
||||||
*/
|
*/
|
||||||
public static Class<? extends Entry> entryClassForFeed(final Class<? extends Feed> resourceClass) {
|
public static Class<? extends Entity> entityClassForEntitySet(final Class<? extends EntitySet> resourceClass) {
|
||||||
Class<? extends Entry> result = null;
|
Class<? extends Entity> result = null;
|
||||||
|
|
||||||
if (AtomFeedImpl.class.equals(resourceClass)) {
|
if (AtomEntitySetImpl.class.equals(resourceClass)) {
|
||||||
result = AtomEntryImpl.class;
|
result = AtomEntityImpl.class;
|
||||||
}
|
}
|
||||||
if (JSONFeedImpl.class.equals(resourceClass)) {
|
if (JSONEntitySetImpl.class.equals(resourceClass)) {
|
||||||
result = JSONEntryImpl.class;
|
result = JSONEntityImpl.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ODataPubFormat formatForEntryClass(final Class<? extends Entry> reference) {
|
public static ODataPubFormat formatForEntityClass(final Class<? extends Entity> reference) {
|
||||||
return reference.equals(AtomEntryImpl.class) ? ODataPubFormat.ATOM : ODataPubFormat.JSON;
|
return reference.equals(AtomEntityImpl.class) ? ODataPubFormat.ATOM : ODataPubFormat.JSON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue