[OLINGO-713] Small tutorial fix
This commit is contained in:
parent
111308124c
commit
f52404f29b
|
@ -138,7 +138,7 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
|
|||
.count(uriInfo.getCountOption())
|
||||
.select(selectOption)
|
||||
.expand(uriInfo.getExpandOption())
|
||||
.setId(id)
|
||||
.id(id)
|
||||
.build();
|
||||
|
||||
// and serialize the content: transform from the EntitySet object to InputStream
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package myservice.mynamespace.service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
|
@ -27,6 +29,7 @@ import org.apache.olingo.commons.api.data.Property;
|
|||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
|
@ -85,7 +88,7 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
|
|||
|
||||
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
|
||||
EntityCollectionSerializerOptions opts =
|
||||
EntityCollectionSerializerOptions.with().setId(id).contextURL(contextUrl).build();
|
||||
EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
|
||||
SerializerResult serializedContent = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);
|
||||
|
||||
// Finally: configure the response object: set the body, headers and status code
|
||||
|
@ -102,28 +105,45 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
|
|||
*/
|
||||
private EntityCollection getData(EdmEntitySet edmEntitySet){
|
||||
|
||||
EntityCollection entityCollection = new EntityCollection();
|
||||
EntityCollection productsCollection = new EntityCollection();
|
||||
// check for which EdmEntitySet the data is requested
|
||||
if(DemoEdmProvider.ES_PRODUCTS_NAME.equals(edmEntitySet.getName())) {
|
||||
List<Entity> entityList = entityCollection.getEntities();
|
||||
List<Entity> productList = productsCollection.getEntities();
|
||||
|
||||
// add some sample product entities
|
||||
entityList.add(new Entity()
|
||||
.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
|
||||
.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
|
||||
.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB")));
|
||||
final Entity e1 = new Entity()
|
||||
.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
|
||||
.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
|
||||
.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
|
||||
"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
|
||||
e1.setId(createId("Products", 1));
|
||||
productList.add(e1);
|
||||
|
||||
entityList.add(new Entity()
|
||||
.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
|
||||
.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
|
||||
.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network")));
|
||||
final Entity e2 = new Entity()
|
||||
.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
|
||||
.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
|
||||
.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
|
||||
"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
|
||||
e2.setId(createId("Products", 1));
|
||||
productList.add(e2);
|
||||
|
||||
entityList.add(new Entity()
|
||||
.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
|
||||
.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
|
||||
.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "17 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960")));
|
||||
final Entity e3 = new Entity()
|
||||
.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
|
||||
.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
|
||||
.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
|
||||
"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
|
||||
e3.setId(createId("Products", 1));
|
||||
productList.add(e3);
|
||||
}
|
||||
|
||||
return entityCollection;
|
||||
return productsCollection;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
|
|||
|
||||
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
|
||||
EntityCollectionSerializerOptions opts =
|
||||
EntityCollectionSerializerOptions.with().setId(id).contextURL(contextUrl).build();
|
||||
EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
|
||||
SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entityCollection, opts);
|
||||
InputStream serializedContent = serializerResult.getContent();
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
|
|||
ContextURL contextUrl = ContextURL.with().entitySet(responseEdmEntitySet).build();
|
||||
final String id = request.getRawBaseUri() + "/" + responseEdmEntitySet.getName();
|
||||
EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with()
|
||||
.contextURL(contextUrl).setId(id).build();
|
||||
.contextURL(contextUrl).id(id).build();
|
||||
EdmEntityType edmEntityType = responseEdmEntitySet.getEntityType();
|
||||
|
||||
ODataSerializer serializer = odata.createSerializer(responseFormat);
|
||||
|
|
|
@ -135,7 +135,7 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
|
|||
|
||||
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
|
||||
EntityCollectionSerializerOptions opts =
|
||||
EntityCollectionSerializerOptions.with().contextURL(contextUrl).setId(id).count(countOption).build();
|
||||
EntityCollectionSerializerOptions.with().contextURL(contextUrl).id(id).count(countOption).build();
|
||||
SerializerResult serializerResult =
|
||||
serializer.entityCollection(serviceMetadata, edmEntityType, returnEntityCollection, opts);
|
||||
InputStream serializedContent = serializerResult.getContent();
|
||||
|
|
|
@ -171,7 +171,7 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
|
|||
.contextURL(contextUrl)
|
||||
.select(selectOption)
|
||||
.expand(expandOption)
|
||||
.setId(id)
|
||||
.id(id)
|
||||
.build();
|
||||
|
||||
ODataSerializer serializer = odata.createSerializer(responseFormat);
|
||||
|
|
Loading…
Reference in New Issue