You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/06/06 14:51:16 UTC
[1/9] First presentable state
Repository: olingo-odata4
Updated Branches:
refs/heads/OLINGO-317_JSON-for-server [created] bd9bf1e26
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java
new file mode 100755
index 0000000..3310723
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java
@@ -0,0 +1,78 @@
+/*
+ * 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.v3;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.commons.api.data.v3.LinkCollection;
+
+public class LinkCollectionImpl implements LinkCollection {
+
+ private final List<URI> links = new ArrayList<URI>();
+ private URI next;
+ private URI metadata;
+
+ /**
+ * Constructor.
+ */
+ public LinkCollectionImpl() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param next next page link.
+ */
+ public LinkCollectionImpl(final URI next) {
+ this.next = next;
+ }
+
+ @Override
+ public List<URI> getLinks() {
+ return links;
+ }
+
+ @Override
+ public void setNext(final URI next) {
+ this.next = next;
+ }
+
+ @Override
+ public URI getNext() {
+ return next;
+ }
+
+ /**
+ * Gets the metadata URI.
+ */
+ public URI getMetadata() {
+ return metadata;
+ }
+
+ /**
+ * Sets the metadata URI.
+ *
+ * @param metadata metadata URI.
+ */
+ public void setMetadata(final URI metadata) {
+ this.metadata = metadata;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/XMLLinkCollectionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/XMLLinkCollectionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/XMLLinkCollectionImpl.java
deleted file mode 100644
index 8d9001c..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/XMLLinkCollectionImpl.java
+++ /dev/null
@@ -1,70 +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.v3;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.olingo.commons.api.data.v3.LinkCollection;
-
-public class XMLLinkCollectionImpl implements LinkCollection {
-
- private final List<URI> links = new ArrayList<URI>();
-
- private URI next;
-
- /**
- * Constructor.
- */
- public XMLLinkCollectionImpl() {
- }
-
- /**
- * Constructor.
- *
- * @param next next page link.
- */
- public XMLLinkCollectionImpl(final URI next) {
- this.next = next;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public List<URI> getLinks() {
- return links;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public void setNext(final URI next) {
- this.next = next;
- }
-
- /**
- * {@inheritDoc }
- */
- @Override
- public URI getNext() {
- return next;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AbstractDelta.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AbstractDelta.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AbstractDelta.java
deleted file mode 100644
index d4a50ed..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AbstractDelta.java
+++ /dev/null
@@ -1,52 +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.v4;
-
-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;
-import org.apache.olingo.commons.core.data.AbstractEntitySet;
-
-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>();
-
- @Override
- public List<DeletedEntity> getDeletedEntities() {
- return deletedEntities;
- }
-
- @Override
- public List<DeltaLink> getAddedLinks() {
- return addedLinks;
- }
-
- @Override
- public List<DeltaLink> getDeletedLinks() {
- return deletedLinks;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AtomDeltaImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AtomDeltaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AtomDeltaImpl.java
deleted file mode 100644
index d2f85b2..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/AtomDeltaImpl.java
+++ /dev/null
@@ -1,25 +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.v4;
-
-public class AtomDeltaImpl extends AbstractDelta {
-
- private static final long serialVersionUID = -730729098008847535L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java
new file mode 100755
index 0000000..021a77d
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java
@@ -0,0 +1,52 @@
+/*
+ * 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.v4;
+
+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;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
+
+public class DeltaImpl extends EntitySetImpl 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>();
+
+ @Override
+ public List<DeletedEntity> getDeletedEntities() {
+ return deletedEntities;
+ }
+
+ @Override
+ public List<DeltaLink> getAddedLinks() {
+ return addedLinks;
+ }
+
+ @Override
+ public List<DeltaLink> getDeletedLinks() {
+ return deletedLinks;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/JSONDeltaImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/JSONDeltaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/JSONDeltaImpl.java
deleted file mode 100644
index 7b60d5f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/JSONDeltaImpl.java
+++ /dev/null
@@ -1,29 +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.v4;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import org.apache.olingo.commons.core.data.JSONDeltaDeserializer;
-
-@JsonDeserialize(using = JSONDeltaDeserializer.class)
-public class JSONDeltaImpl extends AbstractDelta {
-
- private static final long serialVersionUID = -7948494801560470246L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractJacksonTool.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractJacksonTool.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractJacksonTool.java
deleted file mode 100644
index c4c32ad..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractJacksonTool.java
+++ /dev/null
@@ -1,86 +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.op;
-
-import com.fasterxml.aalto.stax.InputFactoryImpl;
-import com.fasterxml.aalto.stax.OutputFactoryImpl;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.InjectableValues;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
-import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
-import com.fasterxml.jackson.dataformat.xml.XmlFactory;
-import com.fasterxml.jackson.dataformat.xml.XmlMapper;
-import java.io.IOException;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-abstract class AbstractJacksonTool {
-
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractJacksonTool.class);
-
- protected final ODataServiceVersion version;
-
- protected AbstractJacksonTool(final ODataServiceVersion client) {
- this.version = client;
- }
-
- protected ObjectMapper getObjectMapper() {
- final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
-
- mapper.setInjectableValues(new InjectableValues.Std().
- addValue(ODataServiceVersion.class, version).
- addValue(Boolean.class, Boolean.FALSE));
-
- mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
- mapper.getSerializationConfig().withAttribute(ODataServiceVersion.class, version).
- withAttribute(Boolean.class, Boolean.FALSE),
- mapper.getSerializerFactory()));
-
- return mapper;
- }
-
- protected XmlMapper getXmlMapper() {
- final XmlMapper xmlMapper = new XmlMapper(
- new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
-
- xmlMapper.setInjectableValues(new InjectableValues.Std().
- addValue(ODataServiceVersion.class, version).
- addValue(Boolean.class, Boolean.FALSE));
-
- xmlMapper.addHandler(new DeserializationProblemHandler() {
- @Override
- public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser jp,
- final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName)
- throws IOException, JsonProcessingException {
-
- // skip any unknown property
- LOG.warn("Skipping unknown property {}", propertyName);
- ctxt.getParser().skipChildren();
- return true;
- }
- });
- return xmlMapper;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java
index f584868..a2ef134 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java
@@ -18,109 +18,84 @@
*/
package org.apache.olingo.commons.core.op;
-import com.fasterxml.jackson.core.type.TypeReference;
+import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.Type;
-import java.net.URI;
+
import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.ODataError;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.op.CommonODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.core.data.AtomDeserializer;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
-import org.apache.olingo.commons.core.data.AtomPropertyImpl;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
-import org.apache.olingo.commons.core.data.JSONODataErrorImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
-import org.apache.olingo.commons.core.data.XMLODataErrorImpl;
-
-public abstract class AbstractODataDeserializer extends AbstractJacksonTool implements CommonODataDeserializer {
+import org.apache.olingo.commons.core.data.JsonDeserializer;
- private static final long serialVersionUID = -4244158979195609909L;
+import com.fasterxml.aalto.stax.InputFactoryImpl;
+import com.fasterxml.aalto.stax.OutputFactoryImpl;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.InjectableValues;
+import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
+import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
+import com.fasterxml.jackson.dataformat.xml.XmlFactory;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
- private final AtomDeserializer atomDeserializer;
+public abstract class AbstractODataDeserializer {
- public AbstractODataDeserializer(final ODataServiceVersion version) {
- super(version);
+ protected final ODataServiceVersion version;
+ protected final ODataDeserializer deserializer;
- this.atomDeserializer = new AtomDeserializer(version);
+ public AbstractODataDeserializer(final ODataServiceVersion version, final Format format) {
+ this.version = version;
+ if (format == ODataFormat.XML || format == ODataPubFormat.ATOM) {
+ deserializer = new AtomDeserializer(version);
+ } else {
+ deserializer = new JsonDeserializer(version, false);
+ }
}
- @Override
- public ResWrap<EntitySet> toEntitySet(final InputStream input, final ODataPubFormat format) {
- return format == ODataPubFormat.ATOM
- ? this.<EntitySet, AtomEntitySetImpl>atom(input, AtomEntitySetImpl.class)
- : this.<EntitySet, JSONEntitySetImpl>json(input, JSONEntitySetImpl.class);
+ public ResWrap<EntitySet> toEntitySet(final InputStream input) throws ODataDeserializerException {
+ return deserializer.toEntitySet(input);
}
- @Override
- public ResWrap<Entity> toEntity(final InputStream input, final ODataPubFormat format) {
- return format == ODataPubFormat.ATOM
- ? this.<Entity, AtomEntityImpl>atom(input, AtomEntityImpl.class)
- : this.<Entity, JSONEntityImpl>json(input, JSONEntityImpl.class);
+ public ResWrap<Entity> toEntity(final InputStream input) throws ODataDeserializerException {
+ return deserializer.toEntity(input);
}
- @Override
- public ResWrap<Property> toProperty(final InputStream input, final ODataFormat format) {
- return format == ODataFormat.XML
- ? this.<Property, AtomPropertyImpl>atom(input, AtomPropertyImpl.class)
- : this.<Property, JSONPropertyImpl>json(input, JSONPropertyImpl.class);
+ public ResWrap<Property> toProperty(final InputStream input) throws ODataDeserializerException {
+ return deserializer.toProperty(input);
}
- @Override
- public ODataError toError(final InputStream input, final boolean isXML) {
- return isXML
- ? this.<ODataError, XMLODataErrorImpl>atom(input, XMLODataErrorImpl.class).getPayload()
- : this.<ODataError, JSONODataErrorImpl>json(input, JSONODataErrorImpl.class).getPayload();
+ public ODataError toError(final InputStream input) throws ODataDeserializerException {
+ return deserializer.toError(input);
}
- /*
- * ------------------ Protected methods ------------------
- */
- protected <T, V extends T> ResWrap<T> atom(final InputStream input, final Class<V> reference) {
- try {
- return atomDeserializer.<T, V>read(input, reference);
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
- }
- }
+ protected XmlMapper getXmlMapper() {
+ final XmlMapper xmlMapper = new XmlMapper(
+ new XmlFactory(new InputFactoryImpl(), new OutputFactoryImpl()), new JacksonXmlModule());
- @SuppressWarnings("unchecked")
- protected <T, V extends T> ResWrap<T> xml(final InputStream input, final Class<V> reference) {
- try {
- final T obj = getXmlMapper().readValue(input, new TypeReference<V>() {
- @Override
- public Type getType() {
- return reference;
- }
- });
+ xmlMapper.setInjectableValues(new InjectableValues.Std().
+ addValue(ODataServiceVersion.class, version).
+ addValue(Boolean.class, Boolean.FALSE));
- return obj instanceof ResWrap ? (ResWrap<T>) obj : new ResWrap<T>((URI) null, null, obj);
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
- }
- }
-
- @SuppressWarnings("unchecked")
- protected <T, V extends T> ResWrap<T> json(final InputStream input, final Class<V> reference) {
- try {
- final T obj = getObjectMapper().readValue(input, new TypeReference<V>() {
- @Override
- public Type getType() {
- return reference;
- }
- });
+ xmlMapper.addHandler(new DeserializationProblemHandler() {
+ @Override
+ public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser jp,
+ final com.fasterxml.jackson.databind.JsonDeserializer<?> deserializer,
+ final Object beanOrClass, final String propertyName)
+ throws IOException, JsonProcessingException {
- return obj instanceof ResWrap ? (ResWrap<T>) obj : new ResWrap<T>((URI) null, null, obj);
- } catch (Exception e) {
- throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
- }
+ // skip any unknown property
+ ctxt.getParser().skipChildren();
+ return true;
+ }
+ });
+ return xmlMapper;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java
deleted file mode 100644
index 32b9e99..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataSerializer.java
+++ /dev/null
@@ -1,141 +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.op;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.op.ODataSerializer;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
-import org.apache.olingo.commons.core.data.AtomPropertyImpl;
-import org.apache.olingo.commons.core.data.AtomSerializer;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
-
-public abstract class AbstractODataSerializer extends AbstractJacksonTool implements ODataSerializer {
-
- private static final long serialVersionUID = -357777648541325363L;
-
- private final AtomSerializer atomSerializer;
-
- public AbstractODataSerializer(final ODataServiceVersion version) {
- super(version);
-
- this.atomSerializer = new AtomSerializer(version);
- }
-
- @Override
- public void entitySet(final EntitySet obj, final OutputStream out) {
- entitySet(obj, new OutputStreamWriter(out));
- }
-
- @Override
- public void entitySet(final EntitySet obj, final Writer writer) {
- if (obj instanceof AtomEntitySetImpl) {
- atom((AtomEntitySetImpl) obj, writer);
- } else {
- json((JSONEntitySetImpl) obj, writer);
- }
- }
-
- @Override
- public void entity(final Entity obj, final OutputStream out) {
- entity(obj, new OutputStreamWriter(out));
- }
-
- @Override
- public void entity(final Entity obj, final Writer writer) {
- if (obj instanceof AtomEntityImpl) {
- atom((AtomEntityImpl) obj, writer);
- } else {
- json((JSONEntityImpl) obj, writer);
- }
- }
-
- @Override
- public void property(final Property obj, final OutputStream out) {
- property(obj, new OutputStreamWriter(out));
- }
-
- @Override
- public void property(final Property obj, final Writer writer) {
- if (obj instanceof AtomPropertyImpl) {
- atom((AtomPropertyImpl) obj, writer);
- } else {
- json((JSONPropertyImpl) obj, writer);
- }
- }
-
- @Override
- public void link(final Link link, final ODataFormat format, final OutputStream out) {
- link(link, format, new OutputStreamWriter(out));
- }
-
- @Override
- public void link(final Link link, final ODataFormat format, final Writer writer) {
- if (format == ODataFormat.XML) {
- atom(link, writer);
- } else {
- jsonLink(link, writer);
- }
- }
-
- /*
- * ------------------ Protected methods ------------------
- */
- protected <T> void atom(final T obj, final Writer writer) {
- try {
- atomSerializer.write(writer, obj);
- } catch (Exception e) {
- throw new IllegalArgumentException("While serializing Atom object", e);
- }
- }
-
- protected <T> void json(final T obj, final Writer writer) {
- try {
- getObjectMapper().writeValue(writer, obj);
- } catch (IOException e) {
- throw new IllegalArgumentException("While serializing JSON object", e);
- }
- }
-
- protected void jsonLink(final Link link, final Writer writer) {
- final ObjectMapper mapper = getObjectMapper();
- final ObjectNode uri = mapper.createObjectNode();
- uri.put(Constants.JSON_URL, link.getHref());
-
- try {
- mapper.writeValue(writer, uri);
- } catch (Exception e) {
- throw new IllegalArgumentException("While serializing JSON link", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java
deleted file mode 100644
index a2efe34..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/ResourceFactory.java
+++ /dev/null
@@ -1,125 +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.op;
-
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
-import org.apache.olingo.commons.core.data.AtomPropertyImpl;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
-
-public class ResourceFactory {
-
- /**
- * Gets a new instance of <tt>EntitySet</tt>.
- *
- * @param resourceClass reference class.
- * @return {@link EntitySet} object.
- */
- public static EntitySet newEntitySet(final Class<? extends EntitySet> resourceClass) {
- EntitySet result = null;
-
- if (AtomEntitySetImpl.class.equals(resourceClass)) {
- result = new AtomEntitySetImpl();
- }
- if (JSONEntitySetImpl.class.equals(resourceClass)) {
- result = new JSONEntitySetImpl();
- }
-
- return result;
- }
-
- /**
- * Gets a new instance of <tt>Entity</tt>.
- *
- * @param resourceClass reference class.
- * @return {@link Entity} object.
- */
- public static Entity newEntity(final Class<? extends Entity> resourceClass) {
- Entity result = null;
- if (AtomEntityImpl.class.equals(resourceClass)) {
- result = new AtomEntityImpl();
- }
- if (JSONEntityImpl.class.equals(resourceClass)) {
- result = new JSONEntityImpl();
- }
-
- return result;
- }
-
- public static Property newProperty(final Class<? extends Entity> resourceClass) {
- Property result = null;
- if (AtomEntityImpl.class.equals(resourceClass)) {
- result = new AtomPropertyImpl();
- }
- if (JSONEntityImpl.class.equals(resourceClass)) {
- result = new JSONPropertyImpl();
- }
-
- return result;
- }
-
- /**
- * Gets entity set reference class from the given format.
- *
- * @param isXML whether it is JSON or XML / Atom
- * @return resource reference class.
- */
- public static Class<? extends EntitySet> entitySetClassForFormat(final boolean isXML) {
- return isXML ? AtomEntitySetImpl.class : JSONEntitySetImpl.class;
- }
-
- /**
- * Gets entity reference class from the given format.
- *
- * @param isXML whether it is JSON or XML / Atom
- * @return resource reference class.
- */
- public static Class<? extends Entity> entityClassForFormat(final boolean isXML) {
- return isXML ? AtomEntityImpl.class : JSONEntityImpl.class;
- }
-
- /**
- * Gets <tt>Entity</tt> object from entity set resource.
- *
- * @param resourceClass entity set reference class.
- * @return {@link Entity} object.
- */
- public static Class<? extends Entity> entityClassForEntitySet(final Class<? extends EntitySet> resourceClass) {
- Class<? extends Entity> result = null;
-
- if (AtomEntitySetImpl.class.equals(resourceClass)) {
- result = AtomEntityImpl.class;
- }
- if (JSONEntitySetImpl.class.equals(resourceClass)) {
- result = JSONEntityImpl.class;
- }
-
- return result;
- }
-
- public static ODataPubFormat formatForEntityClass(final Class<? extends Entity> reference) {
- return reference.equals(AtomEntityImpl.class) ? ODataPubFormat.ATOM : ODataPubFormat.JSON;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index fd57c89..0eaf440 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -20,7 +20,12 @@ package org.apache.olingo.server.api.serializer;
import java.io.InputStream;
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
public interface ODataSerializer {
@@ -30,4 +35,7 @@ public interface ODataSerializer {
InputStream metadataDocument(Edm edm);
+ InputStream entity(EdmEntityType edmEntityType, Entity entity, ContextURL contextURL);
+
+ InputStream entitySet(EdmEntitySet edmEntitySet, EntitySet entitySet, ContextURL contextURL);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
index e5ca20c..cf9f3f3 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
@@ -18,16 +18,31 @@
*/
package org.apache.olingo.server.core;
+import java.io.IOException;
+import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpContentType;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.core.data.EntityImpl;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
+import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
+import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.commons.core.op.InjectableSerializerProvider;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
@@ -37,13 +52,19 @@ import org.apache.olingo.server.api.processor.EntitySetProcessor;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
+import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.apache.olingo.server.core.uri.parser.Parser;
import org.apache.olingo.server.core.uri.validator.UriValidator;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.InjectableValues;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
public class ODataHandler {
private final OData odata;
@@ -113,6 +134,39 @@ public class ODataHandler {
UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
switch (lastPathSegment.getKind()) {
case entitySet:
+ long time = System.nanoTime();
+ ResWrap<EntitySet> wrap = new ResWrap<EntitySet>(
+ ContextURL.getInstance(URI.create("dummyContextURL")), "dummyMetadataETag",
+ createEntitySet());
+ System.out.println((System.nanoTime() - time) / 1000 + " microseconds");
+ time = System.nanoTime();
+ CircleStreamBuffer buffer = new CircleStreamBuffer();
+ if (false) {
+ ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(Include.NON_NULL);
+ mapper.setInjectableValues(new InjectableValues.Std()
+ .addValue(ODataServiceVersion.class, ODataServiceVersion.V40)
+ .addValue(Boolean.class, Boolean.TRUE));
+ mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
+ mapper.getSerializationConfig()
+ .withAttribute(ODataServiceVersion.class, ODataServiceVersion.V40)
+ .withAttribute(Boolean.class, Boolean.TRUE),
+ mapper.getSerializerFactory()));
+ try {
+ mapper.writeValue(buffer.getOutputStream(), wrap);
+ } catch (final IOException e) {}
+ response.setContent(buffer.getInputStream());
+ } else {
+ ODataSerializer serializer = odata.createSerializer(org.apache.olingo.server.api.serializer.ODataFormat.JSON);
+ response.setContent(serializer.entitySet(
+ edm.getEntityContainer(new FullQualifiedName("com.sap.odata.test1", "Container"))
+ .getEntitySet("ESAllPrim"),
+ wrap.getPayload(),
+ ContextURL.getInstance(URI.create("dummyContextURL"))));
+ }
+ System.out.println((System.nanoTime() - time) / 1000 + " microseconds");
+ response.setStatusCode(200);
+ response.setHeader("Content-Type", ContentType.APPLICATION_JSON);
+
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
if (request.getMethod().equals(HttpMethod.GET)) {
EntitySetProcessor esp = selectProcessor(EntitySetProcessor.class);
@@ -186,4 +240,34 @@ public class ODataHandler {
}
}
}
+
+ protected Entity createEntity() {
+ Entity entity = new EntityImpl();
+ Property property = new PropertyImpl();
+ property.setName("PropertyString");
+ property.setType("String"); //"dummyType");
+ property.setValue(new PrimitiveValueImpl("dummyValue"));
+ entity.getProperties().add(property);
+ Property propertyInt = new PropertyImpl();
+ propertyInt.setName("PropertyInt16");
+ // propertyInt.setType("Edm.Int32");
+ propertyInt.setValue(new PrimitiveValueImpl("042"));
+ entity.getProperties().add(propertyInt);
+ Property propertyGuid = new PropertyImpl();
+ propertyGuid.setName("PropertyGuid");
+ propertyGuid.setType("Edm.Guid");
+ propertyGuid.setValue(new PrimitiveValueImpl(UUID.randomUUID().toString()));
+ entity.getProperties().add(propertyGuid);
+ return entity;
+ }
+
+ protected EntitySet createEntitySet() {
+ EntitySet entitySet = new EntitySetImpl();
+ entitySet.setCount(4242);
+ entitySet.setNext(URI.create("nextLinkURI"));
+ for (int i = 0; i < 1000; i++) {
+ entitySet.getEntities().add(createEntity());
+ }
+ return entitySet;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataJsonSerializer.java
index 333d5b7..62634da 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataJsonSerializer.java
@@ -23,8 +23,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
+import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.core.serializer.json.ServiceDocumentJsonSerializer;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
@@ -84,4 +95,97 @@ public class ODataJsonSerializer implements ODataSerializer {
public InputStream metadataDocument(final Edm edm) {
throw new ODataRuntimeException("Metadata in JSON format not supported!");
}
+
+ @Override
+ public InputStream entity(final EdmEntityType edmEntityType, final Entity entity, final ContextURL contextURL) {
+ CircleStreamBuffer buffer = new CircleStreamBuffer();
+ try {
+ JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+ writeEntity(edmEntityType, entity, contextURL, json);
+ json.close();
+ } catch (final IOException e) {
+ throw new ODataRuntimeException(e);
+ }
+ return buffer.getInputStream();
+ }
+
+ protected void writeEntity(final EdmEntityType entityType, final Entity entity, final ContextURL contextURL,
+ JsonGenerator json) throws IOException {
+ json.writeStartObject();
+ if (contextURL != null) {
+ json.writeStringField(Constants.JSON_CONTEXT, contextURL.getURI().toASCIIString());
+ }
+ if (entity.getETag() != null) {
+ json.writeStringField("@odata.etag", entity.getETag());
+ }
+ if (entity.getMediaETag() != null) {
+ json.writeStringField("@odata.mediaEtag", entity.getMediaETag());
+ }
+ if (entity.getMediaContentType() != null) {
+ json.writeStringField("@odata.mediaContentType", entity.getMediaContentType());
+ }
+ for (final String propertyName : entityType.getPropertyNames()) {
+ json.writeFieldName(propertyName);
+ final EdmProperty edmProperty = (EdmProperty) entityType.getProperty(propertyName);
+ final Property property = entity.getProperty(propertyName);
+ if (property == null) {
+ if (edmProperty.isNullable() == Boolean.FALSE) {
+ throw new ODataRuntimeException("Non-nullable property not present!");
+ } else {
+ json.writeNull();
+ }
+ } else {
+ if (edmProperty.isPrimitive()) {
+ final EdmPrimitiveType type = (EdmPrimitiveType) edmProperty.getType();
+ final String value = property.getValue().asPrimitive().get();
+ if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) {
+ json.writeBoolean(Boolean.parseBoolean(value));
+ } else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)
+ || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)
+ || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double)
+ || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)
+ || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)
+ || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)
+ || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)
+ || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single)) {
+ json.writeNumber(value);
+ } else {
+ json.writeString(value);
+ }
+ } else {
+ throw new ODataRuntimeException("Non-primitive properties not yet supported!");
+ }
+ }
+ }
+ json.writeEndObject();
+ }
+
+ @Override
+ public InputStream entitySet(final EdmEntitySet edmEntitySet, final EntitySet entitySet,
+ final ContextURL contextURL) {
+ CircleStreamBuffer buffer = new CircleStreamBuffer();
+ try {
+ JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+ json.writeStartObject();
+ if (contextURL != null) {
+ json.writeStringField(Constants.JSON_CONTEXT, contextURL.getURI().toASCIIString());
+ }
+ if (entitySet.getCount() != null) {
+ json.writeNumberField("@odata.count", entitySet.getCount());
+ }
+ json.writeFieldName(Constants.VALUE);
+ json.writeStartArray();
+ for (Entity entity : entitySet.getEntities()) {
+ writeEntity(edmEntitySet.getEntityType(), entity, null, json);
+ }
+ json.writeEndArray();
+ if (entitySet.getNext() != null) {
+ json.writeStringField("@odata.nextLink", entitySet.getNext().toASCIIString());
+ }
+ json.close();
+ } catch (final IOException e) {
+ throw new ODataRuntimeException(e);
+ }
+ return buffer.getInputStream();
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
index a8a943f..169f7a8 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ODataXmlSerializerImpl.java
@@ -25,7 +25,12 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer;
@@ -70,4 +75,14 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
}
+ @Override
+ public InputStream entity(EdmEntityType edmEntityType, Entity entity, ContextURL contextURL) {
+ throw new ODataRuntimeException("Entity serialization not implemented for XML format");
+ }
+
+ @Override
+ public InputStream entitySet(EdmEntitySet edmEntitySet, EntitySet entitySet, ContextURL contextURL) {
+ throw new ODataRuntimeException("Entityset serialization not implemented for XML format");
+ }
+
}
[2/9] First presentable state
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java
index 61667ac..00f0d3f 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityDeserializer.java
@@ -18,12 +18,6 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-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.ArrayList;
@@ -34,26 +28,35 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.ODataLinkType;
import org.apache.olingo.commons.api.domain.ODataOperation;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
/**
* Reads JSON string into an entity.
* <br/>
* If metadata information is available, the corresponding entity fields and content will be populated.
*/
-public class JSONEntityDeserializer extends AbstractJsonDeserializer<JSONEntityImpl> {
+public class JSONEntityDeserializer extends JsonDeserializer {
+
+ public JSONEntityDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
- @Override
- protected ResWrap<JSONEntityImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+ protected ResWrap<Entity> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = parser.getCodec().readTree(parser);
@@ -61,7 +64,7 @@ public class JSONEntityDeserializer extends AbstractJsonDeserializer<JSONEntityI
throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation());
}
- final JSONEntityImpl entity = new JSONEntityImpl();
+ final EntityImpl entity = new EntityImpl();
final URI contextURL;
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
@@ -212,6 +215,6 @@ public class JSONEntityDeserializer extends AbstractJsonDeserializer<JSONEntityI
populate(entity, entity.getProperties(), tree, parser.getCodec());
- return new ResWrap<JSONEntityImpl>(contextURL, metadataETag, entity);
+ return new ResWrap<Entity>(contextURL, metadataETag, entity);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityImpl.java
deleted file mode 100644
index 57db805..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntityImpl.java
+++ /dev/null
@@ -1,33 +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;
-
-/**
- * A single entity, represented via JSON.
- */
-@JsonSerialize(using = JSONEntitySerializer.class)
-@JsonDeserialize(using = JSONEntityDeserializer.class)
-public class JSONEntityImpl extends AbstractEntity {
-
- private static final long serialVersionUID = -5275365545400797758L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java
index 8ece3ba..36e7ae1 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySerializer.java
@@ -18,11 +18,9 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.net.URI;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
@@ -34,22 +32,23 @@ import org.apache.olingo.commons.api.domain.ODataOperation;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import com.fasterxml.jackson.core.JsonGenerator;
+
/**
* Writes out JSON string from an entity.
*/
-public class JSONEntitySerializer extends AbstractJsonSerializer<JSONEntityImpl> {
+public class JSONEntitySerializer extends JsonSerializer {
- @Override
- protected void doSerialize(final JSONEntityImpl entity, final JsonGenerator jgen, final SerializerProvider provider)
- throws IOException, JsonProcessingException {
+ public JSONEntitySerializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
- doContainerSerialize(new ResWrap<JSONEntityImpl>((URI) null, null, entity), jgen, provider);
+ protected void doSerialize(final Entity entity, final JsonGenerator jgen) throws IOException {
+ doContainerSerialize(new ResWrap<Entity>((URI) null, null, entity), jgen);
}
- @Override
- protected void doContainerSerialize(
- final ResWrap<JSONEntityImpl> container, final JsonGenerator jgen, final SerializerProvider provider)
- throws IOException, JsonProcessingException {
+ protected void doContainerSerialize(final ResWrap<Entity> container, final JsonGenerator jgen)
+ throws IOException {
final Entity entity = container.getPayload();
@@ -58,8 +57,8 @@ public class JSONEntitySerializer extends AbstractJsonSerializer<JSONEntityImpl>
if (serverMode) {
if (container.getContextURL() != null) {
jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0
- ? Constants.JSON_CONTEXT : Constants.JSON_METADATA,
- container.getContextURL().getURI().toASCIIString());
+ ? Constants.JSON_CONTEXT : Constants.JSON_METADATA,
+ container.getContextURL().getURI().toASCIIString());
}
if (version.compareTo(ODataServiceVersion.V40) >= 0 && StringUtils.isNotBlank(container.getMetadataETag())) {
jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag());
@@ -72,7 +71,7 @@ public class JSONEntitySerializer extends AbstractJsonSerializer<JSONEntityImpl>
if (StringUtils.isNotBlank(entity.getType())) {
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE),
- new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version));
+ new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version));
}
if (entity.getId() != null) {
@@ -89,11 +88,11 @@ public class JSONEntitySerializer extends AbstractJsonSerializer<JSONEntityImpl>
if (serverMode && entity.getEditLink() != null && StringUtils.isNotBlank(entity.getEditLink().getHref())) {
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK),
- entity.getEditLink().getHref());
+ entity.getEditLink().getHref());
if (entity.isMediaEntity()) {
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK),
- entity.getEditLink().getHref() + "/$value");
+ entity.getEditLink().getHref() + "/$value");
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java
index 241dcbc..e4cd3ab 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetDeserializer.java
@@ -18,31 +18,34 @@
*/
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 java.util.Map;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
+import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* Reads JSON string into an entity set.
* <br/>
* If metadata information is available, the corresponding entity fields and content will be populated.
*/
-public class JSONEntitySetDeserializer extends AbstractJsonDeserializer<JSONEntitySetImpl> {
+public class JSONEntitySetDeserializer extends JsonDeserializer {
+
+ public JSONEntitySetDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
- @Override
- protected ResWrap<JSONEntitySetImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+ protected ResWrap<EntitySet> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
@@ -50,9 +53,9 @@ public class JSONEntitySetDeserializer extends AbstractJsonDeserializer<JSONEnti
return null;
}
- final JSONEntitySetImpl entitySet = new JSONEntitySetImpl();
+ final EntitySetImpl entitySet = new EntitySetImpl();
- final URI contextURL;
+ URI contextURL;
if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue());
tree.remove(Constants.JSON_CONTEXT);
@@ -88,11 +91,10 @@ public class JSONEntitySetDeserializer extends AbstractJsonDeserializer<JSONEnti
}
if (tree.hasNonNull(Constants.VALUE)) {
+ final JSONEntityDeserializer entityDeserializer = new JSONEntityDeserializer(version, serverMode);
for (final Iterator<JsonNode> itor = tree.get(Constants.VALUE).iterator(); itor.hasNext();) {
entitySet.getEntities().add(
- itor.next().traverse(parser.getCodec()).<ResWrap<JSONEntityImpl>>readValueAs(
- new TypeReference<JSONEntityImpl>() {
- }).getPayload());
+ entityDeserializer.doDeserialize(itor.next().traverse(parser.getCodec())).getPayload());
}
tree.remove(Constants.VALUE);
}
@@ -109,6 +111,6 @@ public class JSONEntitySetDeserializer extends AbstractJsonDeserializer<JSONEnti
}
}
- return new ResWrap<JSONEntitySetImpl>(contextURL, metadataETag, entitySet);
+ return new ResWrap<EntitySet>(contextURL, metadataETag, entitySet);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetImpl.java
deleted file mode 100644
index dac67cd..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetImpl.java
+++ /dev/null
@@ -1,35 +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;
-
-/**
- * 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;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java
index 40eb8e6..1670259 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntitySetSerializer.java
@@ -18,48 +18,47 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.net.URI;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-public class JSONEntitySetSerializer extends AbstractJsonSerializer<JSONEntitySetImpl> {
+import com.fasterxml.jackson.core.JsonGenerator;
- @Override
- protected void doSerialize(
- final JSONEntitySetImpl entitySet, final JsonGenerator jgen, final SerializerProvider provider)
- throws IOException, JsonProcessingException {
+public class JSONEntitySetSerializer extends JsonSerializer {
- doContainerSerialize(new ResWrap<JSONEntitySetImpl>((URI) null, null, entitySet), jgen, provider);
+ public JSONEntitySetSerializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
}
- @Override
- protected void doContainerSerialize(
- final ResWrap<JSONEntitySetImpl> container, final JsonGenerator jgen, final SerializerProvider provider)
- throws IOException, JsonProcessingException {
+ protected void doSerialize(final EntitySet entitySet, final JsonGenerator jgen) throws IOException {
+ doContainerSerialize(new ResWrap<EntitySet>((URI) null, null, entitySet), jgen);
+ }
+
+ protected void doContainerSerialize(final ResWrap<EntitySet> container, final JsonGenerator jgen)
+ throws IOException {
- final JSONEntitySetImpl entitySet = container.getPayload();
+ final EntitySet entitySet = container.getPayload();
jgen.writeStartObject();
if (serverMode) {
if (container.getContextURL() != null) {
jgen.writeStringField(version.compareTo(ODataServiceVersion.V40) >= 0
- ? Constants.JSON_CONTEXT : Constants.JSON_METADATA,
- container.getContextURL().getURI().toASCIIString());
+ ? Constants.JSON_CONTEXT : Constants.JSON_METADATA,
+ container.getContextURL().getURI().toASCIIString());
}
if (version.compareTo(ODataServiceVersion.V40) >= 0 && StringUtils.isNotBlank(container.getMetadataETag())) {
jgen.writeStringField(
- Constants.JSON_METADATA_ETAG,
- container.getMetadataETag());
+ Constants.JSON_METADATA_ETAG,
+ container.getMetadataETag());
}
}
@@ -67,15 +66,15 @@ public class JSONEntitySetSerializer extends AbstractJsonSerializer<JSONEntitySe
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_ID), entitySet.getId().toASCIIString());
}
jgen.writeNumberField(version.getJSONMap().get(ODataServiceVersion.JSON_COUNT),
- entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount());
+ entitySet.getCount() == null ? entitySet.getEntities().size() : entitySet.getCount());
if (serverMode) {
if (entitySet.getNext() != null) {
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK),
- entitySet.getNext().toASCIIString());
+ entitySet.getNext().toASCIIString());
}
if (entitySet.getDeltaLink() != null) {
jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_DELTA_LINK),
- entitySet.getDeltaLink().toASCIIString());
+ entitySet.getDeltaLink().toASCIIString());
}
}
@@ -84,10 +83,12 @@ public class JSONEntitySetSerializer extends AbstractJsonSerializer<JSONEntitySe
}
jgen.writeArrayFieldStart(Constants.VALUE);
+ final JSONEntitySerializer entitySerializer = new JSONEntitySerializer(version, serverMode);
for (Entity entity : entitySet.getEntities()) {
- jgen.writeObject(entity);
+ entitySerializer.doSerialize(entity, jgen);
}
-
jgen.writeEndArray();
+
+ jgen.writeEndObject();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java
index 36818a9..1803c10 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDeserializer.java
@@ -18,28 +18,29 @@
*/
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.ArrayList;
import java.util.Iterator;
import java.util.List;
+
import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.domain.ODataErrorDetail;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
-public class JSONODataErrorDeserializer extends AbstractJsonDeserializer<JSONODataErrorImpl> {
+public class JSONODataErrorDeserializer extends JsonDeserializer {
+
+ public JSONODataErrorDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
- @Override
- protected ResWrap<JSONODataErrorImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+ protected ODataError doDeserialize(final JsonParser parser) throws IOException {
- final JSONODataErrorImpl error = new JSONODataErrorImpl();
+ final ODataErrorImpl error = new ODataErrorImpl();
final ObjectNode tree = parser.getCodec().readTree(parser);
if (tree.has(jsonError)) {
@@ -60,11 +61,12 @@ public class JSONODataErrorDeserializer extends AbstractJsonDeserializer<JSONODa
error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
}
if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) {
- final List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
- for (final Iterator<JsonNode> itor = errorNode.get(Constants.ERROR_DETAILS).iterator(); itor.hasNext();) {
- details.add(itor.next().traverse(parser.getCodec()).<ResWrap<JSONODataErrorDetailImpl>>readValueAs(
- new TypeReference<JSONODataErrorDetailImpl>() {
- }).getPayload());
+ List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
+ JSONODataErrorDetailDeserializer detailDeserializer =
+ new JSONODataErrorDetailDeserializer(version, serverMode);
+ for (Iterator<JsonNode> itor = errorNode.get(Constants.ERROR_DETAILS).iterator(); itor.hasNext();) {
+ details.add(detailDeserializer.doDeserialize(itor.next().traverse(parser.getCodec()))
+ .getPayload());
}
error.setDetails(details);
@@ -79,6 +81,6 @@ public class JSONODataErrorDeserializer extends AbstractJsonDeserializer<JSONODa
}
}
- return new ResWrap<JSONODataErrorImpl>((URI) null, null, error);
+ return error;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java
index 38ea043..6fe51ce 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailDeserializer.java
@@ -18,23 +18,26 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
import java.net.URI;
+
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.ODataErrorDetail;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
-public class JSONODataErrorDetailDeserializer extends AbstractJsonDeserializer<JSONODataErrorDetailImpl> {
+public class JSONODataErrorDetailDeserializer extends JsonDeserializer {
+
+ public JSONODataErrorDetailDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
- @Override
- protected ResWrap<JSONODataErrorDetailImpl> doDeserialize(
- final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+ protected ResWrap<ODataErrorDetail> doDeserialize(final JsonParser parser) throws IOException {
- final JSONODataErrorDetailImpl error = new JSONODataErrorDetailImpl();
+ final ODataErrorDetailImpl error = new ODataErrorDetailImpl();
final JsonNode errorNode = parser.getCodec().readTree(parser);
if (errorNode.has(Constants.ERROR_CODE)) {
error.setCode(errorNode.get(Constants.ERROR_CODE).textValue());
@@ -51,6 +54,6 @@ public class JSONODataErrorDetailDeserializer extends AbstractJsonDeserializer<J
error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
}
- return new ResWrap<JSONODataErrorDetailImpl>((URI) null, null, error);
+ return new ResWrap<ODataErrorDetail>((URI) null, null, error);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailImpl.java
deleted file mode 100644
index 49f3159..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorDetailImpl.java
+++ /dev/null
@@ -1,62 +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 org.apache.olingo.commons.api.domain.ODataErrorDetail;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-
-/*
- * JSONODataErrorDetailImpl, using the JSONODataErrorDetailDeserializer similar to JSONODataErrorImpl's.
- */
-@JsonDeserialize(using = JSONODataErrorDetailDeserializer.class)
-public class JSONODataErrorDetailImpl implements ODataErrorDetail {
-
- private String code;
-
- private String message;
-
- private String target;
-
- @Override
- public String getCode() {
- return code;
- }
-
- public void setCode(final String code) {
- this.code = code;
- }
-
- @Override
- public String getMessage() {
- return message;
- }
-
- public void setMessage(final String message) {
- this.message = message;
- }
-
- @Override
- public String getTarget() {
- return target;
- }
-
- public void setTarget(final String target) {
- this.target = target;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorImpl.java
deleted file mode 100644
index c455d2d..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONODataErrorImpl.java
+++ /dev/null
@@ -1,26 +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;
-
-@JsonDeserialize(using = JSONODataErrorDeserializer.class)
-public class JSONODataErrorImpl extends AbstractODataError {
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
index ea2a9df..465250a 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyDeserializer.java
@@ -18,37 +18,39 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-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 java.util.Map;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
+import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
/**
- * Parse JSON string into <tt>JSONPropertyImpl</tt>.
- *
- * @see JSONPropertyImpl
+ * Parse JSON string into <tt>Property</tt>.
*/
-public class JSONPropertyDeserializer extends AbstractJsonDeserializer<JSONPropertyImpl> {
+public class JSONPropertyDeserializer extends JsonDeserializer {
+
+ public JSONPropertyDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
- @Override
- protected ResWrap<JSONPropertyImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+ protected ResWrap<Property> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
final String metadataETag;
final URI contextURL;
- final JSONPropertyImpl property = new JSONPropertyImpl();
+ final PropertyImpl property = new PropertyImpl();
if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue();
@@ -97,6 +99,6 @@ public class JSONPropertyDeserializer extends AbstractJsonDeserializer<JSONPrope
}
}
- return new ResWrap<JSONPropertyImpl>(contextURL, metadataETag, property);
+ return new ResWrap<Property>(contextURL, metadataETag, property);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyImpl.java
deleted file mode 100644
index 1018666..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertyImpl.java
+++ /dev/null
@@ -1,33 +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;
-
-/**
- * A single property (primitive, complex or collection) represented via JSON.
- */
-@JsonSerialize(using = JSONPropertySerializer.class)
-@JsonDeserialize(using = JSONPropertyDeserializer.class)
-public class JSONPropertyImpl extends AbstractProperty {
-
- private static final long serialVersionUID = 553414431536637434L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertySerializer.java
index 1a7b908..1a82a3b 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertySerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONPropertySerializer.java
@@ -18,37 +18,34 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.net.URI;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import com.fasterxml.jackson.core.JsonGenerator;
+
/**
- * Writes out JSON string from <tt>JSONPropertyImpl</tt>.
- *
- * @see JSONPropertyImpl
+ * Writes out JSON string from <tt>PropertyImpl</tt>.
*/
-public class JSONPropertySerializer extends AbstractJsonSerializer<JSONPropertyImpl> {
+public class JSONPropertySerializer extends JsonSerializer {
- @Override
- protected void doSerialize(final JSONPropertyImpl property, final JsonGenerator jgen,
- final SerializerProvider provider) throws IOException, JsonProcessingException {
+ public JSONPropertySerializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
- doContainerSerialize(new ResWrap<JSONPropertyImpl>((URI) null, null, property), jgen, provider);
+ protected void doSerialize(final Property property, final JsonGenerator jgen) throws IOException {
+ doContainerSerialize(new ResWrap<Property>((URI) null, null, property), jgen);
}
- @Override
- protected void doContainerSerialize(
- final ResWrap<JSONPropertyImpl> container, final JsonGenerator jgen, final SerializerProvider provider)
- throws IOException, JsonProcessingException {
+ protected void doContainerSerialize(final ResWrap<Property> container, final JsonGenerator jgen)
+ throws IOException {
final Property property = container.getPayload();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonDeserializer.java
new file mode 100755
index 0000000..0ecd7f3
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonDeserializer.java
@@ -0,0 +1,463 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.util.AbstractMap.SimpleEntry;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.commons.api.Constants;
+import org.apache.olingo.commons.api.data.Annotatable;
+import org.apache.olingo.commons.api.data.Annotation;
+import org.apache.olingo.commons.api.data.CollectionValue;
+import org.apache.olingo.commons.api.data.ComplexValue;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Linked;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.Valuable;
+import org.apache.olingo.commons.api.data.Value;
+import org.apache.olingo.commons.api.domain.ODataError;
+import org.apache.olingo.commons.api.domain.ODataLinkType;
+import org.apache.olingo.commons.api.domain.ODataPropertyType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.op.ODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class JsonDeserializer implements ODataDeserializer {
+
+ protected final Pattern CUSTOM_ANNOTATION = Pattern.compile("(.+)@(.+)\\.(.+)");
+ protected final ODataServiceVersion version;
+ protected final boolean serverMode;
+
+ protected String jsonType;
+ protected String jsonId;
+ protected String jsonETag;
+ protected String jsonReadLink;
+ protected String jsonEditLink;
+ protected String jsonMediaEditLink;
+ protected String jsonMediaReadLink;
+ protected String jsonMediaContentType;
+ protected String jsonMediaETag;
+ protected String jsonAssociationLink;
+ protected String jsonNavigationLink;
+ protected String jsonCount;
+ protected String jsonNextLink;
+ protected String jsonDeltaLink;
+ protected String jsonError;
+
+ private JSONGeoValueDeserializer geoDeserializer;
+
+ private JsonParser parser;
+
+ public JsonDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ this.version = version;
+ this.serverMode = serverMode;
+
+ jsonType = version.getJSONMap().get(ODataServiceVersion.JSON_TYPE);
+ jsonId = version.getJSONMap().get(ODataServiceVersion.JSON_ID);
+ jsonETag = version.getJSONMap().get(ODataServiceVersion.JSON_ETAG);
+ jsonReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_READ_LINK);
+ jsonEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK);
+ jsonMediaReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK);
+ jsonMediaEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK);
+ jsonMediaContentType = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE);
+ jsonMediaETag = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG);
+ jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK);
+ jsonNavigationLink = version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK);
+ 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);
+}
+
+ private JSONGeoValueDeserializer getGeoDeserializer() {
+ if (geoDeserializer == null) {
+ geoDeserializer = new JSONGeoValueDeserializer(version);
+ }
+ return geoDeserializer;
+ }
+
+ protected String getJSONAnnotation(final String string) {
+ return StringUtils.prependIfMissing(string, "@");
+ }
+
+ protected String getTitle(final Map.Entry<String, JsonNode> entry) {
+ return entry.getKey().substring(0, entry.getKey().indexOf('@'));
+ }
+
+ protected String setInline(final String name, final String suffix, final JsonNode tree,
+ final ObjectCodec codec, final LinkImpl link) throws IOException {
+
+ final String entityNamePrefix = name.substring(0, name.indexOf(suffix));
+ if (tree.has(entityNamePrefix)) {
+ final JsonNode inline = tree.path(entityNamePrefix);
+ JSONEntityDeserializer entityDeserializer = new JSONEntityDeserializer(version, serverMode);
+
+ if (inline instanceof ObjectNode) {
+ link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
+ link.setInlineEntity(entityDeserializer.doDeserialize(inline.traverse(codec)).getPayload());
+
+ } else if (inline instanceof ArrayNode) {
+ link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
+
+ EntitySet entitySet = new EntitySetImpl();
+ Iterator<JsonNode> entries = ((ArrayNode) inline).elements();
+ while (entries.hasNext()) {
+ entitySet.getEntities().add(
+ entityDeserializer.doDeserialize(entries.next().traverse(codec)).getPayload());
+ }
+
+ link.setInlineEntitySet(entitySet);
+ }
+ }
+ return entityNamePrefix;
+ }
+
+ protected void links(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
+ final JsonNode tree, final ObjectCodec codec) throws IOException {
+ if (serverMode) {
+ serverLinks(field, linked, toRemove, tree, codec);
+ } else {
+ clientLinks(field, linked, toRemove, tree, codec);
+ }
+ }
+
+ private void clientLinks(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
+ final JsonNode tree, final ObjectCodec codec) throws IOException {
+
+ if (field.getKey().endsWith(jsonNavigationLink)) {
+ final LinkImpl link = new LinkImpl();
+ link.setTitle(getTitle(field));
+ link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field));
+
+ if (field.getValue().isValueNode()) {
+ link.setHref(field.getValue().textValue());
+ link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
+ }
+
+ linked.getNavigationLinks().add(link);
+
+ toRemove.add(field.getKey());
+ toRemove.add(setInline(field.getKey(), jsonNavigationLink, tree, codec, link));
+ } else if (field.getKey().endsWith(jsonAssociationLink)) {
+ final LinkImpl link = new LinkImpl();
+ link.setTitle(getTitle(field));
+ link.setRel(version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL) + getTitle(field));
+ link.setHref(field.getValue().textValue());
+ link.setType(ODataLinkType.ASSOCIATION.toString());
+ linked.getAssociationLinks().add(link);
+
+ toRemove.add(field.getKey());
+ }
+ }
+
+ private void serverLinks(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
+ final JsonNode tree, final ObjectCodec codec) throws IOException {
+
+ if (field.getKey().endsWith(Constants.JSON_BIND_LINK_SUFFIX)
+ || field.getKey().endsWith(jsonNavigationLink)) {
+
+ if (field.getValue().isValueNode()) {
+ final String suffix = field.getKey().replaceAll("^.*@", "@");
+
+ final LinkImpl link = new LinkImpl();
+ link.setTitle(getTitle(field));
+ link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field));
+ link.setHref(field.getValue().textValue());
+ link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
+ linked.getNavigationLinks().add(link);
+
+ toRemove.add(setInline(field.getKey(), suffix, tree, codec, link));
+ } else if (field.getValue().isArray()) {
+ for (final Iterator<JsonNode> itor = field.getValue().elements(); itor.hasNext();) {
+ final JsonNode node = itor.next();
+
+ final LinkImpl link = new LinkImpl();
+ link.setTitle(getTitle(field));
+ link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field));
+ link.setHref(node.asText());
+ link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
+ linked.getNavigationLinks().add(link);
+ toRemove.add(setInline(field.getKey(), Constants.JSON_BIND_LINK_SUFFIX, tree, codec, link));
+ }
+ }
+ toRemove.add(field.getKey());
+ }
+ }
+
+ private Map.Entry<ODataPropertyType, EdmTypeInfo> guessPropertyType(final JsonNode node) {
+ ODataPropertyType type;
+ EdmTypeInfo typeInfo = null;
+
+ if (node.isValueNode() || node.isNull()) {
+ type = ODataPropertyType.PRIMITIVE;
+
+ EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.String;
+ if (node.isShort()) {
+ kind = EdmPrimitiveTypeKind.Int16;
+ } else if (node.isInt()) {
+ kind = EdmPrimitiveTypeKind.Int32;
+ } else if (node.isLong()) {
+ kind = EdmPrimitiveTypeKind.Int64;
+ } else if (node.isBoolean()) {
+ kind = EdmPrimitiveTypeKind.Boolean;
+ } else if (node.isFloat()) {
+ kind = EdmPrimitiveTypeKind.Single;
+ } else if (node.isDouble()) {
+ kind = EdmPrimitiveTypeKind.Double;
+ } else if (node.isBigDecimal()) {
+ kind = EdmPrimitiveTypeKind.Decimal;
+ }
+ typeInfo = new EdmTypeInfo.Builder().setTypeExpression(kind.getFullQualifiedName().toString()).build();
+ } else if (node.isArray()) {
+ type = ODataPropertyType.COLLECTION;
+ } else if (node.isObject()) {
+ if (node.has(Constants.ATTR_TYPE)) {
+ type = ODataPropertyType.PRIMITIVE;
+ typeInfo = new EdmTypeInfo.Builder().
+ setTypeExpression("Edm.Geography" + node.get(Constants.ATTR_TYPE).asText()).build();
+ } else {
+ type = ODataPropertyType.COMPLEX;
+ }
+ } else {
+ type = ODataPropertyType.EMPTY;
+ }
+
+ return new SimpleEntry<ODataPropertyType, EdmTypeInfo>(type, typeInfo);
+ }
+
+ protected void populate(final Annotatable annotatable, final List<Property> properties,
+ final ObjectNode tree, final ObjectCodec codec) throws IOException {
+
+ String type = null;
+ Annotation annotation = null;
+ for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
+ final Map.Entry<String, JsonNode> field = itor.next();
+ final Matcher customAnnotation = CUSTOM_ANNOTATION.matcher(field.getKey());
+
+ if (field.getKey().charAt(0) == '@') {
+ final Annotation entityAnnot = new AnnotationImpl();
+ entityAnnot.setTerm(field.getKey().substring(1));
+
+ value(entityAnnot, field.getValue(), codec);
+ if (annotatable != null) {
+ annotatable.getAnnotations().add(entityAnnot);
+ }
+ } else if (type == null && field.getKey().endsWith(getJSONAnnotation(jsonType))) {
+ type = field.getValue().asText();
+ } else if (annotation == null && customAnnotation.matches() && !"odata".equals(customAnnotation.group(2))) {
+ annotation = new AnnotationImpl();
+ annotation.setTerm(customAnnotation.group(2) + "." + customAnnotation.group(3));
+ value(annotation, field.getValue(), codec);
+ } else {
+ final PropertyImpl property = new PropertyImpl();
+ property.setName(field.getKey());
+ property.setType(type == null
+ ? null
+ : new EdmTypeInfo.Builder().setTypeExpression(type).build().internal());
+ type = null;
+
+ value(property, field.getValue(), codec);
+ properties.add(property);
+
+ if (annotation != null) {
+ property.getAnnotations().add(annotation);
+ annotation = null;
+ }
+ }
+ }
+ }
+
+ private Value fromPrimitive(final JsonNode node, final EdmTypeInfo typeInfo) {
+ final Value value;
+
+ if (node.isNull()) {
+ value = new NullValueImpl();
+ } else {
+ if (typeInfo != null && typeInfo.getPrimitiveTypeKind().isGeospatial()) {
+ value = new GeospatialValueImpl(getGeoDeserializer().deserialize(node, typeInfo));
+ } else {
+ value = new PrimitiveValueImpl(node.asText());
+ }
+ }
+
+ return value;
+ }
+
+ private ComplexValue fromComplex(final ObjectNode node, final ObjectCodec codec) throws IOException {
+ final ComplexValue value = version.compareTo(ODataServiceVersion.V40) < 0
+ ? new ComplexValueImpl()
+ : new LinkedComplexValueImpl();
+
+ if (value.isLinkedComplex()) {
+ final Set<String> toRemove = new HashSet<String>();
+ for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
+ final Map.Entry<String, JsonNode> field = itor.next();
+
+ links(field, value.asLinkedComplex(), toRemove, node, codec);
+ }
+ node.remove(toRemove);
+ }
+
+ populate(value.asLinkedComplex(), value.get(), node, codec);
+
+ return value;
+ }
+
+ private CollectionValue fromCollection(final Iterator<JsonNode> nodeItor, final EdmTypeInfo typeInfo,
+ final ObjectCodec codec) throws IOException {
+
+ final CollectionValueImpl value = new CollectionValueImpl();
+
+ final EdmTypeInfo type = typeInfo == null
+ ? null
+ : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build();
+
+ while (nodeItor.hasNext()) {
+ final JsonNode child = nodeItor.next();
+
+ if (child.isValueNode()) {
+ if (typeInfo == null || typeInfo.isPrimitiveType()) {
+ value.get().add(fromPrimitive(child, type));
+ } else {
+ value.get().add(new EnumValueImpl(child.asText()));
+ }
+ } else if (child.isContainerNode()) {
+ if (child.has(jsonType)) {
+ ((ObjectNode) child).remove(jsonType);
+ }
+ value.get().add(fromComplex((ObjectNode) child, codec));
+ }
+ }
+
+ return value;
+ }
+
+ protected void value(final Valuable valuable, final JsonNode node, final ObjectCodec codec)
+ throws IOException {
+
+ EdmTypeInfo typeInfo = StringUtils.isBlank(valuable.getType())
+ ? null
+ : new EdmTypeInfo.Builder().setTypeExpression(valuable.getType()).build();
+
+ final Map.Entry<ODataPropertyType, EdmTypeInfo> guessed = guessPropertyType(node);
+ if (typeInfo == null) {
+ typeInfo = guessed.getValue();
+ }
+
+ final ODataPropertyType propType = typeInfo == null
+ ? guessed.getKey()
+ : typeInfo.isCollection()
+ ? ODataPropertyType.COLLECTION
+ : typeInfo.isPrimitiveType()
+ ? ODataPropertyType.PRIMITIVE
+ : node.isValueNode()
+ ? ODataPropertyType.ENUM
+ : ODataPropertyType.COMPLEX;
+
+ switch (propType) {
+ case COLLECTION:
+ valuable.setValue(fromCollection(node.elements(), typeInfo, codec));
+ break;
+
+ case COMPLEX:
+ if (node.has(jsonType)) {
+ valuable.setType(node.get(jsonType).asText());
+ ((ObjectNode) node).remove(jsonType);
+ }
+ valuable.setValue(fromComplex((ObjectNode) node, codec));
+ break;
+
+ case ENUM:
+ valuable.setValue(new EnumValueImpl(node.asText()));
+ break;
+
+ case PRIMITIVE:
+ if (valuable.getType() == null && typeInfo != null) {
+ valuable.setType(typeInfo.getFullQualifiedName().toString());
+ }
+ valuable.setValue(fromPrimitive(node, typeInfo));
+ break;
+
+ case EMPTY:
+ default:
+ valuable.setValue(new PrimitiveValueImpl(StringUtils.EMPTY));
+ }
+ }
+
+ @Override
+ public ResWrap<EntitySet> toEntitySet(InputStream input) throws ODataDeserializerException {
+ try {
+ parser = new JsonFactory(new ObjectMapper()).createParser(input);
+ return new JSONEntitySetDeserializer(version, serverMode).doDeserialize(parser);
+ } catch (final IOException e) {
+ throw new ODataDeserializerException(e);
+ }
+ }
+
+ @Override
+ public ResWrap<Entity> toEntity(InputStream input) throws ODataDeserializerException {
+ try {
+ parser = new JsonFactory(new ObjectMapper()).createParser(input);
+ return new JSONEntityDeserializer(version, serverMode).doDeserialize(parser);
+ } catch (final IOException e) {
+ throw new ODataDeserializerException(e);
+ }
+ }
+
+ @Override
+ public ResWrap<Property> toProperty(InputStream input) throws ODataDeserializerException {
+ try {
+ parser = new JsonFactory(new ObjectMapper()).createParser(input);
+ return new JSONPropertyDeserializer(version, serverMode).doDeserialize(parser);
+ } catch (final IOException e) {
+ throw new ODataDeserializerException(e);
+ }
+ }
+
+ @Override
+ public ODataError toError(InputStream input) throws ODataDeserializerException {
+ try {
+ parser = new JsonFactory(new ObjectMapper()).createParser(input);
+ return new JSONODataErrorDeserializer(version, serverMode).doDeserialize(parser);
+ } catch (final IOException e) {
+ throw new ODataDeserializerException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java
new file mode 100755
index 0000000..e067d88
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java
@@ -0,0 +1,315 @@
+/*
+ * 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.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.apache.olingo.commons.api.Constants;
+import org.apache.olingo.commons.api.data.Annotatable;
+import org.apache.olingo.commons.api.data.Annotation;
+import org.apache.olingo.commons.api.data.CollectionValue;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Linked;
+import org.apache.olingo.commons.api.data.PrimitiveValue;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.data.Valuable;
+import org.apache.olingo.commons.api.data.Value;
+import org.apache.olingo.commons.api.domain.ODataLinkType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.op.ODataSerializer;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+
+public class JsonSerializer implements ODataSerializer {
+
+ protected ODataServiceVersion version;
+ protected boolean serverMode;
+
+ private static final EdmPrimitiveTypeKind[] NUMBER_TYPES = {
+ EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte,
+ EdmPrimitiveTypeKind.Single, EdmPrimitiveTypeKind.Double,
+ EdmPrimitiveTypeKind.Int16, EdmPrimitiveTypeKind.Int32, EdmPrimitiveTypeKind.Int64,
+ EdmPrimitiveTypeKind.Decimal
+ };
+
+ private final JSONGeoValueSerializer geoSerializer = new JSONGeoValueSerializer();
+
+ public JsonSerializer(final ODataServiceVersion version, final boolean serverMode) {
+ this.version = version;
+ this.serverMode = serverMode;
+ }
+
+ @Override
+ public <T> void write(Writer writer, T obj) throws ODataSerializerException {
+ try {
+ JsonGenerator json = new JsonFactory().createGenerator(writer);
+ if (obj instanceof EntitySet) {
+ new JSONEntitySetSerializer(version, serverMode).doSerialize((EntitySet) obj, json);
+ } else if (obj instanceof Entity) {
+ new JSONEntitySerializer(version, serverMode).doSerialize((Entity) obj, json);
+ } else if (obj instanceof Property) {
+ new JSONPropertySerializer(version, serverMode).doSerialize((Property) obj, json);
+ } else if (obj instanceof Link) {
+ link((Link) obj, json);
+ }
+ json.flush();
+ } catch (final IOException e) {
+ throw new ODataSerializerException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> void write(Writer writer, ResWrap<T> container) throws ODataSerializerException {
+ final T obj = container == null ? null : container.getPayload();
+
+ try {
+ JsonGenerator json = new JsonFactory().createGenerator(writer);
+ if (obj instanceof EntitySet) {
+ new JSONEntitySetSerializer(version, serverMode).doContainerSerialize((ResWrap<EntitySet>) container, json);
+ } else if (obj instanceof Entity) {
+ new JSONEntitySerializer(version, serverMode).doContainerSerialize((ResWrap<Entity>) container, json);
+ } else if (obj instanceof Property) {
+ new JSONPropertySerializer(version, serverMode).doSerialize((Property) obj, json);
+ } else if (obj instanceof Link) {
+ link((Link) obj, json);
+ }
+ json.flush();
+ } catch (final IOException e) {
+ throw new ODataSerializerException(e);
+ }
+ }
+
+ protected void link(final Link link, JsonGenerator jgen) throws IOException {
+ jgen.writeStartObject();
+ jgen.writeStringField(Constants.JSON_URL, link.getHref());
+ jgen.writeEndObject();
+ }
+
+ protected void links(final Linked linked, final JsonGenerator jgen) throws IOException {
+ if (serverMode) {
+ serverLinks(linked, jgen);
+ } else {
+ clientLinks(linked, jgen);
+ }
+ }
+
+ protected void clientLinks(final Linked linked, final JsonGenerator jgen) throws IOException {
+ final Map<String, List<String>> entitySetLinks = new HashMap<String, List<String>>();
+ for (Link link : linked.getNavigationLinks()) {
+ for (Annotation annotation : link.getAnnotations()) {
+ valuable(jgen, annotation, link.getTitle() + "@" + annotation.getTerm());
+ }
+
+ ODataLinkType type = null;
+ try {
+ type = ODataLinkType.fromString(version, link.getRel(), link.getType());
+ } catch (IllegalArgumentException e) {
+ // ignore
+ }
+
+ if (type == ODataLinkType.ENTITY_SET_NAVIGATION) {
+ final List<String> uris;
+ if (entitySetLinks.containsKey(link.getTitle())) {
+ uris = entitySetLinks.get(link.getTitle());
+ } else {
+ uris = new ArrayList<String>();
+ entitySetLinks.put(link.getTitle(), uris);
+ }
+ if (StringUtils.isNotBlank(link.getHref())) {
+ uris.add(link.getHref());
+ }
+ } else {
+ if (StringUtils.isNotBlank(link.getHref())) {
+ jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
+ }
+ }
+
+ if (link.getInlineEntity() != null) {
+ jgen.writeFieldName(link.getTitle());
+ new JSONEntitySerializer(version, serverMode).doSerialize(link.getInlineEntity(), jgen);
+ } else if (link.getInlineEntitySet() != null) {
+ jgen.writeArrayFieldStart(link.getTitle());
+ JSONEntitySerializer entitySerializer = new JSONEntitySerializer(version, serverMode);
+ for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
+ entitySerializer.doSerialize(subEntry, jgen);
+ }
+ jgen.writeEndArray();
+ }
+ }
+ for (Map.Entry<String, List<String>> entitySetLink : entitySetLinks.entrySet()) {
+ if (!entitySetLink.getValue().isEmpty()) {
+ jgen.writeArrayFieldStart(entitySetLink.getKey() + Constants.JSON_BIND_LINK_SUFFIX);
+ for (String uri : entitySetLink.getValue()) {
+ jgen.writeString(uri);
+ }
+ jgen.writeEndArray();
+ }
+ }
+ }
+
+ protected void serverLinks(final Linked linked, final JsonGenerator jgen) throws IOException {
+ if (linked instanceof Entity) {
+ for (Link link : ((Entity) linked).getMediaEditLinks()) {
+ if (StringUtils.isNotBlank(link.getHref())) {
+ jgen.writeStringField(
+ link.getTitle() + StringUtils.prependIfMissing(
+ version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), "@"),
+ link.getHref());
+ }
+ }
+ }
+
+ for (Link link : linked.getAssociationLinks()) {
+ if (StringUtils.isNotBlank(link.getHref())) {
+ jgen.writeStringField(
+ link.getTitle() + version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK),
+ link.getHref());
+ }
+ }
+
+ for (Link link : linked.getNavigationLinks()) {
+ for (Annotation annotation : link.getAnnotations()) {
+ valuable(jgen, annotation, link.getTitle() + "@" + annotation.getTerm());
+ }
+
+ if (StringUtils.isNotBlank(link.getHref())) {
+ jgen.writeStringField(
+ link.getTitle() + version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK),
+ link.getHref());
+ }
+
+ if (link.getInlineEntity() != null) {
+ jgen.writeFieldName(link.getTitle());
+ new JSONEntitySerializer(version, serverMode).doSerialize(link.getInlineEntity(), jgen);
+ } else if (link.getInlineEntitySet() != null) {
+ jgen.writeArrayFieldStart(link.getTitle());
+ JSONEntitySerializer entitySerializer = new JSONEntitySerializer(version, serverMode);
+ for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
+ entitySerializer.doSerialize(subEntry, jgen);
+ }
+ jgen.writeEndArray();
+ }
+ }
+ }
+
+ private void collection(final JsonGenerator jgen, final String itemType, final CollectionValue value)
+ throws IOException {
+
+ jgen.writeStartArray();
+ for (Value item : value.get()) {
+ value(jgen, itemType, item);
+ }
+ jgen.writeEndArray();
+ }
+
+ protected void primitiveValue(final JsonGenerator jgen, final EdmTypeInfo typeInfo, final PrimitiveValue value)
+ throws IOException {
+
+ final boolean isNumber = typeInfo == null
+ ? NumberUtils.isNumber(value.get())
+ : ArrayUtils.contains(NUMBER_TYPES, typeInfo.getPrimitiveTypeKind());
+ final boolean isBoolean = typeInfo == null
+ ? (value.get().equalsIgnoreCase(Boolean.TRUE.toString())
+ || value.get().equalsIgnoreCase(Boolean.FALSE.toString()))
+ : typeInfo.getPrimitiveTypeKind() == EdmPrimitiveTypeKind.Boolean;
+
+ if (isNumber) {
+ jgen.writeNumber(value.get());
+ } else if (isBoolean) {
+ jgen.writeBoolean(BooleanUtils.toBoolean(value.get()));
+ } else {
+ jgen.writeString(value.get());
+ }
+ }
+
+ private void value(final JsonGenerator jgen, final String type, final Value value) throws IOException {
+ final EdmTypeInfo typeInfo = type == null
+ ? null
+ : new EdmTypeInfo.Builder().setTypeExpression(type).build();
+
+ if (value == null || value.isNull()) {
+ jgen.writeNull();
+ } else if (value.isPrimitive()) {
+ primitiveValue(jgen, typeInfo, value.asPrimitive());
+ } else if (value.isEnum()) {
+ jgen.writeString(value.asEnum().get());
+ } else if (value.isGeospatial()) {
+ jgen.writeStartObject();
+ geoSerializer.serialize(jgen, value.asGeospatial().get());
+ jgen.writeEndObject();
+ } else if (value.isCollection()) {
+ collection(jgen, typeInfo == null ? null : typeInfo.getFullQualifiedName().toString(), value.asCollection());
+ } else if (value.isComplex()) {
+ jgen.writeStartObject();
+
+ if (typeInfo != null) {
+ jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), typeInfo.external(version));
+ }
+
+ for (Property property : value.asComplex().get()) {
+ valuable(jgen, property, property.getName());
+ }
+ if (value.isLinkedComplex()) {
+ links(value.asLinkedComplex(), jgen);
+ }
+
+ jgen.writeEndObject();
+ }
+ }
+
+ protected void valuable(final JsonGenerator jgen, final Valuable valuable, final String name) throws IOException {
+ if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation) && !valuable.getValue().isComplex()) {
+ String type = valuable.getType();
+ if (StringUtils.isBlank(type) && valuable.getValue().isPrimitive() || valuable.getValue().isNull()) {
+ type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString();
+ }
+ if (StringUtils.isNotBlank(type)) {
+ jgen.writeFieldName(
+ name + StringUtils.prependIfMissing(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), "@"));
+ jgen.writeString(new EdmTypeInfo.Builder().setTypeExpression(type).build().external(version));
+ }
+ }
+
+ if (valuable instanceof Annotatable) {
+ for (Annotation annotation : ((Annotatable) valuable).getAnnotations()) {
+ valuable(jgen, annotation, name + "@" + annotation.getTerm());
+ }
+ }
+
+ jgen.writeFieldName(name);
+ value(jgen, valuable.getType(), valuable.getValue());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorDetailImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorDetailImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorDetailImpl.java
new file mode 100755
index 0000000..3367080
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorDetailImpl.java
@@ -0,0 +1,57 @@
+/*
+ * 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.domain.ODataErrorDetail;
+
+public class ODataErrorDetailImpl implements ODataErrorDetail {
+
+ private String code;
+
+ private String message;
+
+ private String target;
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(final String code) {
+ this.code = code;
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(final String message) {
+ this.message = message;
+ }
+
+ @Override
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(final String target) {
+ this.target = target;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorImpl.java
new file mode 100755
index 0000000..e766ae3
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataErrorImpl.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.core.data;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.commons.api.domain.ODataError;
+import org.apache.olingo.commons.api.domain.ODataErrorDetail;
+
+/**
+ * Example:
+ * <tt>
+ * {
+ * "error": { "code": "501", "message": "Unsupported functionality", "target": "query", "details": [ { "code": "301",
+ * "target": "$search", "message": "$search query option not supported" } ], "innererror": { "trace": [...], "context":
+ * {...} } } }
+ * </tt>.
+ */
+public class ODataErrorImpl implements ODataError {
+
+ private String code;
+
+ private String message;
+
+ private String target;
+
+ private List<ODataErrorDetail> details;
+
+ private Map<String, String> innerError = new LinkedHashMap<String, String>();
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(final String code) {
+ this.code = code;
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(final String message) {
+ this.message = message;
+ }
+
+ @Override
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(final String target) {
+ this.target = target;
+ }
+
+ @Override
+ public List<ODataErrorDetail> getDetails() {
+ return details;
+ }
+
+ public void setDetails(final List<ODataErrorDetail> detail) {
+ this.details = detail;
+ }
+
+ @Override
+ public Map<String, String> getInnerError() {
+ return innerError;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java
deleted file mode 100644
index a6a75b8..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonDeserializer.java
+++ /dev/null
@@ -1,98 +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.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-
-import java.io.IOException;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-public abstract class ODataJacksonDeserializer<T> extends JsonDeserializer<T> {
-
- protected ODataServiceVersion version;
-
- protected boolean serverMode;
-
- protected String jsonType;
-
- protected String jsonId;
-
- protected String jsonETag;
-
- protected String jsonReadLink;
-
- protected String jsonEditLink;
-
- protected String jsonMediaEditLink;
-
- protected String jsonMediaReadLink;
-
- protected String jsonMediaContentType;
-
- protected String jsonMediaETag;
-
- protected String jsonAssociationLink;
-
- protected String jsonNavigationLink;
-
- protected String jsonCount;
-
- protected String jsonNextLink;
-
- protected String jsonDeltaLink;
-
- protected String jsonError;
-
- protected abstract T doDeserialize(JsonParser jp, DeserializationContext ctxt)
- throws IOException, JsonProcessingException;
-
- protected String getJSONAnnotation(final String string) {
- return StringUtils.prependIfMissing(string, "@");
- }
-
- @Override
- public T deserialize(final JsonParser jp, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
-
- version = (ODataServiceVersion) ctxt.findInjectableValue(ODataServiceVersion.class.getName(), null, null);
- serverMode = (Boolean) ctxt.findInjectableValue(Boolean.class.getName(), null, null);
-
- jsonType = version.getJSONMap().get(ODataServiceVersion.JSON_TYPE);
- jsonId = version.getJSONMap().get(ODataServiceVersion.JSON_ID);
- jsonETag = version.getJSONMap().get(ODataServiceVersion.JSON_ETAG);
- jsonReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_READ_LINK);
- jsonEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_EDIT_LINK);
- jsonMediaReadLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAREAD_LINK);
- jsonMediaEditLink = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK);
- jsonMediaContentType = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE);
- jsonMediaETag = version.getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG);
- jsonAssociationLink = version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK);
- jsonNavigationLink = version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK);
- jsonCount = version.getJSONMap().get(ODataServiceVersion.JSON_COUNT);
- jsonNextLink = version.getJSONMap().get(ODataServiceVersion.JSON_NEXT_LINK);
- jsonDeltaLink = version.getJSONMap().get(ODataServiceVersion.JSON_DELTA_LINK);
- jsonError = version.getJSONMap().get(ODataServiceVersion.JSON_ERROR);
-
- return doDeserialize(jp, ctxt);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonSerializer.java
deleted file mode 100644
index 944fb51..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ODataJacksonSerializer.java
+++ /dev/null
@@ -1,57 +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.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-
-import java.io.IOException;
-import org.apache.olingo.commons.api.data.ResWrap;
-
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-public abstract class ODataJacksonSerializer<T> extends JsonSerializer<T> {
-
- protected ODataServiceVersion version;
-
- protected boolean serverMode;
-
- protected abstract void doSerialize(T value, JsonGenerator jgen, SerializerProvider provider)
- throws IOException, JsonProcessingException;
-
- protected abstract void doContainerSerialize(ResWrap<T> value, JsonGenerator jgen, SerializerProvider provider)
- throws IOException, JsonProcessingException;
-
- @Override
- @SuppressWarnings("unchecked")
- public void serialize(final T value, final JsonGenerator jgen, final SerializerProvider provider)
- throws IOException, JsonProcessingException {
-
- version = (ODataServiceVersion) provider.getAttribute(ODataServiceVersion.class);
- serverMode = (Boolean) provider.getAttribute(Boolean.class);
-
- if (value instanceof ResWrap) {
- doContainerSerialize((ResWrap) value, jgen, provider);
- } else {
- doSerialize(value, jgen, provider);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java
new file mode 100755
index 0000000..9d9f35c
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java
@@ -0,0 +1,63 @@
+/*
+ * 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.Property;
+import org.apache.olingo.commons.api.data.Value;
+
+public class PropertyImpl extends AbstractAnnotatedObject implements Property {
+
+ private static final long serialVersionUID = -7175704800169997060L;
+
+ private String name;
+
+ private String type;
+
+ private Value value;
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ @Override
+ public Value getValue() {
+ return value;
+ }
+
+ @Override
+ public void setValue(final Value value) {
+ this.value = value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/XMLODataErrorImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/XMLODataErrorImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/XMLODataErrorImpl.java
deleted file mode 100644
index 36cb682..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/XMLODataErrorImpl.java
+++ /dev/null
@@ -1,23 +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;
-
-public class XMLODataErrorImpl extends AbstractODataError {
-
-}
[8/9] First presentable state
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/V4Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
index 482c194..81f70ee 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
@@ -18,7 +18,6 @@
*/
package org.apache.olingo.fit;
-import com.fasterxml.jackson.core.type.TypeReference;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -33,6 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;
+
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.ws.rs.Consumes;
@@ -51,6 +51,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
+
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@@ -60,20 +61,18 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
import org.apache.olingo.commons.api.data.CollectionValue;
-import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
-import org.apache.olingo.commons.core.data.AtomPropertyImpl;
import org.apache.olingo.commons.core.data.CollectionValueImpl;
+import org.apache.olingo.commons.core.data.EntityImpl;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.EnumValueImpl;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
+import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.methods.PATCH;
@@ -90,18 +89,18 @@ import org.springframework.stereotype.Service;
@Service
@Path("/V40/Static.svc")
-@InInterceptors(classes = {XHTTPMethodInterceptor.class, ResolvingReferencesInterceptor.class})
+@InInterceptors(classes = { XHTTPMethodInterceptor.class, ResolvingReferencesInterceptor.class })
public class V4Services extends AbstractServices {
/**
* CR/LF.
*/
- protected static final byte[] CRLF = {13, 10};
+ protected static final byte[] CRLF = { 13, 10 };
protected static final Pattern RELENTITY_SELECT_PATTERN = Pattern.compile("^.*\\(\\$select=.*\\)$");
protected static final Pattern CROSSJOIN_PATTERN = Pattern.compile(
- "^\\$crossjoin\\(.*\\)\\?\\$filter=\\([a-zA-Z/]+ eq [a-zA-Z/]+\\)$");
+ "^\\$crossjoin\\(.*\\)\\?\\$filter=\\([a-zA-Z/]+ eq [a-zA-Z/]+\\)$");
private final Map<String, String> providedAsync = new HashMap<String, String>();
@@ -116,18 +115,18 @@ public class V4Services extends AbstractServices {
@GET
@Path("/redirect/{name}({id})")
public Response conformanceRedirect(
- @Context UriInfo uriInfo,
- @PathParam("name") String name,
- @PathParam("id") String id) {
+ @Context UriInfo uriInfo,
+ @PathParam("name") String name,
+ @PathParam("id") String id) {
return Response.temporaryRedirect(
- URI.create(uriInfo.getRequestUri().toASCIIString().replace("/redirect", ""))).build();
+ URI.create(uriInfo.getRequestUri().toASCIIString().replace("/redirect", ""))).build();
}
@GET
@Path("/$crossjoin({elements:.*})")
public Response crossjoin(
- @PathParam("elements") String elements,
- @QueryParam("$filter") String filter) {
+ @PathParam("elements") String elements,
+ @QueryParam("$filter") String filter) {
try {
if (CROSSJOIN_PATTERN.matcher("$crossjoin(" + elements + ")?$filter=" + filter).matches()) {
@@ -145,8 +144,8 @@ public class V4Services extends AbstractServices {
@GET
@Path("/relatedEntitySelect/{path:.*}")
public Response relatedEntitySelect(
- @PathParam("path") String path,
- @QueryParam("$expand") String expand) {
+ @PathParam("path") String path,
+ @QueryParam("$expand") String expand) {
if (RELENTITY_SELECT_PATTERN.matcher(expand).matches()) {
return xml.createResponse(null, null, Accept.JSON_FULLMETA);
@@ -180,9 +179,9 @@ public class V4Services extends AbstractServices {
@POST
@Path("/async/$batch")
public Response async(
- @Context final UriInfo uriInfo,
- @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
- final @Multipart MultipartBody attachment) {
+ @Context final UriInfo uriInfo,
+ @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
+ final @Multipart MultipartBody attachment) {
try {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -219,7 +218,7 @@ public class V4Services extends AbstractServices {
bos.close();
return xml.createAsyncResponse(
- uriInfo.getRequestUri().toASCIIString().replace("async/$batch", "") + "monitor/" + uuid.toString());
+ uriInfo.getRequestUri().toASCIIString().replace("async/$batch", "") + "monitor/" + uuid.toString());
} catch (Exception e) {
return xml.createFaultResponse(Accept.JSON.toString(), e);
}
@@ -228,9 +227,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/async/{name}")
public Response async(
- @Context final UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
- @PathParam("name") final String name) {
+ @Context final UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
+ @PathParam("name") final String name) {
try {
final Accept acceptType = Accept.parse(accept, version);
@@ -242,8 +241,8 @@ public class V4Services extends AbstractServices {
final StringBuilder path = new StringBuilder(basePath);
path.append(metadata.getEntitySet(name).isSingleton()
- ? Constants.get(version, ConstantKey.ENTITY)
- : Constants.get(version, ConstantKey.FEED));
+ ? Constants.get(version, ConstantKey.ENTITY)
+ : Constants.get(version, ConstantKey.FEED));
final InputStream feed = FSManager.instance(version).readFile(path.toString(), acceptType);
@@ -257,7 +256,7 @@ public class V4Services extends AbstractServices {
providedAsync.put(uuid.toString(), builder.toString());
return xml.createAsyncResponse(
- uriInfo.getRequestUri().toASCIIString().replaceAll("async/" + name, "") + "monitor/" + uuid.toString());
+ uriInfo.getRequestUri().toASCIIString().replaceAll("async/" + name, "") + "monitor/" + uuid.toString());
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -272,8 +271,8 @@ public class V4Services extends AbstractServices {
@Override
public InputStream exploreMultipart(
- final List<Attachment> attachments, final String boundary, final boolean continueOnError)
- throws IOException {
+ final List<Attachment> attachments, final String boundary, final boolean continueOnError)
+ throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -359,59 +358,59 @@ public class V4Services extends AbstractServices {
@GET
@Path("/People/{type:.*}")
public Response getPeople(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("type") final String type,
- @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) String top,
- @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) String skip,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) String count,
- @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) String filter,
- @QueryParam("$search") @DefaultValue(StringUtils.EMPTY) String search,
- @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) String orderby,
- @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) String skiptoken) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("type") final String type,
+ @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) String top,
+ @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) String skip,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) String count,
+ @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) String filter,
+ @QueryParam("$search") @DefaultValue(StringUtils.EMPTY) String search,
+ @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) String orderby,
+ @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) String skiptoken) {
return StringUtils.isBlank(filter) && StringUtils.isBlank(search)
- ? NumberUtils.isNumber(type)
+ ? NumberUtils.isNumber(type)
? super.getEntityInternal(
- uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null, true)
+ uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null, true)
: super.getEntitySet(accept, "People", type)
- : super.getEntitySet(uriInfo, accept, "People", top, skip, format, count, filter, orderby, skiptoken);
+ : super.getEntitySet(uriInfo, accept, "People", top, skip, format, count, filter, orderby, skiptoken);
}
@GET
@Path("/Boss")
public Response getSingletonBoss(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getEntityInternal(
- uriInfo.getRequestUri().toASCIIString(), accept, "Boss", StringUtils.EMPTY, format, null, null, false);
+ uriInfo.getRequestUri().toASCIIString(), accept, "Boss", StringUtils.EMPTY, format, null, null, false);
}
@GET
@Path("/Company")
public Response getSingletonCompany(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getEntityInternal(
- uriInfo.getRequestUri().toASCIIString(), accept, "Company", StringUtils.EMPTY, format, null, null, false);
+ uriInfo.getRequestUri().toASCIIString(), accept, "Company", StringUtils.EMPTY, format, null, null, false);
}
@PATCH
@Path("/Company")
- @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
- @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
+ @Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public Response patchSingletonCompany(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
- @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) String ifMatch,
- final String changes) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
+ @HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) String ifMatch,
+ final String changes) {
return super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, "Company", StringUtils.EMPTY, changes);
}
@@ -419,11 +418,11 @@ public class V4Services extends AbstractServices {
@GET
@Path("/Customers")
public Response getCustomers(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
- @QueryParam("$deltatoken") @DefaultValue(StringUtils.EMPTY) String deltatoken) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
+ @QueryParam("$deltatoken") @DefaultValue(StringUtils.EMPTY) String deltatoken) {
try {
final Accept acceptType;
@@ -436,29 +435,29 @@ public class V4Services extends AbstractServices {
final InputStream output;
if (StringUtils.isBlank(deltatoken)) {
final InputStream input = (InputStream) getEntitySet(
- uriInfo, accept, "Customers", null, null, format, null, null, null, null).getEntity();
- final AtomEntitySetImpl entitySet = xml.readEntitySet(acceptType, input);
+ uriInfo, accept, "Customers", null, null, format, null, null, null, null).getEntity();
+ final EntitySet entitySet = xml.readEntitySet(acceptType, input);
boolean trackChanges = prefer.contains("odata.track-changes");
if (trackChanges) {
entitySet.setDeltaLink(URI.create("Customers?$deltatoken=8015"));
}
- output = xml.writeEntitySet(acceptType, new ResWrap<AtomEntitySetImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + "Customers"),
- null,
- entitySet));
+ output = xml.writeEntitySet(acceptType, new ResWrap<EntitySet>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + "Customers"),
+ null,
+ entitySet));
} else {
output = FSManager.instance(version).readFile("delta", acceptType);
}
final Response response = xml.createResponse(
- null,
- output,
- null,
- acceptType);
+ null,
+ output,
+ null,
+ acceptType);
if (StringUtils.isNotBlank(prefer)) {
- response.getHeaders().put("Preference-Applied", Collections.<Object>singletonList(prefer));
+ response.getHeaders().put("Preference-Applied", Collections.<Object> singletonList(prefer));
}
return response;
} catch (Exception e) {
@@ -469,8 +468,8 @@ public class V4Services extends AbstractServices {
@GET
@Path("/Company/Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount{paren:[\\(\\)]*}")
public Response functionGetEmployeesCount(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
@@ -480,18 +479,18 @@ public class V4Services extends AbstractServices {
acceptType = Accept.parse(accept, version);
}
- final AtomPropertyImpl property = new AtomPropertyImpl();
+ final Property property = new PropertyImpl();
property.setType("Edm.Int32");
property.setValue(new PrimitiveValueImpl("2"));
- final ResWrap<AtomPropertyImpl> container = new ResWrap<AtomPropertyImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
- property);
+ final ResWrap<Property> container = new ResWrap<Property>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
+ property);
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -500,10 +499,10 @@ public class V4Services extends AbstractServices {
@POST
@Path("/Company/Microsoft.Test.OData.Services.ODataWCFService.IncreaseRevenue{paren:[\\(\\)]*}")
public Response actionIncreaseRevenue(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String param) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String param) {
try {
final Accept acceptType;
@@ -517,10 +516,10 @@ public class V4Services extends AbstractServices {
final Entity entry = xml.readEntity(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING));
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, entry.getProperty("IncreaseValue")),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, entry.getProperty("IncreaseValue")),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -529,9 +528,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/Products({entityId})/Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails({param:.*})")
public Response functionGetProductDetails(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("entityId") String entityId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("entityId") String entityId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
@@ -541,31 +540,31 @@ public class V4Services extends AbstractServices {
acceptType = Accept.parse(accept, version);
}
- final AtomEntityImpl entry = new AtomEntityImpl();
+ final EntityImpl entry = new EntityImpl();
entry.setType("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail");
- final Property productId = new AtomPropertyImpl();
+ final Property productId = new PropertyImpl();
productId.setName("ProductID");
productId.setType("Edm.Int32");
productId.setValue(new PrimitiveValueImpl(entityId));
entry.getProperties().add(productId);
- final Property productDetailId = new AtomPropertyImpl();
+ final Property productDetailId = new PropertyImpl();
productDetailId.setName("ProductDetailID");
productDetailId.setType("Edm.Int32");
productDetailId.setValue(new PrimitiveValueImpl("2"));
entry.getProperties().add(productDetailId);
- final AtomEntitySetImpl feed = new AtomEntitySetImpl();
+ final EntitySetImpl feed = new EntitySetImpl();
feed.getEntities().add(entry);
- final ResWrap<AtomEntitySetImpl> container = new ResWrap<AtomEntitySetImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + "ProductDetail"), null,
- feed);
+ final ResWrap<EntitySet> container = new ResWrap<EntitySet>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + "ProductDetail"), null,
+ feed);
return xml.createResponse(
- null,
- xml.writeEntitySet(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeEntitySet(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -574,10 +573,10 @@ public class V4Services extends AbstractServices {
@POST
@Path("/Products({entityId})/Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight{paren:[\\(\\)]*}")
public Response actionAddAccessRight(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String param) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String param) {
try {
final Accept acceptType;
@@ -596,15 +595,15 @@ public class V4Services extends AbstractServices {
final Property property = entry.getProperty("accessRight");
property.setType("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel");
- final ResWrap<AtomPropertyImpl> result = new ResWrap<AtomPropertyImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()),
- null, (AtomPropertyImpl) property);
+ final ResWrap<Property> result = new ResWrap<Property>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()),
+ null, property);
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, result),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, result),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -613,12 +612,12 @@ public class V4Services extends AbstractServices {
@POST
@Path("/Customers(PersonID={personId})/Microsoft.Test.OData.Services.ODataWCFService.ResetAddress{paren:[\\(\\)]*}")
public Response actionResetAddress(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("personId") String personId,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String param) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("personId") String personId,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String param) {
try {
final Accept contentTypeValue = Accept.parse(contentType, version);
@@ -629,7 +628,7 @@ public class V4Services extends AbstractServices {
assert entry.getProperty("index") != null;
return getEntityInternal(
- uriInfo.getRequestUri().toASCIIString(), accept, "Customers", personId, format, null, null, false);
+ uriInfo.getRequestUri().toASCIIString(), accept, "Customers", personId, format, null, null, false);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -637,26 +636,26 @@ public class V4Services extends AbstractServices {
@GET
@Path("/ProductDetails(ProductID={productId},ProductDetailID={productDetailId})"
- + "/Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct{paren:[\\(\\)]*}")
+ + "/Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct{paren:[\\(\\)]*}")
public Response functionGetRelatedProduct(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("productId") String productId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("productId") String productId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getEntityInternal(
- uriInfo.getRequestUri().toASCIIString(), accept, "Products", productId, format, null, null, false);
+ uriInfo.getRequestUri().toASCIIString(), accept, "Products", productId, format, null, null, false);
}
@POST
@Path("/Accounts({entityId})/Microsoft.Test.OData.Services.ODataWCFService.RefreshDefaultPI{paren:[\\(\\)]*}")
public Response actionRefreshDefaultPI(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @PathParam("entityId") String entityId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String param) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @PathParam("entityId") String entityId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String param) {
try {
final Accept contentTypeValue = Accept.parse(contentType, version);
@@ -674,9 +673,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/Accounts({entityId})/Microsoft.Test.OData.Services.ODataWCFService.GetDefaultPI{paren:[\\(\\)]*}")
public Response functionGetDefaultPI(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("entityId") String entityId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("entityId") String entityId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getContainedEntity(accept, entityId, "MyPaymentInstruments", entityId + "901", format);
}
@@ -684,9 +683,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/Accounts({entityId})/Microsoft.Test.OData.Services.ODataWCFService.GetAccountInfo{paren:[\\(\\)]*}")
public Response functionGetAccountInfo(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("entityId") String entityId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("entityId") String entityId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getPath(accept, "Accounts", entityId, "AccountInfo", format);
}
@@ -694,9 +693,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/Accounts({entityId})/MyGiftCard/Microsoft.Test.OData.Services.ODataWCFService.GetActualAmount({param:.*})")
public Response functionGetActualAmount(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("entityId") String entityId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("entityId") String entityId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
@@ -706,17 +705,17 @@ public class V4Services extends AbstractServices {
acceptType = Accept.parse(accept, version);
}
- final AtomPropertyImpl property = new AtomPropertyImpl();
+ final Property property = new PropertyImpl();
property.setType("Edm.Double");
property.setValue(new PrimitiveValueImpl("41.79"));
- final ResWrap<AtomPropertyImpl> container = new ResWrap<AtomPropertyImpl>((URI) null, null, property);
+ final ResWrap<Property> container = new ResWrap<Property>((URI) null, null, property);
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -733,9 +732,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/{path:.*}/$ref")
public Response getEntityReference(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("path") String path,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("path") String path,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Map.Entry<Accept, AbstractUtilities> utils = getUtilities(accept, format);
@@ -747,10 +746,10 @@ public class V4Services extends AbstractServices {
final String filename = Base64.encodeBase64String(path.getBytes("UTF-8"));
return utils.getValue().createResponse(
- FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF)
- + File.separatorChar + filename, utils.getKey()),
- null,
- utils.getKey());
+ FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF)
+ + File.separatorChar + filename, utils.getKey()),
+ null,
+ utils.getKey());
} catch (Exception e) {
LOG.error("Error retrieving entity", e);
return xml.createFaultResponse(accept, e);
@@ -759,36 +758,36 @@ public class V4Services extends AbstractServices {
@Override
public Response patchEntity(
- final UriInfo uriInfo,
- final String accept,
- final String contentType,
- final String prefer,
- final String ifMatch,
- final String entitySetName,
- final String entityId,
- final String changes) {
+ final UriInfo uriInfo,
+ final String accept,
+ final String contentType,
+ final String prefer,
+ final String ifMatch,
+ final String entitySetName,
+ final String entityId,
+ final String changes) {
final Response response =
- getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
- accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
+ getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
+ accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
return response.getStatus() >= 400
- ? postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes)
- : super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
+ ? postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes)
+ : super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
}
@Override
public Response replaceEntity(
- final UriInfo uriInfo,
- final String accept,
- final String contentType,
- final String prefer,
- final String entitySetName,
- final String entityId,
- final String entity) {
+ final UriInfo uriInfo,
+ final String accept,
+ final String contentType,
+ final String prefer,
+ final String entitySetName,
+ final String entityId,
+ final String entity) {
try {
getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
- accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
+ accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
return super.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity);
} catch (NotFoundException e) {
return postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId);
@@ -797,19 +796,19 @@ public class V4Services extends AbstractServices {
private StringBuilder containedPath(final String entityId, final String containedEntitySetName) {
return new StringBuilder("Accounts").append(File.separatorChar).
- append(entityId).append(File.separatorChar).
- append("links").append(File.separatorChar).
- append(containedEntitySetName);
+ append(entityId).append(File.separatorChar).
+ append("links").append(File.separatorChar).
+ append(containedEntitySetName);
}
@GET
@Path("/Accounts({entityId})/{containedEntitySetName}({containedEntityId})")
public Response getContainedEntity(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("entityId") String entityId,
- @PathParam("containedEntitySetName") String containedEntitySetName,
- @PathParam("containedEntityId") String containedEntityId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("entityId") String entityId,
+ @PathParam("containedEntitySetName") String containedEntitySetName,
+ @PathParam("containedEntityId") String containedEntityId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
@@ -828,13 +827,13 @@ public class V4Services extends AbstractServices {
}
final InputStream entry = FSManager.instance(version).readFile(containedPath.toString(), Accept.ATOM);
- final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entry, AtomEntityImpl.class);
+ final ResWrap<Entity> container = atomDeserializer.toEntity(entry);
return xml.createResponse(
- null,
- xml.writeEntity(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeEntity(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -843,12 +842,12 @@ public class V4Services extends AbstractServices {
@POST
@Path("/Accounts({entityId})/{containedEntitySetName:.*}")
public Response postContainedEntity(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @PathParam("entityId") String entityId,
- @PathParam("containedEntitySetName") String containedEntitySetName,
- final String entity) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @PathParam("entityId") String entityId,
+ @PathParam("containedEntitySetName") String containedEntitySetName,
+ final String entity) {
try {
final Accept acceptType = Accept.parse(accept, version);
@@ -858,43 +857,40 @@ public class V4Services extends AbstractServices {
final AbstractUtilities utils = getUtilities(acceptType);
- // 1. parse the entry (from Atom or JSON) into AtomEntryImpl
- final ResWrap<AtomEntityImpl> entryContainer;
- final AtomEntityImpl entry;
+ // 1. parse the entry (from Atom or JSON)
+ final ResWrap<Entity> entryContainer;
+ final Entity entry;
final Accept contentTypeValue = Accept.parse(contentType, version);
if (Accept.ATOM == contentTypeValue) {
- entryContainer = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntityImpl.class);
+ entryContainer = atomDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING));
entry = entryContainer.getPayload();
} else {
- final ResWrap<JSONEntityImpl> jcontainer =
- mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING),
- new TypeReference<JSONEntityImpl>() {
- });
-
- entry = dataBinder.toAtomEntity(jcontainer.getPayload());
-
- entryContainer = new ResWrap<AtomEntityImpl>(
- jcontainer.getContextURL(),
- jcontainer.getMetadataETag(),
- entry);
+ final ResWrap<Entity> jcontainer = jsonDeserializer.toEntity(
+ IOUtils.toInputStream(entity, Constants.ENCODING));
+ entry = jcontainer.getPayload();
+
+ entryContainer = new ResWrap<Entity>(
+ jcontainer.getContextURL(),
+ jcontainer.getMetadataETag(),
+ entry);
}
final EdmTypeInfo contained = new EdmTypeInfo.Builder().setTypeExpression(metadata.
- getNavigationProperties("Accounts").get(containedEntitySetName).getType()).build();
+ getNavigationProperties("Accounts").get(containedEntitySetName).getType()).build();
final String entityKey = getUtilities(contentTypeValue).
- getDefaultEntryKey(contained.getFullQualifiedName().getName(), entry);
+ getDefaultEntryKey(contained.getFullQualifiedName().getName(), entry);
// 2. Store the new entity
final String atomEntryRelativePath = containedPath(entityId, containedEntitySetName).
- append('(').append(entityKey).append(')').toString();
+ append('(').append(entityKey).append(')').toString();
FSManager.instance(version).putInMemory(
- utils.writeEntity(Accept.ATOM, entryContainer),
- FSManager.instance(version).getAbsolutePath(atomEntryRelativePath, Accept.ATOM));
+ utils.writeEntity(Accept.ATOM, entryContainer),
+ FSManager.instance(version).getAbsolutePath(atomEntryRelativePath, Accept.ATOM));
// 3. Update the contained entity set
final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString();
final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM);
- final ResWrap<AtomEntitySetImpl> feedContainer = atomDeserializer.read(feedIS, AtomEntitySetImpl.class);
+ final ResWrap<EntitySet> feedContainer = atomDeserializer.toEntitySet(feedIS);
feedContainer.getPayload().getEntities().add(entry);
final ByteArrayOutputStream content = new ByteArrayOutputStream();
@@ -904,16 +900,16 @@ public class V4Services extends AbstractServices {
writer.close();
FSManager.instance(version).putInMemory(
- new ByteArrayInputStream(content.toByteArray()),
- FSManager.instance(version).getAbsolutePath(atomFeedRelativePath, Accept.ATOM));
+ new ByteArrayInputStream(content.toByteArray()),
+ FSManager.instance(version).getAbsolutePath(atomFeedRelativePath, Accept.ATOM));
// Finally, return
return utils.createResponse(
- uriInfo.getRequestUri().toASCIIString() + "(" + entityKey + ")",
- utils.writeEntity(acceptType, entryContainer),
- null,
- acceptType,
- Response.Status.CREATED);
+ uriInfo.getRequestUri().toASCIIString() + "(" + entityKey + ")",
+ utils.writeEntity(acceptType, entryContainer),
+ null,
+ acceptType,
+ Response.Status.CREATED);
} catch (Exception e) {
LOG.error("While creating new contained entity", e);
return xml.createFaultResponse(accept, e);
@@ -923,14 +919,14 @@ public class V4Services extends AbstractServices {
@PATCH
@Path("/{entitySetName}({entityId})/{containedEntitySetName}({containedEntityId})")
public Response patchContainedEntity(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @PathParam("entitySetName") String entitySetName,
- @PathParam("entityId") String entityId,
- @PathParam("containedEntitySetName") String containedEntitySetName,
- @PathParam("containedEntityId") String containedEntityId,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String changes) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @PathParam("entitySetName") String entitySetName,
+ @PathParam("entityId") String entityId,
+ @PathParam("containedEntitySetName") String containedEntitySetName,
+ @PathParam("containedEntityId") String containedEntityId,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String changes) {
try {
final Accept acceptType;
@@ -950,26 +946,25 @@ public class V4Services extends AbstractServices {
contentTypeValue = Accept.parse(contentType, version);
final LinkInfo links = xml.readLinks(
- entitySetName, entityId, containedEntitySetName + "(" + containedEntityId + ")", Accept.ATOM);
+ entitySetName, entityId, containedEntitySetName + "(" + containedEntityId + ")", Accept.ATOM);
- ResWrap<AtomEntityImpl> container = atomDeserializer.read(links.getLinks(), AtomEntityImpl.class);
- final AtomEntityImpl original = container.getPayload();
+ ResWrap<Entity> container = atomDeserializer.toEntity(links.getLinks());
+ final Entity original = container.getPayload();
- final AtomEntityImpl entryChanges;
+ final Entity entryChanges;
if (Accept.ATOM == contentTypeValue) {
- container = atomDeserializer.read(IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntityImpl.class);
+ container = atomDeserializer.toEntity(IOUtils.toInputStream(changes, Constants.ENCODING));
entryChanges = container.getPayload();
} else {
final String entityType = metadata.getEntitySet(entitySetName).getType();
final String containedType = metadata.getEntityOrComplexType(entityType).
- getNavigationProperty(containedEntitySetName).getType();
+ getNavigationProperty(containedEntitySetName).getType();
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(containedType).build();
- final ResWrap<JSONEntityImpl> jsonContainer = mapper.readValue(
- IOUtils.toInputStream(changes, Constants.ENCODING), new TypeReference<JSONEntityImpl>() {
- });
+ final ResWrap<Entity> jsonContainer = jsonDeserializer.toEntity(
+ IOUtils.toInputStream(changes, Constants.ENCODING));
jsonContainer.getPayload().setType(typeInfo.getFullQualifiedName().toString());
- entryChanges = dataBinder.toAtomEntity(jsonContainer.getPayload());
+ entryChanges = jsonContainer.getPayload();
}
for (Property property : entryChanges.getProperties()) {
@@ -980,9 +975,8 @@ public class V4Services extends AbstractServices {
original.getProperties().add(property);
}
- FSManager.instance(version).putInMemory(new ResWrap<AtomEntityImpl>((URI) null, null, original),
- xml.getLinksBasePath(entitySetName, entityId) + containedEntitySetName + "(" + containedEntityId + ")",
- dataBinder);
+ FSManager.instance(version).putInMemory(new ResWrap<Entity>((URI) null, null, original),
+ xml.getLinksBasePath(entitySetName, entityId) + containedEntitySetName + "(" + containedEntityId + ")");
return xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT);
} catch (Exception e) {
@@ -993,26 +987,26 @@ public class V4Services extends AbstractServices {
@DELETE
@Path("/Accounts({entityId})/{containedEntitySetName}({containedEntityId})")
public Response removeContainedEntity(
- @PathParam("entityId") String entityId,
- @PathParam("containedEntitySetName") String containedEntitySetName,
- @PathParam("containedEntityId") String containedEntityId) {
+ @PathParam("entityId") String entityId,
+ @PathParam("containedEntitySetName") String containedEntitySetName,
+ @PathParam("containedEntityId") String containedEntityId) {
try {
// 1. Fetch the contained entity to be removed
final InputStream entry = FSManager.instance(version).
- readFile(containedPath(entityId, containedEntitySetName).
- append('(').append(containedEntityId).append(')').toString(), Accept.ATOM);
- final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entry, AtomEntityImpl.class);
+ readFile(containedPath(entityId, containedEntitySetName).
+ append('(').append(containedEntityId).append(')').toString(), Accept.ATOM);
+ final ResWrap<Entity> container = atomDeserializer.toEntity(entry);
// 2. Remove the contained entity
final String atomEntryRelativePath = containedPath(entityId, containedEntitySetName).
- append('(').append(containedEntityId).append(')').toString();
+ append('(').append(containedEntityId).append(')').toString();
FSManager.instance(version).deleteFile(atomEntryRelativePath);
// 3. Update the contained entity set
final String atomFeedRelativePath = containedPath(entityId, containedEntitySetName).toString();
final InputStream feedIS = FSManager.instance(version).readFile(atomFeedRelativePath, Accept.ATOM);
- final ResWrap<AtomEntitySetImpl> feedContainer = atomDeserializer.read(feedIS, AtomEntitySetImpl.class);
+ final ResWrap<EntitySet> feedContainer = atomDeserializer.toEntitySet(feedIS);
feedContainer.getPayload().getEntities().remove(container.getPayload());
final ByteArrayOutputStream content = new ByteArrayOutputStream();
@@ -1022,8 +1016,8 @@ public class V4Services extends AbstractServices {
writer.close();
FSManager.instance(version).putInMemory(
- new ByteArrayInputStream(content.toByteArray()),
- FSManager.instance(version).getAbsolutePath(atomFeedRelativePath, Accept.ATOM));
+ new ByteArrayInputStream(content.toByteArray()),
+ FSManager.instance(version).getAbsolutePath(atomFeedRelativePath, Accept.ATOM));
return xml.createResponse(null, null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) {
@@ -1034,10 +1028,10 @@ public class V4Services extends AbstractServices {
@GET
@Path("/Accounts({entityId})/{containedEntitySetName:.*}")
public Response getContainedEntitySet(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @PathParam("entityId") String entityId,
- @PathParam("containedEntitySetName") String containedEntitySetName,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @PathParam("entityId") String entityId,
+ @PathParam("containedEntitySetName") String containedEntitySetName,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
if ("MyGiftCard".equals(containedEntitySetName)) {
return getContainedEntity(accept, entityId, containedEntitySetName, null, format);
@@ -1062,9 +1056,9 @@ public class V4Services extends AbstractServices {
}
final InputStream feed = FSManager.instance(version).
- readFile(containedPath(entityId, containedEntitySetName).toString(), Accept.ATOM);
+ readFile(containedPath(entityId, containedEntitySetName).toString(), Accept.ATOM);
- final ResWrap<AtomEntitySetImpl> container = atomDeserializer.read(feed, AtomEntitySetImpl.class);
+ final ResWrap<EntitySet> container = atomDeserializer.toEntitySet(feed);
if (derivedType != null) {
final List<Entity> nonMatching = new ArrayList<Entity>();
@@ -1077,10 +1071,10 @@ public class V4Services extends AbstractServices {
}
return xml.createResponse(
- null,
- xml.writeEntitySet(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeEntitySet(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -1089,8 +1083,8 @@ public class V4Services extends AbstractServices {
@GET
@Path("/GetDefaultColor()")
public Response functionGetDefaultColor(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
@@ -1100,18 +1094,18 @@ public class V4Services extends AbstractServices {
acceptType = Accept.parse(accept, version);
}
- final AtomPropertyImpl property = new AtomPropertyImpl();
+ final PropertyImpl property = new PropertyImpl();
property.setType("Microsoft.Test.OData.Services.ODataWCFService.Color");
property.setValue(new EnumValueImpl("Red"));
- final ResWrap<AtomPropertyImpl> container = new ResWrap<AtomPropertyImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
- property);
+ final ResWrap<Property> container = new ResWrap<Property>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
+ property);
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -1120,31 +1114,31 @@ public class V4Services extends AbstractServices {
@GET
@Path("/GetPerson2({param:.*})")
public Response functionGetPerson2(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getEntityInternal(
- uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null, false);
+ uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null, false);
}
@GET
@Path("/GetPerson({param:.*})")
public Response functionGetPerson(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getEntityInternal(
- uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null, false);
+ uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null, false);
}
@GET
@Path("/GetAllProducts()")
public Response functionGetAllProducts(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
return getEntitySet(uriInfo, accept, "Products", null, null, format, null, null, null, null);
}
@@ -1152,9 +1146,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/GetProductsByAccessLevel({param:.*})")
public Response functionGetProductsByAccessLevel(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
@@ -1164,7 +1158,7 @@ public class V4Services extends AbstractServices {
acceptType = Accept.parse(accept, version);
}
- final AtomPropertyImpl property = new AtomPropertyImpl();
+ final PropertyImpl property = new PropertyImpl();
property.setType("Collection(String)");
final CollectionValue value = new CollectionValueImpl();
value.get().add(new PrimitiveValueImpl("Cheetos"));
@@ -1173,15 +1167,15 @@ public class V4Services extends AbstractServices {
value.get().add(new PrimitiveValueImpl("Car"));
value.get().add(new PrimitiveValueImpl("Computer"));
property.setValue(value);
- final ResWrap<AtomPropertyImpl> container = new ResWrap<AtomPropertyImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
- property);
+ final ResWrap<Property> container = new ResWrap<Property>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
+ property);
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -1190,9 +1184,9 @@ public class V4Services extends AbstractServices {
@GET
@Path("/GetBossEmails({param:.*})")
public Response functionGetBossEmails(
- @Context UriInfo uriInfo,
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
+ @Context UriInfo uriInfo,
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format) {
try {
final Accept acceptType;
@@ -1202,21 +1196,21 @@ public class V4Services extends AbstractServices {
acceptType = Accept.parse(accept, version);
}
- final AtomPropertyImpl property = new AtomPropertyImpl();
+ final PropertyImpl property = new PropertyImpl();
property.setType("Collection(Edm.String)");
final CollectionValue value = new CollectionValueImpl();
value.get().add(new PrimitiveValueImpl("first@olingo.apache.org"));
value.get().add(new PrimitiveValueImpl("second@olingo.apache.org"));
property.setValue(value);
- final ResWrap<AtomPropertyImpl> container = new ResWrap<AtomPropertyImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
- property);
+ final ResWrap<Property> container = new ResWrap<Property>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
+ property);
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, container),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, container),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -1225,10 +1219,10 @@ public class V4Services extends AbstractServices {
@POST
@Path("/Discount()")
public Response actionDiscount(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String param) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String param) {
try {
final Accept acceptType;
@@ -1241,14 +1235,12 @@ public class V4Services extends AbstractServices {
final Accept contentTypeValue = Accept.parse(contentType, version);
Property property;
if (contentTypeValue == Accept.ATOM) {
- final ResWrap<AtomPropertyImpl> paramContainer = atomDeserializer.read(
- IOUtils.toInputStream(param, Constants.ENCODING), AtomPropertyImpl.class);
+ final ResWrap<Property> paramContainer = atomDeserializer.toProperty(
+ IOUtils.toInputStream(param, Constants.ENCODING));
property = paramContainer.getPayload();
} else {
- final ResWrap<JSONPropertyImpl> paramContainer =
- mapper.readValue(IOUtils.toInputStream(param, Constants.ENCODING),
- new TypeReference<JSONPropertyImpl>() {
- });
+ final ResWrap<Property> paramContainer = jsonDeserializer.toProperty(
+ IOUtils.toInputStream(param, Constants.ENCODING));
property = paramContainer.getPayload();
}
@@ -1267,10 +1259,10 @@ public class V4Services extends AbstractServices {
@POST
@Path("/ResetBossAddress()")
public Response actionResetBossAddress(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String param) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String param) {
try {
final Accept acceptType;
@@ -1281,22 +1273,22 @@ public class V4Services extends AbstractServices {
}
final Accept contentTypeValue = Accept.parse(contentType, version);
- final AtomEntityImpl entity = xml.readEntity(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING));
+ final Entity entity = xml.readEntity(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING));
assert "Microsoft.Test.OData.Services.ODataWCFService.Address".equals(entity.getType());
assert entity.getProperty("address").getValue().isComplex();
- final ResWrap<AtomPropertyImpl> result = new ResWrap<AtomPropertyImpl>(
- URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
- + "Microsoft.Test.OData.Services.ODataWCFService.Address"),
- null,
- (AtomPropertyImpl) entity.getProperty("address"));
+ final ResWrap<Property> result = new ResWrap<Property>(
+ URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ + "Microsoft.Test.OData.Services.ODataWCFService.Address"),
+ null,
+ entity.getProperty("address"));
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, result),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, result),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -1305,10 +1297,10 @@ public class V4Services extends AbstractServices {
@POST
@Path("/ResetBossEmail()")
public Response actionResetBossEmail(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String param) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String param) {
try {
final Accept acceptType;
@@ -1326,10 +1318,10 @@ public class V4Services extends AbstractServices {
assert entry.getProperty("emails").getValue().isCollection();
return xml.createResponse(
- null,
- xml.writeProperty(acceptType, entry.getProperty("emails")),
- null,
- acceptType);
+ null,
+ xml.writeProperty(acceptType, entry.getProperty("emails")),
+ null,
+ acceptType);
} catch (Exception e) {
return xml.createFaultResponse(accept, e);
}
@@ -1338,10 +1330,10 @@ public class V4Services extends AbstractServices {
@POST
@Path("/Products({productId})/Categories/$ref")
public Response createLinked(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String entity) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String entity) {
return xml.createResponse(null, null, null, Status.NO_CONTENT);
}
@@ -1349,10 +1341,10 @@ public class V4Services extends AbstractServices {
@DELETE
@Path("/Products({productId})/Categories({categoryId})/$ref")
public Response deleteLinked(
- @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
- @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
- @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
- final String entity) {
+ @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
+ @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
+ @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
+ final String entity) {
return xml.createResponse(null, null, null, Status.NO_CONTENT);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java b/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java
deleted file mode 100644
index 0d3318d..0000000
--- a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONEntryContainer.java
+++ /dev/null
@@ -1,36 +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.fit.serializer;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.core.data.JSONEntityDeserializer;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntitySerializer;
-
-@JsonDeserialize(using = JSONEntityDeserializer.class)
-@JsonSerialize(using = JSONEntitySerializer.class)
-public class JSONEntryContainer extends ResWrap<JSONEntityImpl> {
-
- public JSONEntryContainer(final ContextURL contextURL, final String metadataETag, final JSONEntityImpl object) {
- super(contextURL, metadataETag, object);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java b/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java
deleted file mode 100644
index c641444..0000000
--- a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONFeedContainer.java
+++ /dev/null
@@ -1,36 +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.fit.serializer;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.core.data.JSONEntitySetDeserializer;
-import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
-import org.apache.olingo.commons.core.data.JSONEntitySetSerializer;
-
-@JsonDeserialize(using = JSONEntitySetDeserializer.class)
-@JsonSerialize(using = JSONEntitySetSerializer.class)
-public class JSONFeedContainer extends ResWrap<JSONEntitySetImpl> {
-
- public JSONFeedContainer(final ContextURL contextURL, final String metadataETag, final JSONEntitySetImpl object) {
- super(contextURL, metadataETag, object);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/serializer/JSONPropertyContainer.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONPropertyContainer.java b/fit/src/main/java/org/apache/olingo/fit/serializer/JSONPropertyContainer.java
deleted file mode 100644
index f642a19..0000000
--- a/fit/src/main/java/org/apache/olingo/fit/serializer/JSONPropertyContainer.java
+++ /dev/null
@@ -1,36 +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.fit.serializer;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.core.data.JSONPropertyDeserializer;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
-import org.apache.olingo.commons.core.data.JSONPropertySerializer;
-
-@JsonDeserialize(using = JSONPropertyDeserializer.class)
-@JsonSerialize(using = JSONPropertySerializer.class)
-public class JSONPropertyContainer extends ResWrap<JSONPropertyImpl> {
-
- public JSONPropertyContainer(final ContextURL contextURL, final String metadataETag, final JSONPropertyImpl object) {
- super(contextURL, metadataETag, object);
- }
-}
[7/9] First presentable state
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
index 0c60609..99a3320 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.fit.utils;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -37,31 +35,30 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
+
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
-import javax.xml.stream.XMLStreamException;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
-import org.apache.olingo.commons.core.data.AtomPropertyImpl;
+import org.apache.olingo.commons.api.op.ODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.api.op.ODataSerializer;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.commons.core.data.AtomSerializer;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
+import org.apache.olingo.commons.core.data.JsonDeserializer;
+import org.apache.olingo.commons.core.data.JsonSerializer;
import org.apache.olingo.fit.UnsupportedMediaTypeException;
import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.metadata.NavigationProperty;
import org.apache.olingo.fit.serializer.FITAtomDeserializer;
-import org.apache.olingo.fit.serializer.JSONEntryContainer;
-import org.apache.olingo.fit.serializer.JSONFeedContainer;
-import org.apache.olingo.fit.serializer.JSONPropertyContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -90,27 +87,21 @@ public abstract class AbstractUtilities {
public static final String BOUNDARY = "boundary";
protected final ODataServiceVersion version;
-
protected final Metadata metadata;
-
protected final FSManager fsManager;
-
- protected final DataBinder dataBinder;
-
- protected final FITAtomDeserializer atomDeserializer;
-
- protected final AtomSerializer atomSerializer;
-
- protected final ObjectMapper mapper;
+ protected final ODataDeserializer atomDeserializer;
+ protected final ODataDeserializer jsonDeserializer;
+ protected final ODataSerializer atomSerializer;
+ protected final ODataSerializer jsonSerializer;
public AbstractUtilities(final ODataServiceVersion version, final Metadata metadata) throws Exception {
this.version = version;
this.metadata = metadata;
this.fsManager = FSManager.instance(version);
- this.dataBinder = new DataBinder(version, metadata);
- this.atomDeserializer = Commons.getAtomDeserializer(version);
- this.atomSerializer = Commons.getAtomSerializer(version);
- this.mapper = Commons.getJSONMapper(version);
+ atomDeserializer = new FITAtomDeserializer(version);
+ jsonDeserializer = new JsonDeserializer(version, true);
+ atomSerializer = new AtomSerializer(version);
+ jsonSerializer = new JsonSerializer(version, true);
}
public boolean isMediaContent(final String entityName) {
@@ -128,8 +119,8 @@ public abstract class AbstractUtilities {
* @throws IOException
*/
protected abstract InputStream addLinks(
- final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
- throws Exception;
+ final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
+ throws Exception;
/**
* Retrieve all entity link names.
@@ -149,8 +140,8 @@ public abstract class AbstractUtilities {
* @throws IOException
*/
protected abstract NavigationLinks retrieveNavigationInfo(
- final String entitySetName, final InputStream is)
- throws Exception;
+ final String entitySetName, final InputStream is)
+ throws Exception;
/**
* Normalize navigation info and add edit link if missing.
@@ -163,28 +154,28 @@ public abstract class AbstractUtilities {
* @throws IOException
*/
protected abstract InputStream normalizeLinks(
- final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
- throws Exception;
+ final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
+ throws Exception;
public InputStream saveSingleEntity(
- final String key,
- final String entitySetName,
- final InputStream is) throws Exception {
+ final String key,
+ final String entitySetName,
+ final InputStream is) throws Exception {
return saveSingleEntity(key, entitySetName, is, null);
}
public InputStream saveSingleEntity(
- final String key,
- final String entitySetName,
- final InputStream is,
- final NavigationLinks links) throws Exception {
+ final String key,
+ final String entitySetName,
+ final InputStream is,
+ final NavigationLinks links) throws Exception {
// -----------------------------------------
// 0. Get the path
// -----------------------------------------
final String path =
- entitySetName + File.separatorChar + Commons.getEntityKey(key) + File.separatorChar
+ entitySetName + File.separatorChar + Commons.getEntityKey(key) + File.separatorChar
+ Constants.get(version, ConstantKey.ENTITY);
// -----------------------------------------
@@ -203,7 +194,7 @@ public abstract class AbstractUtilities {
return fo.getContent().getInputStream();
}
- private InputStream toInputStream(final AtomEntityImpl entry) throws XMLStreamException {
+ private InputStream toInputStream(final Entity entry) throws ODataSerializerException {
final StringWriter writer = new StringWriter();
atomSerializer.write(writer, entry);
@@ -211,10 +202,10 @@ public abstract class AbstractUtilities {
}
public InputStream addOrReplaceEntity(
- final String key,
- final String entitySetName,
- final InputStream is,
- final AtomEntityImpl entry) throws Exception {
+ final String key,
+ final String entitySetName,
+ final InputStream is,
+ final Entity entry) throws Exception {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copy(is, bos);
@@ -229,7 +220,7 @@ public abstract class AbstractUtilities {
try {
linksToBeKept = new HashSet<String>(navigationProperties.keySet());
} catch (Exception e) {
- linksToBeKept = Collections.<String>emptySet();
+ linksToBeKept = Collections.<String> emptySet();
}
for (String availableLink : new HashSet<String>(linksToBeKept)) {
@@ -263,7 +254,7 @@ public abstract class AbstractUtilities {
// 3. Normalize navigation info; add edit link; ... and save entity ....
// -----------------------------------------
final InputStream createdEntity =
- saveSingleEntity(entityKey, entitySetName, new ByteArrayInputStream(bos.toByteArray()), links);
+ saveSingleEntity(entityKey, entitySetName, new ByteArrayInputStream(bos.toByteArray()), links);
// -----------------------------------------
bos.reset();
@@ -273,7 +264,7 @@ public abstract class AbstractUtilities {
// 4. Add navigation links to be kept
// -----------------------------------------
final InputStream normalizedEntity =
- addLinks(entitySetName, entityKey, new ByteArrayInputStream(bos.toByteArray()), linksToBeKept);
+ addLinks(entitySetName, entityKey, new ByteArrayInputStream(bos.toByteArray()), linksToBeKept);
// -----------------------------------------
IOUtils.closeQuietly(bos);
@@ -282,8 +273,8 @@ public abstract class AbstractUtilities {
// 5. save the entity
// -----------------------------------------
final FileObject fo = fsManager.putInMemory(
- normalizedEntity,
- fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), getDefaultFormat()));
+ normalizedEntity,
+ fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), getDefaultFormat()));
// -----------------------------------------
// -----------------------------------------
@@ -297,30 +288,28 @@ public abstract class AbstractUtilities {
for (final Link link : entry.getNavigationLinks()) {
final NavigationProperty navProp =
- navigationProperties == null ? null : navigationProperties.get(link.getTitle());
+ navigationProperties == null ? null : navigationProperties.get(link.getTitle());
if (navProp != null) {
final String inlineEntitySetName = navProp.getTarget();
if (link.getInlineEntity() != null) {
- final String inlineEntryKey = getDefaultEntryKey(
- inlineEntitySetName, (AtomEntityImpl) link.getInlineEntity());
+ final String inlineEntryKey = getDefaultEntryKey(inlineEntitySetName, link.getInlineEntity());
addOrReplaceEntity(
- inlineEntryKey,
- inlineEntitySetName,
- toInputStream((AtomEntityImpl) link.getInlineEntity()),
- (AtomEntityImpl) link.getInlineEntity());
+ inlineEntryKey,
+ inlineEntitySetName,
+ toInputStream(link.getInlineEntity()),
+ link.getInlineEntity());
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
} else if (link.getInlineEntitySet() != null) {
for (Entity subentry : link.getInlineEntitySet().getEntities()) {
- final String inlineEntryKey = getDefaultEntryKey(
- inlineEntitySetName, (AtomEntityImpl) subentry);
+ final String inlineEntryKey = getDefaultEntryKey(inlineEntitySetName, subentry);
addOrReplaceEntity(
- inlineEntryKey,
- inlineEntitySetName,
- toInputStream((AtomEntityImpl) subentry),
- (AtomEntityImpl) subentry);
+ inlineEntryKey,
+ inlineEntitySetName,
+ toInputStream(subentry),
+ subentry);
hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
}
@@ -337,9 +326,9 @@ public abstract class AbstractUtilities {
}
public void addMediaEntityValue(
- final String entitySetName,
- final String entityKey,
- final InputStream is) throws Exception {
+ final String entitySetName,
+ final String entityKey,
+ final InputStream is) throws Exception {
// -----------------------------------------
// 0. Get default entry key and path (N.B. operation will consume/close the stream; use a copy instead)
@@ -351,17 +340,17 @@ public abstract class AbstractUtilities {
// 1. save the media entity value
// -----------------------------------------
fsManager.putInMemory(is, fsManager.getAbsolutePath(path
- + Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME), null));
+ + Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME), null));
IOUtils.closeQuietly(is);
// -----------------------------------------
}
public void putLinksInMemory(
- final String basePath,
- final String entitySetName,
- final String entityKey,
- final String linkName,
- final Collection<String> links) throws IOException {
+ final String basePath,
+ final String entitySetName,
+ final String entityKey,
+ final String linkName,
+ final Collection<String> links) throws IOException {
final HashSet<String> uris = new HashSet<String>();
@@ -372,8 +361,7 @@ public abstract class AbstractUtilities {
try {
final Map.Entry<String, List<String>> currents = extractLinkURIs(entitySetName, entityKey, linkName);
uris.addAll(currents.getValue());
- } catch (Exception ignore) {
- }
+ } catch (Exception ignore) {}
}
uris.addAll(links);
@@ -382,20 +370,20 @@ public abstract class AbstractUtilities {
}
public void putLinksInMemory(
- final String basePath, final String entitySetName, final String linkName, final Collection<String> uris)
- throws IOException {
+ final String basePath, final String entitySetName, final String linkName, final Collection<String> uris)
+ throws IOException {
fsManager.putInMemory(
- Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry<String, Collection<String>>(linkName, uris)),
- Commons.getLinksPath(version, basePath, linkName, Accept.JSON_FULLMETA));
+ Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry<String, Collection<String>>(linkName, uris)),
+ Commons.getLinksPath(version, basePath, linkName, Accept.JSON_FULLMETA));
fsManager.putInMemory(
- Commons.getLinksAsATOM(version, new SimpleEntry<String, Collection<String>>(linkName, uris)),
- Commons.getLinksPath(version, basePath, linkName, Accept.XML));
+ Commons.getLinksAsATOM(version, new SimpleEntry<String, Collection<String>>(linkName, uris)),
+ Commons.getLinksPath(version, basePath, linkName, Accept.XML));
}
public Response createResponse(
- final String location, final InputStream entity, final String etag, final Accept accept) {
+ final String location, final InputStream entity, final String etag, final Accept accept) {
return createResponse(location, entity, etag, accept, null);
}
@@ -430,26 +418,26 @@ public abstract class AbstractUtilities {
public Response createBatchResponse(final InputStream stream, final String boundary) {
final Response.ResponseBuilder builder = version.compareTo(ODataServiceVersion.V30) <= 0
- ? Response.accepted(stream)
- : Response.ok(stream);
+ ? Response.accepted(stream)
+ : Response.ok(stream);
builder.header(Constants.get(version, ConstantKey.ODATA_SERVICE_VERSION), version.toString() + ";");
return builder.build();
}
public Response createResponse(
- final InputStream entity,
- final String etag,
- final Accept accept,
- final Response.Status status) {
+ final InputStream entity,
+ final String etag,
+ final Accept accept,
+ final Response.Status status) {
return createResponse(null, entity, etag, accept, status);
}
public Response createResponse(
- final String location,
- final InputStream entity,
- final String etag,
- final Accept accept,
- final Response.Status status) {
+ final String location,
+ final InputStream entity,
+ final String etag,
+ final Accept accept,
+ final Response.Status status) {
final Response.ResponseBuilder builder = Response.ok();
if (version.compareTo(ODataServiceVersion.V30) <= 0) {
@@ -543,130 +531,87 @@ public abstract class AbstractUtilities {
return builder.build();
}
- public AtomEntitySetImpl readEntitySet(final Accept accept, final InputStream entitySet)
- throws XMLStreamException, IOException {
-
- final AtomEntitySetImpl entry;
-
- if (accept == Accept.ATOM || accept == Accept.XML) {
- final ResWrap<AtomEntitySetImpl> container = atomDeserializer.read(entitySet, AtomEntitySetImpl.class);
- entry = container.getPayload();
- } else {
- final ResWrap<JSONEntitySetImpl> container =
- mapper.readValue(entitySet, new TypeReference<JSONEntitySetImpl>() {
- });
- entry = dataBinder.toAtomEntitySet(container.getPayload());
- }
-
- return entry;
+ public EntitySet readEntitySet(final Accept accept, final InputStream entitySet)
+ throws ODataDeserializerException {
+ return (accept == Accept.ATOM || accept == Accept.XML ?
+ atomDeserializer.toEntitySet(entitySet) : jsonDeserializer.toEntitySet(entitySet))
+ .getPayload();
}
- public InputStream writeEntitySet(final Accept accept, final ResWrap<AtomEntitySetImpl> container)
- throws XMLStreamException, IOException {
+ public InputStream writeEntitySet(final Accept accept, final ResWrap<EntitySet> container)
+ throws ODataSerializerException, IOException {
final StringWriter writer = new StringWriter();
if (accept == Accept.ATOM || accept == Accept.XML) {
atomSerializer.write(writer, container);
- writer.flush();
- writer.close();
} else {
- mapper.writeValue(
- writer, new JSONFeedContainer(container.getContextURL(),
- container.getMetadataETag(), dataBinder.toJSONEntitySet(container.getPayload())));
+ jsonSerializer.write(writer, container);
}
+ writer.flush();
+ writer.close();
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
}
- public ResWrap<AtomEntityImpl> readContainerEntity(final Accept accept, final InputStream entity)
- throws XMLStreamException, IOException {
- final ResWrap<AtomEntityImpl> container;
-
- if (accept == Accept.ATOM || accept == Accept.XML) {
- container = atomDeserializer.read(entity, AtomEntityImpl.class);
- } else {
- final ResWrap<JSONEntityImpl> jcontainer =
- mapper.readValue(entity, new TypeReference<JSONEntityImpl>() {
- });
- container = new ResWrap<AtomEntityImpl>(
- jcontainer.getContextURL(),
- jcontainer.getMetadataETag(),
- dataBinder.toAtomEntity(jcontainer.getPayload()));
- }
-
- return container;
+ public ResWrap<Entity> readContainerEntity(final Accept accept, final InputStream entity)
+ throws ODataDeserializerException {
+ return accept == Accept.ATOM || accept == Accept.XML ?
+ atomDeserializer.toEntity(entity) : jsonDeserializer.toEntity(entity);
}
- public AtomEntityImpl readEntity(final Accept accept, final InputStream entity)
- throws XMLStreamException, IOException {
-
+ public Entity readEntity(final Accept accept, final InputStream entity)
+ throws IOException, ODataDeserializerException {
return readContainerEntity(accept, entity).getPayload();
}
- public InputStream writeEntity(final Accept accept, final ResWrap<AtomEntityImpl> container)
- throws XMLStreamException, IOException {
+ public InputStream writeEntity(final Accept accept, final ResWrap<Entity> container)
+ throws ODataSerializerException {
+ StringWriter writer = new StringWriter();
- final StringWriter writer = new StringWriter();
if (accept == Accept.ATOM || accept == Accept.XML) {
atomSerializer.write(writer, container);
} else {
- mapper.writeValue(
- writer, new JSONEntryContainer(container.getContextURL(), container.getMetadataETag(),
- dataBinder.toJSONEntity(container.getPayload())));
+ jsonSerializer.write(writer, container);
}
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
}
public InputStream writeProperty(final Accept accept, final Property property)
- throws XMLStreamException, IOException {
+ throws ODataSerializerException {
final StringWriter writer = new StringWriter();
if (accept == Accept.XML || accept == Accept.ATOM) {
- atomSerializer.write(writer, property instanceof AtomPropertyImpl
- ? property : dataBinder.toAtomProperty((JSONPropertyImpl) property, property.getType()));
+ atomSerializer.write(writer, property);
} else {
- mapper.writeValue(writer, property instanceof JSONPropertyImpl
- ? property : dataBinder.toJSONProperty((AtomPropertyImpl) property));
+ jsonSerializer.write(writer, property);
}
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 Property readProperty(final Accept accept, final InputStream property, final String entryType)
+ throws ODataDeserializerException {
+ return (Accept.ATOM == accept || Accept.XML == accept ?
+ atomDeserializer.toProperty(property) : jsonDeserializer.toProperty(property))
+ .getPayload();
}
- public InputStream writeProperty(final Accept accept, final ResWrap<AtomPropertyImpl> container)
- throws XMLStreamException, IOException {
+ public InputStream writeProperty(final Accept accept, final ResWrap<Property> container)
+ throws ODataSerializerException {
final StringWriter writer = new StringWriter();
if (accept == Accept.XML || accept == Accept.ATOM) {
atomSerializer.write(writer, container);
} else {
- mapper.writeValue(
- writer, new JSONPropertyContainer(container.getContextURL(), container.getMetadataETag(),
- dataBinder.toJSONProperty(container.getPayload())));
+ jsonSerializer.write(writer, container);
}
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
}
- private String getDefaultEntryKey(final String entitySetName, final AtomEntityImpl entry, final String propertyName)
- throws Exception {
+ private String getDefaultEntryKey(final String entitySetName, final Entity entry, final String propertyName)
+ throws Exception {
String res;
if (entry.getProperty(propertyName) == null) {
@@ -683,7 +628,7 @@ public abstract class AbstractUtilities {
return res;
}
- public String getDefaultEntryKey(final String entitySetName, final AtomEntityImpl entity) throws IOException {
+ public String getDefaultEntryKey(final String entitySetName, final Entity entity) throws IOException {
try {
String res;
@@ -699,7 +644,7 @@ public abstract class AbstractUtilities {
} else {
productID = Integer.valueOf(entity.getProperty("OrderID").getValue().asPrimitive().get());
res = "OrderID=" + entity.getProperty("OrderID").getValue().asPrimitive().get()
- + ",ProductID=" + entity.getProperty("ProductID").getValue().asPrimitive().get();
+ + ",ProductID=" + entity.getProperty("ProductID").getValue().asPrimitive().get();
}
Commons.SEQUENCE.put(entitySetName, productID);
} else if ("Message".equals(entitySetName)) {
@@ -714,7 +659,7 @@ public abstract class AbstractUtilities {
} else {
messageId = Integer.valueOf(entity.getProperty("MessageId").getValue().asPrimitive().get());
res = "FromUsername=" + entity.getProperty("FromUsername").getValue().asPrimitive().get()
- + ",MessageId=" + entity.getProperty("MessageId").getValue().asPrimitive().get();
+ + ",MessageId=" + entity.getProperty("MessageId").getValue().asPrimitive().get();
}
Commons.SEQUENCE.put(entitySetName, messageId);
} else if ("Order".equals(entitySetName)) {
@@ -759,7 +704,7 @@ public abstract class AbstractUtilities {
productId = Integer.valueOf(entity.getProperty("ProductID").getValue().asPrimitive().get());
productDetailId = Integer.valueOf(entity.getProperty("ProductDetailID").getValue().asPrimitive().get());
res = "ProductID=" + entity.getProperty("ProductID").getValue().asPrimitive().get()
- + ",ProductDetailID=" + entity.getProperty("ProductDetailID").getValue().asPrimitive().get();
+ + ",ProductDetailID=" + entity.getProperty("ProductDetailID").getValue().asPrimitive().get();
}
Commons.SEQUENCE.put(entitySetName, productDetailId);
Commons.SEQUENCE.put("Products", productId);
@@ -781,7 +726,7 @@ public abstract class AbstractUtilities {
public String getLinksBasePath(final String entitySetName, final String entityId) {
return entitySetName + File.separatorChar + Commons.getEntityKey(entityId) + File.separatorChar
- + Constants.get(version, ConstantKey.LINKS_FILE_PATH) + File.separatorChar;
+ + Constants.get(version, ConstantKey.LINKS_FILE_PATH) + File.separatorChar;
}
/**
@@ -794,8 +739,8 @@ public abstract class AbstractUtilities {
* @return a pair of ETag/links stream
*/
public LinkInfo readLinks(
- final String entitySetName, final String entityId, final String linkName, final Accept accept)
- throws Exception {
+ final String entitySetName, final String entityId, final String linkName, final Accept accept)
+ throws Exception {
final String basePath = getLinksBasePath(entitySetName, entityId);
@@ -809,16 +754,16 @@ public abstract class AbstractUtilities {
}
public InputStream putMediaInMemory(
- final String entitySetName, final String entityId, final InputStream value)
- throws IOException {
+ final String entitySetName, final String entityId, final InputStream value)
+ throws IOException {
return putMediaInMemory(entitySetName, entityId, null, value);
}
public InputStream putMediaInMemory(
- final String entitySetName, final String entityId, final String name, final InputStream value)
- throws IOException {
+ final String entitySetName, final String entityId, final String name, final InputStream value)
+ throws IOException {
final FileObject fo = fsManager.putInMemory(value, fsManager.getAbsolutePath(
- Commons.getEntityBasePath(entitySetName, entityId)
+ Commons.getEntityBasePath(entitySetName, entityId)
+ (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name), null));
return fo.getContent().getInputStream();
@@ -829,14 +774,14 @@ public abstract class AbstractUtilities {
}
public Map.Entry<String, InputStream> readMediaEntity(
- final String entitySetName, final String entityId, final String name) {
+ final String entitySetName, final String entityId, final String name) {
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
return new SimpleEntry<String, InputStream>(basePath, fsManager.readFile(basePath
- + (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name)));
+ + (name == null ? Constants.get(version, ConstantKey.MEDIA_CONTENT_FILENAME) : name)));
}
public Map.Entry<String, InputStream> readEntity(
- final String entitySetName, final String entityId, final Accept accept) {
+ final String entitySetName, final String entityId, final Accept accept) {
if (accept == Accept.XML || accept == Accept.TEXT) {
throw new UnsupportedMediaTypeException("Unsupported media type");
@@ -844,14 +789,14 @@ public abstract class AbstractUtilities {
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
return new SimpleEntry<String, InputStream>(basePath,
- fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), accept));
+ fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), accept));
}
public InputStream expandEntity(
- final String entitySetName,
- final String entityId,
- final String linkName)
- throws Exception {
+ final String entitySetName,
+ final String entityId,
+ final String linkName)
+ throws Exception {
// --------------------------------
// 0. Retrieve all 'linkName' navigation link uris (NotFoundException if missing)
@@ -865,18 +810,18 @@ public abstract class AbstractUtilities {
final Map<String, NavigationProperty> navigationProperties = metadata.getNavigationProperties(entitySetName);
return readEntities(
- links.getValue(),
- linkName,
- links.getKey(),
- navigationProperties.get(linkName).isEntitySet());
+ links.getValue(),
+ linkName,
+ links.getKey(),
+ navigationProperties.get(linkName).isEntitySet());
}
public InputStream expandEntity(
- final String entitySetName,
- final String entityId,
- final InputStream entity,
- final String linkName)
- throws Exception {
+ final String entitySetName,
+ final String entityId,
+ final InputStream entity,
+ final String linkName)
+ throws Exception {
// --------------------------------
// 2. Retrieve expanded object (entry or feed)
// --------------------------------
@@ -885,14 +830,14 @@ public abstract class AbstractUtilities {
}
public InputStream deleteProperty(
- final String entitySetName,
- final String entityId,
- final List<String> path,
- final Accept accept) throws Exception {
+ final String entitySetName,
+ final String entityId,
+ final List<String> path,
+ final Accept accept) throws Exception {
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
final Accept acceptType = accept == null || Accept.TEXT == accept
- ? Accept.XML : accept.getExtension().equals(Accept.JSON.getExtension()) ? Accept.JSON_FULLMETA : accept;
+ ? Accept.XML : accept.getExtension().equals(Accept.JSON.getExtension()) ? Accept.JSON_FULLMETA : accept;
// read atom
InputStream stream = fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType);
@@ -902,17 +847,17 @@ public abstract class AbstractUtilities {
// save atom
fsManager.putInMemory(stream,
- fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType));
+ fsManager.getAbsolutePath(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType));
return fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), acceptType);
}
public abstract InputStream readEntities(
- final List<String> links, final String linkName, final String next, final boolean forceFeed)
- throws Exception;
+ final List<String> links, final String linkName, final String next, final boolean forceFeed)
+ throws Exception;
protected abstract InputStream replaceLink(
- final InputStream toBeChanged, final String linkName, final InputStream replacement) throws Exception;
+ final InputStream toBeChanged, final String linkName, final InputStream replacement) throws Exception;
public abstract InputStream selectEntity(final InputStream entity, final String[] propertyNames) throws Exception;
@@ -921,19 +866,19 @@ public abstract class AbstractUtilities {
protected abstract Map<String, InputStream> getChanges(final InputStream src) throws Exception;
public abstract InputStream addEditLink(
- final InputStream content, final String title, final String href) throws Exception;
+ final InputStream content, final String title, final String href) throws Exception;
public abstract InputStream addOperation(
- final InputStream content, final String name, final String metaAnchor, final String href) throws Exception;
+ final InputStream content, final String name, final String metaAnchor, final String href) throws Exception;
protected abstract InputStream replaceProperty(
- final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
- throws Exception;
+ final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
+ throws Exception;
protected abstract InputStream deleteProperty(final InputStream src, final List<String> path) throws Exception;
public abstract Map.Entry<String, List<String>> extractLinkURIs(final InputStream is) throws Exception;
public abstract Map.Entry<String, List<String>> extractLinkURIs(
- final String entitySetName, final String entityId, final String linkName) throws Exception;
+ final String entitySetName, final String entityId, final String linkName) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java b/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
index 65b7eae..c9f4128 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
@@ -18,15 +18,6 @@
*/
package org.apache.olingo.fit.utils;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.InjectableValues;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -42,19 +33,25 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.data.AtomSerializer;
-import org.apache.olingo.commons.core.op.InjectableSerializerProvider;
import org.apache.olingo.fit.metadata.Metadata;
-import org.apache.olingo.fit.serializer.FITAtomDeserializer;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
public abstract class Commons {
/**
@@ -62,15 +59,6 @@ public abstract class Commons {
*/
protected static final Logger LOG = LoggerFactory.getLogger(Commons.class);
- private static final Map<ODataServiceVersion, FITAtomDeserializer> ATOM_DESERIALIZER =
- new EnumMap<ODataServiceVersion, FITAtomDeserializer>(ODataServiceVersion.class);
-
- private static final Map<ODataServiceVersion, AtomSerializer> ATOM_SERIALIZER =
- new EnumMap<ODataServiceVersion, AtomSerializer>(ODataServiceVersion.class);
-
- private static final Map<ODataServiceVersion, ObjectMapper> JSON_MAPPER =
- new EnumMap<ODataServiceVersion, ObjectMapper>(ODataServiceVersion.class);
-
private static final EnumMap<ODataServiceVersion, Metadata> METADATA =
new EnumMap<ODataServiceVersion, Metadata>(ODataServiceVersion.class);
@@ -109,41 +97,6 @@ public abstract class Commons {
new ImmutablePair<String, EdmPrimitiveTypeKind>("ID", EdmPrimitiveTypeKind.Guid));
}
- public static FITAtomDeserializer getAtomDeserializer(final ODataServiceVersion version) {
- if (!ATOM_DESERIALIZER.containsKey(version)) {
- ATOM_DESERIALIZER.put(version, new FITAtomDeserializer(version));
- }
- return ATOM_DESERIALIZER.get(version);
- }
-
- public static AtomSerializer getAtomSerializer(final ODataServiceVersion version) {
- if (!ATOM_SERIALIZER.containsKey(version)) {
- ATOM_SERIALIZER.put(version, new AtomSerializer(version, true));
- }
-
- return ATOM_SERIALIZER.get(version);
- }
-
- public static ObjectMapper getJSONMapper(final ODataServiceVersion version) {
- if (!JSON_MAPPER.containsKey(version)) {
- final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
-
- mapper.setInjectableValues(new InjectableValues.Std()
- .addValue(Boolean.class, Boolean.TRUE)
- .addValue(ODataServiceVersion.class, version));
-
- mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
- mapper.getSerializationConfig()
- .withAttribute(ODataServiceVersion.class, version)
- .withAttribute(Boolean.class, Boolean.TRUE),
- mapper.getSerializerFactory()));
-
- JSON_MAPPER.put(version, mapper);
- }
-
- return JSON_MAPPER.get(version);
- }
-
public static Metadata getMetadata(final ODataServiceVersion version) {
if (!METADATA.containsKey(version)) {
final InputStream is = Commons.class.getResourceAsStream("/" + version.name() + "/metadata.xml");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java b/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java
deleted file mode 100644
index 4dbd725..0000000
--- a/fit/src/main/java/org/apache/olingo/fit/utils/DataBinder.java
+++ /dev/null
@@ -1,347 +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.fit.utils;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.Value;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
-import org.apache.olingo.commons.core.data.AtomPropertyImpl;
-import org.apache.olingo.commons.core.data.CollectionValueImpl;
-import org.apache.olingo.commons.core.data.ComplexValueImpl;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntitySetImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
-import org.apache.olingo.commons.core.data.LinkImpl;
-import org.apache.olingo.fit.metadata.EntityType;
-import org.apache.olingo.fit.metadata.Metadata;
-import org.apache.olingo.fit.metadata.NavigationProperty;
-import org.springframework.beans.BeanUtils;
-
-public class DataBinder {
-
- private final ODataServiceVersion version;
-
- private final Metadata metadata;
-
- public DataBinder(final ODataServiceVersion version, final Metadata metadata) {
- this.version = version;
- this.metadata = metadata;
- }
-
- public JSONEntitySetImpl toJSONEntitySet(final AtomEntitySetImpl atomEntitySet) {
- final JSONEntitySetImpl jsonEntitySet = new JSONEntitySetImpl();
-
- BeanUtils.copyProperties(atomEntitySet, jsonEntitySet, "baseURI", "metadataContextURL");
- jsonEntitySet.setBaseURI(atomEntitySet.getBaseURI() == null
- ? null
- : atomEntitySet.getBaseURI().toASCIIString() + "/$metadata");
-
- final Collection<Entity> entries = jsonEntitySet.getEntities();
- for (Entity entity : atomEntitySet.getEntities()) {
- entries.add(toJSONEntity((AtomEntityImpl) entity));
- }
-
- return jsonEntitySet;
- }
-
- public AtomEntitySetImpl toAtomEntitySet(final JSONEntitySetImpl jsonEntitySet) {
- final AtomEntitySetImpl atomEntitySet = new AtomEntitySetImpl();
-
- BeanUtils.copyProperties(jsonEntitySet, atomEntitySet, "baseURI", "metadataContextURL");
- atomEntitySet.setBaseURI(jsonEntitySet.getBaseURI() == null
- ? null
- : jsonEntitySet.getBaseURI().toASCIIString() + "/$metadata");
-
- final Collection<Entity> entries = atomEntitySet.getEntities();
- for (Entity entity : jsonEntitySet.getEntities()) {
- entries.add(toAtomEntity((JSONEntityImpl) entity));
- }
-
- return atomEntitySet;
- }
-
- public JSONEntityImpl toJSONEntity(final AtomEntityImpl atomEntity) {
- final JSONEntityImpl jsonEntity = new JSONEntityImpl();
- jsonEntity.getAnnotations().addAll(atomEntity.getAnnotations());
-
- BeanUtils.copyProperties(atomEntity, jsonEntity, "baseURI", "properties", "links");
- // This shouldn't ever happen, but...
- if (atomEntity.getType() != null && atomEntity.getType().startsWith("Collection(")) {
- jsonEntity.setType(atomEntity.getType().replaceAll("^Collection\\(", "").replaceAll("\\)$", ""));
- }
- jsonEntity.setBaseURI(atomEntity.getBaseURI() == null ? null : atomEntity.getBaseURI().toASCIIString());
- jsonEntity.getOperations().addAll(atomEntity.getOperations());
-
- for (Link link : atomEntity.getMediaEditLinks()) {
- final Link jlink = new LinkImpl();
- jlink.setHref(link.getHref());
- jlink.setTitle(link.getTitle());
- jlink.setType(link.getType());
- jlink.setRel(link.getRel());
-
- if (link.getInlineEntity() instanceof AtomEntityImpl) {
- final Entity inlineEntity = link.getInlineEntity();
- if (inlineEntity instanceof AtomEntityImpl) {
- jlink.setInlineEntity(toJSONEntity((AtomEntityImpl) link.getInlineEntity()));
- }
- } else if (link.getInlineEntitySet() instanceof AtomEntitySetImpl) {
- final EntitySet inlineEntitySet = link.getInlineEntitySet();
- if (inlineEntitySet instanceof AtomEntitySetImpl) {
- jlink.setInlineEntitySet(toJSONEntitySet((AtomEntitySetImpl) link.getInlineEntitySet()));
- }
- }
-
- jsonEntity.getMediaEditLinks().add(jlink);
- }
-
- for (Link link : atomEntity.getNavigationLinks()) {
- final Link jlink = new LinkImpl();
- jlink.setHref(link.getHref());
- jlink.setTitle(link.getTitle());
- jlink.setType(link.getType());
- jlink.setRel(link.getRel());
- jlink.getAnnotations().addAll(link.getAnnotations());
-
- if (link.getInlineEntity() instanceof AtomEntityImpl) {
- final Entity inlineEntity = link.getInlineEntity();
- if (inlineEntity instanceof AtomEntityImpl) {
- jlink.setInlineEntity(toJSONEntity((AtomEntityImpl) link.getInlineEntity()));
- }
- } else if (link.getInlineEntitySet() instanceof AtomEntitySetImpl) {
- final EntitySet inlineEntitySet = link.getInlineEntitySet();
- if (inlineEntitySet instanceof AtomEntitySetImpl) {
- jlink.setInlineEntitySet(toJSONEntitySet((AtomEntitySetImpl) link.getInlineEntitySet()));
- }
- }
-
- jsonEntity.getNavigationLinks().add(jlink);
- }
-
- final Collection<Property> properties = jsonEntity.getProperties();
- for (Property property : atomEntity.getProperties()) {
- properties.add(toJSONProperty((AtomPropertyImpl) property));
- }
-
- jsonEntity.getAnnotations().addAll(atomEntity.getAnnotations());
-
- return jsonEntity;
- }
-
- public AtomEntityImpl toAtomEntity(final JSONEntityImpl jsonEntity) {
- final AtomEntityImpl atomEntity = new AtomEntityImpl();
-
- BeanUtils.copyProperties(jsonEntity, atomEntity, "baseURI", "properties", "links");
- atomEntity.setBaseURI(jsonEntity.getBaseURI() == null ? null : jsonEntity.getBaseURI().toASCIIString());
-
- for (Link link : jsonEntity.getMediaEditLinks()) {
- final Link alink = new LinkImpl();
- alink.setHref(link.getHref());
- alink.setTitle(link.getTitle());
- alink.setRel(link.getRel());
- alink.setType(link.getType());
-
- if (link.getInlineEntity() instanceof JSONEntityImpl) {
- final Entity inlineEntity = link.getInlineEntity();
- if (inlineEntity instanceof JSONEntityImpl) {
- alink.setInlineEntity(toAtomEntity((JSONEntityImpl) link.getInlineEntity()));
- }
- } else if (link.getInlineEntitySet() instanceof JSONEntitySetImpl) {
- final EntitySet inlineEntitySet = link.getInlineEntitySet();
- if (inlineEntitySet instanceof JSONEntitySetImpl) {
- alink.setInlineEntitySet(toAtomEntitySet((JSONEntitySetImpl) link.getInlineEntitySet()));
- }
- }
-
- atomEntity.getMediaEditLinks().add(alink);
- }
-
- for (Link link : jsonEntity.getNavigationLinks()) {
- final Link alink = new LinkImpl();
- alink.setHref(link.getHref());
- alink.setTitle(link.getTitle());
- alink.getAnnotations().addAll(link.getAnnotations());
-
- final NavigationProperty navPropDetails =
- metadata.getEntityOrComplexType(jsonEntity.getType()).getNavigationProperty(link.getTitle());
-
- alink.setType(navPropDetails != null && navPropDetails.isEntitySet()
- ? Constants.get(ConstantKey.ATOM_LINK_FEED) : Constants.get(ConstantKey.ATOM_LINK_ENTRY));
- alink.setRel(link.getRel());
-
- if (link.getInlineEntity() instanceof JSONEntityImpl) {
- final Entity inlineEntity = link.getInlineEntity();
- if (inlineEntity instanceof JSONEntityImpl) {
- alink.setInlineEntity(toAtomEntity((JSONEntityImpl) link.getInlineEntity()));
- }
- } else if (link.getInlineEntitySet() instanceof JSONEntitySetImpl) {
- final EntitySet inlineEntitySet = link.getInlineEntitySet();
- if (inlineEntitySet instanceof JSONEntitySetImpl) {
- alink.setInlineEntitySet(toAtomEntitySet((JSONEntitySetImpl) link.getInlineEntitySet()));
- }
- }
-
- atomEntity.getNavigationLinks().add(alink);
- }
-
- final EntityType entityType = StringUtils.isBlank(jsonEntity.getType())
- ? null : metadata.getEntityOrComplexType(jsonEntity.getType());
- final Map<String, NavigationProperty> navProperties = entityType == null
- ? Collections.<String, NavigationProperty>emptyMap() : entityType.getNavigationPropertyMap();
-
- final List<Property> properties = atomEntity.getProperties();
-
- for (Property property : jsonEntity.getProperties()) {
- if (navProperties.containsKey(property.getName())) {
- final Link alink = new LinkImpl();
- alink.setTitle(property.getName());
- alink.getAnnotations().addAll(property.getAnnotations());
-
- alink.setType(navProperties.get(property.getName()).isEntitySet()
- ? Constants.get(version, ConstantKey.ATOM_LINK_FEED)
- : Constants.get(version, ConstantKey.ATOM_LINK_ENTRY));
-
- alink.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getName());
-
- if (property.getValue().isComplex()) {
- final Entity inline = new AtomEntityImpl();
- inline.setType(navProperties.get(property.getName()).getType());
- for (Property prop : property.getValue().asComplex().get()) {
- inline.getProperties().add(prop);
- }
- alink.setInlineEntity(inline);
-
- } else if (property.getValue().isCollection()) {
- final EntitySet inline = new AtomEntitySetImpl();
- for (Value value : property.getValue().asCollection().get()) {
- final Entity inlineEntity = new AtomEntityImpl();
- inlineEntity.setType(navProperties.get(property.getName()).getType());
- for (Property prop : value.asComplex().get()) {
- inlineEntity.getProperties().add(toAtomProperty((JSONPropertyImpl) prop, inlineEntity.getType()));
- }
- inline.getEntities().add(inlineEntity);
- }
- alink.setInlineEntitySet(inline);
- } else {
- throw new IllegalStateException("Invalid navigation property " + property);
- }
- atomEntity.getNavigationLinks().add(alink);
- } else {
- properties.add(toAtomProperty((JSONPropertyImpl) property, atomEntity.getType()));
- }
- }
-
- return atomEntity;
- }
-
- public JSONPropertyImpl toJSONProperty(final AtomPropertyImpl atomProperty) {
- final JSONPropertyImpl jsonProperty = new JSONPropertyImpl();
- BeanUtils.copyProperties(atomProperty, jsonProperty, "value");
- jsonProperty.getAnnotations().addAll(atomProperty.getAnnotations());
-
- if (atomProperty.getValue().isComplex()) {
- final ComplexValueImpl complex = new ComplexValueImpl();
- jsonProperty.setValue(complex);
-
- for (Property field : atomProperty.getValue().asComplex().get()) {
- complex.get().add(toJSONProperty((AtomPropertyImpl) field));
- }
- } else if (atomProperty.getValue().isCollection()) {
- final CollectionValueImpl collection = new CollectionValueImpl();
- jsonProperty.setValue(collection);
-
- for (Value element : atomProperty.getValue().asCollection().get()) {
- if (element.isComplex()) {
- final ComplexValueImpl complex = new ComplexValueImpl();
- collection.get().add(complex);
-
- for (Property field : element.asComplex().get()) {
- complex.get().add(toJSONProperty((AtomPropertyImpl) field));
- }
- } else {
- collection.get().add(element);
- }
- }
- } else {
- jsonProperty.setValue(atomProperty.getValue());
- }
-
- return jsonProperty;
- }
-
- public AtomPropertyImpl toAtomProperty(final JSONPropertyImpl jsonProperty, final String entryType) {
- final AtomPropertyImpl atomProperty = new AtomPropertyImpl();
- atomProperty.setName(jsonProperty.getName());
- atomProperty.getAnnotations().addAll(jsonProperty.getAnnotations());
-
- final EntityType entityType = entryType == null
- ? null
- : metadata.getEntityOrComplexType(entryType.replaceAll("^Collection\\(", "").replaceAll("\\)$", ""));
-
- // For non-primitive types, alwasy trust what was sent - if available; otherwise, search metadata
- if (StringUtils.isNotBlank(jsonProperty.getType())
- && ((entityType != null && entityType.isOpenType())
- || jsonProperty.getName() == null
- || !jsonProperty.getType().startsWith(EdmPrimitiveType.EDM_NAMESPACE))) {
-
- atomProperty.setType(jsonProperty.getType());
- } else if (entityType != null) {
- atomProperty.setType(entityType.getProperty(jsonProperty.getName()).getType());
- }
-
- if (jsonProperty.getValue().isComplex()) {
- final ComplexValueImpl complex = new ComplexValueImpl();
- atomProperty.setValue(complex);
-
- for (Property field : jsonProperty.getValue().asComplex().get()) {
- complex.get().add(toAtomProperty((JSONPropertyImpl) field, atomProperty.getType()));
- }
- } else if (jsonProperty.getValue().isCollection()) {
- final CollectionValueImpl collection = new CollectionValueImpl();
- atomProperty.setValue(collection);
-
- for (Value element : jsonProperty.getValue().asCollection().get()) {
- if (element instanceof ComplexValueImpl) {
- final ComplexValueImpl complex = new ComplexValueImpl();
- collection.get().add(complex);
-
- for (Property field : element.asComplex().get()) {
- complex.get().add(toAtomProperty((JSONPropertyImpl) field, atomProperty.getType()));
- }
- } else {
- collection.get().add(element);
- }
- }
- } else {
- atomProperty.setValue(jsonProperty.getValue());
- }
-
- return atomProperty;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
index b8378cb..9031122 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java
@@ -18,7 +18,6 @@
*/
package org.apache.olingo.fit.utils;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -28,7 +27,9 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.EnumMap;
import java.util.Map;
+
import javax.ws.rs.NotFoundException;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSelectInfo;
@@ -37,11 +38,11 @@ import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileType;
import org.apache.commons.vfs2.VFS;
+import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
import org.apache.olingo.commons.core.data.AtomSerializer;
-import org.apache.olingo.fit.serializer.JSONEntryContainer;
+import org.apache.olingo.commons.core.data.JsonSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -112,10 +113,9 @@ public class FSManager {
return memObject;
}
- public void putInMemory(final ResWrap<AtomEntityImpl> container, final String relativePath,
- final DataBinder dataBinder) throws IOException {
+ public void putInMemory(final ResWrap<Entity> container, final String relativePath) throws IOException {
try {
- final AtomSerializer atomSerializer = Commons.getAtomSerializer(version);
+ final AtomSerializer atomSerializer = new AtomSerializer(version);
final ByteArrayOutputStream content = new ByteArrayOutputStream();
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
@@ -126,12 +126,8 @@ public class FSManager {
putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.ATOM));
content.reset();
- final ObjectMapper mapper = Commons.getJSONMapper(version);
- mapper.writeValue(
- writer, new JSONEntryContainer(
- container.getContextURL(),
- container.getMetadataETag(),
- dataBinder.toJSONEntity(container.getPayload())));
+ final JsonSerializer jsonSerializer = new JsonSerializer(version, true);
+ jsonSerializer.write(writer, container);
putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.JSON_FULLMETA));
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
index 7c6a54b..fe3f511 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
@@ -18,10 +18,6 @@
*/
package org.apache.olingo.fit.utils;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.databind.node.TextNode;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -33,17 +29,40 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import javax.ws.rs.NotFoundException;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.core.op.InjectableSerializerProvider;
import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.metadata.NavigationProperty;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.InjectableValues;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.node.TextNode;
+
public class JSONUtilities extends AbstractUtilities {
+ private final ObjectMapper mapper;
+
public JSONUtilities(final ODataServiceVersion version, final Metadata metadata) throws Exception {
super(version, metadata);
+
+ mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ mapper.setInjectableValues(new InjectableValues.Std()
+ .addValue(Boolean.class, Boolean.TRUE)
+ .addValue(ODataServiceVersion.class, version));
+ mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
+ mapper.getSerializationConfig()
+ .withAttribute(ODataServiceVersion.class, version)
+ .withAttribute(Boolean.class, Boolean.TRUE),
+ mapper.getSerializerFactory()));
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
index e606564..d292232 100644
--- a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
@@ -21,6 +21,7 @@ package org.apache.olingo.fit;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
+
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.commons.api.data.Entity;
@@ -28,8 +29,9 @@ import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,7 +48,9 @@ public abstract class AbstractBaseTestITCase {
protected void debugEntity(final Entity entity, final String message) {
if (LOG.isDebugEnabled()) {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(entity, writer);
+ try {
+ getClient().getSerializer(ODataFormat.JSON).write(writer, entity);
+ } catch (final ODataSerializerException e) {}
writer.flush();
LOG.debug(message + "\n{}", writer.toString());
}
@@ -55,7 +59,9 @@ public abstract class AbstractBaseTestITCase {
protected void debugEntitySet(final EntitySet entitySet, final String message) {
if (LOG.isDebugEnabled()) {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().entitySet(entitySet, writer);
+ try {
+ getClient().getSerializer(ODataFormat.JSON).write(writer, entitySet);
+ } catch (final ODataSerializerException e) {}
writer.flush();
LOG.debug(message + "\n{}", writer.toString());
}
@@ -72,12 +78,16 @@ public abstract class AbstractBaseTestITCase {
protected void debugODataEntity(final CommonODataEntity entity, final String message) {
if (LOG.isDebugEnabled()) {
StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, AtomEntityImpl.class), writer);
+ try {
+ getClient().getSerializer(ODataPubFormat.ATOM).write(writer, getClient().getBinder().getEntity(entity));
+ } catch (final ODataSerializerException e) {}
writer.flush();
LOG.debug(message + " (Atom)\n{}", writer.toString());
writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, JSONEntityImpl.class), writer);
+ try {
+ getClient().getSerializer(ODataPubFormat.JSON).write(writer, getClient().getBinder().getEntity(entity));
+ } catch (final ODataSerializerException e) {}
writer.flush();
LOG.debug(message + " (JSON)\n{}", writer.toString());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java
index 0ffe48a..e1df392 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/MediaEntityTestITCase.java
@@ -18,20 +18,21 @@
*/
package org.apache.olingo.fit.proxy.v4;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.UUID;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.fit.proxy.v4.AbstractTestITCase;
import org.apache.olingo.fit.proxy.v4.demo.odatademo.DemoService;
import org.apache.olingo.fit.proxy.v4.demo.odatademo.types.Advertisement;
import org.junit.Test;
@@ -65,7 +66,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
final UUID uuid = UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7");
final Advertisement adv = getContainer().getAdvertisements().get(uuid);
- assertTrue(adv.getAirDate() instanceof Calendar);
+ assertNotNull(adv.getAirDate());
final InputStream is = adv.getStream();
assertNotNull(is);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java
index 1c3c583..2f23551 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/NonTransactionalMediaEntityTestITCase.java
@@ -18,10 +18,9 @@
*/
package org.apache.olingo.fit.proxy.v4;
+import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.ext.proxy.EntityContainerFactory;
-
-import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.fit.proxy.v4.demo.odatademo.DemoService;
public class NonTransactionalMediaEntityTestITCase extends MediaEntityTestITCase {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java
index 9314d2a..043e547 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java
@@ -43,7 +43,6 @@ import org.apache.olingo.commons.api.domain.v3.ODataEntity;
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.op.ResourceFactory;
import org.junit.Test;
/**
@@ -79,8 +78,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
assertNotNull(inline);
- debugEntity(client.getBinder().getEntity(
- inline, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), "Just read");
+ debugEntity(client.getBinder().getEntity(inline), "Just read");
final List<? extends CommonODataProperty> properties = inline.getProperties();
assertEquals(2, properties.size());
@@ -126,8 +124,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
assertNotNull(inline);
- debugEntitySet(client.getBinder().getEntitySet(inline, ResourceFactory.entitySetClassForFormat(
- format == ODataPubFormat.ATOM)), "Just read");
+ debugEntitySet(client.getBinder().getEntitySet(inline), "Just read");
found = true;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java
index 68fb07d..0f8649c 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java
@@ -36,7 +36,6 @@ 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.ODataEntitySet;
import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.op.ResourceFactory;
import org.junit.Test;
/**
@@ -111,8 +110,7 @@ public class EntitySetTestITCase extends AbstractTestITCase {
assertNotNull(feed);
- debugEntitySet(client.getBinder().getEntitySet(feed, ResourceFactory.entitySetClassForFormat(
- ODataPubFormat.ATOM == format)), "Just retrieved feed");
+ debugEntitySet(client.getBinder().getEntitySet(feed), "Just retrieved feed");
assertEquals(2, feed.getEntities().size());
assertNotNull(feed.getNext());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java
index 346a144..7d48860 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/JSONFormatConformanceTestITCase.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import java.math.BigDecimal;
import java.net.URI;
+
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
@@ -116,7 +117,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase {
* .
*/
@Test
- public void item3() throws EdmPrimitiveTypeException {
+ public void item3() throws Exception {
final String fromSection71 = "{"
+ "\"NullValue\": null,"
+ "\"TrueValue\": true,"
@@ -202,7 +203,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase {
* MUST interpret all odata annotations defined according to the OData-Version header of the payload (section 4.5).
*/
@Test
- public void item4() {
+ public void item4() throws Exception {
final String fromSection45_1 = "{"
+ "\"@odata.context\": \"http://host/service/$metadata#Customers/$entity\","
+ "\"@odata.metadataEtag\": \"W/\\\"A1FF3E230954908F\\\"\","
@@ -218,7 +219,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase {
+ "}";
final ResWrap<Entity> entity =
- client.getDeserializer().toEntity(IOUtils.toInputStream(fromSection45_1), ODataPubFormat.JSON);
+ client.getDeserializer(ODataPubFormat.JSON).toEntity(IOUtils.toInputStream(fromSection45_1));
assertEquals("http://host/service/$metadata#Customers/$entity", entity.getContextURL().getURI().toASCIIString());
assertEquals("W/\"A1FF3E230954908F\"", entity.getMetadataETag());
@@ -240,7 +241,7 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase {
+ "}";
final ResWrap<EntitySet> entitySet =
- client.getDeserializer().toEntitySet(IOUtils.toInputStream(fromSection45_2), ODataPubFormat.JSON);
+ client.getDeserializer(ODataPubFormat.JSON).toEntitySet(IOUtils.toInputStream(fromSection45_2));
assertEquals(5, entitySet.getPayload().getCount(), 0);
assertEquals("Customers?$expand=Orders&$skipToken=5", entitySet.getPayload().getNext().toASCIIString());
@@ -249,10 +250,10 @@ public class JSONFormatConformanceTestITCase extends AbstractTestITCase {
/**
* MUST be prepared to receive any annotations, including custom annotations and <tt>odata</tt> annotations not
- * defined in the <tt>OData-Version</tt> header of the payload (section 20).
+ * defined in the <tt>OData-Version</tt> header of the payload (section 20).
*/
@Test
- public void item5() throws EdmPrimitiveTypeException {
+ public void item5() throws Exception {
final String sample = "{"
+ " \"@odata.context\": \"http://host/service/$metadata#Customers\","
+ " \"@odata.notdefined\": 11,"
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
index 1a83849..8c398ca 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java
@@ -26,14 +26,15 @@ import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.CommonRetrieveRequestFactory;
import org.apache.olingo.client.api.op.ClientODataDeserializer;
-import org.apache.olingo.commons.api.domain.CommonODataObjectFactory;
import org.apache.olingo.client.api.op.CommonODataBinder;
import org.apache.olingo.client.api.op.CommonODataReader;
-import org.apache.olingo.commons.api.op.ODataSerializer;
import org.apache.olingo.client.api.op.ODataWriter;
-import org.apache.olingo.client.api.uri.CommonURIBuilder;
import org.apache.olingo.client.api.uri.CommonFilterFactory;
+import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import org.apache.olingo.commons.api.domain.CommonODataObjectFactory;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.op.ODataSerializer;
/**
* Generic client interface (common to all supported OData protocol versions).
@@ -54,9 +55,9 @@ public interface CommonODataClient<UT extends CommonUpdateType> {
CommonFilterFactory getFilterFactory();
- ODataSerializer getSerializer();
+ ODataSerializer getSerializer(Format format);
- ClientODataDeserializer getDeserializer();
+ ClientODataDeserializer getDeserializer(Format format);
CommonODataReader getReader();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java
index f51285d..87cc970 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java
@@ -26,6 +26,7 @@ import java.io.OutputStream;
import java.net.URI;
import java.util.Iterator;
import java.util.NoSuchElementException;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.CommonODataClient;
@@ -35,6 +36,7 @@ import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,8 +56,6 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
*/
private static final Logger LOG = LoggerFactory.getLogger(ODataEntitySetIterator.class);
- private static final long serialVersionUID = 9039605899821494025L;
-
private final CommonODataClient odataClient;
private final InputStream stream;
@@ -120,8 +120,12 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
if (cached == null) {
available = false;
- entitySet = (ES) odataClient.getReader().
- readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), format);
+ try {
+ entitySet = (ES) odataClient.getReader().
+ readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), format);
+ } catch (final ODataDeserializerException e) {
+ available = false;
+ }
close();
}
}
@@ -209,8 +213,8 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
}
if (c >= 0) {
- jsonEntity = odataClient.getDeserializer().toEntity(
- new ByteArrayInputStream(entity.toByteArray()), ODataPubFormat.JSON);
+ jsonEntity = odataClient.getDeserializer(ODataPubFormat.JSON).toEntity(
+ new ByteArrayInputStream(entity.toByteArray()));
}
} else {
while ((c = input.read()) >= 0) {
@@ -238,8 +242,8 @@ public class ODataEntitySetIterator<ES extends CommonODataEntitySet, E extends C
entity.write(">".getBytes(Constants.UTF8));
if (consume(input, "</entry>", entity, true) >= 0) {
- atomEntity = odataClient.getDeserializer().
- toEntity(new ByteArrayInputStream(entity.toByteArray()), ODataPubFormat.ATOM);
+ atomEntity = odataClient.getDeserializer(ODataPubFormat.ATOM).
+ toEntity(new ByteArrayInputStream(entity.toByteArray()));
}
}
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ClientODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ClientODataDeserializer.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ClientODataDeserializer.java
index 9bca91a..f7586bc 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ClientODataDeserializer.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ClientODataDeserializer.java
@@ -19,13 +19,14 @@
package org.apache.olingo.client.api.op;
import java.io.InputStream;
+
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.edm.xml.XMLMetadata;
import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.op.CommonODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
-public interface ClientODataDeserializer extends CommonODataDeserializer {
+public interface ClientODataDeserializer extends ODataDeserializer {
XMLMetadata toMetadata(InputStream input);
@@ -33,8 +34,8 @@ public interface ClientODataDeserializer extends CommonODataDeserializer {
* Gets the ServiceDocument object represented by the given InputStream.
*
* @param input stream to be de-serialized.
- * @param format OData service document format.
* @return <tt>ServiceDocument</tt> object.
+ * @throws ODataDeserializerException
*/
- ResWrap<ServiceDocument> toServiceDocument(InputStream input, ODataFormat format);
+ ResWrap<ServiceDocument> toServiceDocument(InputStream input) throws ODataDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java
index cf7dc5c..530177c 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataBinder.java
@@ -18,57 +18,52 @@
*/
package org.apache.olingo.client.api.op;
-import java.io.Serializable;
+import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-public interface CommonODataBinder extends Serializable {
+public interface CommonODataBinder {
/**
* Gets a <tt>EntitySet</tt> from the given OData entity set.
*
* @param entitySet OData entity set.
- * @param reference reference class.
* @return {@link EntitySet} object.
*/
- EntitySet getEntitySet(CommonODataEntitySet entitySet, Class<? extends EntitySet> reference);
+ EntitySet getEntitySet(CommonODataEntitySet entitySet);
/**
* Gets an <tt>Entity</tt> from the given OData entity.
*
* @param entity OData entity.
- * @param reference reference class.
* @return {@link Entity} object.
*/
- Entity getEntity(CommonODataEntity entity, Class<? extends Entity> reference);
+ Entity getEntity(CommonODataEntity entity);
/**
* Gets a <tt>Link</tt> from the given OData link.
*
* @param link OData link.
- * @param isXML whether it is JSON or XML / Atom
* @return <tt>Link</tt> object.
*/
- Link getLink(ODataLink link, boolean isXML);
+ Link getLink(ODataLink link);
/**
* Gets a <tt>Property</tt> from the given OData property.
*
* @param property OData property.
- * @param reference reference class.
* @return <tt>Property</tt> object.
*/
- Property getProperty(CommonODataProperty property, Class<? extends Entity> reference);
+ Property getProperty(CommonODataProperty property);
/**
* Adds the given property to the given complex value.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java
index 897f8f9..056977f 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/CommonODataReader.java
@@ -19,18 +19,19 @@
package org.apache.olingo.client.api.op;
import java.io.InputStream;
-import java.io.Serializable;
import java.util.Map;
+
import org.apache.olingo.client.api.edm.xml.Schema;
import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
* OData reader.
@@ -39,7 +40,7 @@ import org.apache.olingo.commons.api.format.ODataPubFormat;
* <br/>
* 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 {
/**
* Parses a stream into metadata representation.
@@ -64,8 +65,9 @@ public interface CommonODataReader extends Serializable {
* @param input stream to de-serialize.
* @param format de-serialize as XML or JSON
* @return List of URIs.
+ * @throws ODataDeserializerException
*/
- ODataServiceDocument readServiceDocument(InputStream input, ODataFormat format);
+ ODataServiceDocument readServiceDocument(InputStream input, ODataFormat format) throws ODataDeserializerException;
/**
* De-Serializes a stream into an OData entity set.
@@ -73,8 +75,9 @@ public interface CommonODataReader extends Serializable {
* @param input stream to de-serialize.
* @param format de-serialize format
* @return de-serialized entity set.
+ * @throws ODataDeserializerException
*/
- CommonODataEntitySet readEntitySet(InputStream input, ODataPubFormat format);
+ CommonODataEntitySet readEntitySet(InputStream input, ODataPubFormat format) throws ODataDeserializerException;
/**
* Parses a stream taking care to de-serializes the first OData entity found.
@@ -82,8 +85,9 @@ public interface CommonODataReader extends Serializable {
* @param input stream to de-serialize.
* @param format de-serialize format
* @return entity de-serialized.
+ * @throws ODataDeserializerException
*/
- CommonODataEntity readEntity(InputStream input, ODataPubFormat format);
+ CommonODataEntity readEntity(InputStream input, ODataPubFormat format) throws ODataDeserializerException;
/**
* Parses a stream taking care to de-serialize the first OData entity property found.
@@ -91,17 +95,19 @@ public interface CommonODataReader extends Serializable {
* @param input stream to de-serialize.
* @param format de-serialize as XML or JSON
* @return OData entity property de-serialized.
+ * @throws ODataDeserializerException
*/
- CommonODataProperty readProperty(InputStream input, ODataFormat format);
+ CommonODataProperty readProperty(InputStream input, ODataFormat format) throws ODataDeserializerException;
/**
* Parses a stream into an OData error.
*
* @param inputStream stream to de-serialize.
- * @param isXML 'TRUE' if the error is in XML format.
+ * @param format format
* @return OData error.
+ * @throws ODataDeserializerException
*/
- ODataError readError(InputStream inputStream, boolean isXML);
+ ODataError readError(InputStream inputStream, ODataFormat format) throws ODataDeserializerException;
/**
* Parses a stream into the object type specified by the given reference.
@@ -111,6 +117,7 @@ public interface CommonODataReader extends Serializable {
* @param format format
* @param reference reference.
* @return read object.
+ * @throws ODataDeserializerException
*/
- <T> ResWrap<T> read(InputStream src, String format, Class<T> reference);
+ <T> ResWrap<T> read(InputStream src, String format, Class<T> reference) throws ODataDeserializerException;
}
[5/9] First presentable state
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/AbstractServiceDocument.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/AbstractServiceDocument.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/AbstractServiceDocument.java
deleted file mode 100644
index 45ce766..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/AbstractServiceDocument.java
+++ /dev/null
@@ -1,49 +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.client.core.data.v4;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.client.api.data.ServiceDocumentItem;
-
-public abstract class AbstractServiceDocument
- extends org.apache.olingo.client.core.data.AbstractServiceDocument {
-
- private List<ServiceDocumentItem> functionImports = new ArrayList<ServiceDocumentItem>();
-
- private List<ServiceDocumentItem> singletons = new ArrayList<ServiceDocumentItem>();
-
- private List<ServiceDocumentItem> relatedServiceDocuments = new ArrayList<ServiceDocumentItem>();
-
- @Override
- public List<ServiceDocumentItem> getFunctionImports() {
- return functionImports;
- }
-
- @Override
- public List<ServiceDocumentItem> getSingletons() {
- return singletons;
- }
-
- @Override
- public List<ServiceDocumentItem> getRelatedServiceDocuments() {
- return relatedServiceDocuments;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/JSONServiceDocumentImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/JSONServiceDocumentImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/JSONServiceDocumentImpl.java
deleted file mode 100644
index f3dfd91..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/JSONServiceDocumentImpl.java
+++ /dev/null
@@ -1,28 +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.client.core.data.v4;
-
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-
-@JsonDeserialize(using = JSONServiceDocumentDeserializer.class)
-public class JSONServiceDocumentImpl extends AbstractServiceDocument implements ServiceDocument {
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/XMLServiceDocumentImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/XMLServiceDocumentImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/XMLServiceDocumentImpl.java
deleted file mode 100644
index b3c64b6..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v4/XMLServiceDocumentImpl.java
+++ /dev/null
@@ -1,28 +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.client.core.data.v4;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
-
-@JsonDeserialize(using = XMLServiceDocumentDeserializer.class)
-public class XMLServiceDocumentImpl extends AbstractServiceDocument implements ServiceDocument {
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java
index 14c49a8..9932c71 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.op;
import java.io.StringWriter;
import java.net.URI;
import java.util.Iterator;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.data.ServiceDocument;
@@ -65,23 +66,23 @@ 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.geo.Geospatial;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.commons.core.data.CollectionValueImpl;
import org.apache.olingo.commons.core.data.ComplexValueImpl;
+import org.apache.olingo.commons.core.data.EntityImpl;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.GeospatialValueImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.NullValueImpl;
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
+import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-import org.apache.olingo.commons.core.op.ResourceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractODataBinder implements CommonODataBinder {
- private static final long serialVersionUID = 454285889193689536L;
-
/**
* Logger.
*/
@@ -99,15 +100,15 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
for (ServiceDocumentItem entitySet : resource.getEntitySets()) {
serviceDocument.getEntitySets().
- put(entitySet.getName(), URIUtils.getURI(resource.getBaseURI(), entitySet.getUrl()));
+ put(entitySet.getName(), URIUtils.getURI(resource.getBaseURI(), entitySet.getUrl()));
}
return serviceDocument;
}
@Override
- public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet, final Class<? extends EntitySet> reference) {
- final EntitySet entitySet = ResourceFactory.newEntitySet(reference);
+ public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet) {
+ final EntitySet entitySet = new EntitySetImpl();
entitySet.setCount(odataEntitySet.getCount());
@@ -117,13 +118,13 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
}
for (CommonODataEntity entity : odataEntitySet.getEntities()) {
- entitySet.getEntities().add(getEntity(entity, ResourceFactory.entityClassForEntitySet(reference)));
+ entitySet.getEntities().add(getEntity(entity));
}
return entitySet;
}
- protected void links(final ODataLinked odataLinked, final Linked linked, final Class<? extends Entity> reference) {
+ protected void links(final ODataLinked odataLinked, final Linked linked) {
// -------------------------------------------------------------
// Append navigation links (handling inline entity / entity set as well)
// -------------------------------------------------------------
@@ -131,8 +132,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
for (ODataLink link : odataLinked.getNavigationLinks()) {
// append link
LOG.debug("Append navigation link\n{}", link);
- linked.getNavigationLinks().add(getLink(link,
- ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM));
+ linked.getNavigationLinks().add(getLink(link));
}
// -------------------------------------------------------------
@@ -141,15 +141,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
// -------------------------------------------------------------
for (ODataLink link : odataLinked.getAssociationLinks()) {
LOG.debug("Append association link\n{}", link);
- linked.getAssociationLinks().add(getLink(link,
- ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM));
+ linked.getAssociationLinks().add(getLink(link));
}
// -------------------------------------------------------------
}
@Override
- public Entity getEntity(final CommonODataEntity odataEntity, final Class<? extends Entity> reference) {
- final Entity entity = ResourceFactory.newEntity(reference);
+ public Entity getEntity(final CommonODataEntity odataEntity) {
+ final Entity entity = new EntityImpl();
entity.setType(odataEntity.getTypeName() == null ? null : odataEntity.getTypeName().toString());
@@ -174,15 +173,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
}
// -------------------------------------------------------------
- links(odataEntity, entity, reference);
+ links(odataEntity, entity);
// -------------------------------------------------------------
// Append edit-media links
// -------------------------------------------------------------
for (ODataLink link : odataEntity.getMediaEditLinks()) {
LOG.debug("Append edit-media link\n{}", link);
- entity.getMediaEditLinks().add(getLink(link,
- ResourceFactory.formatForEntityClass(reference) == ODataPubFormat.ATOM));
+ entity.getMediaEditLinks().add(getLink(link));
}
// -------------------------------------------------------------
@@ -193,14 +191,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
}
for (CommonODataProperty property : odataEntity.getProperties()) {
- entity.getProperties().add(getProperty(property, reference));
+ entity.getProperties().add(getProperty(property));
}
return entity;
}
@Override
- public Link getLink(final ODataLink link, boolean isXML) {
+ public Link getLink(final ODataLink link) {
final Link linkResource = new LinkImpl();
linkResource.setRel(link.getRel());
linkResource.setTitle(link.getName());
@@ -213,40 +211,40 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
final CommonODataEntity inlineEntity = ((ODataInlineEntity) link).getEntity();
LOG.debug("Append in-line entity\n{}", inlineEntity);
- linkResource.setInlineEntity(getEntity(inlineEntity, ResourceFactory.entityClassForFormat(isXML)));
+ linkResource.setInlineEntity(getEntity(inlineEntity));
} else if (link instanceof ODataInlineEntitySet) {
// append inline entity set
final CommonODataEntitySet InlineEntitySet = ((ODataInlineEntitySet) link).getEntitySet();
LOG.debug("Append in-line entity set\n{}", InlineEntitySet);
- linkResource.setInlineEntitySet(getEntitySet(InlineEntitySet, ResourceFactory.entitySetClassForFormat(isXML)));
+ linkResource.setInlineEntitySet(getEntitySet(InlineEntitySet));
}
return linkResource;
}
- protected Value getValue(final ODataValue value, final Class<? extends Entity> reference) {
+ protected Value getValue(final ODataValue value) {
Value valueResource = null;
if (value == null) {
valueResource = new NullValueImpl();
} else if (value.isPrimitive()) {
valueResource = value.asPrimitive().getTypeKind().isGeospatial()
- ? new GeospatialValueImpl((Geospatial) value.asPrimitive().toValue())
- : new PrimitiveValueImpl(value.asPrimitive().toString());
+ ? new GeospatialValueImpl((Geospatial) value.asPrimitive().toValue())
+ : new PrimitiveValueImpl(value.asPrimitive().toString());
} else if (value.isComplex()) {
final ODataComplexValue<? extends CommonODataProperty> _value = value.asComplex();
valueResource = new ComplexValueImpl();
for (final Iterator<? extends CommonODataProperty> itor = _value.iterator(); itor.hasNext();) {
- valueResource.asComplex().get().add(getProperty(itor.next(), reference));
+ valueResource.asComplex().get().add(getProperty(itor.next()));
}
} else if (value.isCollection()) {
final ODataCollectionValue<? extends ODataValue> _value = value.asCollection();
valueResource = new CollectionValueImpl();
for (final Iterator<? extends ODataValue> itor = _value.iterator(); itor.hasNext();) {
- valueResource.asCollection().get().add(getValue(itor.next(), reference));
+ valueResource.asCollection().get().add(getValue(itor.next()));
}
}
@@ -259,19 +257,21 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
public CommonODataEntitySet getODataEntitySet(final ResWrap<EntitySet> resource) {
if (LOG.isDebugEnabled()) {
final StringWriter writer = new StringWriter();
- client.getSerializer().entitySet(resource.getPayload(), writer);
+ try {
+ client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload());
+ } catch (final ODataSerializerException e) {}
writer.flush();
LOG.debug("EntitySet -> ODataEntitySet:\n{}", writer.toString());
}
final URI base = resource.getContextURL() == null
- ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
+ ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
final URI next = resource.getPayload().getNext();
final CommonODataEntitySet entitySet = next == null
- ? client.getObjectFactory().newEntitySet()
- : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString()));
+ ? client.getObjectFactory().newEntitySet()
+ : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString()));
if (resource.getPayload().getCount() != null) {
entitySet.setCount(resource.getPayload().getCount());
@@ -279,14 +279,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
for (Entity entityResource : resource.getPayload().getEntities()) {
add(entitySet, getODataEntity(
- new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
+ new ResWrap<Entity>(resource.getContextURL(), resource.getMetadataETag(), entityResource)));
}
return entitySet;
}
protected void odataNavigationLinks(final EdmType edmType,
- 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()) {
final Entity inlineEntity = link.getInlineEntity();
@@ -298,35 +298,35 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
final EdmNavigationProperty navProp = ((EdmStructuredType) edmType).getNavigationProperty(link.getTitle());
if (navProp != null) {
linkType = navProp.isCollection()
- ? ODataLinkType.ENTITY_SET_NAVIGATION
- : ODataLinkType.ENTITY_NAVIGATION;
+ ? ODataLinkType.ENTITY_SET_NAVIGATION
+ : ODataLinkType.ENTITY_NAVIGATION;
}
}
if (linkType == null) {
linkType = link.getType() == null
- ? ODataLinkType.ENTITY_NAVIGATION
- : ODataLinkType.fromString(client.getServiceVersion(), link.getRel(), link.getType());
+ ? ODataLinkType.ENTITY_NAVIGATION
+ : ODataLinkType.fromString(client.getServiceVersion(), link.getRel(), link.getType());
}
odataLinked.addLink(linkType == ODataLinkType.ENTITY_NAVIGATION
- ? client.getObjectFactory().
+ ? client.getObjectFactory().
newEntityNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref()))
- : client.getObjectFactory().
+ : client.getObjectFactory().
newEntitySetNavigationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
} else if (inlineEntity != null) {
odataLinked.addLink(new ODataInlineEntity(client.getServiceVersion(),
- URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_NAVIGATION, link.getTitle(),
- getODataEntity(new ResWrap<Entity>(
- inlineEntity.getBaseURI() == null ? base : inlineEntity.getBaseURI(),
- metadataETag,
- inlineEntity))));
+ URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_NAVIGATION, link.getTitle(),
+ getODataEntity(new ResWrap<Entity>(
+ inlineEntity.getBaseURI() == null ? base : inlineEntity.getBaseURI(),
+ metadataETag,
+ inlineEntity))));
} else {
odataLinked.addLink(new ODataInlineEntitySet(client.getServiceVersion(),
- URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_SET_NAVIGATION, link.getTitle(),
- getODataEntitySet(new ResWrap<EntitySet>(
- inlineEntitySet.getBaseURI() == null ? base : inlineEntitySet.getBaseURI(),
- metadataETag,
- inlineEntitySet))));
+ URIUtils.getURI(base, link.getHref()), ODataLinkType.ENTITY_SET_NAVIGATION, link.getTitle(),
+ getODataEntitySet(new ResWrap<EntitySet>(
+ inlineEntitySet.getBaseURI() == null ? base : inlineEntitySet.getBaseURI(),
+ metadataETag,
+ inlineEntitySet))));
}
}
}
@@ -357,17 +357,17 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
type = bindingTarget.getEntityType();
} else {
final EdmNavigationProperty navProp = bindingTarget.getEntityType().
- getNavigationProperty(contextURL.getNavOrPropertyPath());
+ getNavigationProperty(contextURL.getNavOrPropertyPath());
type = navProp == null
- ? bindingTarget.getEntityType()
- : navProp.getType();
+ ? bindingTarget.getEntityType()
+ : navProp.getType();
}
}
}
if (type == null) {
type = new EdmTypeInfo.Builder().setEdm(edm).
- setTypeExpression(contextURL.getEntitySetOrSingletonOrType()).build().getType();
+ setTypeExpression(contextURL.getEntitySetOrSingletonOrType()).build().getType();
}
} else {
type = edm.getEntityType(new FullQualifiedName(contextURL.getDerivedEntity()));
@@ -381,13 +381,15 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
public CommonODataEntity getODataEntity(final ResWrap<Entity> resource) {
if (LOG.isDebugEnabled()) {
final StringWriter writer = new StringWriter();
- client.getSerializer().entity(resource.getPayload(), writer);
+ try {
+ client.getSerializer(ODataFormat.JSON).write(writer, resource.getPayload());
+ } catch (final ODataSerializerException e) {}
writer.flush();
LOG.debug("EntityResource -> ODataEntity:\n{}", writer.toString());
}
final URI base = resource.getContextURL() == null
- ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
+ ? resource.getPayload().getBaseURI() : resource.getContextURL().getServiceRoot();
final EdmType edmType = findType(resource.getContextURL(), resource.getMetadataETag());
FullQualifiedName typeName = null;
@@ -400,9 +402,9 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
}
final CommonODataEntity entity = resource.getPayload().getSelfLink() == null
- ? client.getObjectFactory().newEntity(typeName)
- : client.getObjectFactory().newEntity(typeName,
- URIUtils.getURI(base, resource.getPayload().getSelfLink().getHref()));
+ ? client.getObjectFactory().newEntity(typeName)
+ : client.getObjectFactory().newEntity(typeName,
+ URIUtils.getURI(base, resource.getPayload().getSelfLink().getHref()));
if (StringUtils.isNotBlank(resource.getPayload().getETag())) {
entity.setETag(resource.getPayload().getETag());
@@ -414,14 +416,14 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
for (Link link : resource.getPayload().getAssociationLinks()) {
entity.addLink(client.getObjectFactory().
- newAssociationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
+ newAssociationLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
}
odataNavigationLinks(edmType, resource.getPayload(), entity, resource.getMetadataETag(), base);
for (Link link : resource.getPayload().getMediaEditLinks()) {
entity.addLink(client.getObjectFactory().
- newMediaEditLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
+ newMediaEditLink(link.getTitle(), URIUtils.getURI(base, link.getHref())));
}
for (ODataOperation operation : resource.getPayload().getOperations()) {
@@ -451,7 +453,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
}
protected EdmTypeInfo buildTypeInfo(final ContextURL contextURL, final String metadataETag,
- final String propertyName, final String propertyType) {
+ final String propertyName, final String propertyType) {
FullQualifiedName typeName = null;
final EdmType type = findType(contextURL, metadataETag);
@@ -487,23 +489,23 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
protected abstract CommonODataProperty getODataProperty(EdmType type, Property resource);
protected ODataValue getODataValue(final FullQualifiedName type,
- final Valuable valuable, final ContextURL contextURL, final String metadataETag) {
+ final Valuable valuable, final ContextURL contextURL, final String metadataETag) {
ODataValue value = null;
- if (valuable.getValue().isPrimitive()) {
+ if (valuable.getValue().isGeospatial()) {
value = client.getObjectFactory().newPrimitiveValueBuilder().
- setText(valuable.getValue().asPrimitive().get()).
- setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
- ? null
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
- } else if (valuable.getValue().isGeospatial()) {
+ setValue(valuable.getValue().asGeospatial().get()).
+ setType(type == null
+ || EdmPrimitiveTypeKind.Geography.getFullQualifiedName().equals(type)
+ || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type)
+ ? valuable.getValue().asGeospatial().get().getEdmPrimitiveTypeKind()
+ : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
+ } else if (valuable.getValue().isPrimitive()) {
value = client.getObjectFactory().newPrimitiveValueBuilder().
- setValue(valuable.getValue().asGeospatial().get()).
- setType(type == null
- || EdmPrimitiveTypeKind.Geography.getFullQualifiedName().equals(type)
- || EdmPrimitiveTypeKind.Geometry.getFullQualifiedName().equals(type)
- ? valuable.getValue().asGeospatial().get().getEdmPrimitiveTypeKind()
- : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
+ setText(valuable.getValue().asPrimitive().get()).
+ setType(type == null || !EdmPrimitiveType.EDM_NAMESPACE.equals(type.getNamespace())
+ ? null
+ : EdmPrimitiveTypeKind.valueOfFQN(client.getServiceVersion(), type.toString())).build();
} else if (valuable.getValue().isComplex()) {
value = client.getObjectFactory().newComplexValue(type == null ? null : type.toString());
@@ -514,7 +516,7 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
for (Value _value : valuable.getValue().asCollection().get()) {
- final Property fake = new JSONPropertyImpl();
+ final Property fake = new PropertyImpl();
fake.setValue(_value);
value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java
index 18aa0cf..1b60736 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataReader.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.op;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
+
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.data.ServiceDocument;
@@ -43,14 +44,13 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.format.ODataValueFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractODataReader implements CommonODataReader {
- private static final long serialVersionUID = -1988865870981207079L;
-
/**
* Logger.
*/
@@ -64,7 +64,7 @@ public abstract class AbstractODataReader implements CommonODataReader {
@Override
public Edm readMetadata(final InputStream input) {
- return readMetadata(client.getDeserializer().toMetadata(input).getSchemaByNsOrAlias());
+ return readMetadata(client.getDeserializer(ODataFormat.XML).toMetadata(input).getSchemaByNsOrAlias());
}
@Override
@@ -73,19 +73,21 @@ public abstract class AbstractODataReader implements CommonODataReader {
}
@Override
- public ODataServiceDocument readServiceDocument(final InputStream input, final ODataFormat format) {
+ public ODataServiceDocument readServiceDocument(final InputStream input, final ODataFormat format)
+ throws ODataDeserializerException {
return client.getBinder().getODataServiceDocument(
- client.getDeserializer().toServiceDocument(input, format).getPayload());
+ client.getDeserializer(format).toServiceDocument(input).getPayload());
}
@Override
- public ODataError readError(final InputStream inputStream, final boolean isXML) {
- return client.getDeserializer().toError(inputStream, isXML);
+ public ODataError readError(final InputStream inputStream, final ODataFormat format )
+ throws ODataDeserializerException {
+ return client.getDeserializer(format).toError(inputStream);
}
@Override
- @SuppressWarnings("unchecked")
- public <T> ResWrap<T> read(final InputStream src, final String format, final Class<T> reference) {
+ public <T> ResWrap<T> read(final InputStream src, final String format, final Class<T> reference)
+ throws ODataDeserializerException {
ResWrap<T> res;
try {
@@ -96,20 +98,20 @@ public abstract class AbstractODataReader implements CommonODataReader {
reference.cast(new ODataEntitySetIterator<CommonODataEntitySet, CommonODataEntity>(
client, src, ODataPubFormat.fromString(format))));
} else if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
- final ResWrap<EntitySet> resource = client.getDeserializer().
- toEntitySet(src, ODataPubFormat.fromString(format));
+ final ResWrap<EntitySet> resource = client.getDeserializer(ODataPubFormat.fromString(format))
+ .toEntitySet(src);
res = new ResWrap<T>(
resource.getContextURL(),
resource.getMetadataETag(),
reference.cast(client.getBinder().getODataEntitySet(resource)));
} else if (CommonODataEntity.class.isAssignableFrom(reference)) {
- final ResWrap<Entity> container = client.getDeserializer().toEntity(src, ODataPubFormat.fromString(format));
+ final ResWrap<Entity> container = client.getDeserializer(ODataPubFormat.fromString(format)).toEntity(src);
res = new ResWrap<T>(
container.getContextURL(),
container.getMetadataETag(),
reference.cast(client.getBinder().getODataEntity(container)));
} else if (CommonODataProperty.class.isAssignableFrom(reference)) {
- final ResWrap<Property> container = client.getDeserializer().toProperty(src, ODataFormat.fromString(format));
+ final ResWrap<Property> container = client.getDeserializer(ODataFormat.fromString(format)).toProperty(src);
res = new ResWrap<T>(
container.getContextURL(),
container.getMetadataETag(),
@@ -130,7 +132,7 @@ public abstract class AbstractODataReader implements CommonODataReader {
reference.cast(readMetadata(src)));
} else if (ODataServiceDocument.class.isAssignableFrom(reference)) {
final ResWrap<ServiceDocument> resource =
- client.getDeserializer().toServiceDocument(src, ODataFormat.fromString(format));
+ client.getDeserializer(ODataFormat.fromString(format)).toServiceDocument(src);
res = new ResWrap<T>(
resource.getContextURL(),
resource.getMetadataETag(),
@@ -139,7 +141,7 @@ public abstract class AbstractODataReader implements CommonODataReader {
res = new ResWrap<T>(
(URI) null,
null,
- reference.cast(readError(src, !format.toString().contains("json"))));
+ reference.cast(readError(src, ODataFormat.fromString(format))));
} else {
throw new IllegalArgumentException("Invalid reference type " + reference);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java
index a1c7e5e..71fe85d 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/ODataWriterImpl.java
@@ -18,38 +18,46 @@
*/
package org.apache.olingo.client.core.op;
-import org.apache.olingo.commons.core.op.ResourceFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Collections;
+
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.client.api.op.ODataWriter;
+import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.client.api.op.ODataWriter;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
public class ODataWriterImpl implements ODataWriter {
- private static final long serialVersionUID = 3265794768412314485L;
-
- protected final CommonODataClient client;
+ protected final CommonODataClient<?> client;
- public ODataWriterImpl(final CommonODataClient client) {
+ public ODataWriterImpl(final CommonODataClient<?> client) {
this.client = client;
}
@Override
- public InputStream writeEntities(final Collection<CommonODataEntity> entities, final ODataPubFormat format) {
- final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ public InputStream writeEntities(final Collection<CommonODataEntity> entities, final ODataPubFormat format)
+ throws ODataSerializerException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ OutputStreamWriter writer;
+ try {
+ writer = new OutputStreamWriter(output, Constants.UTF8);
+ } catch (final UnsupportedEncodingException e) {
+ writer = null;
+ }
try {
for (CommonODataEntity entity : entities) {
- client.getSerializer().entity(client.getBinder().getEntity(
- entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), output);
+ client.getSerializer(format).write(writer, client.getBinder().getEntity(entity));
}
return new ByteArrayInputStream(output.toByteArray());
@@ -59,16 +67,23 @@ public class ODataWriterImpl implements ODataWriter {
}
@Override
- public InputStream writeEntity(final CommonODataEntity entity, final ODataPubFormat format) {
+ public InputStream writeEntity(final CommonODataEntity entity, final ODataPubFormat format)
+ throws ODataSerializerException {
return writeEntities(Collections.<CommonODataEntity>singleton(entity), format);
}
@Override
- public InputStream writeProperty(final CommonODataProperty property, final ODataFormat format) {
+ public InputStream writeProperty(final CommonODataProperty property, final ODataFormat format)
+ throws ODataSerializerException {
final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ OutputStreamWriter writer;
+ try {
+ writer = new OutputStreamWriter(output, Constants.UTF8);
+ } catch (final UnsupportedEncodingException e) {
+ writer = null;
+ }
try {
- client.getSerializer().property(client.getBinder().getProperty(
- property, ResourceFactory.entityClassForFormat(format == ODataFormat.XML)), output);
+ client.getSerializer(format).write(writer, client.getBinder().getProperty(property));
return new ByteArrayInputStream(output.toByteArray());
} finally {
@@ -77,10 +92,16 @@ public class ODataWriterImpl implements ODataWriter {
}
@Override
- public InputStream writeLink(final ODataLink link, final ODataFormat format) {
+ public InputStream writeLink(final ODataLink link, final ODataFormat format) throws ODataSerializerException {
final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ OutputStreamWriter writer;
+ try {
+ writer = new OutputStreamWriter(output, Constants.UTF8);
+ } catch (final UnsupportedEncodingException e) {
+ writer = null;
+ }
try {
- client.getSerializer().link(client.getBinder().getLink(link, format == ODataFormat.XML), format, output);
+ client.getSerializer(format).write(writer, client.getBinder().getLink(link));
return new ByteArrayInputStream(output.toByteArray());
} finally {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java
index e59ad66..932a766 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataBinderImpl.java
@@ -35,21 +35,19 @@ 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.ODataProperty;
import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.domain.v3.ODataPropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-import org.apache.olingo.commons.core.op.ResourceFactory;
public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder {
- private static final long serialVersionUID = 8970843539708952308L;
-
public ODataBinderImpl(final ODataClientImpl client) {
super(client);
}
@Override
public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
- complex.add((ODataProperty) property);
+ complex.add(property);
}
@Override
@@ -63,10 +61,10 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
@Override
- public Property getProperty(final CommonODataProperty property, final Class<? extends Entity> reference) {
- final Property propertyResource = ResourceFactory.newProperty(reference);
+ public Property getProperty(final CommonODataProperty property) {
+ final Property propertyResource = new PropertyImpl();
propertyResource.setName(property.getName());
- propertyResource.setValue(getValue(property.getValue(), reference));
+ propertyResource.setValue(getValue(property.getValue()));
if (property.hasPrimitiveValue()) {
propertyResource.setType(property.getPrimitiveValue().getTypeName());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java
index 2c5ae59..d238a75 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java
@@ -20,27 +20,31 @@ package org.apache.olingo.client.core.op.impl.v3;
import java.io.InputStream;
+import javax.xml.stream.XMLStreamException;
+
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.edm.xml.XMLMetadata;
-import org.apache.olingo.commons.api.data.v3.LinkCollection;
-import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.client.api.op.v3.ODataDeserializer;
-import org.apache.olingo.commons.core.data.v3.JSONLinkCollectionImpl;
-import org.apache.olingo.commons.core.data.v3.XMLLinkCollectionImpl;
-import org.apache.olingo.client.core.data.v3.JSONServiceDocumentImpl;
-import org.apache.olingo.client.core.data.v4.XMLServiceDocumentImpl;
+import org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer;
+import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
import org.apache.olingo.client.core.edm.xml.v3.EdmxImpl;
import org.apache.olingo.client.core.edm.xml.v3.XMLMetadataImpl;
import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
+import org.apache.olingo.commons.api.data.v3.LinkCollection;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.AtomDeserializer;
+import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer {
- private static final long serialVersionUID = -8221085862548914611L;
+ private final Format format;
- public ODataDeserializerImpl(final ODataServiceVersion version) {
- super(version);
+ public ODataDeserializerImpl(final ODataServiceVersion version, final Format format) {
+ super(version, format);
+ this.format = format;
}
@Override
@@ -53,16 +57,20 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer implements
}
@Override
- public ResWrap<ServiceDocument> toServiceDocument(final InputStream input, final ODataFormat format) {
- return format == ODataFormat.XML
- ? this.<ServiceDocument, XMLServiceDocumentImpl>xml(input, XMLServiceDocumentImpl.class)
- : this.<ServiceDocument, JSONServiceDocumentImpl>json(input, JSONServiceDocumentImpl.class);
+ public ResWrap<ServiceDocument> toServiceDocument(final InputStream input) throws ODataDeserializerException {
+ return format == ODataFormat.XML ?
+ new XMLServiceDocumentDeserializer(version, false).toServiceDocument(input) :
+ new JSONServiceDocumentDeserializer(version, false).toServiceDocument(input);
}
@Override
- public ResWrap<LinkCollection> toLinkCollection(final InputStream input, final ODataFormat format) {
- return format == ODataFormat.XML
- ? this.<LinkCollection, XMLLinkCollectionImpl>atom(input, XMLLinkCollectionImpl.class)
- : this.<LinkCollection, JSONLinkCollectionImpl>json(input, JSONLinkCollectionImpl.class);
+ public ResWrap<LinkCollection> toLinkCollection(final InputStream input) throws ODataDeserializerException {
+ try {
+ return format == ODataFormat.XML ?
+ new AtomDeserializer(version).linkCollection(input) :
+ null; //json(input, LinkCollection.class);
+ } catch (final XMLStreamException e) {
+ throw new ODataDeserializerException(e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java
index c64d5c8..16a897d 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataReaderImpl.java
@@ -31,42 +31,46 @@ 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.ODataProperty;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
public class ODataReaderImpl extends AbstractODataReader implements ODataReader {
- private static final long serialVersionUID = -2481293269536406956L;
-
public ODataReaderImpl(final ODataClient client) {
super(client);
}
@Override
- public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
- return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer().toEntitySet(input, format));
+ public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format)
+ throws ODataDeserializerException {
+ return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input));
}
@Override
- public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
- return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer().toEntity(input, format));
+ public ODataEntity readEntity(final InputStream input, final ODataPubFormat format)
+ throws ODataDeserializerException {
+ return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer(format).toEntity(input));
}
@Override
- public ODataProperty readProperty(final InputStream input, final ODataFormat format) {
- return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer().toProperty(input, format));
+ public ODataProperty readProperty(final InputStream input, final ODataFormat format)
+ throws ODataDeserializerException {
+ return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer(format).toProperty(input));
}
@Override
- public ODataLinkCollection readLinks(final InputStream input, final ODataFormat format) {
+ public ODataLinkCollection readLinks(final InputStream input, final ODataFormat format)
+ throws ODataDeserializerException {
return ((ODataClient) client).getBinder().getLinkCollection(
- ((ODataClient) client).getDeserializer().toLinkCollection(input, format).getPayload());
+ ((ODataClient) client).getDeserializer(format).toLinkCollection(input).getPayload());
}
@Override
@SuppressWarnings("unchecked")
- public <T> ResWrap<T> read(final InputStream src, final String format, final Class<T> reference) {
+ public <T> ResWrap<T> read(final InputStream src, final String format, final Class<T> reference)
+ throws ODataDeserializerException {
if (ODataLinkCollection.class.isAssignableFrom(reference)) {
final ResWrap<LinkCollection> container =
- ((ODataClient) client).getDeserializer().toLinkCollection(src, ODataFormat.fromString(format));
+ ((ODataClient) client).getDeserializer(ODataFormat.fromString(format)).toLinkCollection(src);
return new ResWrap<T>(
container.getContextURL(),
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataSerializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataSerializerImpl.java
deleted file mode 100644
index 40b5b06..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataSerializerImpl.java
+++ /dev/null
@@ -1,32 +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.client.core.op.impl.v3;
-
-import org.apache.olingo.commons.core.op.AbstractODataSerializer;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-public class ODataSerializerImpl extends AbstractODataSerializer {
-
- private static final long serialVersionUID = -8861908250297989806L;
-
- public ODataSerializerImpl(final ODataServiceVersion version) {
- super(version);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
index a23d2e8..0d3631a 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java
@@ -19,6 +19,7 @@
package org.apache.olingo.client.core.op.impl.v4;
import java.net.URI;
+
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.data.ServiceDocumentItem;
import org.apache.olingo.client.api.op.v4.ODataBinder;
@@ -69,24 +70,22 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.core.data.AnnotationImpl;
import org.apache.olingo.commons.core.data.EnumValueImpl;
import org.apache.olingo.commons.core.data.LinkedComplexValueImpl;
+import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.domain.v4.ODataAnnotationImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeletedEntityImpl;
import org.apache.olingo.commons.core.domain.v4.ODataDeltaLinkImpl;
import org.apache.olingo.commons.core.domain.v4.ODataPropertyImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-import org.apache.olingo.commons.core.op.ResourceFactory;
public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder {
- private static final long serialVersionUID = -6371110655960799393L;
-
public ODataBinderImpl(final ODataClient client) {
super(client);
}
@Override
public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
- complex.add((ODataProperty) property);
+ complex.add(property);
}
@Override
@@ -122,10 +121,9 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
return serviceDocument;
}
- private void updateValuable(final Valuable propertyResource, final ODataValuable odataValuable,
- final Class<? extends Entity> reference) {
+ private void updateValuable(final Valuable propertyResource, final ODataValuable odataValuable) {
- propertyResource.setValue(getValue(odataValuable.getValue(), reference));
+ propertyResource.setValue(getValue(odataValuable.getValue()));
if (odataValuable.hasPrimitiveValue()) {
propertyResource.setType(odataValuable.getPrimitiveValue().getTypeName());
@@ -138,62 +136,61 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
}
}
- private void annotations(final ODataAnnotatable odataAnnotatable, final Annotatable annotatable,
- final Class<? extends Entity> reference) {
+ private void annotations(final ODataAnnotatable odataAnnotatable, final Annotatable annotatable) {
for (ODataAnnotation odataAnnotation : odataAnnotatable.getAnnotations()) {
final Annotation annotation = new AnnotationImpl();
annotation.setTerm(odataAnnotation.getTerm());
annotation.setType(odataAnnotation.getValue().getTypeName());
- updateValuable(annotation, odataAnnotation, reference);
+ updateValuable(annotation, odataAnnotation);
annotatable.getAnnotations().add(annotation);
}
}
@Override
- public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet, final Class<? extends EntitySet> reference) {
- final EntitySet entitySet = super.getEntitySet(odataEntitySet, reference);
+ public EntitySet getEntitySet(final CommonODataEntitySet odataEntitySet) {
+ final EntitySet entitySet = super.getEntitySet(odataEntitySet);
entitySet.setDeltaLink(((ODataEntitySet) odataEntitySet).getDeltaLink());
- annotations((ODataEntitySet) odataEntitySet, entitySet, ResourceFactory.entityClassForEntitySet(reference));
+ annotations((ODataEntitySet) odataEntitySet, entitySet);
return entitySet;
}
@Override
- protected void links(final ODataLinked odataLinked, final Linked linked, Class<? extends Entity> reference) {
- super.links(odataLinked, linked, reference);
+ protected void links(final ODataLinked odataLinked, final Linked linked) {
+ super.links(odataLinked, linked);
for (Link link : linked.getNavigationLinks()) {
final org.apache.olingo.commons.api.domain.ODataLink odataLink = odataLinked.getNavigationLink(link.getTitle());
if (!(odataLink instanceof ODataInlineEntity) && !(odataLink instanceof ODataInlineEntitySet)) {
- annotations((ODataLink) odataLink, link, reference);
+ annotations((ODataLink) odataLink, link);
}
}
}
@Override
- public Entity getEntity(final CommonODataEntity odataEntity, final Class<? extends Entity> reference) {
- final Entity entity = super.getEntity(odataEntity, reference);
+ public Entity getEntity(final CommonODataEntity odataEntity) {
+ final Entity entity = super.getEntity(odataEntity);
entity.setId(((ODataEntity) odataEntity).getId());
- annotations((ODataEntity) odataEntity, entity, reference);
+ annotations((ODataEntity) odataEntity, entity);
return entity;
}
@Override
- public Property getProperty(final CommonODataProperty property, final Class<? extends Entity> reference) {
+ public Property getProperty(final CommonODataProperty property) {
final ODataProperty _property = (ODataProperty) property;
- final Property propertyResource = ResourceFactory.newProperty(reference);
+ final Property propertyResource = new PropertyImpl();
propertyResource.setName(_property.getName());
- updateValuable(propertyResource, _property, reference);
- annotations(_property, propertyResource, reference);
+ updateValuable(propertyResource, _property);
+ annotations(_property, propertyResource);
return propertyResource;
}
@Override
- protected Value getValue(final ODataValue value, final Class<? extends Entity> reference) {
+ protected Value getValue(final ODataValue value) {
Value valueResource;
if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue
&& ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isEnum()) {
@@ -201,7 +198,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
valueResource = new EnumValueImpl(
((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asEnum().getValue());
} else {
- valueResource = super.getValue(value, reference);
+ valueResource = super.getValue(value);
if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue
&& ((org.apache.olingo.commons.api.domain.v4.ODataValue) value).isLinkedComplex()) {
@@ -211,8 +208,8 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
final ODataLinkedComplexValue linked =
((org.apache.olingo.commons.api.domain.v4.ODataValue) value).asLinkedComplex();
- annotations(linked, lcValueResource, reference);
- links(linked, lcValueResource, reference);
+ annotations(linked, lcValueResource);
+ links(linked, lcValueResource);
valueResource = lcValueResource;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java
index 0e0f72c..445db39 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java
@@ -20,28 +20,33 @@ package org.apache.olingo.client.core.op.impl.v4;
import java.io.InputStream;
+import javax.xml.stream.XMLStreamException;
+
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata;
-import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.client.api.op.v4.ODataDeserializer;
-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.JSONServiceDocumentDeserializer;
+import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
import org.apache.olingo.client.core.edm.xml.v4.EdmxImpl;
import org.apache.olingo.client.core.edm.xml.v4.XMLMetadataImpl;
import org.apache.olingo.commons.api.data.Delta;
import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.data.v4.AtomDeltaImpl;
-import org.apache.olingo.commons.core.data.v4.JSONDeltaImpl;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.AtomDeserializer;
+import org.apache.olingo.commons.core.data.JSONDeltaDeserializer;
+import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer {
- private static final long serialVersionUID = 8593081342440470415L;
+ private final Format format;
- public ODataDeserializerImpl(final ODataServiceVersion version) {
- super(version);
+ public ODataDeserializerImpl(final ODataServiceVersion version, final Format format) {
+ super(version, format);
+ this.format = format;
}
@Override
@@ -54,18 +59,20 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer implements
}
@Override
- public ResWrap<ServiceDocument> toServiceDocument(final InputStream input, final ODataFormat format) {
- return format == ODataFormat.XML
- ? this.<ServiceDocument, XMLServiceDocumentImpl>xml(input, XMLServiceDocumentImpl.class)
- : this.<ServiceDocument, JSONServiceDocumentImpl>json(input, JSONServiceDocumentImpl.class);
-
+ public ResWrap<ServiceDocument> toServiceDocument(final InputStream input) throws ODataDeserializerException {
+ return format == ODataFormat.XML ?
+ new XMLServiceDocumentDeserializer(version, false).toServiceDocument(input) :
+ new JSONServiceDocumentDeserializer(version, false).toServiceDocument(input);
}
@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);
+ public ResWrap<Delta> toDelta(final InputStream input) throws ODataDeserializerException {
+ try {
+ return format == ODataPubFormat.ATOM ?
+ new AtomDeserializer(version).delta(input) :
+ new JSONDeltaDeserializer(version, false).toDelta(input);
+ } catch (XMLStreamException e) {
+ throw new ODataDeserializerException(e);
+ }
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java
index 71c2244..ce146e5 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataReaderImpl.java
@@ -19,6 +19,7 @@
package org.apache.olingo.client.core.op.impl.v4;
import java.io.InputStream;
+
import org.apache.olingo.client.api.op.v4.ODataReader;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.op.AbstractODataReader;
@@ -27,27 +28,29 @@ import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
public class ODataReaderImpl extends AbstractODataReader implements ODataReader {
- private static final long serialVersionUID = -2481293269536406956L;
-
public ODataReaderImpl(final ODataClient client) {
super(client);
}
@Override
- public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format) {
- return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer().toEntitySet(input, format));
+ public ODataEntitySet readEntitySet(final InputStream input, final ODataPubFormat format)
+ throws ODataDeserializerException {
+ return ((ODataClient) client).getBinder().getODataEntitySet(client.getDeserializer(format).toEntitySet(input));
}
@Override
- public ODataEntity readEntity(final InputStream input, final ODataPubFormat format) {
- return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer().toEntity(input, format));
+ public ODataEntity readEntity(final InputStream input, final ODataPubFormat format)
+ throws ODataDeserializerException {
+ return ((ODataClient) client).getBinder().getODataEntity(client.getDeserializer(format).toEntity(input));
}
@Override
- public ODataProperty readProperty(final InputStream input, final ODataFormat format) {
- return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer().toProperty(input, format));
+ public ODataProperty readProperty(final InputStream input, final ODataFormat format)
+ throws ODataDeserializerException {
+ return ((ODataClient) client).getBinder().getODataProperty(client.getDeserializer(format).toProperty(input));
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataSerializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataSerializerImpl.java
deleted file mode 100644
index f75fb3e..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataSerializerImpl.java
+++ /dev/null
@@ -1,32 +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.client.core.op.impl.v4;
-
-import org.apache.olingo.commons.core.op.AbstractODataSerializer;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-
-public class ODataSerializerImpl extends AbstractODataSerializer {
-
- private static final long serialVersionUID = 7587265188399685309L;
-
- public ODataSerializerImpl(final ODataServiceVersion version) {
- super(version);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java
index 8d696ec..2042a9a 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.client.core.v3;
-import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.client.api.v3.Configuration;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory;
@@ -27,12 +25,13 @@ import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFacto
import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.v3.RetrieveRequestFactory;
-import org.apache.olingo.commons.api.op.ODataSerializer;
-import org.apache.olingo.client.api.op.v3.ODataDeserializer;
import org.apache.olingo.client.api.op.v3.ODataBinder;
+import org.apache.olingo.client.api.op.v3.ODataDeserializer;
import org.apache.olingo.client.api.op.v3.ODataReader;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
import org.apache.olingo.client.api.uri.v3.FilterFactory;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.api.v3.Configuration;
+import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.client.core.AbstractODataClient;
import org.apache.olingo.client.core.communication.header.ODataHeadersImpl;
import org.apache.olingo.client.core.communication.request.batch.v3.BatchRequestFactoryImpl;
@@ -42,25 +41,24 @@ import org.apache.olingo.client.core.communication.request.retrieve.v3.RetrieveR
import org.apache.olingo.client.core.op.impl.v3.ODataBinderImpl;
import org.apache.olingo.client.core.op.impl.v3.ODataDeserializerImpl;
import org.apache.olingo.client.core.op.impl.v3.ODataReaderImpl;
-import org.apache.olingo.client.core.op.impl.v3.ODataSerializerImpl;
-import org.apache.olingo.client.core.uri.v3.URIBuilderImpl;
import org.apache.olingo.client.core.uri.v3.FilterFactoryImpl;
+import org.apache.olingo.client.core.uri.v3.URIBuilderImpl;
import org.apache.olingo.commons.api.domain.v3.ODataObjectFactory;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataSerializer;
+import org.apache.olingo.commons.core.data.AtomSerializer;
+import org.apache.olingo.commons.core.data.JsonSerializer;
import org.apache.olingo.commons.core.domain.v3.ODataObjectFactoryImpl;
public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
- private static final long serialVersionUID = -1655712193243609209L;
-
protected final Configuration configuration = new ConfigurationImpl();
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());
- private final ODataDeserializer deserializer = new ODataDeserializerImpl(getServiceVersion());
-
- private final ODataSerializer serializer = new ODataSerializerImpl(getServiceVersion());
-
private final ODataReader reader = new ODataReaderImpl(this);
private final ODataBinder binder = new ODataBinderImpl(this);
@@ -105,13 +103,15 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
}
@Override
- public ODataDeserializer getDeserializer() {
- return deserializer;
+ public ODataDeserializer getDeserializer(final Format format) {
+ return new ODataDeserializerImpl(getServiceVersion(), format);
}
@Override
- public ODataSerializer getSerializer() {
- return serializer;
+ public ODataSerializer getSerializer(final Format format) {
+ return format instanceof ODataPubFormat && format == ODataPubFormat.ATOM
+ || format instanceof ODataFormat && format == ODataFormat.XML ?
+ new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
}
@Override
@@ -134,7 +134,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
return retrieveReqFact;
}
- @SuppressWarnings("unchecked")
@Override
public CUDRequestFactory getCUDRequestFactory() {
return cudReqFact;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java
index 4b4efd4..9f38353 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.client.core.v4;
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.client.api.v4.Configuration;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory;
@@ -28,13 +26,14 @@ import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.v4.RetrieveRequestFactory;
import org.apache.olingo.client.api.communication.request.v4.AsyncRequestFactory;
-import org.apache.olingo.commons.api.op.ODataSerializer;
import org.apache.olingo.client.api.op.v4.ODataBinder;
import org.apache.olingo.client.api.op.v4.ODataDeserializer;
import org.apache.olingo.client.api.op.v4.ODataReader;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
import org.apache.olingo.client.api.uri.v4.FilterFactory;
import org.apache.olingo.client.api.uri.v4.SearchFactory;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.client.api.v4.Configuration;
+import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.AbstractODataClient;
import org.apache.olingo.client.core.communication.header.ODataHeadersImpl;
import org.apache.olingo.client.core.communication.request.batch.v4.BatchRequestFactoryImpl;
@@ -45,27 +44,26 @@ import org.apache.olingo.client.core.communication.request.v4.AsyncRequestFactor
import org.apache.olingo.client.core.op.impl.v4.ODataBinderImpl;
import org.apache.olingo.client.core.op.impl.v4.ODataDeserializerImpl;
import org.apache.olingo.client.core.op.impl.v4.ODataReaderImpl;
-import org.apache.olingo.client.core.op.impl.v4.ODataSerializerImpl;
-import org.apache.olingo.client.core.uri.v4.URIBuilderImpl;
import org.apache.olingo.client.core.uri.v4.FilterFactoryImpl;
+import org.apache.olingo.client.core.uri.v4.URIBuilderImpl;
import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.Format;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataSerializer;
+import org.apache.olingo.commons.core.data.AtomSerializer;
+import org.apache.olingo.commons.core.data.JsonSerializer;
import org.apache.olingo.commons.core.domain.v4.ODataObjectFactoryImpl;
public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
- private static final long serialVersionUID = -6653176125573631964L;
-
protected final Configuration configuration = new ConfigurationImpl();
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());
private final SearchFactory searchFactory = new SearchFactoryImpl();
- private final ODataDeserializer deserializer = new ODataDeserializerImpl(getServiceVersion());
-
- private final ODataSerializer serializer = new ODataSerializerImpl(getServiceVersion());
-
private final ODataReader reader = new ODataReaderImpl(this);
private final ODataBinder binder = new ODataBinderImpl(this);
@@ -116,13 +114,15 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
}
@Override
- public ODataDeserializer getDeserializer() {
- return deserializer;
+ public ODataDeserializer getDeserializer(final Format format) {
+ return new ODataDeserializerImpl(getServiceVersion(), format);
}
@Override
- public ODataSerializer getSerializer() {
- return serializer;
+ public ODataSerializer getSerializer(final Format format) {
+ return format instanceof ODataPubFormat && format == ODataPubFormat.ATOM
+ || format instanceof ODataFormat && format == ODataFormat.XML ?
+ new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
}
@Override
@@ -150,7 +150,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
return retrieveReqFact;
}
- @SuppressWarnings("unchecked")
@Override
public CUDRequestFactory getCUDRequestFactory() {
return cudReqFact;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java
index 1b047a8..2fcdb4c 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/AtomTest.java
@@ -69,10 +69,10 @@ public class AtomTest extends AbstractTest {
protected void entitySet(final String filename, final ODataPubFormat format) throws Exception {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().entitySet(getClient().getDeserializer().toEntitySet(
- getClass().getResourceAsStream("Customer." + getSuffix(format)), format).getPayload(), writer);
+ getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntitySet(
+ getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload());
- assertSimilar("Customer." + getSuffix(format), writer.toString());
+ assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
@Test
@@ -82,8 +82,8 @@ public class AtomTest extends AbstractTest {
protected void entity(final String filename, final ODataPubFormat format) throws Exception {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getDeserializer().toEntity(
- getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer);
+ getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntity(
+ getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload());
assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
@@ -102,9 +102,8 @@ public class AtomTest extends AbstractTest {
protected void property(final String filename, final ODataFormat format) throws Exception {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().property(getClient().getDeserializer().
- toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(),
- writer);
+ getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toProperty(
+ getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload());
assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java
index 46a6995..dd5057d 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntitySetTest.java
@@ -18,19 +18,20 @@
*/
package org.apache.olingo.client.core.v3;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.client.core.AbstractTest;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.core.op.ResourceFactory;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.junit.Test;
public class EntitySetTest extends AbstractTest {
@@ -40,28 +41,27 @@ public class EntitySetTest extends AbstractTest {
return v3Client;
}
- private void read(final ODataPubFormat format) throws IOException {
+ private void read(final ODataPubFormat format) throws IOException, ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format));
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
- getClient().getDeserializer().toEntitySet(input, format));
+ getClient().getDeserializer(format).toEntitySet(input));
assertNotNull(entitySet);
assertEquals(2, entitySet.getEntities().size());
assertNotNull(entitySet.getNext());
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<EntitySet>((URI) null, null,
- getClient().getBinder().getEntitySet(
- entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM))));
+ getClient().getBinder().getEntitySet(entitySet)));
assertEquals(entitySet, written);
}
@Test
- public void fromAtom() throws IOException {
+ public void fromAtom() throws Exception {
read(ODataPubFormat.ATOM);
}
@Test
- public void fromJSON() throws IOException {
+ public void fromJSON() throws Exception {
read(ODataPubFormat.JSON);
}
}
[4/9] First presentable state
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
index b73dc0d..1d4a04f 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/EntityTest.java
@@ -24,19 +24,20 @@ import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.client.core.AbstractTest;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.core.op.ResourceFactory;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.geo.Geospatial;
import org.apache.olingo.commons.api.edm.geo.GeospatialCollection;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.junit.Test;
public class EntityTest extends AbstractTest {
@@ -46,10 +47,10 @@ public class EntityTest extends AbstractTest {
return v3Client;
}
- private void readAndWrite(final ODataPubFormat format) {
+ private void readAndWrite(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("Customer_-10." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getTypeName().toString());
@@ -68,25 +69,24 @@ public class EntityTest extends AbstractTest {
assertTrue(check);
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().
- getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void fromAtom() {
+ public void fromAtom() throws Exception {
readAndWrite(ODataPubFormat.ATOM);
}
@Test
- public void fromJSON() {
+ public void fromJSON() throws Exception {
readAndWrite(ODataPubFormat.JSON_FULL_METADATA);
}
- private void readGeospatial(final ODataPubFormat format) {
+ private void readGeospatial(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-8." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
boolean found = false;
@@ -100,78 +100,75 @@ public class EntityTest extends AbstractTest {
assertTrue(found);
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().
- getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void withGeospatialFromAtom() {
+ public void withGeospatialFromAtom() throws Exception {
readGeospatial(ODataPubFormat.ATOM);
}
@Test
- public void withGeospatialFromJSON() {
+ public void withGeospatialFromJSON() throws Exception {
// this needs to be full, otherwise there is no mean to recognize geospatial types
readGeospatial(ODataPubFormat.JSON_FULL_METADATA);
}
- private void withActions(final ODataPubFormat format) {
+ private void withActions(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("ComputerDetail_-10." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertEquals(1, entity.getOperations().size());
assertEquals("ResetComputerDetailsSpecifications", entity.getOperations().get(0).getTitle());
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().
- getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
entity.getOperations().clear();
assertEquals(entity, written);
}
@Test
- public void withActionsFromAtom() {
+ public void withActionsFromAtom() throws Exception {
withActions(ODataPubFormat.ATOM);
}
@Test
- public void withActionsFromJSON() {
+ public void withActionsFromJSON() throws Exception {
// this needs to be full, otherwise actions will not be provided
withActions(ODataPubFormat.JSON_FULL_METADATA);
}
- private void mediaEntity(final ODataPubFormat format) {
+ private void mediaEntity(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("Car_16." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertTrue(entity.isMediaEntity());
assertNotNull(entity.getMediaContentSource());
assertNotNull(entity.getMediaContentType());
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().
- getBinder().getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void mediaEntityFromAtom() {
+ public void mediaEntityFromAtom() throws Exception {
mediaEntity(ODataPubFormat.ATOM);
}
@Test
- public void mediaEntityFromJSON() {
+ public void mediaEntityFromJSON() throws Exception {
mediaEntity(ODataPubFormat.JSON_FULL_METADATA);
}
- private void issue128(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ private void issue128(final ODataPubFormat format) throws EdmPrimitiveTypeException, ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("AllGeoTypesSet_-5." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
final ODataProperty geogCollection = entity.getProperty("GeogCollection");
@@ -186,12 +183,12 @@ public class EntityTest extends AbstractTest {
}
@Test
- public void issue128FromAtom() throws EdmPrimitiveTypeException {
+ public void issue128FromAtom() throws Exception {
issue128(ODataPubFormat.ATOM);
}
@Test
- public void issue128FromJSON() throws EdmPrimitiveTypeException {
+ public void issue128FromJSON() throws Exception {
issue128(ODataPubFormat.JSON_FULL_METADATA);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ErrorTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ErrorTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ErrorTest.java
index b2cf8e3..1b340e9 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ErrorTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ErrorTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.client.core.AbstractTest;
import org.junit.Test;
@@ -34,40 +35,40 @@ public class ErrorTest extends AbstractTest {
return v3Client;
}
- private ODataError error(final String name, final ODataPubFormat format) {
- final ODataError error = getClient().getDeserializer().toError(
- getClass().getResourceAsStream(name + "." + getSuffix(format)), format == ODataPubFormat.ATOM);
+ private ODataError error(final String name, final ODataPubFormat format) throws ODataDeserializerException {
+ final ODataError error = getClient().getDeserializer(format).toError(
+ getClass().getResourceAsStream(name + "." + getSuffix(format)));
assertNotNull(error);
return error;
}
- private void simple(final ODataPubFormat format) {
+ private void simple(final ODataPubFormat format) throws ODataDeserializerException {
final ODataError error = error("error", format);
assertEquals("The URL representing the root of the service only supports GET requests.", error.getMessage());
}
@Test
- public void jsonSimple() {
+ public void jsonSimple() throws Exception {
simple(ODataPubFormat.JSON);
}
@Test
- public void atomSimple() {
+ public void atomSimple() throws Exception {
simple(ODataPubFormat.ATOM);
}
- private void stacktrace(final ODataPubFormat format) {
+ private void stacktrace(final ODataPubFormat format) throws ODataDeserializerException {
final ODataError error = error("stacktrace", format);
assertEquals("Unsupported media type requested.", error.getMessage());
}
@Test
- public void jsonStacktrace() {
+ public void jsonStacktrace() throws Exception {
stacktrace(ODataPubFormat.JSON);
}
@Test
- public void atomStacktrace() {
+ public void atomStacktrace() throws Exception {
stacktrace(ODataPubFormat.ATOM);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java
index ecd261c..ee83862 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java
@@ -53,6 +53,7 @@ import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.junit.Test;
@@ -175,7 +176,7 @@ public class MetadataTest extends AbstractTest {
@Test
public void parseWithXMLMetadata() {
- final XMLMetadata metadata = getClient().getDeserializer().
+ final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML).
toMetadata(getClass().getResourceAsStream("metadata.xml"));
assertNotNull(metadata);
@@ -212,7 +213,7 @@ public class MetadataTest extends AbstractTest {
@Test
public void multipleSchemas() {
- final XMLMetadata metadata = getClient().getDeserializer().
+ final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML).
toMetadata(getClass().getResourceAsStream("northwind-metadata.xml"));
assertNotNull(metadata);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PropertyTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PropertyTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PropertyTest.java
index 317d1ac..b561f28 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PropertyTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/PropertyTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
+
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.client.core.AbstractTest;
@@ -36,7 +37,8 @@ import org.apache.olingo.commons.api.domain.v3.ODataProperty;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.format.ODataFormat;
-
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.junit.Test;
public class PropertyTest extends AbstractTest {
@@ -58,7 +60,8 @@ public class PropertyTest extends AbstractTest {
assertEquals("-10", value.toString());
}
- private void primitive(final ODataFormat format) throws IOException, EdmPrimitiveTypeException {
+ private void primitive(final ODataFormat format)
+ throws EdmPrimitiveTypeException, ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Customer_-10_CustomerId." + getSuffix(format));
final ODataProperty property = getClient().getReader().readProperty(input, format);
assertNotNull(property);
@@ -83,16 +86,16 @@ public class PropertyTest extends AbstractTest {
}
@Test
- public void xmlPrimitive() throws IOException, EdmPrimitiveTypeException {
+ public void xmlPrimitive() throws Exception {
primitive(ODataFormat.XML);
}
@Test
- public void jsonPrimitive() throws IOException, EdmPrimitiveTypeException {
+ public void jsonPrimitive() throws Exception {
primitive(ODataFormat.JSON);
}
- private void complex(final ODataFormat format) throws IOException {
+ private void complex(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Customer_-10_PrimaryContactInfo." + getSuffix(format));
final ODataProperty property = getClient().getReader().readProperty(input, format);
assertNotNull(property);
@@ -119,16 +122,16 @@ public class PropertyTest extends AbstractTest {
}
@Test
- public void xmlComplex() throws IOException {
+ public void xmlComplex() throws Exception {
complex(ODataFormat.XML);
}
@Test
- public void jsonComplex() throws IOException {
+ public void jsonComplex() throws Exception {
complex(ODataFormat.JSON);
}
- private void collection(final ODataFormat format) throws IOException {
+ private void collection(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Customer_-10_BackupContactInfo." + getSuffix(format));
final ODataProperty property = getClient().getReader().readProperty(input, format);
assertNotNull(property);
@@ -155,12 +158,12 @@ public class PropertyTest extends AbstractTest {
}
@Test
- public void xmlCollection() throws IOException {
+ public void xmlCollection() throws Exception {
collection(ODataFormat.XML);
}
@Test
- public void jsonCollection() throws IOException {
+ public void jsonCollection() throws Exception {
collection(ODataFormat.JSON);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ServiceDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ServiceDocumentTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ServiceDocumentTest.java
index 0929741..b14c635 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ServiceDocumentTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/ServiceDocumentTest.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.v3;
import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.client.core.AbstractTest;
import static org.junit.Assert.assertNotNull;
@@ -39,7 +40,7 @@ public class ServiceDocumentTest extends AbstractTest {
return format == ODataFormat.XML ? "xml" : "json";
}
- private void parse(final ODataFormat format) {
+ private void parse(final ODataFormat format) throws ODataDeserializerException {
final ODataServiceDocument serviceDocument = getClient().getReader().readServiceDocument(
getClass().getResourceAsStream("serviceDocument." + getFileExtension(format)), format);
assertNotNull(serviceDocument);
@@ -47,12 +48,12 @@ public class ServiceDocumentTest extends AbstractTest {
}
@Test
- public void json() {
+ public void json() throws Exception {
parse(ODataFormat.JSON);
}
@Test
- public void xml() {
+ public void xml() throws Exception {
parse(ODataFormat.XML);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java
index 5338e50..453a8ab 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntitySetTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.AbstractTest;
import org.apache.olingo.commons.api.data.EntitySet;
@@ -32,7 +33,7 @@ import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.op.ResourceFactory;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.junit.Test;
public class EntitySetTest extends AbstractTest {
@@ -42,35 +43,34 @@ public class EntitySetTest extends AbstractTest {
return v4Client;
}
- private void read(final ODataPubFormat format) throws IOException {
+ private void read(final ODataPubFormat format) throws IOException, ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("Customers." + getSuffix(format));
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
- getClient().getDeserializer().toEntitySet(input, format));
+ getClient().getDeserializer(format).toEntitySet(input));
assertNotNull(entitySet);
assertEquals(2, entitySet.getEntities().size());
assertNull(entitySet.getNext());
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<EntitySet>((URI) null, null,
- getClient().getBinder().getEntitySet(
- entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM))));
+ getClient().getBinder().getEntitySet(entitySet)));
assertEquals(entitySet, written);
}
@Test
- public void fromAtom() throws IOException {
+ public void fromAtom() throws Exception {
read(ODataPubFormat.ATOM);
}
@Test
- public void fromJSON() throws IOException {
+ public void fromJSON() throws Exception {
read(ODataPubFormat.JSON);
}
- private void ref(final ODataPubFormat format) {
+ private void ref(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(format));
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
- getClient().getDeserializer().toEntitySet(input, format));
+ getClient().getDeserializer(format).toEntitySet(input));
assertNotNull(entitySet);
for (ODataEntity entity : entitySet.getEntities()) {
@@ -79,18 +79,17 @@ public class EntitySetTest extends AbstractTest {
entitySet.setCount(entitySet.getEntities().size());
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(new ResWrap<EntitySet>((URI) null, null,
- getClient().getBinder().getEntitySet(
- entitySet, ResourceFactory.entitySetClassForFormat(format == ODataPubFormat.ATOM))));
+ getClient().getBinder().getEntitySet(entitySet)));
assertEquals(entitySet, written);
}
@Test
- public void atomRef() {
+ public void atomRef() throws Exception {
ref(ODataPubFormat.ATOM);
}
@Test
- public void jsonRef() {
+ public void jsonRef() throws Exception {
ref(ODataPubFormat.JSON);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
index 0fc3495..38cbd8d 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/EntityTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.net.URI;
import java.util.Iterator;
+
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.AbstractTest;
@@ -43,9 +44,9 @@ import org.apache.olingo.commons.api.domain.v4.ODataValue;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
-import org.apache.olingo.commons.core.op.ResourceFactory;
import org.junit.Test;
public class EntityTest extends AbstractTest {
@@ -76,10 +77,10 @@ public class EntityTest extends AbstractTest {
};
}
- private void singleton(final ODataPubFormat format) {
+ private void singleton(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("VipCustomer." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
@@ -120,25 +121,24 @@ public class EntityTest extends AbstractTest {
// operations won't get serialized
entity.getOperations().clear();
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().
- getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomSingleton() {
+ public void atomSingleton() throws Exception {
singleton(ODataPubFormat.ATOM);
}
@Test
- public void jsonSingleton() {
+ public void jsonSingleton() throws Exception {
singleton(ODataPubFormat.JSON_FULL_METADATA);
}
- private void withEnums(final ODataPubFormat format) {
+ private void withEnums(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("Products_5." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
final ODataProperty skinColor = entity.getProperty("SkinColor");
@@ -156,26 +156,25 @@ public class EntityTest extends AbstractTest {
// operations won't get serialized
entity.getOperations().clear();
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().
- getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomWithEnums() {
+ public void atomWithEnums() throws Exception {
withEnums(ODataPubFormat.ATOM);
}
@Test
- public void jsonWithEnums() {
+ public void jsonWithEnums() throws Exception {
withEnums(ODataPubFormat.JSON_FULL_METADATA);
}
- private void withInlineEntitySet(final ODataPubFormat format) {
+ private void withInlineEntitySet(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream(
"Accounts_101_expand_MyPaymentInstruments." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
final ODataLink instruments = entity.getNavigationLink("MyPaymentInstruments");
@@ -191,26 +190,25 @@ public class EntityTest extends AbstractTest {
// operations won't get serialized
entity.getOperations().clear();
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().
- getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomWithInlineEntitySet() {
+ public void atomWithInlineEntitySet() throws Exception {
withInlineEntitySet(ODataPubFormat.ATOM);
}
@Test
- public void jsonWithInlineEntitySet() {
+ public void jsonWithInlineEntitySet() throws Exception {
withInlineEntitySet(ODataPubFormat.JSON_FULL_METADATA);
}
- private void mediaEntity(final ODataPubFormat format) {
+ private void mediaEntity(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream(
"Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertTrue(entity.isMediaEntity());
@@ -218,25 +216,24 @@ public class EntityTest extends AbstractTest {
assertEquals("\"8zOOKKvgOtptr4gt8IrnapX3jds=\"", entity.getMediaETag());
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().
- getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomMediaEntity() {
+ public void atomMediaEntity() throws Exception {
mediaEntity(ODataPubFormat.ATOM);
}
@Test
- public void jsonMediaEntity() {
+ public void jsonMediaEntity() throws Exception {
mediaEntity(ODataPubFormat.JSON_FULL_METADATA);
}
- private void withStream(final ODataPubFormat format) {
+ private void withStream(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertFalse(entity.isMediaEntity());
@@ -245,49 +242,47 @@ public class EntityTest extends AbstractTest {
assertNotNull(editMedia);
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().
- getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomWithStream() {
+ public void atomWithStream() throws Exception {
withStream(ODataPubFormat.ATOM);
}
@Test
- public void jsonWithStream() {
+ public void jsonWithStream() throws Exception {
withStream(ODataPubFormat.JSON_FULL_METADATA);
}
- private void ref(final ODataPubFormat format) {
+ private void ref(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertNotNull(entity.getId());
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().
- getEntity(entity, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomRef() {
+ public void atomRef() throws Exception {
ref(ODataPubFormat.ATOM);
}
@Test
- public void jsonRef() {
+ public void jsonRef() throws Exception {
ref(ODataPubFormat.JSON);
}
- private void complexNavigationProperties(final ODataPubFormat format) {
+ private void complexNavigationProperties(final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
final ODataLinkedComplexValue addressValue = entity.getProperty("Address").getLinkedComplexValue();
@@ -297,25 +292,24 @@ public class EntityTest extends AbstractTest {
// ETag is not serialized
entity.setETag(null);
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity,
- ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomComplexNavigationProperties() {
+ public void atomComplexNavigationProperties() throws Exception {
complexNavigationProperties(ODataPubFormat.ATOM);
}
@Test
- public void jsonComplexNavigationProperties() {
+ public void jsonComplexNavigationProperties() throws Exception {
complexNavigationProperties(ODataPubFormat.JSON);
}
- private void annotated(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ private void annotated(final ODataPubFormat format) throws EdmPrimitiveTypeException, ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("annotated." + getSuffix(format));
final ODataEntity entity = getClient().getBinder().getODataEntity(
- getClient().getDeserializer().toEntity(input, format));
+ getClient().getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertFalse(entity.getAnnotations().isEmpty());
@@ -343,24 +337,23 @@ public class EntityTest extends AbstractTest {
annotation.getValue().asLinkedComplex().get("order").getPrimitiveValue().toCastValue(Integer.class), 0);
final ODataEntity written = getClient().getBinder().getODataEntity(
- new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity,
- ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM))));
+ new ResWrap<Entity>((URI) null, null, getClient().getBinder().getEntity(entity)));
assertEquals(entity, written);
}
@Test
- public void atomAnnotated() {
+ public void atomAnnotated() throws Exception {
complexNavigationProperties(ODataPubFormat.ATOM);
}
@Test
- public void jsonAnnotated() {
+ public void jsonAnnotated() throws Exception {
complexNavigationProperties(ODataPubFormat.JSON);
}
- private void derived(final ODataClient client, final ODataPubFormat format) {
+ private void derived(final ODataClient client, final ODataPubFormat format) throws ODataDeserializerException {
final InputStream input = getClass().getResourceAsStream("Customer." + getSuffix(format));
- final ODataEntity entity = client.getBinder().getODataEntity(client.getDeserializer().toEntity(input, format));
+ final ODataEntity entity = client.getBinder().getODataEntity(client.getDeserializer(format).toEntity(input));
assertNotNull(entity);
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
@@ -369,17 +362,17 @@ public class EntityTest extends AbstractTest {
}
@Test
- public void derivedFromAtom() {
+ public void derivedFromAtom() throws Exception {
derived(getClient(), ODataPubFormat.ATOM);
}
@Test
- public void derivedFromJSON() {
+ public void derivedFromJSON() throws Exception {
derived(getEdmEnabledClient(), ODataPubFormat.JSON);
}
@Test
- public void derivedFromFullJSON() {
+ public void derivedFromFullJSON() throws Exception {
derived(getClient(), ODataPubFormat.JSON_FULL_METADATA);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java
index c89fa39..b221ade 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ErrorTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.client.core.AbstractTest;
import org.junit.Test;
@@ -34,14 +35,14 @@ public class ErrorTest extends AbstractTest {
return v4Client;
}
- private ODataError error(final String name, final ODataPubFormat format) {
- final ODataError error = getClient().getDeserializer().toError(
- getClass().getResourceAsStream(name + "." + getSuffix(format)), format == ODataPubFormat.ATOM);
+ private ODataError error(final String name, final ODataPubFormat format) throws ODataDeserializerException {
+ final ODataError error = getClient().getDeserializer(format).toError(
+ getClass().getResourceAsStream(name + "." + getSuffix(format)));
assertNotNull(error);
return error;
}
- private void simple(final ODataPubFormat format) {
+ private void simple(final ODataPubFormat format) throws ODataDeserializerException {
final ODataError error = error("error", format);
assertEquals("501", error.getCode());
assertEquals("Unsupported functionality", error.getMessage());
@@ -49,12 +50,12 @@ public class ErrorTest extends AbstractTest {
}
@Test
- public void jsonSimple() {
+ public void jsonSimple() throws Exception {
simple(ODataPubFormat.JSON);
}
@Test
- public void atomSimple() {
+ public void atomSimple() throws Exception {
simple(ODataPubFormat.ATOM);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java
index 39e7a1e..20967b9 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/JSONTest.java
@@ -92,16 +92,16 @@ public class JSONTest extends AbstractTest {
final Map.Entry<String, JsonNode> field = itor.next();
if (field.getKey().charAt(0) == '#'
- || field.getKey().endsWith(
- getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))
- || field.getKey().endsWith(
- getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))
- || field.getKey().endsWith(
- getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))
- || field.getKey().endsWith(
- getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK))
- || field.getKey().endsWith(
- getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) {
+ || field.getKey().endsWith(
+ getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_TYPE))
+ || field.getKey().endsWith(
+ getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK))
+ || field.getKey().endsWith(
+ getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_CONTENT_TYPE))
+ || field.getKey().endsWith(
+ getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK))
+ || field.getKey().endsWith(
+ getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_MEDIA_ETAG))) {
toRemove.add(field.getKey());
} else if (field.getValue().isObject()) {
@@ -120,8 +120,8 @@ public class JSONTest extends AbstractTest {
protected void assertSimilar(final String filename, final String actual) throws Exception {
final JsonNode expected = OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream(filename)).
- replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK),
- Constants.JSON_BIND_LINK_SUFFIX));
+ replace(getClient().getServiceVersion().getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK),
+ Constants.JSON_BIND_LINK_SUFFIX));
cleanup((ObjectNode) expected);
final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes()));
cleanup(actualNode);
@@ -130,8 +130,8 @@ public class JSONTest extends AbstractTest {
protected void entitySet(final String filename, final ODataPubFormat format) throws Exception {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().entitySet(getClient().getDeserializer().toEntitySet(
- getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer);
+ getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntitySet(
+ getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload());
assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
@@ -144,8 +144,8 @@ public class JSONTest extends AbstractTest {
protected void entity(final String filename, final ODataPubFormat format) throws Exception {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getDeserializer().toEntity(
- getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(), writer);
+ getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).toEntity(
+ getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload());
assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
@@ -171,9 +171,8 @@ public class JSONTest extends AbstractTest {
protected void property(final String filename, final ODataFormat format) throws Exception {
final StringWriter writer = new StringWriter();
- getClient().getSerializer().property(getClient().getDeserializer().
- toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload(),
- writer);
+ getClient().getSerializer(format).write(writer, getClient().getDeserializer(format).
+ toProperty(getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload());
assertSimilar(filename + "." + getSuffix(format), writer.toString());
}
@@ -188,13 +187,13 @@ public class JSONTest extends AbstractTest {
@Test
public void crossjoin() throws Exception {
- assertNotNull(getClient().getDeserializer().toEntitySet(
- getClass().getResourceAsStream("crossjoin.json"), ODataPubFormat.JSON_FULL_METADATA));
+ assertNotNull(getClient().getDeserializer(ODataPubFormat.JSON_FULL_METADATA).toEntitySet(
+ getClass().getResourceAsStream("crossjoin.json")));
}
protected void delta(final String filename, final ODataPubFormat format) throws Exception {
- final Delta delta = getClient().getDeserializer().toDelta(
- getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getPayload();
+ final Delta delta = getClient().getDeserializer(format).toDelta(
+ getClass().getResourceAsStream(filename + "." + getSuffix(format))).getPayload();
assertNotNull(delta);
assertNotNull(delta.getDeltaLink());
assertEquals(5, delta.getCount(), 0);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
index 8ca024a..dd69685 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java
@@ -62,6 +62,7 @@ import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.annotation.EdmUrlRef;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
@@ -137,7 +138,7 @@ public class MetadataTest extends AbstractTest {
@Test
public void demo() {
- final XMLMetadata metadata = getClient().getDeserializer().
+ final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML).
toMetadata(getClass().getResourceAsStream("demo-metadata.xml"));
assertNotNull(metadata);
@@ -178,7 +179,7 @@ public class MetadataTest extends AbstractTest {
@Test
public void multipleSchemas() {
- final XMLMetadata metadata = getClient().getDeserializer().
+ final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML).
toMetadata(getClass().getResourceAsStream("northwind-metadata.xml"));
assertNotNull(metadata);
@@ -199,7 +200,7 @@ public class MetadataTest extends AbstractTest {
*/
@Test
public void fromdoc1() {
- final XMLMetadata metadata = getClient().getDeserializer().
+ final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML).
toMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml"));
assertNotNull(metadata);
@@ -270,8 +271,8 @@ public class MetadataTest extends AbstractTest {
*/
@Test
public void fromdoc2() {
- final XMLMetadata metadata = getClient().getDeserializer().
- toMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml"));
+ final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML)
+ .toMetadata(getClass().getResourceAsStream("fromdoc2-metadata.xml"));
assertNotNull(metadata);
// Check displayName
@@ -334,7 +335,7 @@ public class MetadataTest extends AbstractTest {
*/
@Test
public void fromdoc4() {
- final XMLMetadata metadata = getClient().getDeserializer().
+ final XMLMetadata metadata = getClient().getDeserializer(ODataFormat.XML).
toMetadata(getClass().getResourceAsStream("fromdoc4-metadata.xml"));
assertNotNull(metadata);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java
index 022496c..1535355 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/PropertyTest.java
@@ -18,21 +18,22 @@
*/
package org.apache.olingo.client.core.v4;
-import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.InputStream;
import java.util.Iterator;
+
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.AbstractTest;
import org.apache.olingo.commons.api.domain.ODataCollectionValue;
import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
import org.apache.olingo.commons.api.domain.v4.ODataValue;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.format.ODataFormat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.junit.Test;
public class PropertyTest extends AbstractTest {
@@ -42,7 +43,7 @@ public class PropertyTest extends AbstractTest {
return v4Client;
}
- private void _enum(final ODataFormat format) {
+ private void _enum(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Products_5_SkinColor." + getSuffix(format));
final ODataProperty property = getClient().getReader().readProperty(input, format);
assertNotNull(property);
@@ -61,16 +62,16 @@ public class PropertyTest extends AbstractTest {
}
@Test
- public void xmlEnum() throws IOException, EdmPrimitiveTypeException {
+ public void xmlEnum() throws Exception {
_enum(ODataFormat.XML);
}
@Test
- public void jsonEnum() throws IOException, EdmPrimitiveTypeException {
+ public void jsonEnum() throws Exception {
_enum(ODataFormat.JSON);
}
- private void complex(final ODataFormat format) throws IOException {
+ private void complex(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Employees_3_HomeAddress." + getSuffix(format));
final ODataProperty property = getClient().getReader().readProperty(input, format);
assertNotNull(property);
@@ -93,16 +94,16 @@ public class PropertyTest extends AbstractTest {
}
@Test
- public void xmlComplex() throws IOException {
+ public void xmlComplex() throws Exception {
complex(ODataFormat.XML);
}
@Test
- public void jsonComplex() throws IOException {
+ public void jsonComplex() throws Exception {
complex(ODataFormat.JSON);
}
- private void collection(final ODataFormat format) throws IOException {
+ private void collection(final ODataFormat format) throws ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Products_5_CoverColors." + getSuffix(format));
final ODataProperty property = getClient().getReader().readProperty(input, format);
assertNotNull(property);
@@ -127,12 +128,12 @@ public class PropertyTest extends AbstractTest {
}
@Test
- public void xmlCollection() throws IOException {
+ public void xmlCollection() throws Exception {
collection(ODataFormat.XML);
}
@Test
- public void jsonCollection() throws IOException {
+ public void jsonCollection() throws Exception {
collection(ODataFormat.JSON);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java
index f515bdc..403fbcf 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/ServiceDocumentTest.java
@@ -23,10 +23,12 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.net.URI;
+
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.client.core.AbstractTest;
import org.apache.olingo.commons.api.data.ResWrap;
import org.junit.Test;
@@ -42,9 +44,9 @@ public class ServiceDocumentTest extends AbstractTest {
return format == ODataFormat.XML ? "xml" : "json";
}
- private ODataServiceDocument parse(final ODataFormat format) {
- ResWrap<ServiceDocument> service = getClient().getDeserializer().toServiceDocument(
- getClass().getResourceAsStream("serviceDocument." + getFileExtension(format)), format);
+ private ODataServiceDocument parse(final ODataFormat format) throws ODataDeserializerException {
+ ResWrap<ServiceDocument> service = getClient().getDeserializer(format).toServiceDocument(
+ getClass().getResourceAsStream("serviceDocument." + getFileExtension(format)));
assertEquals(URI.create("http://host/service/$metadata"), service.getContextURL().getURI());
assertEquals("W/\"MjAxMy0wNS0xM1QxNDo1NFo=\"", service.getMetadataETag());
@@ -62,12 +64,12 @@ public class ServiceDocumentTest extends AbstractTest {
}
@Test
- public void json() {
+ public void json() throws Exception {
parse(ODataFormat.JSON);
}
@Test
- public void xml() {
+ public void xml() throws Exception {
parse(ODataFormat.XML);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java
deleted file mode 100644
index a0d9a87..0000000
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/CommonODataDeserializer.java
+++ /dev/null
@@ -1,71 +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.api.op;
-
-import java.io.InputStream;
-import java.io.Serializable;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.domain.ODataError;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-
-/**
- * Interface for de-serialization.
- */
-public interface CommonODataDeserializer extends Serializable {
-
- /**
- * Gets an entity set object from the given InputStream.
- *
- * @param input stream to be de-serialized.
- * @param format Atom or JSON
- * @return {@link EntitySet} instance.
- */
- ResWrap<EntitySet> toEntitySet(InputStream input, ODataPubFormat format);
-
- /**
- * Gets an entity object from the given InputStream.
- *
- * @param input stream to be de-serialized.
- * @param format Atom or JSON
- * @return {@link Entity} instance.
- */
- ResWrap<Entity> toEntity(InputStream input, ODataPubFormat format);
-
- /**
- * Gets a property object from the given InputStream.
- *
- * @param input stream to be de-serialized.
- * @param format XML or JSON
- * @return Property instance.
- */
- ResWrap<Property> toProperty(InputStream input, ODataFormat format);
-
- /**
- * Gets the ODataError object represented by the given InputStream.
- *
- * @param input stream to be parsed and de-serialized.
- * @param isXML 'TRUE' if the error is represented by XML; 'FALSE' otherwise.
- * @return
- */
- ODataError toError(InputStream input, boolean isXML);
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializer.java
new file mode 100755
index 0000000..9b6bd5a
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializer.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.op;
+
+import java.io.InputStream;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.ODataError;
+
+/**
+ * Interface for de-serialization.
+ */
+public interface ODataDeserializer {
+
+ /**
+ * Gets an entity set object from the given InputStream.
+ *
+ * @param input stream to be de-serialized.
+ * @return {@link EntitySet} instance.
+ */
+ ResWrap<EntitySet> toEntitySet(InputStream input) throws ODataDeserializerException;
+
+ /**
+ * Gets an entity object from the given InputStream.
+ *
+ * @param input stream to be de-serialized.
+ * @return {@link Entity} instance.
+ */
+ ResWrap<Entity> toEntity(InputStream input) throws ODataDeserializerException;
+
+ /**
+ * Gets a property object from the given InputStream.
+ *
+ * @param input stream to be de-serialized.
+ * @return Property instance.
+ */
+ ResWrap<Property> toProperty(InputStream input) throws ODataDeserializerException;
+
+ /**
+ * Gets the ODataError object represented by the given InputStream.
+ *
+ * @param input stream to be parsed and de-serialized.
+ * @return
+ */
+ ODataError toError(InputStream input) throws ODataDeserializerException;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializerException.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializerException.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializerException.java
new file mode 100755
index 0000000..7852a5f
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataDeserializerException.java
@@ -0,0 +1,38 @@
+/*
+ * 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.op;
+
+import org.apache.olingo.commons.api.ODataException;
+
+public class ODataDeserializerException extends ODataException {
+
+ private static final long serialVersionUID = -3236099963180859670L;
+
+ public ODataDeserializerException(final String msg) {
+ super(msg);
+ }
+
+ public ODataDeserializerException(final Throwable cause) {
+ super(cause);
+ }
+
+ public ODataDeserializerException(final String msg, final Throwable cause) {
+ super(msg, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java
index c8a02cf..6fc95da 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializer.java
@@ -18,83 +18,16 @@
*/
package org.apache.olingo.commons.api.op;
-import java.io.OutputStream;
-import java.io.Serializable;
import java.io.Writer;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.format.ODataFormat;
+
+import org.apache.olingo.commons.api.data.ResWrap;
/**
- * Utility class for serialization.
+ * Interface for serialization.
*/
-public interface ODataSerializer extends Serializable {
-
- /**
- * Writes entity set object onto the given stream.
- *
- * @param obj object to be streamed.
- * @param out output stream.
- */
- void entitySet(EntitySet obj, OutputStream out);
-
- /**
- * Writes entity set object by the given writer.
- *
- * @param obj object to be streamed.
- * @param writer writer.
- */
- void entitySet(EntitySet obj, Writer writer);
-
- /**
- * Writes entity object onto the given stream.
- *
- * @param obj object to be streamed.
- * @param out output stream.
- */
- void entity(Entity obj, OutputStream out);
-
- /**
- * Writes entity object by the given writer.
- *
- * @param obj object to be streamed.
- * @param writer writer.
- */
- void entity(Entity obj, Writer writer);
-
- /**
- * Writes the property object onto the given stream.
- *
- * @param property object to be streamed.
- * @param out output stream.
- */
- void property(Property property, OutputStream out);
-
- /**
- * Writes the property object by the given writer.
- *
- * @param property object to be streamed.
- * @param writer writer.
- */
- void property(Property property, Writer writer);
+public interface ODataSerializer {
- /**
- * Writes link onto the given stream.
- *
- * @param link OData link to be streamed.
- * @param format streaming format.
- * @param out output stream.
- */
- void link(Link link, ODataFormat format, OutputStream out);
+ public <T> void write(final Writer writer, final T obj) throws ODataSerializerException;
- /**
- * Writes link by the given writer.
- *
- * @param link OData link to be streamed.
- * @param format streaming format.
- * @param writer writer.
- */
- void link(Link link, ODataFormat format, Writer writer);
+ public <T> void write(final Writer writer, final ResWrap<T> container) throws ODataSerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializerException.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializerException.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializerException.java
new file mode 100755
index 0000000..69b5c3f
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/op/ODataSerializerException.java
@@ -0,0 +1,38 @@
+/*
+ * 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.op;
+
+import org.apache.olingo.commons.api.ODataException;
+
+public class ODataSerializerException extends ODataException {
+
+ private static final long serialVersionUID = -3236099963180859670L;
+
+ public ODataSerializerException(final String msg) {
+ super(msg);
+ }
+
+ public ODataSerializerException(final Throwable cause) {
+ super(cause);
+ }
+
+ public ODataSerializerException(final String msg, final Throwable cause) {
+ super(msg, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java
deleted file mode 100644
index 7bc3fd5..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntity.java
+++ /dev/null
@@ -1,193 +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 java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-
-/**
- * Abstract base for classes implementing an OData entity in Atom and JSON.
- */
-public abstract class AbstractEntity extends AbstractODataObject implements Entity {
-
- private static final long serialVersionUID = 2127764552600969783L;
-
- private String eTag;
-
- private String type;
-
- private Link readLink;
-
- private Link editLink;
-
- private final List<Link> associationLinks = new ArrayList<Link>();
-
- private final List<Link> navigationLinks = new ArrayList<Link>();
-
- private final List<Link> mediaEditLinks = new ArrayList<Link>();
-
- private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
-
- private final List<Property> properties = new ArrayList<Property>();
-
- private URI mediaContentSource;
-
- private String mediaContentType;
-
- private String mediaETag;
-
- @Override
- public String getETag() {
- return eTag;
- }
-
- public void setETag(final String eTag) {
- this.eTag = eTag;
- }
-
- @Override
- public String getType() {
- return type;
- }
-
- @Override
- public void setType(final String type) {
- this.type = type;
- }
-
- @Override
- public Link getSelfLink() {
- return readLink;
- }
-
- @Override
- public void setSelfLink(final Link readLink) {
- this.readLink = readLink;
- }
-
- @Override
- public Link getEditLink() {
- return editLink;
- }
-
- @Override
- public void setEditLink(final Link editLink) {
- this.editLink = editLink;
- }
-
- private Link getOneByTitle(final String name, final List<Link> links) {
- Link result = null;
-
- for (Link link : links) {
- if (name.equals(link.getTitle())) {
- result = link;
- }
- }
-
- return result;
- }
-
- @Override
- public Link getAssociationLink(final String name) {
- return getOneByTitle(name, associationLinks);
- }
-
- @Override
- public List<Link> getAssociationLinks() {
- return associationLinks;
- }
-
- @Override
- public Link getNavigationLink(final String name) {
- return getOneByTitle(name, navigationLinks);
- }
-
- @Override
- public List<Link> getNavigationLinks() {
- return navigationLinks;
- }
-
- @Override
- public List<Link> getMediaEditLinks() {
- return mediaEditLinks;
- }
-
- @Override
- public List<ODataOperation> getOperations() {
- return operations;
- }
-
- @Override
- public List<Property> getProperties() {
- return properties;
- }
-
- @Override
- public Property getProperty(final String name) {
- Property result = null;
-
- for (Property property : properties) {
- if (name.equals(property.getName())) {
- result = property;
- }
- }
-
- return result;
- }
-
- @Override
- public String getMediaContentType() {
- return this.mediaContentType;
- }
-
- @Override
- public void setMediaContentType(final String mediaContentType) {
- this.mediaContentType = mediaContentType;
- }
-
- @Override
- public URI getMediaContentSource() {
- return this.mediaContentSource;
- }
-
- @Override
- public void setMediaContentSource(final URI mediaContentSource) {
- this.mediaContentSource = mediaContentSource;
- }
-
- @Override
- public String getMediaETag() {
- return mediaETag;
- }
-
- @Override
- public void setMediaETag(final String eTag) {
- this.mediaETag = eTag;
- }
-
- @Override
- public boolean isMediaEntity() {
- return this.mediaContentSource != null;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntitySet.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntitySet.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntitySet.java
deleted file mode 100644
index 510c22a..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractEntitySet.java
+++ /dev/null
@@ -1,74 +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 java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-
-public abstract class AbstractEntitySet extends AbstractODataObject implements EntitySet {
-
- private static final long serialVersionUID = -9159884750819150969L;
-
- private Integer count;
-
- private final List<Entity> entities = new ArrayList<Entity>();
-
- private URI next;
-
- private URI deltaLink;
-
- @Override
- public void setCount(final Integer count) {
- this.count = count;
- }
-
- @Override
- public Integer getCount() {
- return count;
- }
-
- @Override
- public List<Entity> getEntities() {
- return entities;
- }
-
- @Override
- public void setNext(final URI next) {
- this.next = next;
- }
-
- @Override
- public URI getNext() {
- return next;
- }
-
- @Override
- public URI getDeltaLink() {
- return deltaLink;
- }
-
- @Override
- public void setDeltaLink(final URI deltaLink) {
- this.deltaLink = deltaLink;
- }
-
-}
[3/9] First presentable state
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java
deleted file mode 100644
index 133c916..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonDeserializer.java
+++ /dev/null
@@ -1,372 +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.core.ObjectCodec;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import java.io.IOException;
-import java.util.AbstractMap.SimpleEntry;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Annotatable;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.CollectionValue;
-import org.apache.olingo.commons.api.data.ComplexValue;
-import org.apache.olingo.commons.api.data.Linked;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.data.Valuable;
-import org.apache.olingo.commons.api.data.Value;
-import org.apache.olingo.commons.api.domain.ODataLinkType;
-import org.apache.olingo.commons.api.domain.ODataPropertyType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-
-abstract class AbstractJsonDeserializer<T> extends ODataJacksonDeserializer<ResWrap<T>> {
-
- protected final Pattern CUSTOM_ANNOTATION = Pattern.compile("(.+)@(.+)\\.(.+)");
-
- private JSONGeoValueDeserializer geoDeserializer;
-
- private JSONGeoValueDeserializer getGeoDeserializer() {
- if (geoDeserializer == null) {
- geoDeserializer = new JSONGeoValueDeserializer(version);
- }
- return geoDeserializer;
- }
-
- protected String getTitle(final Map.Entry<String, JsonNode> entry) {
- return entry.getKey().substring(0, entry.getKey().indexOf('@'));
- }
-
- protected String setInline(final String name, final String suffix, final JsonNode tree,
- final ObjectCodec codec, final LinkImpl link) throws IOException {
-
- final String entityNamePrefix = name.substring(0, name.indexOf(suffix));
- if (tree.has(entityNamePrefix)) {
- final JsonNode inline = tree.path(entityNamePrefix);
-
- if (inline instanceof ObjectNode) {
- link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
-
- link.setInlineEntity(inline.traverse(codec).<ResWrap<JSONEntityImpl>>readValueAs(
- new TypeReference<JSONEntityImpl>() {
- }).getPayload());
- }
-
- if (inline instanceof ArrayNode) {
- link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
-
- final JSONEntitySetImpl entitySet = new JSONEntitySetImpl();
- final Iterator<JsonNode> entries = ((ArrayNode) inline).elements();
- while (entries.hasNext()) {
- entitySet.getEntities().add(entries.next().traverse(codec).<ResWrap<JSONEntityImpl>>readValuesAs(
- new TypeReference<JSONEntityImpl>() {
- }).next().getPayload());
- }
-
- link.setInlineEntitySet(entitySet);
- }
- }
- return entityNamePrefix;
- }
-
- protected void links(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
- final JsonNode tree, final ObjectCodec codec) throws IOException {
- if (serverMode) {
- serverLinks(field, linked, toRemove, tree, codec);
- } else {
- clientLinks(field, linked, toRemove, tree, codec);
- }
- }
-
- private void clientLinks(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
- final JsonNode tree, final ObjectCodec codec) throws IOException {
-
- if (field.getKey().endsWith(jsonNavigationLink)) {
- final LinkImpl link = new LinkImpl();
- link.setTitle(getTitle(field));
- link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field));
-
- if (field.getValue().isValueNode()) {
- link.setHref(field.getValue().textValue());
- link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
- }
-
- linked.getNavigationLinks().add(link);
-
- toRemove.add(field.getKey());
- toRemove.add(setInline(field.getKey(), jsonNavigationLink, tree, codec, link));
- } else if (field.getKey().endsWith(jsonAssociationLink)) {
- final LinkImpl link = new LinkImpl();
- link.setTitle(getTitle(field));
- link.setRel(version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL) + getTitle(field));
- link.setHref(field.getValue().textValue());
- link.setType(ODataLinkType.ASSOCIATION.toString());
- linked.getAssociationLinks().add(link);
-
- toRemove.add(field.getKey());
- }
- }
-
- private void serverLinks(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
- final JsonNode tree, final ObjectCodec codec) throws IOException {
-
- if (field.getKey().endsWith(Constants.JSON_BIND_LINK_SUFFIX)
- || field.getKey().endsWith(jsonNavigationLink)) {
-
- if (field.getValue().isValueNode()) {
- final String suffix = field.getKey().replaceAll("^.*@", "@");
-
- final LinkImpl link = new LinkImpl();
- link.setTitle(getTitle(field));
- link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field));
- link.setHref(field.getValue().textValue());
- link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
- linked.getNavigationLinks().add(link);
-
- toRemove.add(setInline(field.getKey(), suffix, tree, codec, link));
- } else if (field.getValue().isArray()) {
- for (final Iterator<JsonNode> itor = field.getValue().elements(); itor.hasNext();) {
- final JsonNode node = itor.next();
-
- final LinkImpl link = new LinkImpl();
- link.setTitle(getTitle(field));
- link.setRel(version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL) + getTitle(field));
- link.setHref(node.asText());
- link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
- linked.getNavigationLinks().add(link);
- toRemove.add(setInline(field.getKey(), Constants.JSON_BIND_LINK_SUFFIX, tree, codec, link));
- }
- }
- toRemove.add(field.getKey());
- }
- }
-
- private Map.Entry<ODataPropertyType, EdmTypeInfo> guessPropertyType(final JsonNode node) {
- ODataPropertyType type;
- EdmTypeInfo typeInfo = null;
-
- if (node.isValueNode() || node.isNull()) {
- type = ODataPropertyType.PRIMITIVE;
-
- EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.String;
- if (node.isShort()) {
- kind = EdmPrimitiveTypeKind.Int16;
- } else if (node.isInt()) {
- kind = EdmPrimitiveTypeKind.Int32;
- } else if (node.isLong()) {
- kind = EdmPrimitiveTypeKind.Int64;
- } else if (node.isBoolean()) {
- kind = EdmPrimitiveTypeKind.Boolean;
- } else if (node.isFloat()) {
- kind = EdmPrimitiveTypeKind.Single;
- } else if (node.isDouble()) {
- kind = EdmPrimitiveTypeKind.Double;
- } else if (node.isBigDecimal()) {
- kind = EdmPrimitiveTypeKind.Decimal;
- }
- typeInfo = new EdmTypeInfo.Builder().setTypeExpression(kind.getFullQualifiedName().toString()).build();
- } else if (node.isArray()) {
- type = ODataPropertyType.COLLECTION;
- } else if (node.isObject()) {
- if (node.has(Constants.ATTR_TYPE)) {
- type = ODataPropertyType.PRIMITIVE;
- typeInfo = new EdmTypeInfo.Builder().
- setTypeExpression("Edm.Geography" + node.get(Constants.ATTR_TYPE).asText()).build();
- } else {
- type = ODataPropertyType.COMPLEX;
- }
- } else {
- type = ODataPropertyType.EMPTY;
- }
-
- return new SimpleEntry<ODataPropertyType, EdmTypeInfo>(type, typeInfo);
- }
-
- protected void populate(final Annotatable annotatable, final List<Property> properties,
- final ObjectNode tree, final ObjectCodec codec) throws IOException {
-
- String type = null;
- Annotation annotation = null;
- for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
- final Map.Entry<String, JsonNode> field = itor.next();
- final Matcher customAnnotation = CUSTOM_ANNOTATION.matcher(field.getKey());
-
- if (field.getKey().charAt(0) == '@') {
- final Annotation entityAnnot = new AnnotationImpl();
- entityAnnot.setTerm(field.getKey().substring(1));
-
- value(entityAnnot, field.getValue(), codec);
- if (annotatable != null) {
- annotatable.getAnnotations().add(entityAnnot);
- }
- } else if (type == null && field.getKey().endsWith(getJSONAnnotation(jsonType))) {
- type = field.getValue().asText();
- } else if (annotation == null && customAnnotation.matches() && !"odata".equals(customAnnotation.group(2))) {
- annotation = new AnnotationImpl();
- annotation.setTerm(customAnnotation.group(2) + "." + customAnnotation.group(3));
- value(annotation, field.getValue(), codec);
- } else {
- final JSONPropertyImpl property = new JSONPropertyImpl();
- property.setName(field.getKey());
- property.setType(type == null
- ? null
- : new EdmTypeInfo.Builder().setTypeExpression(type).build().internal());
- type = null;
-
- value(property, field.getValue(), codec);
- properties.add(property);
-
- if (annotation != null) {
- property.getAnnotations().add(annotation);
- annotation = null;
- }
- }
- }
- }
-
- private Value fromPrimitive(final JsonNode node, final EdmTypeInfo typeInfo) {
- final Value value;
-
- if (node.isNull()) {
- value = new NullValueImpl();
- } else {
- if (typeInfo != null && typeInfo.getPrimitiveTypeKind().isGeospatial()) {
- value = new GeospatialValueImpl(getGeoDeserializer().deserialize(node, typeInfo));
- } else {
- value = new PrimitiveValueImpl(node.asText());
- }
- }
-
- return value;
- }
-
- private ComplexValue fromComplex(final ObjectNode node, final ObjectCodec codec) throws IOException {
- final ComplexValue value = version.compareTo(ODataServiceVersion.V40) < 0
- ? new ComplexValueImpl()
- : new LinkedComplexValueImpl();
-
- if (value.isLinkedComplex()) {
- final Set<String> toRemove = new HashSet<String>();
- for (final Iterator<Map.Entry<String, JsonNode>> itor = node.fields(); itor.hasNext();) {
- final Map.Entry<String, JsonNode> field = itor.next();
-
- links(field, value.asLinkedComplex(), toRemove, node, codec);
- }
- node.remove(toRemove);
- }
-
- populate(value.asLinkedComplex(), value.get(), node, codec);
-
- return value;
- }
-
- private CollectionValue fromCollection(final Iterator<JsonNode> nodeItor, final EdmTypeInfo typeInfo,
- final ObjectCodec codec) throws IOException {
-
- final CollectionValueImpl value = new CollectionValueImpl();
-
- final EdmTypeInfo type = typeInfo == null
- ? null
- : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build();
-
- while (nodeItor.hasNext()) {
- final JsonNode child = nodeItor.next();
-
- if (child.isValueNode()) {
- if (typeInfo == null || typeInfo.isPrimitiveType()) {
- value.get().add(fromPrimitive(child, type));
- } else {
- value.get().add(new EnumValueImpl(child.asText()));
- }
- } else if (child.isContainerNode()) {
- if (child.has(jsonType)) {
- ((ObjectNode) child).remove(jsonType);
- }
- value.get().add(fromComplex((ObjectNode) child, codec));
- }
- }
-
- return value;
- }
-
- protected void value(final Valuable valuable, final JsonNode node, final ObjectCodec codec)
- throws IOException {
-
- EdmTypeInfo typeInfo = StringUtils.isBlank(valuable.getType())
- ? null
- : new EdmTypeInfo.Builder().setTypeExpression(valuable.getType()).build();
-
- final Map.Entry<ODataPropertyType, EdmTypeInfo> guessed = guessPropertyType(node);
- if (typeInfo == null) {
- typeInfo = guessed.getValue();
- }
-
- final ODataPropertyType propType = typeInfo == null
- ? guessed.getKey()
- : typeInfo.isCollection()
- ? ODataPropertyType.COLLECTION
- : typeInfo.isPrimitiveType()
- ? ODataPropertyType.PRIMITIVE
- : node.isValueNode()
- ? ODataPropertyType.ENUM
- : ODataPropertyType.COMPLEX;
-
- switch (propType) {
- case COLLECTION:
- valuable.setValue(fromCollection(node.elements(), typeInfo, codec));
- break;
-
- case COMPLEX:
- if (node.has(jsonType)) {
- valuable.setType(node.get(jsonType).asText());
- ((ObjectNode) node).remove(jsonType);
- }
- valuable.setValue(fromComplex((ObjectNode) node, codec));
- break;
-
- case ENUM:
- valuable.setValue(new EnumValueImpl(node.asText()));
- break;
-
- case PRIMITIVE:
- if (valuable.getType() == null && typeInfo != null) {
- valuable.setType(typeInfo.getFullQualifiedName().toString());
- }
- valuable.setValue(fromPrimitive(node, typeInfo));
- break;
-
- case EMPTY:
- default:
- valuable.setValue(new PrimitiveValueImpl(StringUtils.EMPTY));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java
deleted file mode 100644
index 1713a7c..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractJsonSerializer.java
+++ /dev/null
@@ -1,248 +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.core.JsonGenerator;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.BooleanUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.Annotatable;
-import org.apache.olingo.commons.api.data.Annotation;
-import org.apache.olingo.commons.api.data.CollectionValue;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Linked;
-import org.apache.olingo.commons.api.data.PrimitiveValue;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.Valuable;
-import org.apache.olingo.commons.api.data.Value;
-import org.apache.olingo.commons.api.domain.ODataLinkType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-
-abstract class AbstractJsonSerializer<T> extends ODataJacksonSerializer<T> {
-
- private static final EdmPrimitiveTypeKind[] NUMBER_TYPES = {
- EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte,
- EdmPrimitiveTypeKind.Single, EdmPrimitiveTypeKind.Double,
- EdmPrimitiveTypeKind.Int16, EdmPrimitiveTypeKind.Int32, EdmPrimitiveTypeKind.Int64,
- EdmPrimitiveTypeKind.Decimal
- };
-
- private final JSONGeoValueSerializer geoSerializer = new JSONGeoValueSerializer();
-
- protected void links(final Linked linked, final JsonGenerator jgen) throws IOException {
- if (serverMode) {
- serverLinks(linked, jgen);
- } else {
- clientLinks(linked, jgen);
- }
- }
-
- protected void clientLinks(final Linked linked, final JsonGenerator jgen) throws IOException {
- final Map<String, List<String>> entitySetLinks = new HashMap<String, List<String>>();
- for (Link link : linked.getNavigationLinks()) {
- for (Annotation annotation : link.getAnnotations()) {
- valuable(jgen, annotation, link.getTitle() + "@" + annotation.getTerm());
- }
-
- ODataLinkType type = null;
- try {
- type = ODataLinkType.fromString(version, link.getRel(), link.getType());
- } catch (IllegalArgumentException e) {
- // ignore
- }
-
- if (type == ODataLinkType.ENTITY_SET_NAVIGATION) {
- final List<String> uris;
- if (entitySetLinks.containsKey(link.getTitle())) {
- uris = entitySetLinks.get(link.getTitle());
- } else {
- uris = new ArrayList<String>();
- entitySetLinks.put(link.getTitle(), uris);
- }
- if (StringUtils.isNotBlank(link.getHref())) {
- uris.add(link.getHref());
- }
- } else {
- if (StringUtils.isNotBlank(link.getHref())) {
- jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
- }
- }
-
- if (link.getInlineEntity() != null) {
- jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
- } else if (link.getInlineEntitySet() != null) {
- jgen.writeArrayFieldStart(link.getTitle());
- for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
- jgen.writeObject(subEntry);
- }
- jgen.writeEndArray();
- }
- }
- for (Map.Entry<String, List<String>> entitySetLink : entitySetLinks.entrySet()) {
- if (!entitySetLink.getValue().isEmpty()) {
- jgen.writeArrayFieldStart(entitySetLink.getKey() + Constants.JSON_BIND_LINK_SUFFIX);
- for (String uri : entitySetLink.getValue()) {
- jgen.writeString(uri);
- }
- jgen.writeEndArray();
- }
- }
- }
-
- protected void serverLinks(final Linked linked, final JsonGenerator jgen) throws IOException {
- if (linked instanceof JSONEntityImpl) {
- for (Link link : ((JSONEntityImpl) linked).getMediaEditLinks()) {
- if (StringUtils.isNotBlank(link.getHref())) {
- jgen.writeStringField(
- link.getTitle() + StringUtils.prependIfMissing(
- version.getJSONMap().get(ODataServiceVersion.JSON_MEDIAEDIT_LINK), "@"),
- link.getHref());
- }
- }
- }
-
- for (Link link : linked.getAssociationLinks()) {
- if (StringUtils.isNotBlank(link.getHref())) {
- jgen.writeStringField(
- link.getTitle() + version.getJSONMap().get(ODataServiceVersion.JSON_ASSOCIATION_LINK),
- link.getHref());
- }
- }
-
- for (Link link : linked.getNavigationLinks()) {
- for (Annotation annotation : link.getAnnotations()) {
- valuable(jgen, annotation, link.getTitle() + "@" + annotation.getTerm());
- }
-
- if (StringUtils.isNotBlank(link.getHref())) {
- jgen.writeStringField(
- link.getTitle() + version.getJSONMap().get(ODataServiceVersion.JSON_NAVIGATION_LINK),
- link.getHref());
- }
-
- if (link.getInlineEntity() != null) {
- jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
- } else if (link.getInlineEntitySet() != null) {
- jgen.writeArrayFieldStart(link.getTitle());
- for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
- jgen.writeObject(subEntry);
- }
- jgen.writeEndArray();
- }
- }
- }
-
- private void collection(final JsonGenerator jgen, final String itemType, final CollectionValue value)
- throws IOException {
-
- jgen.writeStartArray();
- for (Value item : value.get()) {
- value(jgen, itemType, item);
- }
- jgen.writeEndArray();
- }
-
- protected void primitiveValue(final JsonGenerator jgen, final EdmTypeInfo typeInfo, final PrimitiveValue value)
- throws IOException {
-
- final boolean isNumber = typeInfo == null
- ? NumberUtils.isNumber(value.get())
- : ArrayUtils.contains(NUMBER_TYPES, typeInfo.getPrimitiveTypeKind());
- final boolean isBoolean = typeInfo == null
- ? (value.get().equalsIgnoreCase(Boolean.TRUE.toString())
- || value.get().equalsIgnoreCase(Boolean.FALSE.toString()))
- : typeInfo.getPrimitiveTypeKind() == EdmPrimitiveTypeKind.Boolean;
-
- if (isNumber) {
- jgen.writeNumber(value.get());
- } else if (isBoolean) {
- jgen.writeBoolean(BooleanUtils.toBoolean(value.get()));
- } else {
- jgen.writeString(value.get());
- }
- }
-
- private void value(final JsonGenerator jgen, final String type, final Value value) throws IOException {
- final EdmTypeInfo typeInfo = type == null
- ? null
- : new EdmTypeInfo.Builder().setTypeExpression(type).build();
-
- if (value == null || value.isNull()) {
- jgen.writeNull();
- } else if (value.isPrimitive()) {
- primitiveValue(jgen, typeInfo, value.asPrimitive());
- } else if (value.isEnum()) {
- jgen.writeString(value.asEnum().get());
- } else if (value.isGeospatial()) {
- jgen.writeStartObject();
- geoSerializer.serialize(jgen, value.asGeospatial().get());
- jgen.writeEndObject();
- } else if (value.isCollection()) {
- collection(jgen, typeInfo == null ? null : typeInfo.getFullQualifiedName().toString(), value.asCollection());
- } else if (value.isComplex()) {
- jgen.writeStartObject();
-
- if (typeInfo != null) {
- jgen.writeStringField(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), typeInfo.external(version));
- }
-
- for (Property property : value.asComplex().get()) {
- valuable(jgen, property, property.getName());
- }
- if (value.isLinkedComplex()) {
- links(value.asLinkedComplex(), jgen);
- }
-
- jgen.writeEndObject();
- }
- }
-
- protected void valuable(final JsonGenerator jgen, final Valuable valuable, final String name) throws IOException {
- if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation) && !valuable.getValue().isComplex()) {
- String type = valuable.getType();
- if (StringUtils.isBlank(type) && valuable.getValue().isPrimitive() || valuable.getValue().isNull()) {
- type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString();
- }
- if (StringUtils.isNotBlank(type)) {
- jgen.writeFieldName(
- name + StringUtils.prependIfMissing(version.getJSONMap().get(ODataServiceVersion.JSON_TYPE), "@"));
- jgen.writeString(new EdmTypeInfo.Builder().setTypeExpression(type).build().external(version));
- }
- }
-
- if (valuable instanceof Annotatable) {
- for (Annotation annotation : ((Annotatable) valuable).getAnnotations()) {
- valuable(jgen, annotation, name + "@" + annotation.getTerm());
- }
- }
-
- jgen.writeFieldName(name);
- value(jgen, valuable.getType(), valuable.getValue());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataError.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataError.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataError.java
deleted file mode 100644
index 1e9cf51..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataError.java
+++ /dev/null
@@ -1,89 +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 java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.commons.api.domain.ODataError;
-import org.apache.olingo.commons.api.domain.ODataErrorDetail;
-
-/**
- * Example:
- * <tt>
- * {
- * "error": { "code": "501", "message": "Unsupported functionality", "target": "query", "details": [ { "code": "301",
- * "target": "$search", "message": "$search query option not supported" } ], "innererror": { "trace": [...], "context":
- * {...} } } }
- * </tt>.
- */
-public abstract class AbstractODataError implements ODataError {
-
- private String code;
-
- private String message;
-
- private String target;
-
- private List<ODataErrorDetail> details;
-
- private Map<String, String> innerError = new LinkedHashMap<String, String>();
-
- @Override
- public String getCode() {
- return code;
- }
-
- public void setCode(final String code) {
- this.code = code;
- }
-
- @Override
- public String getMessage() {
- return message;
- }
-
- public void setMessage(final String message) {
- this.message = message;
- }
-
- @Override
- public String getTarget() {
- return target;
- }
-
- public void setTarget(final String target) {
- this.target = target;
- }
-
- @Override
- public List<ODataErrorDetail> getDetails() {
- return details;
- }
-
- public void setDetails(final List<ODataErrorDetail> detail) {
- this.details = detail;
- }
-
- @Override
- public Map<String, String> getInnerError() {
- return innerError;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractProperty.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractProperty.java
deleted file mode 100644
index 2363c0b..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractProperty.java
+++ /dev/null
@@ -1,63 +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 org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.Value;
-
-public abstract class AbstractProperty extends AbstractAnnotatedObject implements Property {
-
- private static final long serialVersionUID = -7175704800169997060L;
-
- private String name;
-
- private String type;
-
- private Value value;
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public String getType() {
- return type;
- }
-
- @Override
- public void setType(final String type) {
- this.type = type;
- }
-
- @Override
- public Value getValue() {
- return value;
- }
-
- @Override
- public void setValue(final Value value) {
- this.value = value;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
index 51a5465..dec0028 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomDeserializer.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.aalto.stax.InputFactoryImpl;
-import org.apache.olingo.commons.core.data.v4.AtomDeltaImpl;
import java.io.InputStream;
import java.net.URI;
import java.text.ParseException;
@@ -27,6 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
@@ -34,25 +33,35 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
import org.apache.olingo.commons.api.data.CollectionValue;
import org.apache.olingo.commons.api.data.DeletedEntity.Reason;
+import org.apache.olingo.commons.api.data.Delta;
+import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Valuable;
import org.apache.olingo.commons.api.data.Value;
+import org.apache.olingo.commons.api.data.v3.LinkCollection;
+import org.apache.olingo.commons.api.domain.ODataError;
import org.apache.olingo.commons.api.domain.ODataOperation;
import org.apache.olingo.commons.api.domain.ODataPropertyType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.core.data.v3.XMLLinkCollectionImpl;
+import org.apache.olingo.commons.api.op.ODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.v3.LinkCollectionImpl;
+import org.apache.olingo.commons.core.data.v4.DeltaImpl;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-public class AtomDeserializer extends AbstractAtomDealer {
+import com.fasterxml.aalto.stax.InputFactoryImpl;
+
+public class AtomDeserializer extends AbstractAtomDealer implements ODataDeserializer {
protected static final XMLInputFactory FACTORY = new InputFactoryImpl();
@@ -68,7 +77,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private Value fromPrimitive(final XMLEventReader reader, final StartElement start,
- final EdmTypeInfo typeInfo) throws XMLStreamException {
+ final EdmTypeInfo typeInfo) throws XMLStreamException {
Value value = null;
@@ -78,12 +87,12 @@ public class AtomDeserializer extends AbstractAtomDealer {
if (event.isStartElement() && typeInfo != null && typeInfo.getPrimitiveTypeKind().isGeospatial()) {
final EdmPrimitiveTypeKind geoType = EdmPrimitiveTypeKind.valueOfFQN(
- version, typeInfo.getFullQualifiedName().toString());
+ version, typeInfo.getFullQualifiedName().toString());
value = new GeospatialValueImpl(this.geoDeserializer.deserialize(reader, event.asStartElement(), geoType));
}
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()
- && (typeInfo == null || !typeInfo.getPrimitiveTypeKind().isGeospatial())) {
+ && (typeInfo == null || !typeInfo.getPrimitiveTypeKind().isGeospatial())) {
value = new PrimitiveValueImpl(event.asCharacters().getData());
}
@@ -97,7 +106,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private Value fromComplexOrEnum(final XMLEventReader reader, final StartElement start)
- throws XMLStreamException {
+ throws XMLStreamException {
Value value = null;
@@ -108,8 +117,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
if (event.isStartElement()) {
if (value == null) {
value = version.compareTo(ODataServiceVersion.V40) < 0
- ? new ComplexValueImpl()
- : new LinkedComplexValueImpl();
+ ? new ComplexValueImpl()
+ : new LinkedComplexValueImpl();
}
if (Constants.QNAME_ATOM_ELEM_LINK.equals(event.asStartElement().getName())) {
@@ -132,12 +141,12 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
if (link.getRel().startsWith(
- version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
+ version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
value.asLinkedComplex().getNavigationLinks().add(link);
inline(reader, event.asStartElement(), link);
} else if (link.getRel().startsWith(
- version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
+ version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
value.asLinkedComplex().getAssociationLinks().add(link);
}
@@ -159,13 +168,13 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private CollectionValue fromCollection(final XMLEventReader reader, final StartElement start,
- final EdmTypeInfo typeInfo) throws XMLStreamException {
+ final EdmTypeInfo typeInfo) throws XMLStreamException {
final CollectionValueImpl value = new CollectionValueImpl();
final EdmTypeInfo type = typeInfo == null
- ? null
- : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build();
+ ? null
+ : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build();
boolean foundEndProperty = false;
while (reader.hasNext() && !foundEndProperty) {
@@ -173,16 +182,16 @@ public class AtomDeserializer extends AbstractAtomDealer {
if (event.isStartElement()) {
switch (guessPropertyType(reader, typeInfo)) {
- case COMPLEX:
- case ENUM:
- value.get().add(fromComplexOrEnum(reader, event.asStartElement()));
- break;
+ case COMPLEX:
+ case ENUM:
+ value.get().add(fromComplexOrEnum(reader, event.asStartElement()));
+ break;
- case PRIMITIVE:
- value.get().add(fromPrimitive(reader, event.asStartElement(), type));
- break;
+ case PRIMITIVE:
+ value.get().add(fromPrimitive(reader, event.asStartElement(), type));
+ break;
- default:
+ default:
// do not add null or empty values
}
}
@@ -196,7 +205,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private ODataPropertyType guessPropertyType(final XMLEventReader reader, final EdmTypeInfo typeInfo)
- throws XMLStreamException {
+ throws XMLStreamException {
XMLEvent child = null;
while (reader.hasNext() && child == null) {
@@ -211,8 +220,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
final ODataPropertyType type;
if (child == null) {
type = typeInfo == null || typeInfo.isPrimitiveType()
- ? ODataPropertyType.PRIMITIVE
- : ODataPropertyType.ENUM;
+ ? ODataPropertyType.PRIMITIVE
+ : ODataPropertyType.ENUM;
} else {
if (child.isStartElement()) {
if (Constants.NS_GML.equals(child.asStartElement().getName().getNamespaceURI())) {
@@ -224,8 +233,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
} else if (child.isCharacters()) {
type = typeInfo == null || typeInfo.isPrimitiveType()
- ? ODataPropertyType.PRIMITIVE
- : ODataPropertyType.ENUM;
+ ? ODataPropertyType.PRIMITIVE
+ : ODataPropertyType.ENUM;
} else {
type = ODataPropertyType.EMPTY;
}
@@ -234,10 +243,10 @@ public class AtomDeserializer extends AbstractAtomDealer {
return type;
}
- private AtomPropertyImpl property(final XMLEventReader reader, final StartElement start)
- throws XMLStreamException {
+ private Property property(final XMLEventReader reader, final StartElement start)
+ throws XMLStreamException {
- final AtomPropertyImpl property = new AtomPropertyImpl();
+ final PropertyImpl property = new PropertyImpl();
if (ODataServiceVersion.V40 == version && propertyValueQName.equals(start.getName())) {
// retrieve name from context
@@ -255,7 +264,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private void valuable(final Valuable valuable, final XMLEventReader reader, final StartElement start)
- throws XMLStreamException {
+ throws XMLStreamException {
final Attribute nullAttr = start.getAttributeByName(this.nullQName);
@@ -265,41 +274,41 @@ public class AtomDeserializer extends AbstractAtomDealer {
final String typeAttrValue = typeAttr == null ? null : typeAttr.getValue();
final EdmTypeInfo typeInfo = StringUtils.isBlank(typeAttrValue)
- ? null
- : new EdmTypeInfo.Builder().setTypeExpression(typeAttrValue).build();
+ ? null
+ : new EdmTypeInfo.Builder().setTypeExpression(typeAttrValue).build();
if (typeInfo != null) {
valuable.setType(typeInfo.internal());
}
final ODataPropertyType propType = typeInfo == null
- ? guessPropertyType(reader, typeInfo)
- : typeInfo.isCollection()
+ ? guessPropertyType(reader, typeInfo)
+ : typeInfo.isCollection()
? ODataPropertyType.COLLECTION
: typeInfo.isPrimitiveType()
- ? ODataPropertyType.PRIMITIVE
- : ODataPropertyType.COMPLEX;
+ ? ODataPropertyType.PRIMITIVE
+ : ODataPropertyType.COMPLEX;
switch (propType) {
- case COLLECTION:
- value = fromCollection(reader, start, typeInfo);
- break;
-
- case COMPLEX:
- value = fromComplexOrEnum(reader, start);
- break;
-
- case PRIMITIVE:
- // No type specified? Defaults to Edm.String
- if (typeInfo == null) {
- valuable.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString());
- }
- value = fromPrimitive(reader, start, typeInfo);
- break;
+ case COLLECTION:
+ value = fromCollection(reader, start, typeInfo);
+ break;
+
+ case COMPLEX:
+ value = fromComplexOrEnum(reader, start);
+ break;
+
+ case PRIMITIVE:
+ // No type specified? Defaults to Edm.String
+ if (typeInfo == null) {
+ valuable.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString());
+ }
+ value = fromPrimitive(reader, start, typeInfo);
+ break;
- case EMPTY:
- default:
- value = new PrimitiveValueImpl(StringUtils.EMPTY);
+ case EMPTY:
+ default:
+ value = new PrimitiveValueImpl(StringUtils.EMPTY);
}
} else {
value = new NullValueImpl();
@@ -308,10 +317,15 @@ public class AtomDeserializer extends AbstractAtomDealer {
valuable.setValue(value);
}
- private ResWrap<AtomPropertyImpl> property(final InputStream input) throws XMLStreamException {
- final XMLEventReader reader = getReader(input);
- final StartElement start = skipBeforeFirstStartElement(reader);
- return getContainer(start, property(reader, start));
+ @Override
+ public ResWrap<Property> toProperty(final InputStream input) throws ODataDeserializerException {
+ try {
+ final XMLEventReader reader = getReader(input);
+ final StartElement start = skipBeforeFirstStartElement(reader);
+ return getContainer(start, property(reader, start));
+ } catch (XMLStreamException e) {
+ throw new ODataDeserializerException(e);
+ }
}
private StartElement skipBeforeFirstStartElement(final XMLEventReader reader) throws XMLStreamException {
@@ -330,7 +344,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private void common(final XMLEventReader reader, final StartElement start,
- final AbstractODataObject object, final String key) throws XMLStreamException {
+ final AbstractODataObject object, final String key) throws XMLStreamException {
boolean foundEndElement = false;
while (reader.hasNext() && !foundEndElement) {
@@ -351,7 +365,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private void inline(final XMLEventReader reader, final StartElement start, final LinkImpl link)
- throws XMLStreamException {
+ throws XMLStreamException {
boolean foundEndElement = false;
while (reader.hasNext() && !foundEndElement) {
@@ -387,17 +401,17 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
}
- private ResWrap<AtomDeltaImpl> delta(final InputStream input) throws XMLStreamException {
+ public ResWrap<Delta> 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 {
+ private Delta 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 DeltaImpl delta = new DeltaImpl();
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
if (xmlBase != null) {
delta.setBaseURI(xmlBase.getValue());
@@ -449,7 +463,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
delta.getDeletedEntities().add(deletedEntity);
} else if (linkQName.equals(event.asStartElement().getName())
- || deletedLinkQName.equals(event.asStartElement().getName())) {
+ || deletedLinkQName.equals(event.asStartElement().getName())) {
final DeltaLinkImpl link = new DeltaLinkImpl();
@@ -458,7 +472,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
link.setSource(URI.create(source.getValue()));
}
final Attribute relationship =
- event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_RELATIONSHIP));
+ event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_RELATIONSHIP));
if (relationship != null) {
link.setRelationship(relationship.getValue());
}
@@ -483,16 +497,16 @@ public class AtomDeserializer extends AbstractAtomDealer {
return delta;
}
- private ResWrap<XMLLinkCollectionImpl> linkCollection(final InputStream input) throws XMLStreamException {
+ public ResWrap<LinkCollection> linkCollection(final InputStream input) throws XMLStreamException {
final XMLEventReader reader = getReader(input);
final StartElement start = skipBeforeFirstStartElement(reader);
return getContainer(start, linkCollection(reader, start));
}
- private XMLLinkCollectionImpl linkCollection(final XMLEventReader reader, final StartElement start)
- throws XMLStreamException {
+ private LinkCollection linkCollection(final XMLEventReader reader, final StartElement start)
+ throws XMLStreamException {
- final XMLLinkCollectionImpl linkCollection = new XMLLinkCollectionImpl();
+ final LinkCollectionImpl linkCollection = new LinkCollectionImpl();
boolean isURI = false;
boolean isNext = false;
@@ -517,8 +531,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
return linkCollection;
}
- private void properties(final XMLEventReader reader, final StartElement start, final AtomEntityImpl entity)
- throws XMLStreamException {
+ private void properties(final XMLEventReader reader, final StartElement start, final EntityImpl entity)
+ throws XMLStreamException {
final Map<String, List<Annotation>> annotations = new HashMap<String, List<Annotation>>();
@@ -529,7 +543,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
if (event.isStartElement()) {
if (annotationQName.equals(event.asStartElement().getName())) {
final String target = event.asStartElement().
- getAttributeByName(QName.valueOf(Constants.ATTR_TARGET)).getValue();
+ getAttributeByName(QName.valueOf(Constants.ATTR_TARGET)).getValue();
if (!annotations.containsKey(target)) {
annotations.put(target, new ArrayList<Annotation>());
}
@@ -552,7 +566,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
private Annotation annotation(final XMLEventReader reader, final StartElement start)
- throws XMLStreamException {
+ throws XMLStreamException {
final Annotation annotation = new AnnotationImpl();
@@ -562,8 +576,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
return annotation;
}
- private AtomEntityImpl entityRef(final StartElement start) throws XMLStreamException {
- final AtomEntityImpl entity = new AtomEntityImpl();
+ private EntityImpl entityRef(final StartElement start) throws XMLStreamException {
+ final EntityImpl entity = new EntityImpl();
final Attribute entityRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
if (entityRefId != null) {
@@ -573,12 +587,12 @@ public class AtomDeserializer extends AbstractAtomDealer {
return entity;
}
- private AtomEntityImpl entity(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
- final AtomEntityImpl entity;
+ private Entity entity(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
+ final EntityImpl entity;
if (entryRefQName.equals(start.getName())) {
entity = entityRef(start);
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) {
- entity = new AtomEntityImpl();
+ entity = new EntityImpl();
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
if (xmlBase != null) {
entity.setBaseURI(xmlBase.getValue());
@@ -636,16 +650,16 @@ public class AtomDeserializer extends AbstractAtomDealer {
entity.setMediaETag(mediaETag.getValue());
}
} else if (link.getRel().startsWith(
- version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
-
+ version.getNamespaceMap().get(ODataServiceVersion.NAVIGATION_LINK_REL))) {
+
entity.getNavigationLinks().add(link);
inline(reader, event.asStartElement(), link);
} else if (link.getRel().startsWith(
- version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
+ version.getNamespaceMap().get(ODataServiceVersion.ASSOCIATION_LINK_REL))) {
entity.getAssociationLinks().add(link);
} else if (link.getRel().startsWith(
- version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) {
+ version.getNamespaceMap().get(ODataServiceVersion.MEDIA_EDIT_LINK_REL))) {
final Attribute metag = event.asStartElement().getAttributeByName(etagQName);
if (metag != null) {
@@ -656,7 +670,7 @@ public class AtomDeserializer extends AbstractAtomDealer {
} else if (actionQName.equals(event.asStartElement().getName())) {
final ODataOperation operation = new ODataOperation();
final Attribute metadata =
- event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_METADATA));
+ event.asStartElement().getAttributeByName(QName.valueOf(Constants.ATTR_METADATA));
if (metadata != null) {
operation.setMetadataAnchor(metadata.getValue());
}
@@ -699,14 +713,19 @@ public class AtomDeserializer extends AbstractAtomDealer {
return entity;
}
- private ResWrap<AtomEntityImpl> entity(final InputStream input) throws XMLStreamException {
- final XMLEventReader reader = getReader(input);
- final StartElement start = skipBeforeFirstStartElement(reader);
- return getContainer(start, entity(reader, start));
+ @Override
+ public ResWrap<Entity> toEntity(final InputStream input) throws ODataDeserializerException {
+ try {
+ final XMLEventReader reader = getReader(input);
+ final StartElement start = skipBeforeFirstStartElement(reader);
+ return getContainer(start, entity(reader, start));
+ } catch (XMLStreamException e) {
+ throw new ODataDeserializerException(e);
+ }
}
private void count(final XMLEventReader reader, final StartElement start, final EntitySet entitySet)
- throws XMLStreamException {
+ throws XMLStreamException {
boolean foundEndElement = false;
while (reader.hasNext() && !foundEndElement) {
@@ -722,11 +741,11 @@ public class AtomDeserializer extends AbstractAtomDealer {
}
}
- private AtomEntitySetImpl entitySet(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
+ private EntitySet entitySet(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
if (!Constants.QNAME_ATOM_ELEM_FEED.equals(start.getName())) {
return null;
}
- final AtomEntitySetImpl entitySet = new AtomEntitySetImpl();
+ final EntitySetImpl entitySet = new EntitySetImpl();
final Attribute xmlBase = start.getAttributeByName(Constants.QNAME_ATTR_XML_BASE);
if (xmlBase != null) {
entitySet.setBaseURI(xmlBase.getValue());
@@ -779,14 +798,19 @@ public class AtomDeserializer extends AbstractAtomDealer {
return entitySet;
}
- private ResWrap<AtomEntitySetImpl> entitySet(final InputStream input) throws XMLStreamException {
- final XMLEventReader reader = getReader(input);
- final StartElement start = skipBeforeFirstStartElement(reader);
- return getContainer(start, entitySet(reader, start));
+ @Override
+ public ResWrap<EntitySet> toEntitySet(final InputStream input) throws ODataDeserializerException {
+ try {
+ final XMLEventReader reader = getReader(input);
+ final StartElement start = skipBeforeFirstStartElement(reader);
+ return getContainer(start, entitySet(reader, start));
+ } catch (XMLStreamException e) {
+ throw new ODataDeserializerException(e);
+ }
}
- private XMLODataErrorImpl error(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
- final XMLODataErrorImpl error = new XMLODataErrorImpl();
+ private ODataError error(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
+ final ODataErrorImpl error = new ODataErrorImpl();
boolean setCode = false;
boolean codeSet = false;
@@ -835,10 +859,15 @@ public class AtomDeserializer extends AbstractAtomDealer {
return error;
}
- private ResWrap<XMLODataErrorImpl> error(final InputStream input) throws XMLStreamException {
- final XMLEventReader reader = getReader(input);
- final StartElement start = skipBeforeFirstStartElement(reader);
- return getContainer(start, error(reader, start));
+ @Override
+ public ODataError toError(final InputStream input) throws ODataDeserializerException {
+ try {
+ final XMLEventReader reader = getReader(input);
+ final StartElement start = skipBeforeFirstStartElement(reader);
+ return error(reader, start);
+ } catch (XMLStreamException e) {
+ throw new ODataDeserializerException(e);
+ }
}
private <T> ResWrap<T> getContainer(final StartElement start, final T object) {
@@ -846,28 +875,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
final Attribute metadataETag = start.getAttributeByName(metadataEtagQName);
return new ResWrap<T>(
- context == null ? null : URI.create(context.getValue()),
- metadataETag == null ? null : metadataETag.getValue(),
- object);
- }
-
- @SuppressWarnings("unchecked")
- public <T, V extends T> ResWrap<T> read(final InputStream input, final Class<V> reference)
- throws XMLStreamException {
-
- if (XMLODataErrorImpl.class.equals(reference)) {
- return (ResWrap<T>) error(input);
- } else if (AtomEntitySetImpl.class.equals(reference)) {
- return (ResWrap<T>) entitySet(input);
- } else if (AtomEntityImpl.class.equals(reference)) {
- return (ResWrap<T>) entity(input);
- } else if (AtomPropertyImpl.class.equals(reference)) {
- return (ResWrap<T>) property(input);
- } else if (XMLLinkCollectionImpl.class.equals(reference)) {
- return (ResWrap<T>) linkCollection(input);
- } else if (AtomDeltaImpl.class.equals(reference)) {
- return (ResWrap<T>) delta(input);
- }
- return null;
+ context == null ? null : URI.create(context.getValue()),
+ metadataETag == null ? null : metadataETag.getValue(),
+ object);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntityImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntityImpl.java
deleted file mode 100644
index 6c7fb13..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntityImpl.java
+++ /dev/null
@@ -1,25 +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;
-
-public class AtomEntityImpl extends AbstractEntity {
-
- private static final long serialVersionUID = 6973729343868293279L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntitySetImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntitySetImpl.java
deleted file mode 100644
index 397b18e..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomEntitySetImpl.java
+++ /dev/null
@@ -1,28 +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;
-
-/**
- * List of entries, represented via Atom.
- */
-public class AtomEntitySetImpl extends AbstractEntitySet {
-
- private static final long serialVersionUID = 5466590540021319153L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyImpl.java
deleted file mode 100644
index e0018bc..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomPropertyImpl.java
+++ /dev/null
@@ -1,25 +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;
-
-public class AtomPropertyImpl extends AbstractProperty {
-
- private static final long serialVersionUID = 48748492242474814L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
index 200a4bf..3d4eae6 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java
@@ -18,31 +18,36 @@
*/
package org.apache.olingo.commons.core.data;
-import com.fasterxml.aalto.stax.OutputFactoryImpl;
import java.io.Writer;
import java.util.Collections;
import java.util.List;
+
import javax.xml.XMLConstants;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.Annotation;
import org.apache.olingo.commons.api.data.CollectionValue;
-import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Value;
import org.apache.olingo.commons.api.domain.ODataOperation;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.op.ODataSerializer;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-public class AtomSerializer extends AbstractAtomDealer {
+import com.fasterxml.aalto.stax.OutputFactoryImpl;
+
+public class AtomSerializer extends AbstractAtomDealer implements ODataSerializer {
private static final XMLOutputFactory FACTORY = new OutputFactoryImpl();
@@ -64,10 +69,10 @@ public class AtomSerializer extends AbstractAtomDealer {
for (Value item : value.get()) {
if (version.compareTo(ODataServiceVersion.V40) < 0) {
writer.writeStartElement(Constants.PREFIX_DATASERVICES, Constants.ELEM_ELEMENT,
- version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
+ version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
} else {
writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT,
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
+ version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
}
value(writer, item);
writer.writeEndElement();
@@ -91,14 +96,14 @@ public class AtomSerializer extends AbstractAtomDealer {
}
public void property(final XMLStreamWriter writer, final Property property, final boolean standalone)
- throws XMLStreamException {
+ throws XMLStreamException {
if (version.compareTo(ODataServiceVersion.V40) >= 0 && standalone) {
writer.writeStartElement(Constants.PREFIX_METADATA, Constants.VALUE,
- version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
+ version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
} else {
writer.writeStartElement(Constants.PREFIX_DATASERVICES, property.getName(),
- version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
+ version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
}
if (standalone) {
@@ -109,13 +114,13 @@ public class AtomSerializer extends AbstractAtomDealer {
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(property.getType()).build();
if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) {
writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATTR_TYPE, typeInfo.external(version));
+ Constants.ATTR_TYPE, typeInfo.external(version));
}
}
if (property.getValue().isNull()) {
writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATTR_NULL, Boolean.TRUE.toString());
+ Constants.ATTR_NULL, Boolean.TRUE.toString());
} else {
value(writer, property.getValue());
if (property.getValue().isLinkedComplex()) {
@@ -174,7 +179,7 @@ public class AtomSerializer extends AbstractAtomDealer {
if (link.getInlineEntity() != null || link.getInlineEntitySet() != null) {
writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE,
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
+ version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
if (link.getInlineEntity() != null) {
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
@@ -214,10 +219,10 @@ public class AtomSerializer extends AbstractAtomDealer {
}
private void annotation(final XMLStreamWriter writer, final Annotation annotation, final String target)
- throws XMLStreamException {
+ throws XMLStreamException {
writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ANNOTATION,
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
+ version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
writer.writeAttribute(Constants.ATOM_ATTR_TERM, annotation.getTerm());
@@ -229,13 +234,13 @@ public class AtomSerializer extends AbstractAtomDealer {
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build();
if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) {
writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATTR_TYPE, typeInfo.external(version));
+ Constants.ATTR_TYPE, typeInfo.external(version));
}
}
if (annotation.getValue().isNull()) {
writer.writeAttribute(Constants.PREFIX_METADATA, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATTR_NULL, Boolean.TRUE.toString());
+ Constants.ATTR_NULL, Boolean.TRUE.toString());
} else {
value(writer, annotation.getValue());
}
@@ -250,8 +255,8 @@ public class AtomSerializer extends AbstractAtomDealer {
if (serverMode && StringUtils.isNotBlank(entity.getETag())) {
writer.writeAttribute(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATOM_ATTR_ETAG, entity.getETag());
+ version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
+ Constants.ATOM_ATTR_ETAG, entity.getETag());
}
if (entity.getId() != null) {
@@ -264,7 +269,7 @@ public class AtomSerializer extends AbstractAtomDealer {
writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
if (StringUtils.isNotBlank(entity.getType())) {
writer.writeAttribute(Constants.ATOM_ATTR_TERM,
- new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version));
+ new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version));
}
writer.writeEndElement();
@@ -289,7 +294,7 @@ public class AtomSerializer extends AbstractAtomDealer {
if (serverMode) {
for (ODataOperation operation : entity.getOperations()) {
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_TITLE, operation.getTitle());
writer.writeAttribute(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
@@ -384,7 +389,7 @@ public class AtomSerializer extends AbstractAtomDealer {
if (entitySet.getCount() != null) {
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(entitySet.getCount()));
writer.writeEndElement();
}
@@ -416,14 +421,14 @@ public class AtomSerializer extends AbstractAtomDealer {
next.setRel(Constants.NEXT_LINK_REL);
next.setHref(entitySet.getNext().toASCIIString());
- links(writer, Collections.<Link>singletonList(next));
+ links(writer, Collections.<Link> singletonList(next));
}
if (entitySet.getDeltaLink() != null) {
final LinkImpl next = new LinkImpl();
next.setRel(Constants.DELTA_LINK_REL);
next.setHref(entitySet.getDeltaLink().toASCIIString());
- links(writer, Collections.<Link>singletonList(next));
+ links(writer, Collections.<Link> singletonList(next));
}
}
}
@@ -472,56 +477,64 @@ public class AtomSerializer extends AbstractAtomDealer {
writer.flush();
}
- public <T> void write(final Writer writer, final T obj) throws XMLStreamException {
- if (obj instanceof EntitySet) {
- entitySet(writer, (EntitySet) obj);
- } else if (obj instanceof Entity) {
- entity(writer, (Entity) obj);
- } else if (obj instanceof Property) {
- property(writer, (Property) obj);
- } else if (obj instanceof Link) {
- link(writer, (Link) obj);
+ public <T> void write(final Writer writer, final T obj) throws ODataSerializerException {
+ try {
+ if (obj instanceof EntitySet) {
+ entitySet(writer, (EntitySet) obj);
+ } else if (obj instanceof Entity) {
+ entity(writer, (Entity) obj);
+ } else if (obj instanceof Property) {
+ property(writer, (Property) obj);
+ } else if (obj instanceof Link) {
+ link(writer, (Link) obj);
+ }
+ } catch (final XMLStreamException e) {
+ throw new ODataSerializerException(e);
}
}
@SuppressWarnings("unchecked")
- 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 ODataSerializerException {
final T obj = container == null ? null : container.getPayload();
- if (obj instanceof EntitySet) {
- this.entitySet(writer, (ResWrap<EntitySet>) container);
- } else if (obj instanceof Entity) {
- entity(writer, (ResWrap<Entity>) container);
- } else if (obj instanceof Property) {
- property(writer, (Property) obj);
- } else if (obj instanceof Link) {
- link(writer, (Link) obj);
+ try {
+ if (obj instanceof EntitySet) {
+ this.entitySet(writer, (ResWrap<EntitySet>) container);
+ } else if (obj instanceof Entity) {
+ entity(writer, (ResWrap<Entity>) container);
+ } else if (obj instanceof Property) {
+ property(writer, (Property) obj);
+ } else if (obj instanceof Link) {
+ link(writer, (Link) obj);
+ }
+ } catch (final XMLStreamException e) {
+ throw new ODataSerializerException(e);
}
}
private <T> void addContextInfo(
- final XMLStreamWriter writer, final ResWrap<T> container) throws XMLStreamException {
+ final XMLStreamWriter writer, final ResWrap<T> container) throws XMLStreamException {
if (container.getContextURL() != null) {
String base = container.getContextURL().getServiceRoot().toASCIIString();
- if (container.getPayload() instanceof AtomEntitySetImpl) {
- ((AtomEntitySetImpl) container.getPayload()).setBaseURI(base);
+ if (container.getPayload() instanceof EntitySet) {
+ ((EntitySetImpl) container.getPayload()).setBaseURI(base);
}
- if (container.getPayload() instanceof AtomEntityImpl) {
- ((AtomEntityImpl) container.getPayload()).setBaseURI(base);
+ if (container.getPayload() instanceof Entity) {
+ ((EntityImpl) container.getPayload()).setBaseURI(base);
}
writer.writeAttribute(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.CONTEXT,
- container.getContextURL().getURI().toASCIIString());
+ version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
+ Constants.CONTEXT,
+ container.getContextURL().getURI().toASCIIString());
}
if (StringUtils.isNotBlank(container.getMetadataETag())) {
writer.writeAttribute(
- version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
- Constants.ATOM_ATTR_METADATAETAG,
- container.getMetadataETag());
+ version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
+ Constants.ATOM_ATTR_METADATAETAG,
+ container.getMetadataETag());
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java
new file mode 100755
index 0000000..28451a9
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java
@@ -0,0 +1,193 @@
+/*
+ * 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.Entity;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.domain.ODataOperation;
+
+/**
+ * Class implementing an OData entity.
+ */
+public class EntityImpl extends AbstractODataObject implements Entity {
+
+ private static final long serialVersionUID = 2127764552600969783L;
+
+ private String eTag;
+
+ private String type;
+
+ private Link readLink;
+
+ private Link editLink;
+
+ private final List<Link> associationLinks = new ArrayList<Link>();
+
+ private final List<Link> navigationLinks = new ArrayList<Link>();
+
+ private final List<Link> mediaEditLinks = new ArrayList<Link>();
+
+ private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
+
+ private final List<Property> properties = new ArrayList<Property>();
+
+ private URI mediaContentSource;
+
+ private String mediaContentType;
+
+ private String mediaETag;
+
+ @Override
+ public String getETag() {
+ return eTag;
+ }
+
+ public void setETag(final String eTag) {
+ this.eTag = eTag;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ @Override
+ public Link getSelfLink() {
+ return readLink;
+ }
+
+ @Override
+ public void setSelfLink(final Link readLink) {
+ this.readLink = readLink;
+ }
+
+ @Override
+ public Link getEditLink() {
+ return editLink;
+ }
+
+ @Override
+ public void setEditLink(final Link editLink) {
+ this.editLink = editLink;
+ }
+
+ private Link getOneByTitle(final String name, final List<Link> links) {
+ Link result = null;
+
+ for (Link link : links) {
+ if (name.equals(link.getTitle())) {
+ result = link;
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public Link getAssociationLink(final String name) {
+ return getOneByTitle(name, associationLinks);
+ }
+
+ @Override
+ public List<Link> getAssociationLinks() {
+ return associationLinks;
+ }
+
+ @Override
+ public Link getNavigationLink(final String name) {
+ return getOneByTitle(name, navigationLinks);
+ }
+
+ @Override
+ public List<Link> getNavigationLinks() {
+ return navigationLinks;
+ }
+
+ @Override
+ public List<Link> getMediaEditLinks() {
+ return mediaEditLinks;
+ }
+
+ @Override
+ public List<ODataOperation> getOperations() {
+ return operations;
+ }
+
+ @Override
+ public List<Property> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public Property getProperty(final String name) {
+ Property result = null;
+
+ for (Property property : properties) {
+ if (name.equals(property.getName())) {
+ result = property;
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public String getMediaContentType() {
+ return this.mediaContentType;
+ }
+
+ @Override
+ public void setMediaContentType(final String mediaContentType) {
+ this.mediaContentType = mediaContentType;
+ }
+
+ @Override
+ public URI getMediaContentSource() {
+ return this.mediaContentSource;
+ }
+
+ @Override
+ public void setMediaContentSource(final URI mediaContentSource) {
+ this.mediaContentSource = mediaContentSource;
+ }
+
+ @Override
+ public String getMediaETag() {
+ return mediaETag;
+ }
+
+ @Override
+ public void setMediaETag(final String eTag) {
+ this.mediaETag = eTag;
+ }
+
+ @Override
+ public boolean isMediaEntity() {
+ return this.mediaContentSource != null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java
new file mode 100755
index 0000000..1920809
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java
@@ -0,0 +1,74 @@
+/*
+ * 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.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+
+public class EntitySetImpl extends AbstractODataObject implements EntitySet {
+
+ private static final long serialVersionUID = -9159884750819150969L;
+
+ private Integer count;
+
+ private final List<Entity> entities = new ArrayList<Entity>();
+
+ private URI next;
+
+ private URI deltaLink;
+
+ @Override
+ public void setCount(final Integer count) {
+ this.count = count;
+ }
+
+ @Override
+ public Integer getCount() {
+ return count;
+ }
+
+ @Override
+ public List<Entity> getEntities() {
+ return entities;
+ }
+
+ @Override
+ public void setNext(final URI next) {
+ this.next = next;
+ }
+
+ @Override
+ public URI getNext() {
+ return next;
+ }
+
+ @Override
+ public URI getDeltaLink() {
+ return deltaLink;
+ }
+
+ @Override
+ public void setDeltaLink(final URI deltaLink) {
+ this.deltaLink = deltaLink;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java
index f712e74..9ca82f1 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONDeltaDeserializer.java
@@ -18,37 +18,40 @@
*/
package org.apache.olingo.commons.core.data;
-import org.apache.olingo.commons.core.data.v4.JSONDeltaImpl;
-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.io.InputStream;
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.Delta;
import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.v4.DeltaImpl;
-public class JSONDeltaDeserializer extends AbstractJsonDeserializer<JSONDeltaImpl> {
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
- @Override
- protected ResWrap<JSONDeltaImpl> doDeserialize(final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+public class JSONDeltaDeserializer extends JsonDeserializer {
+
+ public JSONDeltaDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
+
+ protected ResWrap<Delta> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = parser.getCodec().readTree(parser);
- final JSONDeltaImpl delta = new JSONDeltaImpl();
+ final DeltaImpl delta = new DeltaImpl();
- final URI contextURL;
- if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
- contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue());
- } else {
- contextURL = null;
- }
+ final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ?
+ URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null;
if (contextURL != null) {
delta.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
}
@@ -64,17 +67,15 @@ public class JSONDeltaDeserializer extends AbstractJsonDeserializer<JSONDeltaImp
}
if (tree.hasNonNull(Constants.VALUE)) {
+ JSONEntityDeserializer entityDeserializer = new JSONEntityDeserializer(version, serverMode);
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;
+ ? 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());
+ delta.getEntities().add(entityDeserializer.doDeserialize(item.traverse(parser.getCodec())).getPayload());
} else if (itemContextURL.isDeltaDeletedEntity()) {
delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntityImpl.class));
} else if (itemContextURL.isDeltaLink()) {
@@ -85,7 +86,15 @@ public class JSONDeltaDeserializer extends AbstractJsonDeserializer<JSONDeltaImp
}
}
- return new ResWrap<JSONDeltaImpl>(contextURL, null, delta);
+ return new ResWrap<Delta>(contextURL, null, delta);
}
+ public ResWrap<Delta> toDelta(InputStream input) throws ODataDeserializerException {
+ try {
+ JsonParser parser = new JsonFactory(new ObjectMapper()).createParser(input);
+ return doDeserialize(parser);
+ } catch (final IOException e) {
+ throw new ODataDeserializerException(e);
+ }
+ }
}
[6/9] First presentable state
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java
index 2f54ecd..6cd8b7a 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/ODataWriter.java
@@ -19,13 +19,14 @@
package org.apache.olingo.client.api.op;
import java.io.InputStream;
-import java.io.Serializable;
import java.util.Collection;
+
import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
/**
* OData writer.
@@ -34,7 +35,7 @@ import org.apache.olingo.commons.api.format.ODataPubFormat;
* <br/>
* This interface provides method helpers to serialize a set of entities and a single entity as well.
*/
-public interface ODataWriter extends Serializable {
+public interface ODataWriter {
/**
* Writes a collection of OData entities.
@@ -42,8 +43,10 @@ public interface ODataWriter extends Serializable {
* @param entities entities to be serialized.
* @param format serialization format.
* @return stream of serialized objects.
+ * @throws ODataSerializerException
*/
- InputStream writeEntities(Collection<CommonODataEntity> entities, ODataPubFormat format);
+ InputStream writeEntities(Collection<CommonODataEntity> entities, ODataPubFormat format)
+ throws ODataSerializerException;
/**
* Serializes a single OData entity.
@@ -51,8 +54,10 @@ public interface ODataWriter extends Serializable {
* @param entity entity to be serialized.
* @param format serialization format.
* @return stream of serialized object.
+ * @throws ODataSerializerException
*/
- InputStream writeEntity(CommonODataEntity entity, ODataPubFormat format);
+ InputStream writeEntity(CommonODataEntity entity, ODataPubFormat format)
+ throws ODataSerializerException;
/**
* Writes a single OData entity property.
@@ -60,8 +65,10 @@ public interface ODataWriter extends Serializable {
* @param property entity property to be serialized.
* @param format serialization format.
* @return stream of serialized object.
+ * @throws ODataSerializerException
*/
- InputStream writeProperty(CommonODataProperty property, ODataFormat format);
+ InputStream writeProperty(CommonODataProperty property, ODataFormat format)
+ throws ODataSerializerException;
/**
* Writes an OData link.
@@ -69,6 +76,8 @@ public interface ODataWriter extends Serializable {
* @param link link to be serialized.
* @param format serialization format.
* @return stream of serialized object.
+ * @throws ODataSerializerException
*/
- InputStream writeLink(ODataLink link, ODataFormat format);
+ InputStream writeLink(ODataLink link, ODataFormat format)
+ throws ODataSerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataDeserializer.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataDeserializer.java
index ff559a1..e71ed05 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataDeserializer.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataDeserializer.java
@@ -19,10 +19,11 @@
package org.apache.olingo.client.api.op.v3;
import java.io.InputStream;
+
import org.apache.olingo.client.api.op.ClientODataDeserializer;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.v3.LinkCollection;
-import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
public interface ODataDeserializer extends ClientODataDeserializer {
@@ -30,9 +31,8 @@ public interface ODataDeserializer extends ClientODataDeserializer {
* Gets a list of links from the given InputStream.
*
* @param input stream to be de-serialized.
- * @param format OData format.
* @return de-serialized links.
+ * @throws ODataDeserializerException
*/
- ResWrap<LinkCollection> toLinkCollection(InputStream input, ODataFormat format);
-
+ ResWrap<LinkCollection> toLinkCollection(InputStream input) throws ODataDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataReader.java
index 2e72ce4..4b91f16 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataReader.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v3/ODataReader.java
@@ -19,6 +19,7 @@
package org.apache.olingo.client.api.op.v3;
import java.io.InputStream;
+
import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.client.api.op.CommonODataReader;
@@ -26,17 +27,18 @@ 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.ODataProperty;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
public interface ODataReader extends CommonODataReader {
@Override
- ODataEntitySet readEntitySet(InputStream input, ODataPubFormat format);
+ ODataEntitySet readEntitySet(InputStream input, ODataPubFormat format) throws ODataDeserializerException;
@Override
- ODataEntity readEntity(InputStream input, ODataPubFormat format);
+ ODataEntity readEntity(InputStream input, ODataPubFormat format) throws ODataDeserializerException;
@Override
- ODataProperty readProperty(InputStream input, ODataFormat format);
+ ODataProperty readProperty(InputStream input, ODataFormat format) throws ODataDeserializerException;
/**
* Parses a $links request response.
@@ -45,6 +47,5 @@ public interface ODataReader extends CommonODataReader {
* @param format de-serialize as XML or JSON
* @return List of URIs.
*/
- ODataLinkCollection readLinks(InputStream input, ODataFormat format);
-
+ ODataLinkCollection readLinks(InputStream input, ODataFormat format) throws ODataDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java
index 199e98f..e20c66e 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataDeserializer.java
@@ -24,7 +24,7 @@ import org.apache.olingo.client.api.edm.xml.v4.XMLMetadata;
import org.apache.olingo.client.api.op.ClientODataDeserializer;
import org.apache.olingo.commons.api.data.Delta;
import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
public interface ODataDeserializer extends ClientODataDeserializer {
@@ -35,8 +35,8 @@ public interface ODataDeserializer extends ClientODataDeserializer {
* Gets a delta object from the given InputStream.
*
* @param input stream to be de-serialized.
- * @param format Atom or JSON
* @return {@link Delta} instance.
+ * @throws ODataDeserializerException
*/
- ResWrap<Delta> toDelta(InputStream input, ODataPubFormat format);
+ ResWrap<Delta> toDelta(InputStream input) throws ODataDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataReader.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataReader.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataReader.java
index c976c05..8877e7e 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataReader.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/op/v4/ODataReader.java
@@ -19,21 +19,23 @@
package org.apache.olingo.client.api.op.v4;
import java.io.InputStream;
+
import org.apache.olingo.client.api.op.CommonODataReader;
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.ODataProperty;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
public interface ODataReader extends CommonODataReader {
@Override
- ODataEntitySet readEntitySet(InputStream input, ODataPubFormat format);
+ ODataEntitySet readEntitySet(InputStream input, ODataPubFormat format) throws ODataDeserializerException;
@Override
- ODataEntity readEntity(InputStream input, ODataPubFormat format);
+ ODataEntity readEntity(InputStream input, ODataPubFormat format) throws ODataDeserializerException;
@Override
- ODataProperty readProperty(InputStream input, ODataFormat format);
+ ODataProperty readProperty(InputStream input, ODataFormat format) throws ODataDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java
index 7606313..86e5b6d 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java
@@ -29,6 +29,7 @@ import org.apache.olingo.client.api.op.v3.ODataReader;
import org.apache.olingo.client.api.uri.v3.URIBuilder;
import org.apache.olingo.client.api.uri.v3.FilterFactory;
import org.apache.olingo.commons.api.domain.v3.ODataObjectFactory;
+import org.apache.olingo.commons.api.format.Format;
public interface ODataClient extends CommonODataClient<UpdateType> {
@@ -36,7 +37,7 @@ public interface ODataClient extends CommonODataClient<UpdateType> {
Configuration getConfiguration();
@Override
- ODataDeserializer getDeserializer();
+ ODataDeserializer getDeserializer(Format format);
@Override
ODataReader getReader();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java
index eff7ce7..383a488 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java
@@ -31,6 +31,7 @@ import org.apache.olingo.client.api.uri.v4.URIBuilder;
import org.apache.olingo.client.api.uri.v4.FilterFactory;
import org.apache.olingo.client.api.uri.v4.SearchFactory;
import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory;
+import org.apache.olingo.commons.api.format.Format;
public interface ODataClient extends CommonODataClient<UpdateType> {
@@ -38,7 +39,7 @@ public interface ODataClient extends CommonODataClient<UpdateType> {
Configuration getConfiguration();
@Override
- ODataDeserializer getDeserializer();
+ ODataDeserializer getDeserializer(Format format);
@Override
ODataReader getReader();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
index 0632c42..da9b40f 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
@@ -16,8 +16,6 @@
package org.apache.olingo.client.core.communication.request;
import java.io.IOException;
-import java.io.InputStream;
-import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -26,11 +24,11 @@ import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.ODataServerErrorException;
-import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.domain.ODataError;
-import org.apache.olingo.commons.core.data.JSONODataErrorImpl;
-import org.apache.olingo.commons.core.data.XMLODataErrorImpl;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.ODataErrorImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,36 +39,28 @@ public abstract class AbstractRequest {
*/
protected static final Logger LOG = LoggerFactory.getLogger(AbstractRequest.class);
- private ODataError getGenericError(final int code, final String errorMsg, final boolean isXML) {
- final ODataError error;
- if (isXML) {
- error = new XMLODataErrorImpl();
- ((XMLODataErrorImpl) error).setCode(String.valueOf(code));
- ((XMLODataErrorImpl) error).setMessage(errorMsg);
- } else {
- error = new JSONODataErrorImpl();
- ((JSONODataErrorImpl) error).setCode(String.valueOf(code));
- ((JSONODataErrorImpl) error).setMessage(errorMsg);
- }
-
+ private ODataError getGenericError(final int code, final String errorMsg) {
+ final ODataErrorImpl error = new ODataErrorImpl();
+ error.setCode(String.valueOf(code));
+ error.setMessage(errorMsg);
return error;
}
protected void checkRequest(final CommonODataClient<?> odataClient, final HttpUriRequest request) {
// If using and Edm enabled client, checks that the cached service root matches the request URI
if (odataClient instanceof CommonEdmEnabledODataClient
- && !request.getURI().toASCIIString().startsWith(
+ && !request.getURI().toASCIIString().startsWith(
((CommonEdmEnabledODataClient) odataClient).getServiceRoot())) {
throw new IllegalArgumentException(
- String.format("The current request URI %s does not match the configured service root %s",
+ String.format("The current request URI %s does not match the configured service root %s",
request.getURI().toASCIIString(),
((CommonEdmEnabledODataClient) odataClient).getServiceRoot()));
}
}
protected void checkResponse(
- final CommonODataClient<?> odataClient, final HttpResponse response, final String accept) {
+ final CommonODataClient<?> odataClient, final HttpResponse response, final String accept) {
if (response.getStatusLine().getStatusCode() >= 400) {
try {
@@ -78,27 +68,21 @@ public abstract class AbstractRequest {
if (httpEntity == null) {
throw new ODataClientErrorException(response.getStatusLine());
} else {
- boolean isXML;
- if (!accept.contains("json") && !accept.contains("xml")) {
- isXML = true;
- for (Header header : response.getHeaders(HeaderName.contentType.toString())) {
- if (header.getValue() != null && header.getValue().contains("json")) {
- isXML = false;
- }
- }
- } else {
- isXML = !accept.contains("json");
- }
+ ODataFormat format = accept.contains("xml") ? ODataFormat.XML : ODataFormat.JSON;
ODataError error;
try {
- error = odataClient.getReader().readError(httpEntity.getContent(), isXML);
- } catch (IllegalArgumentException e) {
+ error = odataClient.getReader().readError(httpEntity.getContent(), format);
+ } catch (final RuntimeException e) {
+ LOG.warn("Error deserializing error response", e);
+ error = getGenericError(
+ response.getStatusLine().getStatusCode(),
+ response.getStatusLine().getReasonPhrase());
+ } catch (final ODataDeserializerException e) {
LOG.warn("Error deserializing error response", e);
error = getGenericError(
- response.getStatusLine().getStatusCode(),
- response.getStatusLine().getReasonPhrase(),
- isXML);
+ response.getStatusLine().getStatusCode(),
+ response.getStatusLine().getReasonPhrase());
}
if (response.getStatusLine().getStatusCode() >= 500) {
@@ -109,7 +93,7 @@ public abstract class AbstractRequest {
}
} catch (IOException e) {
throw new HttpClientException(
- "Received '" + response.getStatusLine() + "' but could not extract error body", e);
+ "Received '" + response.getStatusLine() + "' but could not extract error body", e);
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java
index 2822d82..10236e0 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.cud;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -29,6 +30,9 @@ import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateR
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
@@ -67,7 +71,11 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
*/
@Override
protected InputStream getPayload() {
- return odataClient.getWriter().writeEntity(entity, ODataPubFormat.fromString(getContentType()));
+ try {
+ return odataClient.getWriter().writeEntity(entity, ODataPubFormat.fromString(getContentType()));
+ } catch (final ODataSerializerException e) {
+ throw new HttpClientException(e);
+ }
}
/**
@@ -119,10 +127,12 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
public E getBody() {
if (entity == null) {
try {
- final ResWrap<Entity> resource = odataClient.getDeserializer().
- toEntity(getRawResponse(), ODataPubFormat.fromString(getAccept()));
+ final ResWrap<Entity> resource = odataClient.getDeserializer(ODataPubFormat.fromString(getAccept()))
+ .toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java
index c3b8359..acbe764 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.cud;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -29,6 +30,9 @@ import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateR
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
@@ -42,8 +46,8 @@ import org.apache.olingo.commons.api.data.Entity;
* @param <E> concrete ODataEntity implementation
*/
public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
- extends AbstractODataBasicRequest<ODataEntityUpdateResponse<E>, ODataPubFormat>
- implements ODataEntityUpdateRequest<E> {
+ extends AbstractODataBasicRequest<ODataEntityUpdateResponse<E>, ODataPubFormat>
+ implements ODataEntityUpdateRequest<E> {
/**
* Changes to be applied.
@@ -59,7 +63,7 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
* @param changes changes to be applied.
*/
public ODataEntityUpdateRequestImpl(final CommonODataClient<?> odataClient,
- final HttpMethod method, final URI uri, final E changes) {
+ final HttpMethod method, final URI uri, final E changes) {
super(odataClient, ODataPubFormat.class, method, uri);
this.changes = changes;
@@ -80,12 +84,13 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
}
}
- /**
- * {@inheritDoc }
- */
@Override
protected InputStream getPayload() {
- return odataClient.getWriter().writeEntity(changes, ODataPubFormat.fromString(getContentType()));
+ try {
+ return odataClient.getWriter().writeEntity(changes, ODataPubFormat.fromString(getContentType()));
+ } catch (final ODataSerializerException e) {
+ throw new HttpClientException(e);
+ }
}
/**
@@ -103,8 +108,7 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
* <p>
* Just to create response templates to be initialized from batch.
*/
- private ODataEntityUpdateResponseImpl() {
- }
+ private ODataEntityUpdateResponseImpl() {}
/**
* Constructor.
@@ -116,18 +120,17 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
super(client, res);
}
- /**
- * {@inheritDoc ]
- */
@Override
@SuppressWarnings("unchecked")
public E getBody() {
if (entity == null) {
try {
- final ResWrap<Entity> resource = odataClient.getDeserializer().
- toEntity(getRawResponse(), ODataPubFormat.fromString(getAccept()));
+ final ResWrap<Entity> resource = odataClient.getDeserializer(ODataPubFormat.fromString(getAccept()))
+ .toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
index fe2fdbb..759ebbb 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.cud;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -27,14 +28,17 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
-import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
-import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
/**
* This class implements an OData update entity property request.
@@ -77,7 +81,11 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
@Override
protected InputStream getPayload() {
- return odataClient.getWriter().writeProperty(property, ODataFormat.fromString(getContentType()));
+ try {
+ return odataClient.getWriter().writeProperty(property, ODataFormat.fromString(getContentType()));
+ } catch (final ODataSerializerException e) {
+ throw new HttpClientException(e);
+ }
}
/**
@@ -105,17 +113,16 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
super(client, res);
}
- /**
- * {@inheritDoc }
- */
@Override
public CommonODataProperty getBody() {
if (property == null) {
try {
- final ResWrap<Property> resource = odataClient.getDeserializer().
- toProperty(getRawResponse(), ODataFormat.fromString(getAccept()));
+ final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept()))
+ .toProperty(getRawResponse());
property = odataClient.getBinder().getODataProperty(resource);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkCreateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkCreateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkCreateRequestImpl.java
index 7c97ec3..df31813 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkCreateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkCreateRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.cud.v3;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -29,6 +30,8 @@ import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkCreate
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
@@ -52,7 +55,7 @@ public class ODataLinkCreateRequestImpl extends AbstractODataBasicRequest<ODataL
* @param targetURI entity set URI.
* @param link entity to be linked.
*/
- ODataLinkCreateRequestImpl(final CommonODataClient odataClient, final URI targetURI, final ODataLink link) {
+ ODataLinkCreateRequestImpl(final CommonODataClient<?> odataClient, final URI targetURI, final ODataLink link) {
super(odataClient, ODataFormat.class, HttpMethod.POST, targetURI);
// set request body
this.link = link;
@@ -73,12 +76,13 @@ public class ODataLinkCreateRequestImpl extends AbstractODataBasicRequest<ODataL
}
}
- /**
- * {@inheritDoc}
- */
@Override
protected InputStream getPayload() {
- return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
+ try {
+ return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
+ } catch (final ODataSerializerException e) {
+ throw new HttpClientException(e);
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java
index c445cc0..ae1756c 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.cud.v3;
import java.io.InputStream;
import java.net.URI;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -29,6 +30,8 @@ import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkUpdate
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
@@ -53,7 +56,7 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
* @param targetURI entity URI.
* @param link entity to be linked.
*/
- ODataLinkUpdateRequestImpl(final CommonODataClient odataClient,
+ ODataLinkUpdateRequestImpl(final CommonODataClient<?> odataClient,
final HttpMethod method, final URI targetURI, final ODataLink link) {
super(odataClient, ODataFormat.class, method, targetURI);
@@ -61,9 +64,6 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
this.link = link;
}
- /**
- * {@inheritDoc }
- */
@Override
public ODataLinkOperationResponse execute() {
final InputStream input = getPayload();
@@ -76,12 +76,13 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
}
}
- /**
- * {@inheritDoc }
- */
@Override
protected InputStream getPayload() {
- return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
+ try {
+ return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
+ } catch (final ODataSerializerException e) {
+ throw new HttpClientException(e);
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
index 5cf9308..bcd45d9 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -40,6 +41,8 @@ import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.api.v4.ODataClient;
@@ -137,7 +140,11 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
}
}
- return odataClient.getWriter().writeEntity(tmp, getPOSTParameterFormat());
+ try {
+ return odataClient.getWriter().writeEntity(tmp, getPOSTParameterFormat());
+ } catch (final ODataSerializerException e) {
+ throw new HttpClientException(e);
+ }
}
return null;
@@ -216,6 +223,8 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
}
} catch (IOException e) {
throw new HttpClientException(e);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
index 8652086..2904577 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
@@ -19,15 +19,18 @@
package org.apache.olingo.client.core.communication.request.retrieve;
import java.net.URI;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
* This class implements an OData retrieve query request returning a single entity.
@@ -81,10 +84,12 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
public E getBody() {
if (entity == null) {
try {
- final ResWrap<Entity> resource = odataClient.getDeserializer().
- toEntity(getRawResponse(), ODataPubFormat.fromString(getContentType()));
+ final ResWrap<Entity> resource = odataClient.getDeserializer(ODataPubFormat.fromString(getContentType()))
+ .toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
index 1783789..90df1e2 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
@@ -19,15 +19,18 @@
package org.apache.olingo.client.core.communication.request.retrieve;
import java.net.URI;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
* This class implements an OData EntitySet query request.
@@ -45,7 +48,7 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
* @param odataClient client instance getting this request
* @param query query to be executed.
*/
- public ODataEntitySetRequestImpl(final CommonODataClient odataClient, final URI query) {
+ public ODataEntitySetRequestImpl(final CommonODataClient<?> odataClient, final URI query) {
super(odataClient, ODataPubFormat.class, query);
}
@@ -90,10 +93,12 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
public ES getBody() {
if (entitySet == null) {
try {
- final ResWrap<EntitySet> resource = odataClient.getDeserializer().
- toEntitySet(getRawResponse(), ODataPubFormat.fromString(getContentType()));
+ final ResWrap<EntitySet> resource = odataClient.getDeserializer(ODataPubFormat.fromString(getContentType()))
+ .toEntitySet(getRawResponse());
entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java
index f0d6924..0be7920 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.retrieve;
import java.io.IOException;
import java.net.URI;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
@@ -27,6 +28,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataProperty
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Property;
@@ -80,12 +82,14 @@ public class ODataPropertyRequestImpl<T extends CommonODataProperty>
public T getBody() {
if (property == null) {
try {
- final ResWrap<Property> resource = odataClient.getDeserializer().toProperty(
- res.getEntity().getContent(), ODataFormat.fromString(getContentType()));
+ final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType()))
+ .toProperty(res.getEntity().getContent());
property = (T) odataClient.getBinder().getODataProperty(resource);
} catch (IOException e) {
throw new HttpClientException(e);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java
index 003a013..faa8a28 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.communication.request.retrieve;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
+
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -28,6 +29,8 @@ import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
import org.apache.olingo.client.api.communication.response.ODataRawResponse;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
@@ -45,7 +48,7 @@ public class ODataRawRequestImpl extends AbstractODataRequest<ODataPubFormat>
* @param odataClient client instance getting this request
* @param uri request URI.
*/
- ODataRawRequestImpl(final CommonODataClient odataClient, final URI uri) {
+ ODataRawRequestImpl(final CommonODataClient<?> odataClient, final URI uri) {
super(odataClient, ODataPubFormat.class, HttpMethod.GET, uri);
}
@@ -94,8 +97,12 @@ public class ODataRawRequestImpl extends AbstractODataRequest<ODataPubFormat>
}
}
- return odataClient.getReader().
- read(new ByteArrayInputStream(obj), getContentType(), reference);
+ try {
+ return odataClient.getReader().
+ read(new ByteArrayInputStream(obj), getContentType(), reference);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
index 2222c0d..b8605f9 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
@@ -19,21 +19,24 @@
package org.apache.olingo.client.core.communication.request.retrieve;
import java.net.URI;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
* This class implements an OData service document request.
*/
public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveRequest<ODataServiceDocument, ODataFormat>
- implements ODataServiceDocumentRequest {
+ implements ODataServiceDocumentRequest {
/**
* Constructor.
@@ -41,7 +44,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
* @param odataClient client instance getting this request
* @param uri request URI.
*/
- ODataServiceDocumentRequestImpl(final CommonODataClient odataClient, final URI uri) {
+ ODataServiceDocumentRequestImpl(final CommonODataClient<?> odataClient, final URI uri) {
super(odataClient, ODataFormat.class, uri);
}
@@ -66,8 +69,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
* <p>
* Just to create response templates to be initialized from batch.
*/
- private ODataServiceResponseImpl() {
- }
+ private ODataServiceResponseImpl() {}
/**
* Constructor.
@@ -83,10 +85,13 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
public ODataServiceDocument getBody() {
if (serviceDocument == null) {
try {
- final ResWrap<ServiceDocument> resource = odataClient.getDeserializer().
- toServiceDocument(getRawResponse(), ODataFormat.fromString(getContentType()));
+ final ResWrap<ServiceDocument> resource =
+ odataClient.getDeserializer(ODataFormat.fromString(getContentType()))
+ .toServiceDocument(getRawResponse());
serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload());
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java
index e64a764..9cd5419 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.retrieve.v3;
import java.io.IOException;
import java.net.URI;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.v3.ODataClient;
@@ -27,6 +28,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.v3.ODataLinkC
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.core.communication.request.retrieve.AbstractODataRetrieveRequest;
@@ -78,9 +80,6 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest
super(client, res);
}
- /**
- * {@inheritDoc }
- */
@Override
public ODataLinkCollection getBody() {
if (links == null) {
@@ -89,6 +88,8 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest
res.getEntity().getContent(), ODataFormat.fromString(getContentType()));
} catch (IOException e) {
throw new HttpClientException(e);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java
index 8a480ee..1304b84 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.communication.request.retrieve.v3;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -30,6 +31,7 @@ import org.apache.olingo.client.api.edm.xml.Schema;
import org.apache.olingo.client.api.edm.xml.XMLMetadata;
import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.client.core.communication.request.retrieve.AbstractMetadataRequestImpl;
+import org.apache.olingo.commons.api.format.ODataFormat;
public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<String, Schema>>
implements XMLMetadataRequest {
@@ -71,7 +73,8 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
if (schemas == null) {
schemas = new HashMap<String, Schema>();
try {
- final XMLMetadata metadata = odataClient.getDeserializer().toMetadata(getRawResponse());
+ final XMLMetadata metadata = odataClient.getDeserializer(ODataFormat.XML)
+ .toMetadata(getRawResponse());
for (Schema schema : metadata.getSchemas()) {
schemas.put(schema.getNamespace(), schema);
if (StringUtils.isNotBlank(schema.getAlias())) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java
index 570eb36..00a61cc 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.retrieve.v4;
import java.io.IOException;
import java.net.URI;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
@@ -32,9 +33,10 @@ import org.apache.olingo.commons.api.data.Delta;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.v4.ODataDelta;
import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDelta, ODataPubFormat>
- implements ODataDeltaRequest {
+ implements ODataDeltaRequest {
public ODataDeltaRequestImpl(final CommonODataClient<?> odataClient, final URI query) {
super(odataClient, ODataPubFormat.class, query);
@@ -64,12 +66,15 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDel
public ODataDelta getBody() {
if (delta == null) {
try {
- final ResWrap<Delta> resource = ((ODataClient) odataClient).getDeserializer().toDelta(
- res.getEntity().getContent(), ODataPubFormat.fromString(getContentType()));
+ final ResWrap<Delta> resource = ((ODataClient) odataClient)
+ .getDeserializer(ODataPubFormat.fromString(getContentType()))
+ .toDelta(res.getEntity().getContent());
delta = ((ODataClient) odataClient).getBinder().getODataDelta(resource);
} catch (IOException e) {
throw new HttpClientException(e);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java
index 865b95c..88fb07a 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.communication.request.retrieve.v4;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
@@ -35,6 +36,7 @@ import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.communication.request.retrieve.AbstractMetadataRequestImpl;
import org.apache.olingo.client.core.edm.xml.v4.AnnotationsImpl;
import org.apache.olingo.client.core.edm.xml.v4.SchemaImpl;
+import org.apache.olingo.commons.api.format.ODataFormat;
public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<String, Schema>>
implements XMLMetadataRequest {
@@ -132,7 +134,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
@Override
public XMLMetadata getBody() {
try {
- return ((ODataClient) odataClient).getDeserializer().toMetadata(getRawResponse());
+ return ((ODataClient) odataClient).getDeserializer(ODataFormat.XML).toMetadata(getRawResponse());
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
index 60bca42..4e27bea 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityCreateRequestImpl.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.communication.request.streamed;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.TimeUnit;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
@@ -28,11 +29,13 @@ import org.apache.olingo.client.api.communication.request.streamed.MediaEntityCr
import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
import org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
* This class implements an OData Media Entity create request. Get instance by using ODataStreamedRequestFactory.
@@ -115,17 +118,17 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
super(client, res);
}
- /**
- * {@inheritDoc }
- */
@Override
@SuppressWarnings("unchecked")
public E getBody() {
if (entity == null) {
try {
- final ResWrap<Entity> resource = odataClient.getDeserializer().toEntity(getRawResponse(), getFormat());
+ final ResWrap<Entity> resource = odataClient.getDeserializer(getFormat())
+ .toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
index a63efa8..f06bed2 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core.communication.request.streamed;
import java.io.InputStream;
import java.net.URI;
import java.util.concurrent.TimeUnit;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
@@ -28,11 +29,13 @@ import org.apache.olingo.client.api.communication.request.streamed.MediaEntityUp
import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataMediaEntityUpdateResponse;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
* This class implements an OData Media Entity create request. Get instance by using ODataStreamedRequestFactory.
@@ -122,9 +125,11 @@ public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
public E getBody() {
if (entity == null) {
try {
- final ResWrap<Entity> resource = odataClient.getDeserializer().toEntity(getRawResponse(), getFormat());
+ final ResWrap<Entity> resource = odataClient.getDeserializer(getFormat()).toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource);
+ } catch (final ODataDeserializerException e) {
+ throw new HttpClientException(e);
} finally {
this.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractServiceDocument.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractServiceDocument.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractServiceDocument.java
deleted file mode 100644
index 9631e85..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/AbstractServiceDocument.java
+++ /dev/null
@@ -1,139 +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.client.core.data;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.api.data.ServiceDocumentItem;
-import org.apache.olingo.commons.api.Constants;
-
-public abstract class AbstractServiceDocument implements ServiceDocument {
-
- private String title;
-
- private final List<ServiceDocumentItem> entitySets = new ArrayList<ServiceDocumentItem>();
-
- private String metadata;
-
- @Override
- public URI getBaseURI() {
- URI baseURI = null;
- if (metadata != null) {
- final String metadataURI = getMetadata();
- baseURI = URI.create(metadataURI.substring(0, metadataURI.indexOf(Constants.METADATA)));
- }
-
- return baseURI;
- }
-
- /**
- * Gets the metadata URI.
- *
- * @return the metadata URI
- */
- public String getMetadata() {
- return metadata;
- }
-
- /**
- * Sets the metadata URI.
- *
- * @param metadata metadata URI.
- */
- public void setMetadata(final String metadata) {
- this.metadata = metadata;
- }
-
- @Override
- public String getTitle() {
- return title;
- }
-
- public void setTitle(final String title) {
- this.title = title;
- }
-
- protected ServiceDocumentItem getByName(final List<ServiceDocumentItem> elements, final String name) {
- ServiceDocumentItem result = null;
- for (ServiceDocumentItem element : elements) {
- if (name.equals(element.getName())) {
- result = element;
- }
- }
- return result;
- }
-
- @Override
- public List<ServiceDocumentItem> getEntitySets() {
- return entitySets;
- }
-
- @Override
- public ServiceDocumentItem getEntitySetByName(final String name) {
- return getByName(getEntitySets(), name);
- }
-
- @Override
- public List<ServiceDocumentItem> getFunctionImports() {
- return Collections.<ServiceDocumentItem>emptyList();
- }
-
- @Override
- public ServiceDocumentItem getFunctionImportByName(final String name) {
- return getByName(getFunctionImports(), name);
- }
-
- @Override
- public List<ServiceDocumentItem> getSingletons() {
- return Collections.<ServiceDocumentItem>emptyList();
- }
-
- @Override
- public ServiceDocumentItem getSingletonByName(final String name) {
- return getByName(getSingletons(), name);
- }
-
- @Override
- public List<ServiceDocumentItem> getRelatedServiceDocuments() {
- return Collections.<ServiceDocumentItem>emptyList();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
- }
-
- @Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
- }
-
- @Override
- public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java
index 4f84fc6..1bf5c4d 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java
@@ -18,34 +18,36 @@
*/
package org.apache.olingo.client.core.data;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-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.io.InputStream;
import java.net.URI;
import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.data.ODataJacksonDeserializer;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.JsonDeserializer;
-public class JSONServiceDocumentDeserializer extends ODataJacksonDeserializer<ResWrap<AbstractServiceDocument>> {
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
- @Override
- protected ResWrap<AbstractServiceDocument> doDeserialize(
- final JsonParser parser, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+public class JSONServiceDocumentDeserializer extends JsonDeserializer {
+
+ public JSONServiceDocumentDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
+
+ protected ResWrap<ServiceDocument> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser);
- final AbstractServiceDocument serviceDocument = ODataServiceVersion.V30 == version
- ? new org.apache.olingo.client.core.data.v3.JSONServiceDocumentImpl()
- : new org.apache.olingo.client.core.data.v4.JSONServiceDocumentImpl();
+ ServiceDocumentImpl serviceDocument = new ServiceDocumentImpl();
final String metadataETag;
if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
@@ -87,6 +89,15 @@ public class JSONServiceDocumentDeserializer extends ODataJacksonDeserializer<Re
}
}
- return new ResWrap<AbstractServiceDocument>(contextURL, metadataETag, serviceDocument);
+ return new ResWrap<ServiceDocument>(contextURL, metadataETag, serviceDocument);
+ }
+
+ public ResWrap<ServiceDocument> toServiceDocument(final InputStream input) throws ODataDeserializerException {
+ try {
+ JsonParser parser = new JsonFactory(new ObjectMapper()).createParser(input);
+ return doDeserialize(parser);
+ } catch (final IOException e) {
+ throw new ODataDeserializerException(e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentImpl.java
new file mode 100755
index 0000000..ec10e9d
--- /dev/null
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentImpl.java
@@ -0,0 +1,141 @@
+/*
+ * 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.client.core.data;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.client.api.data.ServiceDocumentItem;
+import org.apache.olingo.commons.api.Constants;
+
+public class ServiceDocumentImpl implements ServiceDocument {
+
+ private String title;
+
+ private final List<ServiceDocumentItem> entitySets = new ArrayList<ServiceDocumentItem>();
+ private final List<ServiceDocumentItem> functionImports = new ArrayList<ServiceDocumentItem>();
+ private final List<ServiceDocumentItem> singletons = new ArrayList<ServiceDocumentItem>();
+ private final List<ServiceDocumentItem> relatedServiceDocuments = new ArrayList<ServiceDocumentItem>();
+
+ private String metadata;
+
+ @Override
+ public URI getBaseURI() {
+ URI baseURI = null;
+ if (metadata != null) {
+ final String metadataURI = getMetadata();
+ baseURI = URI.create(metadataURI.substring(0, metadataURI.indexOf(Constants.METADATA)));
+ }
+
+ return baseURI;
+ }
+
+ /**
+ * Gets the metadata URI.
+ *
+ * @return the metadata URI
+ */
+ public String getMetadata() {
+ return metadata;
+ }
+
+ /**
+ * Sets the metadata URI.
+ *
+ * @param metadata metadata URI.
+ */
+ public void setMetadata(final String metadata) {
+ this.metadata = metadata;
+ }
+
+ @Override
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(final String title) {
+ this.title = title;
+ }
+
+ protected ServiceDocumentItem getByName(final List<ServiceDocumentItem> elements, final String name) {
+ ServiceDocumentItem result = null;
+ for (ServiceDocumentItem element : elements) {
+ if (name.equals(element.getName())) {
+ result = element;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public List<ServiceDocumentItem> getEntitySets() {
+ return entitySets;
+ }
+
+ @Override
+ public ServiceDocumentItem getEntitySetByName(final String name) {
+ return getByName(getEntitySets(), name);
+ }
+
+ @Override
+ public List<ServiceDocumentItem> getFunctionImports() {
+ return functionImports;
+ }
+
+ @Override
+ public ServiceDocumentItem getFunctionImportByName(final String name) {
+ return getByName(getFunctionImports(), name);
+ }
+
+ @Override
+ public List<ServiceDocumentItem> getSingletons() {
+ return singletons;
+ }
+
+ @Override
+ public ServiceDocumentItem getSingletonByName(final String name) {
+ return getByName(getSingletons(), name);
+ }
+
+ @Override
+ public List<ServiceDocumentItem> getRelatedServiceDocuments() {
+ return relatedServiceDocuments;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return EqualsBuilder.reflectionEquals(this, obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeBuilder.reflectionHashCode(this);
+ }
+
+ @Override
+ public String toString() {
+ return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java
index 6b38382..22d5dc8 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java
@@ -18,22 +18,27 @@
*/
package org.apache.olingo.client.core.data;
-import org.apache.olingo.commons.core.data.ODataJacksonDeserializer;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.JsonToken;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
-
import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.op.ODataDeserializerException;
+import org.apache.olingo.commons.core.data.JsonDeserializer;
-public class XMLServiceDocumentDeserializer extends ODataJacksonDeserializer<ResWrap<ServiceDocument>> {
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.dataformat.xml.XmlFactory;
+import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
+
+public class XMLServiceDocumentDeserializer extends JsonDeserializer {
+
+ public XMLServiceDocumentDeserializer(final ODataServiceVersion version, final boolean serverMode) {
+ super(version, serverMode);
+ }
private String getName(final JsonParser jp) throws IOException {
String title = jp.nextTextValue();
@@ -47,11 +52,11 @@ public class XMLServiceDocumentDeserializer extends ODataJacksonDeserializer<Res
}
private ServiceDocumentItemImpl deserializeElement(final JsonParser jp, final String elementName)
- throws IOException {
+ throws IOException {
final ServiceDocumentItemImpl element = new ServiceDocumentItemImpl();
for (; jp.getCurrentToken() != JsonToken.END_OBJECT
- || !elementName.equals(((FromXmlParser) jp).getStaxReader().getLocalName()); jp.nextToken()) {
+ || !elementName.equals(((FromXmlParser) jp).getStaxReader().getLocalName()); jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
@@ -66,20 +71,16 @@ public class XMLServiceDocumentDeserializer extends ODataJacksonDeserializer<Res
return element;
}
- @Override
- protected ResWrap<ServiceDocument> doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
- throws IOException, JsonProcessingException {
+ protected ResWrap<ServiceDocument> doDeserialize(final JsonParser jp) throws IOException {
- final AbstractServiceDocument sdoc = ODataServiceVersion.V30 == version
- ? new org.apache.olingo.client.core.data.v3.XMLServiceDocumentImpl()
- : new org.apache.olingo.client.core.data.v4.XMLServiceDocumentImpl();
+ ServiceDocumentImpl sdoc = new ServiceDocumentImpl();
URI contextURL = null;
String metadataETag = null;
String base = null;
for (; jp.getCurrentToken() != JsonToken.END_OBJECT
- || !"service".equals(((FromXmlParser) jp).getStaxReader().getLocalName()); jp.nextToken()) {
+ || !"service".equals(((FromXmlParser) jp).getStaxReader().getLocalName()); jp.nextToken()) {
final JsonToken token = jp.getCurrentToken();
if (token == JsonToken.FIELD_NAME) {
@@ -112,11 +113,20 @@ public class XMLServiceDocumentDeserializer extends ODataJacksonDeserializer<Res
}
sdoc.setMetadata((contextURL == null
- ? URIUtils.getURI(base, "$metadata")
- : URIUtils.getURI(base, contextURL.toASCIIString())).toASCIIString());
+ ? URIUtils.getURI(base, "$metadata")
+ : URIUtils.getURI(base, contextURL.toASCIIString())).toASCIIString());
return new ResWrap<ServiceDocument>(
- contextURL == null ? null : URIUtils.getURI(sdoc.getBaseURI(), contextURL),
- metadataETag, sdoc);
+ contextURL == null ? null : URIUtils.getURI(sdoc.getBaseURI(), contextURL),
+ metadataETag, sdoc);
+ }
+
+ public ResWrap<ServiceDocument> toServiceDocument(InputStream input) throws ODataDeserializerException {
+ try {
+ JsonParser parser = new XmlFactory().createParser(input);
+ return doDeserialize(parser);
+ } catch (final IOException e) {
+ throw new ODataDeserializerException(e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/JSONServiceDocumentImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/JSONServiceDocumentImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/JSONServiceDocumentImpl.java
deleted file mode 100644
index af957a1..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/JSONServiceDocumentImpl.java
+++ /dev/null
@@ -1,35 +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.client.core.data.v3;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-
-
-import org.apache.olingo.client.core.data.AbstractServiceDocument;
-import org.apache.olingo.client.core.data.JSONServiceDocumentDeserializer;
-
-/**
- * Service document, represented via JSON.
- */
-@JsonDeserialize(using = JSONServiceDocumentDeserializer.class)
-public class JSONServiceDocumentImpl extends AbstractServiceDocument {
-
- private static final long serialVersionUID = 4195734928526398830L;
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/XMLServiceDocumentImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/XMLServiceDocumentImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/XMLServiceDocumentImpl.java
deleted file mode 100644
index e09b092..0000000
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/v3/XMLServiceDocumentImpl.java
+++ /dev/null
@@ -1,30 +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.client.core.data.v3;
-
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-
-
-import org.apache.olingo.client.api.data.ServiceDocument;
-import org.apache.olingo.client.core.data.AbstractServiceDocument;
-import org.apache.olingo.client.core.data.XMLServiceDocumentDeserializer;
-
-@JsonDeserialize(using = XMLServiceDocumentDeserializer.class)
-public class XMLServiceDocumentImpl extends AbstractServiceDocument implements ServiceDocument {
-}
[9/9] git commit: First presentable state
Posted by mi...@apache.org.
First presentable state
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/bd9bf1e2
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/bd9bf1e2
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/bd9bf1e2
Branch: refs/heads/OLINGO-317_JSON-for-server
Commit: bd9bf1e267d589cfb6b058b8bd8eee4b716a41ef
Parents: 8ad297f
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Jun 6 14:46:07 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Jun 6 14:46:07 2014 +0200
----------------------------------------------------------------------
.../org/apache/olingo/fit/AbstractServices.java | 208 +++---
.../java/org/apache/olingo/fit/V4Services.java | 694 +++++++++----------
.../fit/serializer/JSONEntryContainer.java | 36 -
.../fit/serializer/JSONFeedContainer.java | 36 -
.../fit/serializer/JSONPropertyContainer.java | 36 -
.../olingo/fit/utils/AbstractUtilities.java | 367 +++++-----
.../org/apache/olingo/fit/utils/Commons.java | 65 +-
.../org/apache/olingo/fit/utils/DataBinder.java | 347 ----------
.../org/apache/olingo/fit/utils/FSManager.java | 20 +-
.../apache/olingo/fit/utils/JSONUtilities.java | 27 +-
.../olingo/fit/AbstractBaseTestITCase.java | 22 +-
.../fit/proxy/v4/MediaEntityTestITCase.java | 9 +-
.../NonTransactionalMediaEntityTestITCase.java | 3 +-
.../olingo/fit/v3/EntityRetrieveTestITCase.java | 7 +-
.../olingo/fit/v3/EntitySetTestITCase.java | 4 +-
.../fit/v4/JSONFormatConformanceTestITCase.java | 13 +-
.../olingo/client/api/CommonODataClient.java | 11 +-
.../api/domain/ODataEntitySetIterator.java | 20 +-
.../client/api/op/ClientODataDeserializer.java | 11 +-
.../olingo/client/api/op/CommonODataBinder.java | 19 +-
.../olingo/client/api/op/CommonODataReader.java | 27 +-
.../olingo/client/api/op/ODataWriter.java | 23 +-
.../client/api/op/v3/ODataDeserializer.java | 8 +-
.../olingo/client/api/op/v3/ODataReader.java | 11 +-
.../client/api/op/v4/ODataDeserializer.java | 6 +-
.../olingo/client/api/op/v4/ODataReader.java | 8 +-
.../olingo/client/api/v3/ODataClient.java | 3 +-
.../olingo/client/api/v4/ODataClient.java | 3 +-
.../communication/request/AbstractRequest.java | 58 +-
.../cud/ODataEntityCreateRequestImpl.java | 16 +-
.../cud/ODataEntityUpdateRequestImpl.java | 31 +-
.../cud/ODataPropertyUpdateRequestImpl.java | 27 +-
.../cud/v3/ODataLinkCreateRequestImpl.java | 14 +-
.../cud/v3/ODataLinkUpdateRequestImpl.java | 17 +-
.../invoke/AbstractODataInvokeRequest.java | 11 +-
.../retrieve/ODataEntityRequestImpl.java | 9 +-
.../retrieve/ODataEntitySetRequestImpl.java | 11 +-
.../retrieve/ODataPropertyRequestImpl.java | 8 +-
.../request/retrieve/ODataRawRequestImpl.java | 13 +-
.../ODataServiceDocumentRequestImpl.java | 17 +-
.../v3/ODataLinkCollectionRequestImpl.java | 7 +-
.../retrieve/v3/XMLMetadataRequestImpl.java | 5 +-
.../retrieve/v4/ODataDeltaRequestImpl.java | 11 +-
.../retrieve/v4/XMLMetadataRequestImpl.java | 4 +-
.../ODataMediaEntityCreateRequestImpl.java | 11 +-
.../ODataMediaEntityUpdateRequestImpl.java | 7 +-
.../core/data/AbstractServiceDocument.java | 139 ----
.../data/JSONServiceDocumentDeserializer.java | 43 +-
.../client/core/data/ServiceDocumentImpl.java | 141 ++++
.../data/XMLServiceDocumentDeserializer.java | 52 +-
.../core/data/v3/JSONServiceDocumentImpl.java | 35 -
.../core/data/v3/XMLServiceDocumentImpl.java | 30 -
.../core/data/v4/AbstractServiceDocument.java | 49 --
.../core/data/v4/JSONServiceDocumentImpl.java | 28 -
.../core/data/v4/XMLServiceDocumentImpl.java | 28 -
.../client/core/op/AbstractODataBinder.java | 154 ++--
.../client/core/op/AbstractODataReader.java | 32 +-
.../olingo/client/core/op/ODataWriterImpl.java | 55 +-
.../client/core/op/impl/v3/ODataBinderImpl.java | 12 +-
.../core/op/impl/v3/ODataDeserializerImpl.java | 44 +-
.../client/core/op/impl/v3/ODataReaderImpl.java | 28 +-
.../core/op/impl/v3/ODataSerializerImpl.java | 32 -
.../client/core/op/impl/v4/ODataBinderImpl.java | 51 +-
.../core/op/impl/v4/ODataDeserializerImpl.java | 45 +-
.../client/core/op/impl/v4/ODataReaderImpl.java | 19 +-
.../core/op/impl/v4/ODataSerializerImpl.java | 32 -
.../olingo/client/core/v3/ODataClientImpl.java | 35 +-
.../olingo/client/core/v4/ODataClientImpl.java | 33 +-
.../apache/olingo/client/core/v3/AtomTest.java | 15 +-
.../olingo/client/core/v3/EntitySetTest.java | 18 +-
.../olingo/client/core/v3/EntityTest.java | 59 +-
.../apache/olingo/client/core/v3/ErrorTest.java | 19 +-
.../olingo/client/core/v3/MetadataTest.java | 5 +-
.../olingo/client/core/v3/PropertyTest.java | 23 +-
.../client/core/v3/ServiceDocumentTest.java | 7 +-
.../olingo/client/core/v4/EntitySetTest.java | 25 +-
.../olingo/client/core/v4/EntityTest.java | 101 ++-
.../apache/olingo/client/core/v4/ErrorTest.java | 13 +-
.../apache/olingo/client/core/v4/JSONTest.java | 45 +-
.../olingo/client/core/v4/MetadataTest.java | 13 +-
.../olingo/client/core/v4/PropertyTest.java | 31 +-
.../client/core/v4/ServiceDocumentTest.java | 12 +-
.../commons/api/op/CommonODataDeserializer.java | 71 --
.../commons/api/op/ODataDeserializer.java | 65 ++
.../api/op/ODataDeserializerException.java | 38 +
.../olingo/commons/api/op/ODataSerializer.java | 79 +--
.../api/op/ODataSerializerException.java | 38 +
.../commons/core/data/AbstractEntity.java | 193 ------
.../commons/core/data/AbstractEntitySet.java | 74 --
.../core/data/AbstractJsonDeserializer.java | 372 ----------
.../core/data/AbstractJsonSerializer.java | 248 -------
.../commons/core/data/AbstractODataError.java | 89 ---
.../commons/core/data/AbstractProperty.java | 63 --
.../commons/core/data/AtomDeserializer.java | 259 +++----
.../commons/core/data/AtomEntityImpl.java | 25 -
.../commons/core/data/AtomEntitySetImpl.java | 28 -
.../commons/core/data/AtomPropertyImpl.java | 25 -
.../commons/core/data/AtomSerializer.java | 115 +--
.../olingo/commons/core/data/EntityImpl.java | 193 ++++++
.../olingo/commons/core/data/EntitySetImpl.java | 74 ++
.../core/data/JSONDeltaDeserializer.java | 57 +-
.../core/data/JSONEntityDeserializer.java | 29 +-
.../commons/core/data/JSONEntityImpl.java | 33 -
.../commons/core/data/JSONEntitySerializer.java | 33 +-
.../core/data/JSONEntitySetDeserializer.java | 34 +-
.../commons/core/data/JSONEntitySetImpl.java | 35 -
.../core/data/JSONEntitySetSerializer.java | 49 +-
.../core/data/JSONODataErrorDeserializer.java | 40 +-
.../data/JSONODataErrorDetailDeserializer.java | 25 +-
.../core/data/JSONODataErrorDetailImpl.java | 62 --
.../commons/core/data/JSONODataErrorImpl.java | 26 -
.../core/data/JSONPropertyDeserializer.java | 30 +-
.../commons/core/data/JSONPropertyImpl.java | 33 -
.../core/data/JSONPropertySerializer.java | 29 +-
.../commons/core/data/JsonDeserializer.java | 463 +++++++++++++
.../commons/core/data/JsonSerializer.java | 315 +++++++++
.../commons/core/data/ODataErrorDetailImpl.java | 57 ++
.../commons/core/data/ODataErrorImpl.java | 89 +++
.../core/data/ODataJacksonDeserializer.java | 98 ---
.../core/data/ODataJacksonSerializer.java | 57 --
.../olingo/commons/core/data/PropertyImpl.java | 63 ++
.../commons/core/data/XMLODataErrorImpl.java | 23 -
.../core/data/v3/LinkCollectionImpl.java | 78 +++
.../core/data/v3/XMLLinkCollectionImpl.java | 70 --
.../commons/core/data/v4/AbstractDelta.java | 52 --
.../commons/core/data/v4/AtomDeltaImpl.java | 25 -
.../olingo/commons/core/data/v4/DeltaImpl.java | 52 ++
.../commons/core/data/v4/JSONDeltaImpl.java | 29 -
.../commons/core/op/AbstractJacksonTool.java | 86 ---
.../core/op/AbstractODataDeserializer.java | 135 ++--
.../core/op/AbstractODataSerializer.java | 141 ----
.../olingo/commons/core/op/ResourceFactory.java | 125 ----
.../server/api/serializer/ODataSerializer.java | 8 +
.../apache/olingo/server/core/ODataHandler.java | 84 +++
.../core/serializer/ODataJsonSerializer.java | 104 +++
.../core/serializer/ODataXmlSerializerImpl.java | 15 +
136 files changed, 3749 insertions(+), 4808 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bd9bf1e2/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index 7fd0b58..71a7bf5 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -18,9 +18,6 @@
*/
package org.apache.olingo.fit;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -41,6 +38,7 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import javax.mail.Header;
import javax.mail.internet.MimeBodyPart;
import javax.ws.rs.Consumes;
@@ -61,6 +59,7 @@ import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
@@ -69,44 +68,45 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
import org.apache.olingo.commons.api.data.ComplexValue;
-import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.core.data.AtomEntitySetImpl;
-import org.apache.olingo.commons.core.data.LinkImpl;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.AtomPropertyImpl;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.op.ODataDeserializer;
+import org.apache.olingo.commons.api.op.ODataSerializer;
import org.apache.olingo.commons.core.data.AtomSerializer;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.apache.olingo.commons.core.data.JSONPropertyImpl;
+import org.apache.olingo.commons.core.data.EntityImpl;
+import org.apache.olingo.commons.core.data.JsonDeserializer;
+import org.apache.olingo.commons.core.data.JsonSerializer;
+import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.NullValueImpl;
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
+import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.fit.metadata.EntityType;
+import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.metadata.NavigationProperty;
import org.apache.olingo.fit.methods.MERGE;
import org.apache.olingo.fit.methods.PATCH;
import org.apache.olingo.fit.serializer.FITAtomDeserializer;
+import org.apache.olingo.fit.utils.AbstractUtilities;
import org.apache.olingo.fit.utils.Accept;
-import org.apache.olingo.fit.utils.FSManager;
import org.apache.olingo.fit.utils.Commons;
-import org.apache.olingo.fit.utils.JSONUtilities;
-import org.apache.olingo.fit.utils.AbstractUtilities;
-import org.apache.olingo.fit.utils.XMLUtilities;
-import org.apache.olingo.fit.utils.LinkInfo;
-import org.apache.olingo.fit.metadata.Metadata;
-import org.apache.olingo.fit.serializer.JSONFeedContainer;
-import org.apache.olingo.fit.serializer.JSONEntryContainer;
import org.apache.olingo.fit.utils.ConstantKey;
import org.apache.olingo.fit.utils.Constants;
-import org.apache.olingo.fit.utils.DataBinder;
+import org.apache.olingo.fit.utils.FSManager;
+import org.apache.olingo.fit.utils.JSONUtilities;
+import org.apache.olingo.fit.utils.LinkInfo;
+import org.apache.olingo.fit.utils.XMLUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
public abstract class AbstractServices {
/**
@@ -123,28 +123,24 @@ public abstract class AbstractServices {
protected static final String BOUNDARY = "batch_243234_25424_ef_892u748";
protected final ODataServiceVersion version;
-
protected final Metadata metadata;
- protected final FITAtomDeserializer atomDeserializer;
-
- protected final AtomSerializer atomSerializer;
-
- protected final ObjectMapper mapper;
-
- protected final DataBinder dataBinder;
+ protected final ODataDeserializer atomDeserializer;
+ protected final ODataDeserializer jsonDeserializer;
+ protected final ODataSerializer atomSerializer;
+ protected final ODataSerializer jsonSerializer;
protected final XMLUtilities xml;
-
protected final JSONUtilities json;
public AbstractServices(final ODataServiceVersion version, final Metadata metadata) throws Exception {
this.version = version;
this.metadata = metadata;
- this.atomDeserializer = Commons.getAtomDeserializer(version);
- this.atomSerializer = Commons.getAtomSerializer(version);
- this.mapper = Commons.getJSONMapper(version);
- this.dataBinder = new DataBinder(version, metadata);
+
+ atomDeserializer = new FITAtomDeserializer(version);
+ jsonDeserializer = new JsonDeserializer(version, true);
+ atomSerializer = new AtomSerializer(version, true);
+ jsonSerializer = new JsonSerializer(version, true);
this.xml = new XMLUtilities(version, metadata);
this.json = new JSONUtilities(version, metadata);
@@ -223,9 +219,9 @@ public abstract class AbstractServices {
@GET
@Path("/StoredPIs(1000)")
public Response getStoredPI(@Context UriInfo uriInfo) {
- final JSONEntityImpl entity = new JSONEntityImpl();
+ final Entity entity = new EntityImpl();
entity.setType("Microsoft.Test.OData.Services.ODataWCFService.StoredPI");
- final Property id = new JSONPropertyImpl();
+ final Property id = new PropertyImpl();
id.setType("Edm.Int32");
id.setName("StoredPIID");
id.setValue(new PrimitiveValueImpl("1000"));
@@ -239,7 +235,7 @@ public abstract class AbstractServices {
final ByteArrayOutputStream content = new ByteArrayOutputStream();
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
try {
- mapper.writeValue(writer, new JSONEntryContainer(null, null, entity));
+ jsonSerializer.write(writer, new ResWrap<Entity>((URI) null, null, entity));
return xml.createResponse(new ByteArrayInputStream(content.toByteArray()), null, Accept.JSON_FULLMETA);
} catch (Exception e) {
LOG.error("While creating StoredPI", e);
@@ -261,7 +257,7 @@ public abstract class AbstractServices {
protected Response bodyPartRequest(final MimeBodyPart body, final Map<String, String> references) throws Exception {
@SuppressWarnings("unchecked")
- final Enumeration<Header> en = (Enumeration<Header>) body.getAllHeaders();
+ final Enumeration<Header> en = body.getAllHeaders();
Header header = en.nextElement();
final String request =
@@ -455,22 +451,19 @@ public abstract class AbstractServices {
final Accept contentTypeValue = Accept.parse(contentType, version);
- final AtomEntityImpl entryChanges;
+ final Entity entryChanges;
if (contentTypeValue == Accept.XML || contentTypeValue == Accept.TEXT) {
throw new UnsupportedMediaTypeException("Unsupported media type");
} else if (contentTypeValue == Accept.ATOM) {
- entryChanges = atomDeserializer.<AtomEntityImpl, AtomEntityImpl>read(
- IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntityImpl.class).getPayload();
+ entryChanges = atomDeserializer.toEntity(
+ IOUtils.toInputStream(changes, Constants.ENCODING)).getPayload();
} else {
- final ResWrap<JSONEntityImpl> jcont = mapper.readValue(IOUtils.toInputStream(changes, Constants.ENCODING),
- new TypeReference<JSONEntityImpl>() {
- });
-
- entryChanges = dataBinder.toAtomEntity(jcont.getPayload());
+ final ResWrap<Entity> jcont = jsonDeserializer.toEntity(IOUtils.toInputStream(changes, Constants.ENCODING));
+ entryChanges = jcont.getPayload();
}
- final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entityInfo.getValue(), AtomEntityImpl.class);
+ final ResWrap<Entity> container = atomDeserializer.toEntity(entityInfo.getValue());
for (Property property : entryChanges.getProperties()) {
final Property _property = container.getPayload().getProperty(property.getName());
@@ -494,13 +487,13 @@ public abstract class AbstractServices {
final InputStream res = xml.addOrReplaceEntity(
entityId, entitySetName, new ByteArrayInputStream(content.toByteArray()), container.getPayload());
- final ResWrap<AtomEntityImpl> cres = atomDeserializer.read(res, AtomEntityImpl.class);
+ final ResWrap<Entity> cres = atomDeserializer.toEntity(res);
normalizeAtomEntry(cres.getPayload(), entitySetName, entityId);
final String path = Commons.getEntityBasePath(entitySetName, entityId);
FSManager.instance(version).putInMemory(
- cres, path + File.separatorChar + Constants.get(version, ConstantKey.ENTITY), dataBinder);
+ cres, path + File.separatorChar + Constants.get(version, ConstantKey.ENTITY));
final Response response;
if ("return-content".equalsIgnoreCase(prefer)) {
@@ -551,19 +544,16 @@ public abstract class AbstractServices {
IOUtils.toInputStream(entity, Constants.ENCODING),
xml.readEntity(acceptType, IOUtils.toInputStream(entity, Constants.ENCODING)));
- final ResWrap<AtomEntityImpl> cres;
+ final ResWrap<Entity> cres;
if (acceptType == Accept.ATOM) {
- cres = atomDeserializer.read(res, AtomEntityImpl.class);
+ cres = atomDeserializer.toEntity(res);
} else {
- final ResWrap<JSONEntityImpl> jcont = mapper.readValue(res, new TypeReference<JSONEntityImpl>() {
- });
- cres = new ResWrap<AtomEntityImpl>(jcont.getContextURL(), jcont.getMetadataETag(),
- dataBinder.toAtomEntity(jcont.getPayload()));
+ cres = jsonDeserializer.toEntity(res);
}
final String path = Commons.getEntityBasePath(entitySetName, entityId);
FSManager.instance(version).putInMemory(
- cres, path + File.separatorChar + Constants.get(version, ConstantKey.ENTITY), dataBinder);
+ cres, path + File.separatorChar + Constants.get(version, ConstantKey.ENTITY));
final Response response;
if ("return-content".equalsIgnoreCase(prefer)) {
@@ -611,14 +601,14 @@ public abstract class AbstractServices {
throw new UnsupportedMediaTypeException("Unsupported media type");
}
- final ResWrap<AtomEntityImpl> container;
+ final ResWrap<Entity> container;
final org.apache.olingo.fit.metadata.EntitySet entitySet = metadata.getEntitySet(entitySetName);
- final AtomEntityImpl entry;
+ final Entity entry;
final String entityKey;
if (xml.isMediaContent(entitySetName)) {
- entry = new AtomEntityImpl();
+ entry = new EntityImpl();
entry.setMediaContentType(ContentType.WILDCARD);
entry.setType(entitySet.getType());
@@ -628,7 +618,7 @@ public abstract class AbstractServices {
final Pair<String, EdmPrimitiveTypeKind> id = Commons.getMediaContent().get(entitySetName);
if (id != null) {
- final AtomPropertyImpl prop = new AtomPropertyImpl();
+ final Property prop = new PropertyImpl();
prop.setName(id.getKey());
prop.setType(id.getValue().toString());
prop.setValue(new PrimitiveValueImpl(entityKey));
@@ -643,21 +633,18 @@ public abstract class AbstractServices {
entry.setMediaContentSource(URI.create(editLink.getHref() + "/$value"));
- container = new ResWrap<AtomEntityImpl>((URI) null, null, entry);
+ container = new ResWrap<Entity>((URI) null, null, entry);
} else {
final Accept contentTypeValue = Accept.parse(contentType, version);
if (Accept.ATOM == contentTypeValue) {
- container = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntityImpl.class);
+ container = atomDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING));
entry = container.getPayload();
} else {
- final ResWrap<JSONEntityImpl> jcontainer =
- mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING),
- new TypeReference<JSONEntityImpl>() {
- });
-
- entry = dataBinder.toAtomEntity(jcontainer.getPayload());
+ final ResWrap<Entity> jcontainer = jsonDeserializer.toEntity(
+ IOUtils.toInputStream(entity, Constants.ENCODING));
+ entry = jcontainer.getPayload();
- container = new ResWrap<AtomEntityImpl>(
+ container = new ResWrap<Entity>(
jcontainer.getContextURL(),
jcontainer.getMetadataETag(),
entry);
@@ -677,14 +664,14 @@ public abstract class AbstractServices {
final InputStream serialization =
xml.addOrReplaceEntity(entityKey, entitySetName, new ByteArrayInputStream(content.toByteArray()), entry);
- ResWrap<AtomEntityImpl> result = atomDeserializer.read(serialization, AtomEntityImpl.class);
- result = new ResWrap<AtomEntityImpl>(
+ ResWrap<Entity> result = atomDeserializer.toEntity(serialization);
+ result = new ResWrap<Entity>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)),
null, result.getPayload());
final String path = Commons.getEntityBasePath(entitySetName, entityKey);
- FSManager.instance(version).putInMemory(result, path + Constants.get(version, ConstantKey.ENTITY), dataBinder);
+ FSManager.instance(version).putInMemory(result, path + Constants.get(version, ConstantKey.ENTITY));
final String location = uriInfo.getRequestUri().toASCIIString() + "(" + entityKey + ")";
@@ -734,7 +721,7 @@ public abstract class AbstractServices {
final Map.Entry<String, InputStream> entityInfo = xml.readEntity("Person", entityId, Accept.ATOM);
final InputStream entity = entityInfo.getValue();
- final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entity, AtomEntityImpl.class);
+ final ResWrap<Entity> container = atomDeserializer.toEntity(entity);
container.getPayload().getProperty("Salary").setValue(new PrimitiveValueImpl("0"));
container.getPayload().getProperty("Title").setValue(new PrimitiveValueImpl("[Sacked]"));
@@ -826,7 +813,7 @@ public abstract class AbstractServices {
final Map.Entry<String, InputStream> entityInfo = xml.readEntity("Product", entityId, Accept.ATOM);
final InputStream entity = entityInfo.getValue();
- final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entity, AtomEntityImpl.class);
+ final ResWrap<Entity> container = atomDeserializer.toEntity(entity);
final Entity param = xml.readEntity(utils.getKey(), IOUtils.toInputStream(argument, Constants.ENCODING));
@@ -861,7 +848,7 @@ public abstract class AbstractServices {
final Map.Entry<String, InputStream> entityInfo = xml.readEntity("ComputerDetail", entityId, Accept.ATOM);
final InputStream entity = entityInfo.getValue();
- final ResWrap<AtomEntityImpl> container = atomDeserializer.read(entity, AtomEntityImpl.class);
+ final ResWrap<Entity> container = atomDeserializer.toEntity(entity);
final Entity param = xml.readEntity(utils.getKey(), IOUtils.toInputStream(argument, Constants.ENCODING));
@@ -985,7 +972,7 @@ public abstract class AbstractServices {
final InputStream feed = FSManager.instance(version).readFile(builder.toString(), Accept.ATOM);
- final ResWrap<AtomEntitySetImpl> container = atomDeserializer.read(feed, AtomEntitySetImpl.class);
+ final ResWrap<EntitySet> container = atomDeserializer.toEntitySet(feed);
setInlineCount(container.getPayload(), count);
@@ -1011,13 +998,11 @@ public abstract class AbstractServices {
if (acceptType == Accept.ATOM) {
atomSerializer.write(writer, container);
- writer.flush();
- writer.close();
} else {
- mapper.writeValue(
- writer, new JSONFeedContainer(container.getContextURL(), container.getMetadataETag(),
- dataBinder.toJSONEntitySet(container.getPayload())));
+ jsonSerializer.write(writer, container);
}
+ writer.flush();
+ writer.close();
return xml.createResponse(
location,
@@ -1185,9 +1170,9 @@ public abstract class AbstractServices {
final InputStream entity = entityInfo.getValue();
- ResWrap<AtomEntityImpl> container = atomDeserializer.read(entity, AtomEntityImpl.class);
+ ResWrap<Entity> container = atomDeserializer.toEntity(entity);
if (container.getContextURL() == null) {
- container = new ResWrap<AtomEntityImpl>(URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ container = new ResWrap<Entity>(URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ entitySetName + Constants.get(version, ConstantKey.ODATA_METADATA_ENTITY_SUFFIX)),
container.getMetadataETag(), container.getPayload());
}
@@ -1241,15 +1226,13 @@ public abstract class AbstractServices {
rep.setType(link.getType());
if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_ENTRY))) {
// inline entry
- final Entity inline = atomDeserializer.<Entity, AtomEntityImpl>read(
- xml.expandEntity(entitySetName, entityId, link.getTitle()),
- AtomEntityImpl.class).getPayload();
+ final Entity inline = atomDeserializer.toEntity(
+ xml.expandEntity(entitySetName, entityId, link.getTitle())).getPayload();
rep.setInlineEntity(inline);
} else if (link.getType().equals(Constants.get(version, ConstantKey.ATOM_LINK_FEED))) {
// inline feed
- final EntitySet inline = atomDeserializer.<EntitySet, AtomEntitySetImpl>read(
- xml.expandEntity(entitySetName, entityId, link.getTitle()),
- AtomEntitySetImpl.class).getPayload();
+ final EntitySet inline = atomDeserializer.toEntitySet(
+ xml.expandEntity(entitySetName, entityId, link.getTitle())).getPayload();
rep.setInlineEntitySet(inline);
}
replace.put(link, rep);
@@ -1336,10 +1319,10 @@ public abstract class AbstractServices {
final FSManager fsManager = FSManager.instance(version);
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
- final ResWrap<AtomEntityImpl> container = xml.readContainerEntity(Accept.ATOM,
+ final ResWrap<Entity> container = xml.readContainerEntity(Accept.ATOM,
fsManager.readFile(basePath + Constants.get(version, ConstantKey.ENTITY), Accept.ATOM));
- final AtomEntityImpl entry = container.getPayload();
+ final Entity entry = container.getPayload();
Property toBeReplaced = null;
for (String element : path.split("/")) {
@@ -1363,7 +1346,7 @@ public abstract class AbstractServices {
// just for primitive values
toBeReplaced.setValue(new PrimitiveValueImpl(changes));
} else {
- final AtomPropertyImpl pchanges = xml.readProperty(
+ final Property pchanges = xml.readProperty(
Accept.parse(contentType, version),
IOUtils.toInputStream(changes, Constants.ENCODING),
entry.getType());
@@ -1639,7 +1622,6 @@ public abstract class AbstractServices {
* @param entityId
* @param path
* @param format
- * @param changes
* @return
*/
@DELETE
@@ -1729,34 +1711,24 @@ public abstract class AbstractServices {
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
if (linkInfo.isFeed()) {
- final ResWrap<EntitySet> container =
- atomDeserializer.<EntitySet, AtomEntitySetImpl>read(stream, AtomEntitySetImpl.class);
+ final ResWrap<EntitySet> container = atomDeserializer.toEntitySet(stream);
if (acceptType == Accept.ATOM) {
atomSerializer.write(writer, container);
- writer.flush();
- writer.close();
} else {
- mapper.writeValue(
- writer,
- new JSONFeedContainer(container.getContextURL(),
- container.getMetadataETag(),
- dataBinder.toJSONEntitySet((AtomEntitySetImpl) container.getPayload())));
+ jsonSerializer.write(writer, container);
}
+ writer.flush();
+ writer.close();
} else {
- final ResWrap<Entity> container =
- atomDeserializer.<Entity, AtomEntityImpl>read(stream, AtomEntityImpl.class);
+ final ResWrap<Entity> container = atomDeserializer.toEntity(stream);
if (acceptType == Accept.ATOM) {
atomSerializer.write(writer, container);
- writer.flush();
- writer.close();
} else {
- mapper.writeValue(
- writer,
- new JSONEntryContainer(container.getContextURL(),
- container.getMetadataETag(),
- dataBinder.toJSONEntity((AtomEntityImpl) container.getPayload())));
+ jsonSerializer.write(writer, container);
}
+ writer.flush();
+ writer.close();
}
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
@@ -1804,18 +1776,18 @@ public abstract class AbstractServices {
final InputStream entity = entityInfo.getValue();
- final ResWrap<AtomEntityImpl> entryContainer = atomDeserializer.read(entity, AtomEntityImpl.class);
+ final ResWrap<Entity> entryContainer = atomDeserializer.toEntity(entity);
final String[] pathElems = StringUtils.split(path, "/");
- AtomPropertyImpl property = (AtomPropertyImpl) entryContainer.getPayload().getProperty(pathElems[0]);
+ Property property = entryContainer.getPayload().getProperty(pathElems[0]);
if (pathElems.length > 1 && property.getValue().isComplex()) {
for (Property sub : property.getValue().asComplex().get()) {
if (pathElems[1].equals(sub.getName())) {
- property = (AtomPropertyImpl) sub;
+ property = sub;
if (pathElems.length > 2 && property.getValue().isComplex()) {
for (Property subsub : property.getValue().asComplex().get()) {
if (pathElems[2].equals(subsub.getName())) {
- property = (AtomPropertyImpl) subsub;
+ property = subsub;
}
}
}
@@ -1823,7 +1795,7 @@ public abstract class AbstractServices {
}
}
- final ResWrap<AtomPropertyImpl> container = new ResWrap<AtomPropertyImpl>(
+ final ResWrap<Property> container = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ (version.compareTo(ODataServiceVersion.V40) >= 0
? entitySetName + "(" + entityId + ")/" + path
@@ -1899,13 +1871,13 @@ public abstract class AbstractServices {
return utils;
}
- protected void normalizeAtomEntry(final AtomEntityImpl entry, final String entitySetName, final String entityKey) {
+ protected void normalizeAtomEntry(final Entity entry, final String entitySetName, final String entityKey) {
final org.apache.olingo.fit.metadata.EntitySet entitySet = metadata.getEntitySet(entitySetName);
final EntityType entityType = metadata.getEntityOrComplexType(entitySet.getType());
for (Map.Entry<String, org.apache.olingo.fit.metadata.Property> property
: entityType.getPropertyMap().entrySet()) {
if (entry.getProperty(property.getKey()) == null && property.getValue().isNullable()) {
- final AtomPropertyImpl prop = new AtomPropertyImpl();
+ final PropertyImpl prop = new PropertyImpl();
prop.setName(property.getKey());
prop.setValue(new NullValueImpl());
entry.getProperties().add(prop);