Merge from master
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/6c7aef90 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/6c7aef90 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/6c7aef90 Branch: refs/heads/master Commit: 6c7aef90eae4eaf93ca948fe70ddd59bd20275ba Parents: e26d55d 639941c Author: Francesco Chicchiriccò <[email protected]> Authored: Tue Apr 29 10:59:19 2014 +0200 Committer: Francesco Chicchiriccò <[email protected]> Committed: Tue Apr 29 10:59:19 2014 +0200 ---------------------------------------------------------------------- fit/pom.xml | 14 --- .../org/apache/olingo/fit/AbstractServices.java | 117 ++++++++++++------- .../java/org/apache/olingo/fit/V3OpenType.java | 3 +- .../java/org/apache/olingo/fit/V4OpenType.java | 2 +- .../apache/olingo/fit/metadata/Metadata.java | 50 +++++--- .../olingo/fit/utils/AbstractUtilities.java | 64 +++++----- .../org/apache/olingo/fit/utils/Commons.java | 6 +- .../apache/olingo/fit/utils/ConstantKey.java | 3 + .../org/apache/olingo/fit/utils/Constants.java | 12 ++ .../org/apache/olingo/fit/utils/XMLElement.java | 5 +- .../olingo/fit/utils/XMLEventReaderWrapper.java | 29 ++--- .../apache/olingo/fit/utils/XMLUtilities.java | 73 ++++++------ fit/src/main/resources/V30/openTypeMetadata.xml | 2 +- .../client/core/it/v4/PropertyTestITCase.java | 57 ++++++++- 14 files changed, 268 insertions(+), 169 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6c7aef90/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java ---------------------------------------------------------------------- diff --cc fit/src/main/java/org/apache/olingo/fit/AbstractServices.java index e43a37b,5ce5790..f3be7ce --- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java +++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java @@@ -1142,26 -1144,50 +1144,50 @@@ public abstract class AbstractServices final String changes, final boolean justValue) { + // if the given path is not about any link then search for property + LOG.info("Retrieve property {}", path); + try { - Accept acceptType = null; - if (StringUtils.isNotBlank(format)) { - acceptType = Accept.valueOf(format.toUpperCase()); - } else if (StringUtils.isNotBlank(accept)) { - acceptType = Accept.parse(accept, version, null); + final FSManager fsManager = FSManager.instance(version); + + final String basePath = Commons.getEntityBasePath(entitySetName, entityId); - final ResWrap<AtomEntityImpl> container = xml.readContainerEntry(Accept.ATOM, ++ final ResWrap<AtomEntityImpl> container = xml.readContainerEntity(Accept.ATOM, + fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), Accept.ATOM)); + + final AtomEntityImpl entry = container.getPayload(); + + Property toBeReplaced = null; + for (String element : path.split("/")) { + if (toBeReplaced == null) { + toBeReplaced = entry.getProperty(element.trim()); + } else { + ComplexValue value = toBeReplaced.getValue().asComplex(); + for (Property field : value.get()) { + if (field.getName().equalsIgnoreCase(element)) { + toBeReplaced = field; + } + } + } } - // if the given path is not about any link then search for property - LOG.info("Retrieve property {}", path); + if (toBeReplaced == null) { + throw new NotFoundException(); + } - final AbstractUtilities utils = getUtilities(acceptType); + if (justValue) { + // just for primitive values + toBeReplaced.setValue(new PrimitiveValueImpl(changes)); + } else { + final AtomPropertyImpl pchanges = xml.readProperty( + Accept.parse(contentType, version), + IOUtils.toInputStream(changes, Constants.ENCODING), + entry.getType()); - utils.replaceProperty( - entitySetName, - entityId, - IOUtils.toInputStream(changes, Constants.ENCODING), - Arrays.asList(path.split("/")), - acceptType, - justValue); + toBeReplaced.setValue(pchanges.getValue()); + } + - fsManager.putInMemory(xml.writeEntry(Accept.ATOM, container), ++ fsManager.putInMemory(xml.writeEntity(Accept.ATOM, container), + fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), Accept.ATOM)); final Response response; if ("return-content".equalsIgnoreCase(prefer)) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6c7aef90/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java ---------------------------------------------------------------------- diff --cc fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java index 770f97c,2882784..f202fc4 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java @@@ -576,25 -556,32 +575,32 @@@ public abstract class AbstractUtilitie return IOUtils.toInputStream(writer.toString(), Constants.ENCODING); } - public AtomEntityImpl readEntity(final Accept accept, final InputStream entity) - public ResWrap<AtomEntityImpl> readContainerEntry(final Accept accept, final InputStream entity) ++ public ResWrap<AtomEntityImpl> readContainerEntity(final Accept accept, final InputStream entity) throws XMLStreamException, IOException { - - final AtomEntityImpl entry; + final ResWrap<AtomEntityImpl> container; if (accept == Accept.ATOM || accept == Accept.XML) { - final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entity, AtomEntityImpl.class); - entry = container.getPayload(); + container = atomDeserializer.read(entity, AtomEntityImpl.class); } else { - final ResWrap<JSONEntityImpl> container = + final ResWrap<JSONEntityImpl> jcontainer = mapper.readValue(entity, new TypeReference<JSONEntityImpl>() { - }); + }); - entry = dataBinder.toAtomEntity(container.getPayload()); + container = new ResWrap<AtomEntityImpl>( + jcontainer.getContextURL(), + jcontainer.getMetadataETag(), + dataBinder.toAtomEntity(jcontainer.getPayload())); } - return entry; + return container; + } + - public AtomEntityImpl readEntry(final Accept accept, final InputStream entity) ++ public AtomEntityImpl readEntity(final Accept accept, final InputStream entity) + throws XMLStreamException, IOException { - return readContainerEntry(accept, entity).getPayload(); + ++ return readContainerEntity(accept, entity).getPayload(); } - public InputStream writeEntry(final Accept accept, final ResWrap<AtomEntityImpl> container) + public InputStream writeEntity(final Accept accept, final ResWrap<AtomEntityImpl> container) throws XMLStreamException, IOException { final StringWriter writer = new StringWriter(); @@@ -624,6 -611,23 +630,23 @@@ return IOUtils.toInputStream(writer.toString(), Constants.ENCODING); } + public AtomPropertyImpl readProperty(final Accept accept, final InputStream property, final String entryType) + throws XMLStreamException, IOException { + final AtomPropertyImpl atomProperty; + if (Accept.ATOM == accept || Accept.XML == accept) { + final ResWrap<AtomPropertyImpl> container = atomDeserializer.read(property, AtomPropertyImpl.class); + atomProperty = container.getPayload(); + } else { + final ResWrap<JSONPropertyImpl> jcontainer = mapper.readValue(property, + new TypeReference<JSONPropertyImpl>() { - }); ++ }); + + atomProperty = dataBinder.toAtomProperty(jcontainer.getPayload(), entryType); + } + + return atomProperty; + } + public InputStream writeProperty(final Accept accept, final ResWrap<AtomPropertyImpl> container) throws XMLStreamException, IOException { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6c7aef90/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java ----------------------------------------------------------------------
