You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2019/05/28 07:31:58 UTC

svn commit: r1860189 - /olingo/site/trunk/content/doc/odata4/tutorials/od4_basic_client_read.mdtext

Author: ramyav
Date: Tue May 28 07:31:58 2019
New Revision: 1860189

URL: http://svn.apache.org/viewvc?rev=1860189&view=rev
Log:
Bug fixes

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

Modified: olingo/site/trunk/content/doc/odata4/tutorials/od4_basic_client_read.mdtext
URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/odata4/tutorials/od4_basic_client_read.mdtext?rev=1860189&r1=1860188&r2=1860189&view=diff
==============================================================================
--- olingo/site/trunk/content/doc/odata4/tutorials/od4_basic_client_read.mdtext (original)
+++ olingo/site/trunk/content/doc/odata4/tutorials/od4_basic_client_read.mdtext Tue May 28 07:31:58 2019
@@ -46,7 +46,7 @@ With this Quickstart guide the runnable
     odataClient.getConfiguration().setDefaultPubFormat(ContentType.APPLICATION_JSON);
 
 ###Read EDM
-For an OData Service the Entity Data Model (EDM) defines all metadata information about the provided data of the service. This includes all entities with their type, properties and relations, which entities are provided as entity sets and additional functions and operations provided by the OData Service. The EDM also have to be provided by the OData Service via a unique URI (e.g. http://localhost:8080/DemoService/DemoService.svc/$metadata) in the EDMX format.
+For an OData Service the Entity Data Model (EDM) defines all metadata information about the provided data of the service. This includes all entities with their type, properties and relations, which entities are provided as entity sets and additional functions and operations provided by the OData Service. The EDM also have to be provided by the OData Service via a unique URI (e.g. http://localhost:8080/cars.svc/$metadata) in the EDMX format.
 This fact is important because the Apache Olingo library requires the metadata for serialization and de-serialization of the data of an entity (e.g. the validation of the data is done against the EDM provided metadata). Hence the first step in this sample is to read the whole EDM of an OData Service.
 ###Code sample: Read EDM ($metadata)
 
@@ -56,16 +56,23 @@ This fact is important because the Apach
 If annotations defined in external vocabulary file has to be loaded then the below code has to be used
 
     List<InputStream> streams = new ArrayList<InputStream>();
+    //If file is locally available    
     streams.add(getClass().getResourceAsStream("annotations.xml"));
     XMLMetadata xmlMetadata = getClient().getRetrieveRequestFactory().getXMLMetadataRequest(serviceUrl).execute().getBody();
-    final Edm edm = getClient().getReader().readMetadata(xmlMetadata, terms);
+    //If the reference uri's have to be loaded 
+    String vocabUrl = metadata.getReferences().get(0).getUri().toString();
+    URI uri = new URI(vocabUrl);
+    ODataRawRequest request = getClient().getRetrieveRequestFactory().getRawRequest(uri);
+    ODataRawResponse response = request.execute();
+    streams.add(response.getRawResponse());
+    final Edm edm = getClient().getReader().readMetadata(xmlMetadata, streams);
     return edm;
 
 Here the serviceUrl is the root Url of the odata service.
 For read and de-serialize of the EDM this is all what have to be done and the resulting EDM instance than can be used for necessary serialization and de-serialization in combination of CRUD operations supported by Apache Olingo library.
 
 ###Read Entity
-For reading entities this sample provides two methods. First is read of a complete OData Feed / Entity Set and second is read os a single Entity. In general, for both first create the request and execute the request.
+For reading entities this sample provides two methods. First is read of a complete collection / Entity Set and second is read of a single Entity. In general, for both first create the request and execute the request.
 
 ###Read entityCollection
 
@@ -95,17 +102,14 @@ For read of a single ODataEntry the requ
             .appendPropertySegment(“Name”).build());
     final ODataRetrieveResponse<ClientProperty> response = request.execute();
     final ClientProperty property = response.getBody();
-
-If the property is a Complex Type and if value has to be fetched
+    //If property is a primitive type and if value has to be fetched
+    final ClientProperty property = property.get("Name");
+    final ClientPrimitiveValue clientValue = property.getPrimitiveValue();
+    //If the property is a Complex Type and if value has to be fetched
     // Here Address is a complex property
     final ClientComplexValue complexValue = prop.getComplexValue();
     final ClientValue propertyComp = complexValue.get("Street").getValue();
 
-If property is a primitive type and if value has to be fetched
-
-    final ClientProperty property = property.get("Name");
-    final ClientPrimitiveValue clientValue = property.getPrimitiveValue();
-
 ###Create Entity
 
 To create an entity a HTTP POST on the corresponding entity set URI with the whole entity data as POST Body in a supported format (e.g. atom-xml, json) has to be done. With Apache Olingo the required POST Body can be created (serialized) with the methods available on ClientObjectFactory. This method creates a ClientEntity which contains the content (i.e. the required POST Body) which then can be send to the server. If the entry was created successfully an HTTP Status: 201 created will be returned as well as the complete entry.
@@ -117,7 +121,7 @@ For simplicity in the code sample below
     newEntity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(“Name”,
             getFactory().newPrimitiveValueBuilder().buildString(“MyCarManufacturer”)));
     newEntity.addLink(getClient().getObjectFactory().newEntityNavigationLink(“Cars”,
-            client.newURIBuilder(SERVICE_URI)
+            client.newURIBuilder(serviceUrl)
                 .appendEntitySetSegment(“Cars”)
                 .appendKeySegment(1)
                 .build()));