[OLINGO-777] Fix sample/server's xml serialization
Signed-off-by: Michael Bolz <michael.bolz@sap.com>
This commit is contained in:
parent
908a143751
commit
92fa7cd62e
|
@ -18,10 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.server.sample.data;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntityCollection;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
|
@ -94,41 +97,50 @@ public class DataProvider {
|
|||
|
||||
private EntityCollection createCars() {
|
||||
EntityCollection entitySet = new EntityCollection();
|
||||
|
||||
entitySet.getEntities().add(new Entity()
|
||||
Entity el = new Entity()
|
||||
.addProperty(createPrimitive("Id", 1))
|
||||
.addProperty(createPrimitive("Model", "F1 W03"))
|
||||
.addProperty(createPrimitive("ModelYear", "2012"))
|
||||
.addProperty(createPrimitive("Price", 189189.43))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
.addProperty(createPrimitive("Currency", "EUR"));
|
||||
el.setId(createId(CarsEdmProvider.ES_CARS_NAME, 1));
|
||||
entitySet.getEntities().add(el);
|
||||
|
||||
entitySet.getEntities().add(new Entity()
|
||||
el = new Entity()
|
||||
.addProperty(createPrimitive("Id", 2))
|
||||
.addProperty(createPrimitive("Model", "F1 W04"))
|
||||
.addProperty(createPrimitive("ModelYear", "2013"))
|
||||
.addProperty(createPrimitive("Price", 199999.99))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
.addProperty(createPrimitive("Currency", "EUR"));
|
||||
el.setId(createId(CarsEdmProvider.ES_CARS_NAME, 2));
|
||||
entitySet.getEntities().add(el);
|
||||
|
||||
entitySet.getEntities().add(new Entity()
|
||||
el = new Entity()
|
||||
.addProperty(createPrimitive("Id", 3))
|
||||
.addProperty(createPrimitive("Model", "F2012"))
|
||||
.addProperty(createPrimitive("ModelYear", "2012"))
|
||||
.addProperty(createPrimitive("Price", 137285.33))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
.addProperty(createPrimitive("Currency", "EUR"));
|
||||
el.setId(createId(CarsEdmProvider.ES_CARS_NAME, 3));
|
||||
entitySet.getEntities().add(el);
|
||||
|
||||
entitySet.getEntities().add(new Entity()
|
||||
el = new Entity()
|
||||
.addProperty(createPrimitive("Id", 4))
|
||||
.addProperty(createPrimitive("Model", "F2013"))
|
||||
.addProperty(createPrimitive("ModelYear", "2013"))
|
||||
.addProperty(createPrimitive("Price", 145285.00))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
.addProperty(createPrimitive("Currency", "EUR"));
|
||||
el.setId(createId(CarsEdmProvider.ES_CARS_NAME, 4));
|
||||
entitySet.getEntities().add(el);
|
||||
|
||||
entitySet.getEntities().add(new Entity()
|
||||
el = new Entity()
|
||||
.addProperty(createPrimitive("Id", 5))
|
||||
.addProperty(createPrimitive("Model", "F1 W02"))
|
||||
.addProperty(createPrimitive("ModelYear", "2011"))
|
||||
.addProperty(createPrimitive("Price", 167189.00))
|
||||
.addProperty(createPrimitive("Currency", "EUR")));
|
||||
.addProperty(createPrimitive("Currency", "EUR"));
|
||||
el.setId(createId(CarsEdmProvider.ES_CARS_NAME, 5));
|
||||
entitySet.getEntities().add(el);
|
||||
|
||||
for (Entity entity:entitySet.getEntities()) {
|
||||
entity.setType(CarsEdmProvider.ET_CAR.getFullQualifiedNameAsString());
|
||||
|
@ -139,15 +151,19 @@ public class DataProvider {
|
|||
private EntityCollection createManufacturers() {
|
||||
EntityCollection entitySet = new EntityCollection();
|
||||
|
||||
entitySet.getEntities().add(new Entity()
|
||||
Entity el = new Entity()
|
||||
.addProperty(createPrimitive("Id", 1))
|
||||
.addProperty(createPrimitive("Name", "Star Powered Racing"))
|
||||
.addProperty(createAddress("Star Street 137", "Stuttgart", "70173", "Germany")));
|
||||
.addProperty(createAddress("Star Street 137", "Stuttgart", "70173", "Germany"));
|
||||
el.setId(createId(CarsEdmProvider.ES_MANUFACTURER_NAME, 1));
|
||||
entitySet.getEntities().add(el);
|
||||
|
||||
entitySet.getEntities().add(new Entity()
|
||||
el = new Entity()
|
||||
.addProperty(createPrimitive("Id", 2))
|
||||
.addProperty(createPrimitive("Name", "Horse Powered Racing"))
|
||||
.addProperty(createAddress("Horse Street 1", "Maranello", "41053", "Italy")));
|
||||
.addProperty(createAddress("Horse Street 1", "Maranello", "41053", "Italy"));
|
||||
el.setId(createId(CarsEdmProvider.ES_MANUFACTURER_NAME, 2));
|
||||
entitySet.getEntities().add(el);
|
||||
|
||||
for (Entity entity:entitySet.getEntities()) {
|
||||
entity.setType(CarsEdmProvider.ET_MANUFACTURER.getFullQualifiedNameAsString());
|
||||
|
@ -168,4 +184,12 @@ public class DataProvider {
|
|||
private Property createPrimitive(final String name, final Object value) {
|
||||
return new Property(null, name, ValueType.PRIMITIVE, value);
|
||||
}
|
||||
|
||||
private URI createId(String entitySetName, Object id) {
|
||||
try {
|
||||
return new URI(entitySetName + "(" + String.valueOf(id) + ")");
|
||||
} catch (URISyntaxException e) {
|
||||
throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,8 +105,10 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
|
|||
// Now the content is serialized using the serializer.
|
||||
final ExpandOption expand = uriInfo.getExpandOption();
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
|
||||
InputStream serializedContent = serializer.entityCollection(edm, edmEntitySet.getEntityType(), entitySet,
|
||||
EntityCollectionSerializerOptions.with()
|
||||
.id(id)
|
||||
.contextURL(isODataMetadataNone(requestedContentType) ? null :
|
||||
getContextUrl(edmEntitySet, false, expand, select, null))
|
||||
.count(uriInfo.getCountOption())
|
||||
|
|
Loading…
Reference in New Issue