You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by bu...@apache.org on 2015/11/17 13:30:18 UTC

svn commit: r972695 - in /websites/staging/olingo/trunk/content: ./ doc/odata4/tutorials/deep_insert/ doc/odata4/tutorials/deep_insert/tutorial_deep_insert.html

Author: buildbot
Date: Tue Nov 17 12:30:18 2015
New Revision: 972695

Log:
Staging update by buildbot for olingo

Added:
    websites/staging/olingo/trunk/content/doc/odata4/tutorials/deep_insert/
    websites/staging/olingo/trunk/content/doc/odata4/tutorials/deep_insert/tutorial_deep_insert.html
Modified:
    websites/staging/olingo/trunk/content/   (props changed)

Propchange: websites/staging/olingo/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Nov 17 12:30:18 2015
@@ -1 +1 @@
-1714770
+1714771

Added: websites/staging/olingo/trunk/content/doc/odata4/tutorials/deep_insert/tutorial_deep_insert.html
==============================================================================
--- websites/staging/olingo/trunk/content/doc/odata4/tutorials/deep_insert/tutorial_deep_insert.html (added)
+++ websites/staging/olingo/trunk/content/doc/odata4/tutorials/deep_insert/tutorial_deep_insert.html Tue Nov 17 12:30:18 2015
@@ -0,0 +1,210 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html lang="en">
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="description" content="Apache Olingo provides libraries which enable developers to implement OData producers and OData consumers. The available OData Java library implements OData version 2.0. In future on goal is to provide an OData 4.0 compliant library once the OData standard is published at OASIS. The focus within the community is currently on the Java technology but it is up to the community to discuss if other environments find interest.">
+    <meta name="author" content="">
+    <link rel="icon" href="/favicon.ico">
+    <title>
+      Apache Olingo Library
+    </title><!-- Bootstrap core CSS -->
+    <link href="/css/bootstrap.css" rel="stylesheet" type="text/css"><!-- Custom styles for this template -->
+    <link href="/css/navbar.css" rel="stylesheet" type="text/css"><!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
+    <link href="/css/offcanvas.css" rel="stylesheet" type="text/css"><!-- Custom styles for this template -->
+    <link rel="stylesheet" href="/css/main.css">
+    <!--[if lt IE 9]><script src="/js/ie8-responsive-file-warning.js"></script><![endif]-->
+
+    <script src="/js/ie-emulation-modes-warning.js" type="text/javascript">
+</script><!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
+
+    <script src="/js/ie10-viewport-bug-workaround.js" type="text/javascript">
+</script><!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
+    <!--[if lt IE 9]>
+      <script src="/js/html5shiv.min.js"></script>
+      <script src="/js/respond.min.js"></script>
+    <![endif]-->
+  </head>
+
+  <body>
+    <div class="container">
+      <!-- Static navbar -->
+      <div class="navbar navbar-default" role="navigation">
+        <div class="container-fluid">
+          <div class="navbar-header">
+            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
+              <span class="sr-only">Toggle navigation</span>
+             <span class="icon-bar"></span>
+             <span class="icon-bar"></span>
+             <span class="icon-bar"></span>
+            </button>
+              <img class="navbar-brand" src="/img/OlingoOrangeTM.png" style="width:62px;" >
+              <a class="navbar-brand" href="#">Apache Olingo™</a>
+          </div>
+          <div class="navbar-collapse collapse">
+            <ul class="nav navbar-nav">
+
+              <li><a href="/">Home</a></li>
+              <li class="dropdown">
+                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">ASF <b class="caret"></b></a>
+                  <ul class="dropdown-menu">
+                      <li><a href="http://www.apache.org/foundation/">ASF Home</a></li>
+                      <li><a href="http://projects.apache.org/">Projects</a></li>
+                      <li><a href="http://people.apache.org/">People</a></li>
+                      <li><a href="http://www.apache.org/foundation/getinvolved.html">Get Involved</a></li>
+                      <li><a href="http://www.apache.org/dyn/closer.cgi">Download</a></li>
+                      <li><a href="http://www.apache.org/security/">Security</a></li>
+                      <li><a href="http://www.apache.org/foundation/sponsorship.html">Support Apache</a></li>
+                  </ul>
+              </li>
+
+              <li><a href="http://www.apache.org/licenses/">License</a></li>
+
+              <li class="dropdown">
+                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Download <b class="caret"></b></a>
+                  <ul class="dropdown-menu">
+                      <li><a href="/doc/odata2/download.html">Download OData 2.0 Java</a></li>
+                      <li><a href="/doc/odata4/download.html">Download OData 4.0 Java</a></li>
+                      <li><a href="/doc/javascript/download.html">Download OData 4.0 JavaScript</a></li>
+                  </ul>
+              </li>
+
+              <li class="dropdown">
+                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Documentation <b class="caret"></b></a>
+                  <ul class="dropdown-menu">
+                    <li><a href="/doc/odata2/index.html">Documentation OData 2.0 Java</a></li>
+                    <li><a href="/doc/odata4/index.html">Documentation OData 4.0 Java</a></li>
+                    <li><a href="/doc/javascript/index.html">Documentation OData 4.0 JavaScript</a></li>
+                  </ul>
+              </li>
+              <li><a href="/support.html">Support</a></li>
+
+            </ul>
+
+			  <img class="navbar-right" height="50px" src="/img/asf-logo.gif">
+
+			</div><!--/.nav-collapse -->
+        </div><!--/.container-fluid -->
+      </div><!-- Main component for a primary marketing message or call to action --><style type="text/css">
+/* The following code is added by mdx_elementid.py
+   It was originally lifted from http://subversion.apache.org/style/site.css */
+/*
+ * Hide class="elementid-permalink", except when an enclosing heading
+ * has the :hover property.
+ */
+.headerlink, .elementid-permalink {
+  visibility: hidden;
+}
+h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
+<h1 id="how-to-build-an-odata-service-with-olingo-v4">How to build an OData Service with Olingo V4<a class="headerlink" href="#how-to-build-an-odata-service-with-olingo-v4" title="Permanent link">&para;</a></h1>
+<h1 id="part-7-handling-deep-insert-requests">Part 7: Handling "Deep Insert" requests<a class="headerlink" href="#part-7-handling-deep-insert-requests" title="Permanent link">&para;</a></h1>
+<h2 id="introduction">Introduction<a class="headerlink" href="#introduction" title="Permanent link">&para;</a></h2>
+<p>In the present tutorial, we will implement the handling of deep insert requests.</p>
+<p><strong>Note:</strong>
+The final source code can be found in the project <a href="https://git-wip-us.apache.org/repos/asf/olingo-odata4">git repository</a>.
+A detailed description how to checkout the tutorials can be found <a href="/doc/odata4/tutorials/prerequisites/prerequisites.html">here</a>. <br />
+This tutorial can be found in subdirectory /samples/tutorials/p11_batch</p>
+<p><strong>Table of Contents</strong></p>
+<ol>
+<li>Introduction</li>
+<li>Preparation</li>
+<li>Implementation</li>
+<li>Run the implemented service</li>
+<li>Links</li>
+</ol>
+<h1 id="1-introduction">1. Introduction<a class="headerlink" href="#1-introduction" title="Permanent link">&para;</a></h1>
+<p>In this tutorial shows how to handle "deep insert" requests. OData gives us the possibility to create  related entities, and bind existing entities to a new created entity in a single request. (More detailed information: <a href="http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398326">OData Version 4.0 Part 1: Protocol</a>, <a href="http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940637">OData JSON Format Version 4.0</a>)</p>
+<p>OData uses to create a related entity the same syntax as for an expanded navigation property, as descripted in <a href="http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940637">OData JSON Format</a>. To bind an existing entity, OData uses the <code>odata.bind</code> property annotation. The value of the annotation is either an entity-Id or a collection of entity-Ids. An <a href="http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398204">entity-Id</a> is a durable, opaque, globally unique <a href="https://www.ietf.org/rfc/rfc3987.txt">IRI</a>. The specification recommends to use the canonical URL of the entity. In this tutorial the relative canonical URL of an entity is used.</p>
+<p><strong>Example</strong></p>
+<p>For example you may want to create a new category and also create new products, which are related to the new created category. In addition you would like to bind an existing entity to the new created category.
+Such a request is issued againest the URL of the entity set. </p>
+<p>In this example, a new Category "Food" and two products ("Bread", "Milk") are created. In addition the Product with the key 5 is bind to the just created entity.</p>
+<div class="codehilite"><pre><span class="n">POST</span> <span class="o">/</span><span class="n">Categories</span> <span class="n">HTTP</span><span class="o">/</span>1<span class="p">.</span>1
+<span class="n">Content</span><span class="o">-</span><span class="n">Type</span><span class="p">:</span> <span class="n">application</span><span class="o">/</span><span class="n">json</span>
+
+<span class="p">{</span>
+    &quot;<span class="n">name</span>&quot;<span class="p">:</span> &quot;<span class="n">Food</span>&quot;<span class="p">,</span>
+    &quot;<span class="n">Products</span><span class="p">@</span><span class="n">odata</span><span class="p">.</span><span class="n">bind</span>&quot;<span class="p">:</span> <span class="p">[</span>
+        &quot;<span class="n">Products</span><span class="p">(</span>5<span class="p">)</span>&quot;
+    <span class="p">],</span>
+    &quot;<span class="n">Products</span>&quot;<span class="p">:</span> <span class="p">[</span>
+        <span class="p">{</span>
+            &quot;<span class="n">Name</span>&quot;<span class="p">:</span> &quot;<span class="n">Bread</span>&quot;<span class="p">,</span>
+            &quot;<span class="n">Description</span>&quot;<span class="p">:</span> &quot;<span class="n">Whole</span> <span class="n">grain</span> <span class="n">bread</span>&quot;
+        <span class="p">},</span>
+        <span class="p">{</span>
+            &quot;<span class="n">Name</span>&quot;<span class="p">:</span> &quot;<span class="n">Milk</span>&quot;<span class="p">,</span>
+            &quot;<span class="n">Description</span>&quot;<span class="p">:</span> &quot;<span class="n">Low</span> <span class="n">fat</span> <span class="n">milk</span>&quot;
+        <span class="p">}</span>
+    <span class="p">]</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<h1 id="2-preparation">2. Preparation<a class="headerlink" href="#2-preparation" title="Permanent link">&para;</a></h1>
+<p>You should read the previous tutorials first to have an idea how to read and write entities. In addition the following code is based on the write tutorial merged with the navigation tutorial.</p>
+<p>As a shortcut you should checkout the prepared tutorial project in the <a href="https://git-wip-us.apache.org/repos/asf/olingo-odata4">git repository</a> in folder /samples/tutorials/p12_deep_insert_preparation.</p>
+<p>Afterwards do a Deploy and run: it should be working. At this state you can perform CRUD operations and do navigations between products and categories.</p>
+<h1 id="2-implementation">2. Implementation<a class="headerlink" href="#2-implementation" title="Permanent link">&para;</a></h1>
+<p>Before we start with the implementation, please have a look at the class <code>myservice.mynamespace.data.Storage</code>. In difference to the <a href="http://olingo.apache.org/doc/odata4/tutorials/navigation/tutorial_navigation.html">navigation tutorial</a> the relations between two entities can not be hard coded because we would like to create and change relations between entities. In the constructor of the data storage the sample data is created. After that the method <code>linkProductsAndCategories</code>is called. This methods sets a few links between the just created entities.</p>
+<p>To express the relation between two entities, Olingo uses the class <a href="http://olingo.apache.org/javadoc/odata4/org/apache/olingo/commons/api/data/Link.html">Link</a>. This class is used for related entites (directly connected via Java references) and bindings (which are actually strings) to other entities dynamically. To get the related entites for a particual navigation property, you can ask an entity with the method <a href="http://olingo.apache.org/javadoc/odata4/org/apache/olingo/commons/api/data/Linked.html#getNavigationLink(java.lang.String)"><code>getNavigationLink(String name)</code></a> for an navigation property. The link will contain either an entity or a collection of entities dependenting on the type of the navigation property. To get the actual entities use the methods <a href="http://olingo.apache.org/javadoc/odata4/org/apache/olingo/commons/api/data/Link.html#getInlineEntity()"><code>getInlineEntity()</code></a> or <a href="http://olingo.apache.org/javadoc/o
 data4/org/apache/olingo/commons/api/data/Link.html#getInlineEntitySet()"><code>getInlineEntitySet()</code></a>
+The same can be done for bindings via the method <a href="http://olingo.apache.org/javadoc/odata4/org/apache/olingo/commons/api/data/Linked.html#getNavigationBinding(java.lang.String)"><code>getNavigationBinding(String name)</code></a>. The values of the Binding can be got by the methods <a href="http://olingo.apache.org/javadoc/odata4/org/apache/olingo/commons/api/data/Link.html#getBindingLink()"><code>getBindingLink()</code></a> and <a href="http://olingo.apache.org/javadoc/odata4/org/apache/olingo/commons/api/data/Link.html#getBindingLinks()"><code>getBindingLinks()</code></a>. </p>
+<p>The point is that the Entity deserializer uses the same concept to represent the payload as Java objects.
+In the previous tutorials the entity object returned by the deserializer is passed to the data store. Please open the class <code>myservice.mynamespace.data.Storage</code> and jump the method <code>createEntity</code>.</p>
+<h1 id="4-run-the-implemented-service">4. Run the implemented service<a class="headerlink" href="#4-run-the-implemented-service" title="Permanent link">&para;</a></h1>
+<p>After building and deploying your service to your server, you can try the following requests:</p>
+<h1 id="5-links">5. Links<a class="headerlink" href="#5-links" title="Permanent link">&para;</a></h1>
+<h3 id="tutorials">Tutorials<a class="headerlink" href="#tutorials" title="Permanent link">&para;</a></h3>
+<p>Further topics to be covered by follow-up tutorials:</p>
+<ul>
+<li>Tutorial OData V4 service part 1: <a href="/doc/odata4/tutorials/read/tutorial_read.html">Read Entity Collection</a></li>
+<li>Tutorial OData V4 service part 2: <a href="/doc/odata4/tutorials/readep/tutorial_readep.html">Read Entity, Read Property</a> </li>
+<li>Tutorial OData V4 service part 3: <a href="/doc/odata4/tutorials/write/tutorial_write.html">Write (Create, Update, Delete Entity)</a></li>
+<li>Tutorial OData V4 service, part 4: <a href="/doc/odata4/tutorials/navigation/tutorial_navigation.html">Navigation</a></li>
+<li>Tutorial OData V4 service, part 5.1: <a href="/doc/odata4/tutorials/sqo_tcs/tutorial_sqo_tcs.html">System Query Options $top, $skip, $count (this page)</a></li>
+<li>Tutorial OData V4 service, part 5.2: <a href="/doc/odata4/tutorials/sqo_es/tutorial_sqo_es.html">System Query Options $select, $expand</a></li>
+<li>Tutorial OData V4 service, part 5.3: <a href="/doc/odata4/tutorials/sqo_o/tutorial_sqo_o.html">System Query Options $orderby</a></li>
+<li>Tutorial OData V4 service, part 5.4: <a href="/doc/odata4/tutorials/sqo_f/tutorial_sqo_f.html">System Query Options $filter</a></li>
+<li>Tutoral ODATA V4 service, part 6: <a href="/doc/odata4/tutorials/action/tutorial_action.html">Action and Function Imports</a></li>
+<li>Tutoral ODATA V4 service, part 6: <a href="/doc/odata4/tutorials/batch/tutorial_batch.html">Batch Request support</a></li>
+<li>Tutoral ODATA V4 service, part 6: Handling "Deep Insert" requests </li>
+</ul>
+<h3 id="code-and-repository">Code and Repository<a class="headerlink" href="#code-and-repository" title="Permanent link">&para;</a></h3>
+<ul>
+<li><a href="https://git-wip-us.apache.org/repos/asf/olingo-odata4">Git Repository</a></li>
+<li><a href="/doc/odata4/tutorials/prerequisites/prerequisites.html">Guide - To fetch the tutorial sources</a></li>
+<li><a href="http://www.apache.org/dyn/closer.lua/olingo/odata4/4.0.0/DemoService_Tutorial.zip">Demo Service source code as zip file (contains all tutorials)</a></li>
+</ul>
+<h3 id="further-reading">Further reading<a class="headerlink" href="#further-reading" title="Permanent link">&para;</a></h3>
+<ul>
+<li><a href="http://odata.org/">Official OData Homepage</a></li>
+<li><a href="http://www.odata.org/documentation/">OData documentation</a></li>
+<li><a href="/javadoc/odata4/index.html">Olingo Javadoc</a></li>
+</ul><div align="center">
+<p>Copyright © 2013-2015, The Apache Software Foundation<br>
+				                Apache Olingo, Olingo, Apache, the Apache feather, and
+				the Apache Olingo project logo are trademarks of the Apache Software
+				Foundation.</p>
+        <small><a href="/doc/odata2/privacy.html">Privacy</a></small>
+      </div>
+    </div><!-- /container -->
+    <!-- Bootstrap core JavaScript
+    ================================================== -->
+    <!-- Placed at the end of the document so the pages load faster -->
+    <script src="/js/jquery.js" type="text/javascript">
+</script>
+	  <script src="/js/bootstrap.js" type="text/javascript">
+	  <script src="/js/offcanvas.js" type="text/javascript">
+</script>
+        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
+        <script>
+            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
+            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
+            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
+            e.src='//www.google-analytics.com/analytics.js';
+            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
+            ga('create','UA-44963757-1');ga('send','pageview');
+        </script>
+  </body>
+</html>