[OLINGO-200] More ref tests
This commit is contained in:
parent
525767c0c9
commit
6aaec814c4
|
@ -25,9 +25,9 @@ import static org.junit.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import org.apache.olingo.client.api.v4.ODataClient;
|
import org.apache.olingo.client.api.v4.ODataClient;
|
||||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
|
||||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||||
import org.apache.olingo.client.core.AbstractTest;
|
import org.apache.olingo.client.core.AbstractTest;
|
||||||
|
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||||
import org.apache.olingo.commons.core.op.ResourceFactory;
|
import org.apache.olingo.commons.core.op.ResourceFactory;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -48,8 +48,8 @@ public class EntitySetTest extends AbstractTest {
|
||||||
assertEquals(2, entitySet.getEntities().size());
|
assertEquals(2, entitySet.getEntities().size());
|
||||||
assertNull(entitySet.getNext());
|
assertNull(entitySet.getNext());
|
||||||
|
|
||||||
final CommonODataEntitySet written = getClient().getBinder().getODataEntitySet(getClient().
|
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(getClient().getBinder().
|
||||||
getBinder().getFeed(entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM)));
|
getFeed(entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM)));
|
||||||
assertEquals(entitySet, written);
|
assertEquals(entitySet, written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,4 +62,30 @@ public class EntitySetTest extends AbstractTest {
|
||||||
public void fromJSON() throws IOException {
|
public void fromJSON() throws IOException {
|
||||||
read(ODataPubFormat.JSON);
|
read(ODataPubFormat.JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ref(final ODataPubFormat format) {
|
||||||
|
final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(format));
|
||||||
|
final ODataEntitySet entitySet = getClient().getBinder().getODataEntitySet(
|
||||||
|
getClient().getDeserializer().toFeed(input, format).getObject());
|
||||||
|
assertNotNull(entitySet);
|
||||||
|
|
||||||
|
for (ODataEntity entity : entitySet.getEntities()) {
|
||||||
|
assertNotNull(entity.getReference());
|
||||||
|
}
|
||||||
|
entitySet.setCount(entitySet.getEntities().size());
|
||||||
|
|
||||||
|
final ODataEntitySet written = getClient().getBinder().getODataEntitySet(getClient().getBinder().
|
||||||
|
getFeed(entitySet, ResourceFactory.feedClassForFormat(format == ODataPubFormat.ATOM)));
|
||||||
|
assertEquals(entitySet, written);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void atomRef() {
|
||||||
|
ref(ODataPubFormat.ATOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jsonRef() {
|
||||||
|
ref(ODataPubFormat.JSON);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,4 +224,27 @@ public class EntityTest extends AbstractTest {
|
||||||
public void jsonWithStream() {
|
public void jsonWithStream() {
|
||||||
withStream(ODataPubFormat.JSON_FULL_METADATA);
|
withStream(ODataPubFormat.JSON_FULL_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ref(final ODataPubFormat format) {
|
||||||
|
final InputStream input = getClass().getResourceAsStream("entityReference." + getSuffix(format));
|
||||||
|
final ODataEntity entity = getClient().getBinder().getODataEntity(
|
||||||
|
getClient().getDeserializer().toEntry(input, format).getObject());
|
||||||
|
assertNotNull(entity);
|
||||||
|
|
||||||
|
assertNotNull(entity.getReference());
|
||||||
|
|
||||||
|
final ODataEntity written = getClient().getBinder().getODataEntity(getClient().getBinder().
|
||||||
|
getEntry(entity, ResourceFactory.entryClassForFormat(format == ODataPubFormat.ATOM)));
|
||||||
|
assertEquals(entity, written);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void atomRef() {
|
||||||
|
ref(ODataPubFormat.ATOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jsonRef() {
|
||||||
|
ref(ODataPubFormat.JSON);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,20 @@ public class JSONTest extends AbstractTest {
|
||||||
assertEquals(orig, OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())));
|
assertEquals(orig, OBJECT_MAPPER.readTree(new ByteArrayInputStream(actual.getBytes())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void feed(final String filename, final ODataPubFormat format) throws Exception {
|
||||||
|
final StringWriter writer = new StringWriter();
|
||||||
|
getClient().getSerializer().feed(getClient().getDeserializer().toFeed(
|
||||||
|
getClass().getResourceAsStream(filename + "." + getSuffix(format)), format).getObject(), writer);
|
||||||
|
|
||||||
|
assertSimilar(filename + "." + getSuffix(format), writer.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void feeds() throws Exception {
|
||||||
|
feed("Customers", getODataPubFormat());
|
||||||
|
feed("collectionOfEntityReferences", getODataPubFormat());
|
||||||
|
}
|
||||||
|
|
||||||
protected void entry(final String filename, final ODataPubFormat format) throws Exception {
|
protected void entry(final String filename, final ODataPubFormat format) throws Exception {
|
||||||
final StringWriter writer = new StringWriter();
|
final StringWriter writer = new StringWriter();
|
||||||
getClient().getSerializer().entry(getClient().getDeserializer().toEntry(
|
getClient().getSerializer().entry(getClient().getDeserializer().toEntry(
|
||||||
|
@ -137,6 +151,8 @@ public class JSONTest extends AbstractTest {
|
||||||
public void entries() throws Exception {
|
public void entries() throws Exception {
|
||||||
entry("Products_5", getODataPubFormat());
|
entry("Products_5", getODataPubFormat());
|
||||||
entry("VipCustomer", getODataPubFormat());
|
entry("VipCustomer", getODataPubFormat());
|
||||||
|
entry("Advertisements_f89dee73-af9f-4cd4-b330-db93c25ff3c7", getODataPubFormat());
|
||||||
|
entry("entityReference", getODataPubFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void property(final String filename, final ODataFormat format) throws Exception {
|
protected void property(final String filename, final ODataFormat format) throws Exception {
|
||||||
|
@ -150,5 +166,8 @@ public class JSONTest extends AbstractTest {
|
||||||
@Test
|
@Test
|
||||||
public void properties() throws Exception {
|
public void properties() throws Exception {
|
||||||
property("Products_5_SkinColor", getODataFormat());
|
property("Products_5_SkinColor", getODataFormat());
|
||||||
|
property("Products_5_CoverColors", getODataFormat());
|
||||||
|
property("Employees_3_HomeAddress", getODataFormat());
|
||||||
|
property("Employees_3_HomeAddress", getODataFormat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,26 +28,26 @@
|
||||||
m:context="http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Customers">
|
m:context="http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Customers">
|
||||||
<m:count>2</m:count>
|
<m:count>2</m:count>
|
||||||
<id>http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers</id>
|
<id>http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers</id>
|
||||||
<title />
|
<title/>
|
||||||
<updated>2014-03-31T09:35:14Z</updated>
|
<updated>2014-03-31T09:35:14Z</updated>
|
||||||
<entry>
|
<entry>
|
||||||
<id>http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)</id>
|
<id>http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)</id>
|
||||||
<category term="#Microsoft.Test.OData.Services.ODataWCFService.Customer" scheme="http://docs.oasis-open.org/odata/ns/scheme" />
|
<category term="#Microsoft.Test.OData.Services.ODataWCFService.Customer" scheme="http://docs.oasis-open.org/odata/ns/scheme"/>
|
||||||
<link rel="edit" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)" />
|
<link rel="edit" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)"/>
|
||||||
<link rel="http://docs.oasis-open.org/odata/ns/related/Parent" type="application/atom+xml;type=entry" title="Parent" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)/Parent" />
|
<link rel="http://docs.oasis-open.org/odata/ns/related/Parent" type="application/atom+xml;type=entry" title="Parent" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)/Parent"/>
|
||||||
<link rel="http://docs.oasis-open.org/odata/ns/related/Orders" type="application/atom+xml;type=feed" title="Orders" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)/Orders" />
|
<link rel="http://docs.oasis-open.org/odata/ns/related/Orders" type="application/atom+xml;type=feed" title="Orders" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)/Orders"/>
|
||||||
<link rel="http://docs.oasis-open.org/odata/ns/related/Company" type="application/atom+xml;type=entry" title="Company" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)/Company" />
|
<link rel="http://docs.oasis-open.org/odata/ns/related/Company" type="application/atom+xml;type=entry" title="Company" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=1)/Company"/>
|
||||||
<title />
|
<title/>
|
||||||
<updated>2014-03-31T09:35:14Z</updated>
|
<updated>2014-03-31T09:35:14Z</updated>
|
||||||
<author>
|
<author>
|
||||||
<name />
|
<name/>
|
||||||
</author>
|
</author>
|
||||||
<content type="application/xml">
|
<content type="application/xml">
|
||||||
<m:properties>
|
<m:properties>
|
||||||
<d:PersonID m:type="Int32">1</d:PersonID>
|
<d:PersonID m:type="Int32">1</d:PersonID>
|
||||||
<d:FirstName>Bob</d:FirstName>
|
<d:FirstName>Bob</d:FirstName>
|
||||||
<d:LastName>Cat</d:LastName>
|
<d:LastName>Cat</d:LastName>
|
||||||
<d:MiddleName m:null="true" />
|
<d:MiddleName m:null="true"/>
|
||||||
<d:HomeAddress m:type="#Microsoft.Test.OData.Services.ODataWCFService.HomeAddress">
|
<d:HomeAddress m:type="#Microsoft.Test.OData.Services.ODataWCFService.HomeAddress">
|
||||||
<d:Street>1 Microsoft Way</d:Street>
|
<d:Street>1 Microsoft Way</d:Street>
|
||||||
<d:City>London</d:City>
|
<d:City>London</d:City>
|
||||||
|
@ -73,30 +73,30 @@
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<id>http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)</id>
|
<id>http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)</id>
|
||||||
<category term="#Microsoft.Test.OData.Services.ODataWCFService.Customer" scheme="http://docs.oasis-open.org/odata/ns/scheme" />
|
<category term="#Microsoft.Test.OData.Services.ODataWCFService.Customer" scheme="http://docs.oasis-open.org/odata/ns/scheme"/>
|
||||||
<link rel="edit" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)" />
|
<link rel="edit" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)"/>
|
||||||
<link rel="http://docs.oasis-open.org/odata/ns/related/Parent" type="application/atom+xml;type=entry" title="Parent" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)/Parent" />
|
<link rel="http://docs.oasis-open.org/odata/ns/related/Parent" type="application/atom+xml;type=entry" title="Parent" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)/Parent"/>
|
||||||
<link rel="http://docs.oasis-open.org/odata/ns/related/Orders" type="application/atom+xml;type=feed" title="Orders" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)/Orders" />
|
<link rel="http://docs.oasis-open.org/odata/ns/related/Orders" type="application/atom+xml;type=feed" title="Orders" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)/Orders"/>
|
||||||
<link rel="http://docs.oasis-open.org/odata/ns/related/Company" type="application/atom+xml;type=entry" title="Company" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)/Company" />
|
<link rel="http://docs.oasis-open.org/odata/ns/related/Company" type="application/atom+xml;type=entry" title="Company" href="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Customers(PersonID=2)/Company"/>
|
||||||
<title />
|
<title/>
|
||||||
<updated>2014-03-31T09:35:14Z</updated>
|
<updated>2014-03-31T09:35:14Z</updated>
|
||||||
<author>
|
<author>
|
||||||
<name />
|
<name/>
|
||||||
</author>
|
</author>
|
||||||
<content type="application/xml">
|
<content type="application/xml">
|
||||||
<m:properties>
|
<m:properties>
|
||||||
<d:PersonID m:type="Int32">2</d:PersonID>
|
<d:PersonID m:type="Int32">2</d:PersonID>
|
||||||
<d:FirstName>Jill</d:FirstName>
|
<d:FirstName>Jill</d:FirstName>
|
||||||
<d:LastName>Jones</d:LastName>
|
<d:LastName>Jones</d:LastName>
|
||||||
<d:MiddleName m:null="true" />
|
<d:MiddleName m:null="true"/>
|
||||||
<d:HomeAddress m:null="true" />
|
<d:HomeAddress m:null="true"/>
|
||||||
<d:Home m:type="GeographyPoint">
|
<d:Home m:type="GeographyPoint">
|
||||||
<gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
|
<gml:Point gml:srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
|
||||||
<gml:pos>15 161.8</gml:pos>
|
<gml:pos>15.0 161.8</gml:pos>
|
||||||
</gml:Point>
|
</gml:Point>
|
||||||
</d:Home>
|
</d:Home>
|
||||||
<d:Numbers m:type="#Collection(String)" />
|
<d:Numbers m:type="#Collection(String)"/>
|
||||||
<d:Emails m:type="#Collection(String)" />
|
<d:Emails m:type="#Collection(String)"/>
|
||||||
<d:City>Sydney</d:City>
|
<d:City>Sydney</d:City>
|
||||||
<d:Birthday m:type="DateTimeOffset">1983-01-15T00:00:00Z</d:Birthday>
|
<d:Birthday m:type="DateTimeOffset">1983-01-15T00:00:00Z</d:Birthday>
|
||||||
<d:TimeBetweenLastTwoOrders m:type="Duration">PT0.0000002S</d:TimeBetweenLastTwoOrders>
|
<d:TimeBetweenLastTwoOrders m:type="Duration">PT0.0000002S</d:TimeBetweenLastTwoOrders>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Collection($ref)",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/OrderDetails(OrderID=7,ProductID=5)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/OrderDetails(OrderID=7,ProductID=6)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
-->
|
||||||
|
<feed xmlns:m="http://docs.oasis-open.org/odata/ns/metadata"
|
||||||
|
m:context="http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#Collection($ref)"
|
||||||
|
xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<m:ref id="http://odatae2etest.azurewebsites.net/javatest/DefaultService/OrderDetails(OrderID=7,ProductID=5)"/>
|
||||||
|
<m:ref id="http://odatae2etest.azurewebsites.net/javatest/DefaultService/OrderDetails(OrderID=7,ProductID=6)"/>
|
||||||
|
</feed>
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"@odata.context": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#$ref",
|
||||||
|
"@odata.id": "http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(PersonID=3)"
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
-->
|
||||||
|
<m:ref m:context="http://odatae2etest.azurewebsites.net/javatest/DefaultService/$metadata#$ref"
|
||||||
|
id="http://odatae2etest.azurewebsites.net/javatest/DefaultService/Employees(PersonID=3)"
|
||||||
|
xmlns:m="http://docs.oasis-open.org/odata/ns/metadata"/>
|
|
@ -170,9 +170,9 @@ public interface Constants {
|
||||||
|
|
||||||
public final static String ATOM_ELEM_ENTRY_REF = "ref";
|
public final static String ATOM_ELEM_ENTRY_REF = "ref";
|
||||||
|
|
||||||
public final static String ATOM_ELEM_ENTRY_REF_ID = "id";
|
public final static String ATOM_ATTR_ID = "id";
|
||||||
|
|
||||||
public final static QName QNAME_ATOM_ELEM_ENTRY_REF_ID = new QName(ATOM_ELEM_ENTRY_REF_ID);
|
public final static QName QNAME_ATOM_ATTR_ID = new QName(ATOM_ATTR_ID);
|
||||||
|
|
||||||
public static final QName QNAME_ATOM_ELEM_ENTRY = new QName(NS_ATOM, ATOM_ELEM_ENTRY);
|
public static final QName QNAME_ATOM_ELEM_ENTRY = new QName(NS_ATOM, ATOM_ELEM_ENTRY);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ abstract class AbstractAtomDealer {
|
||||||
|
|
||||||
protected final QName contextQName;
|
protected final QName contextQName;
|
||||||
|
|
||||||
protected final QName entityRefQName;
|
protected final QName entryRefQName;
|
||||||
|
|
||||||
protected final QName v4PropertyValueQName;
|
protected final QName v4PropertyValueQName;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ abstract class AbstractAtomDealer {
|
||||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.NEXT_LINK_REL);
|
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.NEXT_LINK_REL);
|
||||||
this.contextQName =
|
this.contextQName =
|
||||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.CONTEXT);
|
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.CONTEXT);
|
||||||
this.entityRefQName =
|
this.entryRefQName =
|
||||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ENTRY_REF);
|
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ENTRY_REF);
|
||||||
this.v4PropertyValueQName =
|
this.v4PropertyValueQName =
|
||||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.VALUE);
|
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.VALUE);
|
||||||
|
|
|
@ -171,9 +171,20 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AtomEntryImpl entryRef(final StartElement start) throws XMLStreamException {
|
||||||
|
final AtomEntryImpl entry = new AtomEntryImpl();
|
||||||
|
|
||||||
|
final Attribute entryRefId = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
|
||||||
|
if (entryRefId != null) {
|
||||||
|
entry.setId(entryRefId.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
private AtomEntryImpl entry(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
|
private AtomEntryImpl entry(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
|
||||||
final AtomEntryImpl entry;
|
final AtomEntryImpl entry;
|
||||||
if (entityRefQName.equals(start.getName())) {
|
if (entryRefQName.equals(start.getName())) {
|
||||||
entry = entryRef(start);
|
entry = entryRef(start);
|
||||||
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) {
|
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(start.getName())) {
|
||||||
entry = new AtomEntryImpl();
|
entry = new AtomEntryImpl();
|
||||||
|
@ -296,18 +307,6 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AtomEntryImpl entryRef(final StartElement start) throws XMLStreamException {
|
|
||||||
final AtomEntryImpl entry = new AtomEntryImpl();
|
|
||||||
|
|
||||||
final Attribute entryRefId = start.getAttributeByName(Constants.QNAME_ATOM_ELEM_ENTRY_REF_ID);
|
|
||||||
|
|
||||||
if (entryRefId != null) {
|
|
||||||
entry.setId(entryRefId.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Container<AtomEntryImpl> entry(final InputStream input) throws XMLStreamException {
|
private Container<AtomEntryImpl> entry(final InputStream input) throws XMLStreamException {
|
||||||
final XMLEventReader reader = FACTORY.createXMLEventReader(input);
|
final XMLEventReader reader = FACTORY.createXMLEventReader(input);
|
||||||
final StartElement start = skipBeforeFirstStartElement(reader);
|
final StartElement start = skipBeforeFirstStartElement(reader);
|
||||||
|
@ -365,6 +364,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(event.asStartElement().getName())) {
|
} else if (Constants.QNAME_ATOM_ELEM_ENTRY.equals(event.asStartElement().getName())) {
|
||||||
feed.getEntries().add(entry(reader, event.asStartElement()));
|
feed.getEntries().add(entry(reader, event.asStartElement()));
|
||||||
|
} else if (entryRefQName.equals(event.asStartElement().getName())) {
|
||||||
|
feed.getEntries().add(entryRef(event.asStartElement()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,12 +171,25 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void entryRef(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException {
|
||||||
|
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
|
||||||
|
writer.writeNamespace(StringUtils.EMPTY, version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
||||||
|
writer.writeAttribute(Constants.ATOM_ATTR_ID, entry.getId());
|
||||||
|
}
|
||||||
|
|
||||||
private void entry(final Writer outWriter, final Entry entry) throws XMLStreamException {
|
private void entry(final Writer outWriter, final Entry entry) throws XMLStreamException {
|
||||||
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
||||||
|
|
||||||
|
if (entry.getType() == null && entry.getProperties().isEmpty()) {
|
||||||
|
writer.writeStartDocument();
|
||||||
|
writer.setDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));
|
||||||
|
|
||||||
|
entryRef(writer, entry);
|
||||||
|
} else {
|
||||||
startDocument(writer, Constants.ATOM_ELEM_ENTRY);
|
startDocument(writer, Constants.ATOM_ELEM_ENTRY);
|
||||||
|
|
||||||
entry(writer, entry);
|
entry(writer, entry);
|
||||||
|
}
|
||||||
|
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
writer.writeEndDocument();
|
writer.writeEndDocument();
|
||||||
|
@ -206,10 +219,15 @@ public class AtomSerializer extends AbstractAtomDealer {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry entry : feed.getEntries()) {
|
for (Entry entry : feed.getEntries()) {
|
||||||
|
if (entry.getType() == null && entry.getProperties().isEmpty()) {
|
||||||
|
entryRef(writer, entry);
|
||||||
|
writer.writeEndElement();
|
||||||
|
} else {
|
||||||
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
|
writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
|
||||||
entry(writer, entry);
|
entry(writer, entry);
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (feed.getNext() != null) {
|
if (feed.getNext() != null) {
|
||||||
final LinkImpl next = new LinkImpl();
|
final LinkImpl next = new LinkImpl();
|
||||||
|
|
Loading…
Reference in New Issue