You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/10/21 14:53:33 UTC
svn commit: r1709823 -
/olingo/site/trunk/content/doc/odata4/tutorials/media/tutorial_media.mdtext
Author: chrish
Date: Wed Oct 21 12:53:33 2015
New Revision: 1709823
URL: http://svn.apache.org/viewvc?rev=1709823&view=rev
Log:
CMS commit to olingo by chrish
Modified:
olingo/site/trunk/content/doc/odata4/tutorials/media/tutorial_media.mdtext
Modified: olingo/site/trunk/content/doc/odata4/tutorials/media/tutorial_media.mdtext
URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/odata4/tutorials/media/tutorial_media.mdtext?rev=1709823&r1=1709822&r2=1709823&view=diff
==============================================================================
--- olingo/site/trunk/content/doc/odata4/tutorials/media/tutorial_media.mdtext (original)
+++ olingo/site/trunk/content/doc/odata4/tutorials/media/tutorial_media.mdtext Wed Oct 21 12:53:33 2015
@@ -44,10 +44,10 @@ Afterwards do a Deploy and run: it shoul
## Implementation
-In this tutorial we will implement a media entity set. The idea is to store advertisments and a related image. The metadata document have to be extended by the following elements:
+In this tutorial we will implement a media entity set. The idea is to store advertisements and a related image. The metadata document have to be extended by the following elements:
::::xml
- <EntityType Name="Advertisment" HasStream="true">
+ <EntityType Name="Advertisement" HasStream="true">
<Key>
<PropertyRef Name="ID"/>
</Key>
@@ -57,7 +57,7 @@ In this tutorial we will implement a med
</EntityType>
<EntityContainer Name="Container">
- <EntitySet Name="Advertisments" EntityType="OData.Demo.Advertisment"/>
+ <EntitySet Name="Advertisements" EntityType="OData.Demo.Advertisement"/>
</EntityContainer>
As you can see, the XML tag `EntityType` has a property `HasStream`, which tells us that this entity has an associated media stream. Such an Entity consists of common properties like *ID* and *Name* and the media stream.
@@ -84,7 +84,7 @@ We start with method `DemoEdmProvider.ge
} else if (entityTypeName.equals(ET_CATEGORY_FQN)) {
// Definition of entity type Category
// ...
- } else if(entityTypeName.equals(ET_ADVERTISMENT_FQN)) {
+ } else if(entityTypeName.equals(ET_ADVERTISEMENT_FQN)) {
CsdlProperty id = new CsdlProperty().setName("ID")
.setType(EdmPrimitiveTypeKind.Guid.getFullQualifiedName());
CsdlProperty name = new CsdlProperty().setName("Name")
@@ -96,7 +96,7 @@ We start with method `DemoEdmProvider.ge
propertyRef.setName("ID");
entityType = new CsdlEntityType();
- entityType.setName(ET_ADVERTISMENT_NAME);
+ entityType.setName(ET_ADVERTISEMENT_NAME);
entityType.setProperties(Arrays.asList(id, name, airDate));
entityType.setKey(Collections.singletonList(propertyRef));
entityType.setHasStream(true); // <- Enable the media entity stream
@@ -117,10 +117,10 @@ Further we have to create a new entity
// Definition of entity set Products
} else if (entitySetName.equals(ES_CATEGORIES_NAME)) {
// Definition if entity set Categories
- } else if (entitySetName.equals(ES_ADVERTISMENTS_NAME)) {
+ } else if (entitySetName.equals(ES_ADVERTISEMENTS_NAME)) {
entitySet = new CsdlEntitySet();
- entitySet.setName(ES_ADVERTISMENTS_NAME);
- entitySet.setType(ET_ADVERTISMENT_FQN);
+ entitySet.setName(ES_ADVERTISEMENTS_NAME);
+ entitySet.setType(ET_ADVERTISEMENT_FQN);
}
}
@@ -133,7 +133,7 @@ And finally announce the entity type and
@Override
public List<CsdlSchema> getSchemas() {
// ...
- entityTypes.add(getEntityType(ET_ADVERTISMENT_FQN));
+ entityTypes.add(getEntityType(ET_ADVERTISEMENT_FQN));
// ...
return schemas;
@@ -141,7 +141,7 @@ And finally announce the entity type and
public CsdlEntityContainer getEntityContainer() {
// ...
- entitySets.add(getEntitySet(CONTAINER, ES_ADVERTISMENTS_NAME));
+ entitySets.add(getEntitySet(CONTAINER, ES_ADVERTISEMENTS_NAME));
}
### Enable the data store to handle media entities
@@ -153,7 +153,7 @@ To read the content to a media entity, w
::::java
private static final String MEDIA_PROPERTY_NAME = "$value";
- private List<Entity> advertisments;
+ private List<Entity> advertisements;
public byte[] readMedia(final Entity entity) {
return (byte[]) entity.getProperty(MEDIA_PROPERTY_NAME).asPrimitive();
@@ -174,7 +174,7 @@ If a client creates a new media entity,
public Entity createMediaEntity(final EdmEntityType edmEntityType, final String mediaContentType, final byte[] data) {
Entity entity = null;
- if(edmEntityType.getName().equals(DemoEdmProvider.ET_ADVERTISMENT_NAME)) {
+ if(edmEntityType.getName().equals(DemoEdmProvider.ET_ADVERTISEMENT_NAME)) {
entity = new Entity();
entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, UUID.randomUUID()));
entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, null));
@@ -183,7 +183,7 @@ If a client creates a new media entity,
entity.setMediaContentType(mediaContentType);
entity.addProperty(new Property(null, MEDIA_PROPERTY_NAME, ValueType.PRIMITIVE, data));
- advertisments.add(entity);
+ advertisements.add(entity);
}
return entity;
@@ -192,14 +192,14 @@ If a client creates a new media entity,
Add an initial set of data to our data store:
::::java
- private void initAdvertismentSampleData() {
+ private void initAdvertisementSampleData() {
Entity entity = new Entity();
entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7")));
entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Old School Lemonade Store, Retro Style"));
entity.addProperty(new Property(null, "AirDate", ValueType.PRIMITIVE, Timestamp.valueOf("2012-11-07 00:00:00")));
entity.addProperty(new Property(null, MEDIA_PROPERTY_NAME, ValueType.PRIMITIVE, "Super content".getBytes()));
entity.setMediaContentType(ContentType.parse("text/plain").toContentTypeString());
- advertisments.add(entity);
+ advertisements.add(entity);
entity = new Entity();
entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE,
@@ -208,17 +208,17 @@ Add an initial set of data to our data s
entity.addProperty(new Property(null, "AirDate", ValueType.PRIMITIVE, Timestamp.valueOf("2000-02-29 00:00:00")));
entity.addProperty(new Property(null, MEDIA_PROPERTY_NAME, ValueType.PRIMITIVE, "Super content2".getBytes()));
entity.setMediaContentType(ContentType.parse("text/plain").toContentTypeString());
- advertisments.add(entity);
+ advertisements.add(entity);
}
-Call `initAdvertismentSampleData()` in the constructor.
+Call `initAdvertisementSampleData()` in the constructor.
::::java
public Storage() {
// ...
- advertisments = new ArrayList<Entity>();
+ advertisements = new ArrayList<Entity>();
// ...
- initAdvertismentSampleData();
+ initAdvertisementSampleData();
}
Enable the regular entity set for CRUD opertations:
@@ -228,8 +228,8 @@ Enable the regular entity set for CRUD o
if (edmEntitySet.getName().equals(DemoEdmProvider.ES_PRODUCTS_NAME)) {
// ...
- } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISMENTS_NAME)) {
- return getEntityCollection(advertisments);
+ } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISEMENTS_NAME)) {
+ return getEntityCollection(advertisements);
}
return null;
@@ -241,8 +241,8 @@ Enable the regular entity set for CRUD o
EdmEntityType edmEntityType = edmEntitySet.getEntityType();
if (edmEntitySet.getName().equals(DemoEdmProvider.ES_PRODUCTS_NAME)) {
// ...
- } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISMENTS_NAME)) {
- return getEntity(edmEntityType, keyParams, advertisments);
+ } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISEMENTS_NAME)) {
+ return getEntity(edmEntityType, keyParams, advertisements);
}
return null;
@@ -266,8 +266,8 @@ Enable the regular entity set for CRUD o
EdmEntityType edmEntityType = edmEntitySet.getEntityType();
if (edmEntitySet.getName().equals(DemoEdmProvider.ES_PRODUCTS_NAME)) {
// ...
- } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISMENTS_NAME)) {
- updateEntity(edmEntityType, keyParams, updateEntity, httpMethod, advertisments);
+ } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISEMENTS_NAME)) {
+ updateEntity(edmEntityType, keyParams, updateEntity, httpMethod, advertisements);
}
}
@@ -277,8 +277,8 @@ Enable the regular entity set for CRUD o
EdmEntityType edmEntityType = edmEntitySet.getEntityType();
if (edmEntitySet.getName().equals(DemoEdmProvider.ES_PRODUCTS_NAME)) {
// ...
- } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISMENTS_NAME)) {
- deleteEntity(edmEntityType, keyParams, advertisments);
+ } else if(edmEntitySet.getName().equals(DemoEdmProvider.ES_ADVERTISEMENTS_NAME)) {
+ deleteEntity(edmEntityType, keyParams, advertisements);
}
}
@@ -300,8 +300,8 @@ The easiest part is to delete an media e
* A real service may store the content on the file system. So we have to take care to
* delete external files too.
*
- * DELETE request to /Advertisments(ID) will be dispatched to the deleteEntity(...) method
- * DELETE request to /Advertisments(ID)/$value will be dispatched to the deleteMediaEntity(...) method
+ * DELETE request to /Advertisements(ID) will be dispatched to the deleteEntity(...) method
+ * DELETE request to /Advertisements(ID)/$value will be dispatched to the deleteMediaEntity(...) method
*
* So it is a good idea handle deletes in a central place.
*/
@@ -407,16 +407,16 @@ Updating a media entity in our scenario
After building and deploying the project, we can invoke our OData service.
* Read media entity set
- **GET** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments)
+ **GET** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments)
* Read media entity
- **GET** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7)](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7))
+ **GET** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7))
* Read media entity content
- **GET** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f- 4cd4-b330-db93c25ff3c7)/$value)
+ **GET** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f- 4cd4-b330-db93c25ff3c7)/$value)
* Create a new Media Entity
- **POST** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments
+ **POST** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements
Content-Type: image/svg+xml
@@ -432,7 +432,7 @@ Content-Type: image/svg+xml
* Update the content of a media entity
- **PUT** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value)
+ **PUT** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7)/$value)
Content-Type: text/plain
@@ -441,7 +441,7 @@ Content-Type: text/plain
Super super nice content
* Update the properties of a media entity
-**PUT** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7)](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7))
+**PUT** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7))
Content-Type: application/json
@@ -455,10 +455,10 @@ Content-Type: application/json
* Delete a media entity
- **DELETE** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7)](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7))
+ **DELETE** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements(f89dee73-af9f-4cd4-b330-db93c25ff3c7)](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(f89dee73-af9f-4cd4-b330-db93c25ff3c7))
* Delete a media entity
- **DELETE** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(db2d2186-1c29-4d1e-88ef-127f521b9c67)/$value](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(db2d2186-1c29-4d1e-88ef-127f521b9c67)/$value)
+ **DELETE** [http://localhost:8080/DemoService-Media/DemoService.svc/Advertisements(db2d2186-1c29-4d1e-88ef-127f521b9c67)/$value](http://localhost:8080/DemoService-Media/DemoService.svc/Advertisments(db2d2186-1c29-4d1e-88ef-127f521b9c67)/$value)
# Links