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/08/04 12:34:22 UTC

svn commit: r1694021 - /olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext

Author: chrish
Date: Tue Aug  4 10:34:22 2015
New Revision: 1694021

URL: http://svn.apache.org/r1694021
Log:
CMS commit to olingo by chrish

Modified:
    olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext

Modified: olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext
URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext?rev=1694021&r1=1694020&r2=1694021&view=diff
==============================================================================
--- olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext (original)
+++ olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext Tue Aug  4 10:34:22 2015
@@ -34,7 +34,7 @@ The OData service that we are create wil
 ![datamodel](model1.png "The OData model")
 
 The service will display a list of products and a few properties that describe each product.
-This data model will be enhanced in the subsequent tutorials in order to display Categories and to support navigation from a product to its Category.
+This data model will be enhanced in the subsequent tutorials in order to display categories and to support navigation from a product to its category.
 
 
 **Goal**
@@ -141,7 +141,7 @@ The description within this section is b
 **Create Project using the maven archetype “webapp”**
 
 Within Eclipse, open the Maven Project wizard via
-*File -> New -> other -> Maven -> Maven Project*
+*File -> New -> Other -> Maven -> Maven Project*
 
 On the second wizard page, choose  the archetype: maven-archetype-webapp
 
@@ -149,7 +149,6 @@ On the second wizard page, choose  the a
 
 On the next page, enter the following information:  
 
-  * Project Name: *DemoService*
   * Groupd Id: *my.group.id*
   * Artifact Id: *DemoService*
   * Version: *0.0.1*
@@ -288,16 +287,16 @@ The following section will guide you thr
 
 ### 4.1.1. Background
 
-According to the OData specification, an OData service has to declare its structure in the so-called *metadata document*.
+According to the OData specification, an OData service has to declare its structure in the so-called *Metadata Document*.
 This document defines the contract, such that the user of the service knows which requests can be executed, the structure of the result and how the service can be navigated.
 
-The metadata document can be invoked via the following URI:
+The Metadata Document can be invoked via the following URI:
 
     :::html
     <serviceroot>/$metadata
 
 
-Furthermore, OData specifies the usage of the so-called service document
+Furthermore, OData specifies the usage of the so-called Service Document
 Here, the user can see which Entity Collections are offered by an OData service.
 
 The service document can be invoked via the following URI:
@@ -306,7 +305,7 @@ The service document can be invoked via
     <serviceroot>/
 
 The information that is given by these 2 URIs, has to be implemented in the service code.
-Olingo provides API for it and we will use it in the implementation of our *CsdlEdmProvider*.
+Olingo provides an API for it and we will use it in the implementation of our *CsdlEdmProvider*.
 
 
 ### 4.1.2. Create class
@@ -317,7 +316,7 @@ Create class *DemoEdmProvider* and speci
 Note: **edm** is the abbreviation for **Entity Data Model**.  
 Accordingly, we understand that the *CsdlEdmProvider* is supposed to provide static descriptive information.
 
-The Entity Model of the service can be defined in the EDM Provider. The EDM model basically defines the available EntityTypes and the relation between the entities. An EntityType consists of primitive, complex or navigation properties. The model can be invoked with the metadata document request.
+The Entity Model of the service can be defined in the EDM Provider. The EDM model basically defines the available EntityTypes and the relation between the entities. An EntityType consists of primitive, complex or navigation properties. The model can be invoked with the Metadata Document request.
 
 As we can see, the Olingo server API provides one package that contains interfaces for the description of the metadata:
 
@@ -334,7 +333,7 @@ You can find the Javadoc here: <http://o
 The base class *CsdlAbstractEdmProvider* provides methods for declaring the metadata of all OData elements.
 
 For example:
-* The entries that are displayed in the service document are provided by the method
+* The entries that are displayed in the Service Document are provided by the method
 *getEntityContainerInfo()*
 * The structure of EntityTypes is declared in the method *getEntityType()*
 
@@ -508,24 +507,22 @@ Then our elements are added to the Schem
 
 
     :::java
-    public CsdlEntityContainer getEntityContainer() throws ODataException {
-
-      // create EntitySets
-      List<CsdlEntitySet> entitySets = new ArrayList<CsdlEntitySet>();
-      entitySets.add(getEntitySet(CONTAINER, ES_PRODUCTS_NAME));
+    public CsdlEntityContainerInfo getEntityContainerInfo(FullQualifiedName entityContainerName) throws ODataException {
 
-      // create EntityContainer
-      CsdlEntityContainer entityContainer = new CsdlEntityContainer();
-      entityContainer.setName(CONTAINER_NAME);
-      entityContainer.setEntitySets(entitySets);
+        // This method is invoked when displaying the Service Document at e.g. http://localhost:8080/DemoService/DemoService.svc
+        if (entityContainerName == null || entityContainerName.equals(CONTAINER)) {
+            CsdlEntityContainerInfo entityContainerInfo = new CsdlEntityContainerInfo();
+            entityContainerInfo.setContainerName(CONTAINER);
+            return entityContainerInfo;
+        }
 
-      return entityContainer;
+        return null;
     }
 
 
 **Summary:**  
 We have created a class that declares the metadata of our OData service.
-We have declared the main elements of an OData service: _EntityType_, _EntitySet_, _EntityContainer_ and _Schema_ (with us of the according Olingo classes `CsdlEntityType`, `CsdlEntitySet`, `CsdlEntityContainer` and `CsdlSchema`).
+We have declared the main elements of an OData service: _EntityType_, _EntitySet_, _EntityContainer_ and _Schema_ (with the corresponding Olingo classes `CsdlEntityType`, `CsdlEntitySet`, `CsdlEntityContainer` and `CsdlSchema`).
 
 At runtime of an OData service, such metadata can be viewed by invoking the Metadata Document.
 
@@ -556,11 +553,11 @@ Give us the result below:
 
 The Service Document can be invoked to view the Entity Sets, like in our example at the URL: <http://localhost:8080/DemoService/DemoService.svc/>
 
-Which give us the service document as result:
+Which give us the Service Document as result:
 
     :::json
     {
-      "@odata.context" : "http://localhost:8080/DemoService/DemoService.svc/$metadata",
+      "@odata.context" : "$metadata",
       "value" : [
       {
         "name" : "Products",
@@ -570,7 +567,7 @@ Which give us the service document as re
 
 
 > Note:  
-> After implementing the _EdmProvider_, we can, as an intermediate step, build/deploy the service and invoke the 2 static pages:   service document and metadata document.  
+> After implementing the _EdmProvider_, we can, as an intermediate step, build/deploy the service and invoke the 2 static pages:   Service Document and Metadata Document.  
 > If desired, you can proceed with implementing the required steps for web application as described in
 4.3. and run the application as described in chapter 5.
 
@@ -587,7 +584,7 @@ The work that we have to do in this chap
   1. Check the URI  
       We need to identify the requested resource and have to consider Query Options (if available)
   2. Provide the data  
-      Based on the URI info, we have to obtain the data from our data store (can be e.g. a Database)
+      Based on the URI info, we have to obtain the data from our data store (can be e.g. a database)
   3. Serialize the data  
       The data has to be transformed into the required format
   4. Configure the response  
@@ -603,13 +600,13 @@ _Olingo_ provides API for processing dif
 Such a service request can ask for a list of entities, or for one entity, or one property.
 
 Example:  
-In our example, we have stated in our metadata document that We will provide a list of “products” whenever the _EntitySet_ with name “Products” is invoked.  
+In our example, we have stated in our Metadata Document that we will provide a list of “products” whenever the _EntitySet_ with name “Products” is invoked.  
 This means that the user of our OData service will append the _EntitySet_ name to the root URL of the service and then invoke the full URL.  
 This is http://localhost:8080/DemoService/DemoServlet1.svc/Products
 So, whenever this URL is fired, Olingo will invoke the `EntityCollectionProcessor` implementation of our OData service.
 Then our `EntityCollectionProcessor` implementation is expected to provide a list of products.
 
-As we have already mentioned, the metadata document is the contract for providing data.
+As we have already mentioned, the Metadata Document is the contract for providing data.
 This means that when it comes to provide the actual data, we have to do it according to the specified metadata.  
 For example, the property names have to match, also the types of the properties, and, if specified, the length of the strings, etc
 
@@ -645,13 +642,15 @@ We will need it later, so we store it as
     :::java
     public void init(OData odata, ServiceMetadata serviceMetadata) {
       this.odata = odata;
+      this.serviceMetadata = serviceMetadata;
     }
 
 
-Don’t forget to declare the member variable
+Don’t forget to declare the member variables
 
     :::java
     private OData odata;
+    private ServiceMetadata serviceMetadata;
 
 **_readEntityCollection()_**
 
@@ -706,7 +705,7 @@ The steps for implementating the method
   1. Which data is requested?  
     Usually, an OData service provides different _EntitySets_, so first it is required to identify which _EntitySet_ has been requested. This information can be retrieved from the _uriInfo_ object.
 
-  2. Fetch the data
+  2. Fetch the data   
     As a developer of the OData service, you have to know how and where the data is stored. In many cases, this would be a database. At this point, you would connect to your database and fetch the requested data with an appropriate SQL statement. The data that is fetched from the data storage has to be put into an _EntityCollection_ object.
     The package `org.apache.olingo.commons.api.data` provides interfaces that describe the actual data, not the metadata.
 
@@ -904,7 +903,7 @@ We ignore it. Instead, we open our OData
 > Note:
 > If you face problems related to the server, it helps to restart your Eclipse IDE.
 
-### The service-URLs
+### The Service URLs
 
 Try the following URLs:
 
@@ -913,12 +912,12 @@ Try the following URLs:
     :::html
     http://localhost:8080/DemoService/DemoService.svc/
 
-The expected result is the service document which displays our _EntityContainerInfo_:
+The expected result is the Service Document which displays our _EntityContainerInfo_:
 
 
     :::json
     {
-      "@odata.context" : "http://localhost:8080/DemoService/DemoService.svc/$metadata",
+      "@odata.context" : "$metadata",
       "value" : [
       {
         "name" : "Products",
@@ -932,7 +931,7 @@ The expected result is the service docum
     :::html
     http://localhost:8080/DemoService/DemoService.svc/$metadata
 
-The expected result is the metadata document that displays our _Schema_, _EntityType_, _EntityContainer_ and _EntitySet_.
+The expected result is the Metadata Document that displays our _Schema_, _EntityType_, _EntityContainer_ and _EntitySet_.
 
 
     :::xml
@@ -993,7 +992,7 @@ The expected result is the hardcoded lis
 # 6. Summary
 
 Finally, we have created our first OData service based on the V4 version of the OData specification and using the V4 server library provided by _Olingo_.  
-Our first OData service is very simple; it only allows invoking one entity collection, apart from the service document and the metadata document.
+Our first OData service is very simple; it only allows invoking one entity collection, apart from the Service Document and the Metadata Document.
 
 The project as final result can be download [here](http://www.apache.org/dyn/closer.cgi/olingo/odata4/Tutorials/DemoService_Tutorial_Read.zip) ([md5](https://dist.apache.org/repos/dist/release/olingo/odata4/Tutorials/DemoService_Tutorial_Read.zip.md5), [sha512](https://dist.apache.org/repos/dist/release/olingo/odata4/Tutorials/DemoService_Tutorial_Read.zip.sha512), [pgp](https://dist.apache.org/repos/dist/release/olingo/odata4/Tutorials/DemoService_Tutorial_Read.zip.asc)).
 
@@ -1011,4 +1010,4 @@ Further topics to be covered by follow-u
 ### Further reading
 
   * OData specification: <http://odata.org/>  
-  * Olingo Javadoc: [http://olingo.apache.org/javadoc/odata4/index.html](/javadoc/odata4/index.html)
+  * Olingo Javadoc: [http://olingo.apache.org/javadoc/odata4/index.html](/javadoc/odata4/index.html)
\ No newline at end of file