[Project] Extending bookshop tutorial
This commit is contained in:
parent
da1afe7d69
commit
eecabe7a7f
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="google-site-verification" content="CPhbjooaiTdROm7Vs4E7kuHZvBfkeLUtonGgcVUbTL8"/>
|
||||
<meta name="google-site-verification" content="CPhbjooaiTdROm7Vs4E7kuHZvBfkeLUtonGgcVUbTL8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
@ -53,20 +53,27 @@
|
|||
<div class="content">
|
||||
<p>Dos and Don'ts</p>
|
||||
<ul>
|
||||
<li>1 <code>Service</code> per use-case, services are throw away implementations</li>
|
||||
<li><code>Services</code> call <code>Commands</code> - no logic in Services, no calling other services</li>
|
||||
<li><code>Commands</code> implement parts of use-cases and are thus re-usable</li>
|
||||
<li>1 <code>Service</code> per use-case, should mostly delegate to <code>Commands</code>.</li>
|
||||
<li><code>Commands</code> implement use-cases or parts of it, and are thus reusable.</li>
|
||||
<li>Subclass <code>ResourceQuery</code> and <code>OrderQuery</code> when implementing use-case specific
|
||||
querying
|
||||
querying - this allows privilege checking.
|
||||
</li>
|
||||
<li>One Transaction at a time - no TX inside of another TX.</li>
|
||||
<li>Commands are added to TXs and performed on close: <code>tx.addCommand(Command)</code> and then <code>tx.commitOnClose()</code>
|
||||
</li>
|
||||
<li>One Transaction at a time - no TX in TX</li>
|
||||
<li>Commands are added to TXs and performed on close: <code>tx.addCommand(Command)</code></li>
|
||||
<li>Use <code>tx.flush() and as late as possible in your TX <code>tx.commitOnClose()</code></code>
|
||||
</li>
|
||||
<li>Only access <code>ElementMap</code>s if really no other way, mostly use <code>tx.get*By()</code>, <code>tx.findBy()</code>
|
||||
and queries - if a specific get is missing, then add the method to <code>StrolchTransaction</code> and
|
||||
send a pull request!
|
||||
</li>
|
||||
<li>Don't write logic in REST API beans. Delegate to other classes, making your code reusable!</li>
|
||||
<li>Transform to JSON using the <code>StrolchElementToJsonVisitor</code>.</li>
|
||||
<li>References between objects is done by adding a <code>ParameterBag</code> with the id
|
||||
<code>relations</code> to the object and then <code>StringParameters</code> with the value being the ID,
|
||||
the UOM set to the type of element being referenced and the Interpretation set to the class type being
|
||||
referenced.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- content here -->
|
||||
|
@ -106,7 +113,7 @@
|
|||
s.parentNode.insertBefore(g, s);
|
||||
})();
|
||||
</script>
|
||||
<noscript><p><img src="http://piwik.eitchnet.ch/piwik.php?idsite=2" style="border:0;" alt=""/></p></noscript>
|
||||
<noscript><p><img src="http://piwik.eitchnet.ch/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
|
||||
<!-- End Piwik Code -->
|
||||
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="google-site-verification" content="CPhbjooaiTdROm7Vs4E7kuHZvBfkeLUtonGgcVUbTL8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<link rel="shortcut icon" href="ico/favicon.ico">
|
||||
|
||||
<title>Strolch: Tutorial CRUD Book</title>
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="css/custom.css" rel="stylesheet">
|
||||
|
||||
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --><!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script><![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="index.html">Strolch</a>
|
||||
</div>
|
||||
<div class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="api.html">API</a></li>
|
||||
<li><a href="documentation.html">Documentation</a></li>
|
||||
<li class="active"><a href="tutorial.html">Tutorial</a></li>
|
||||
<li><a href="downloads.html">Downloads</a></li>
|
||||
<li><a href="development.html">Development</a></li>
|
||||
<li><a href="blog.html">Blog</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!--/.nav-collapse -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Tutorial: CRUD Book</h1>
|
||||
|
||||
<p class="lead page-description">Writing the CRUD services for books.</p>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<a href="tutorial-model.html" class="pull-left">Previous: Model</a> <br><br>
|
||||
|
||||
<p>Coming soon...</p>
|
||||
|
||||
<a href="tutorial-model.html" class="pull-left">Previous: Model</a>
|
||||
<!-- content here -->
|
||||
|
||||
<a href="tutorial-model.html"></a>
|
||||
|
||||
</div>
|
||||
<!-- /.content -->
|
||||
|
||||
<div id="footer">
|
||||
<div class="container">
|
||||
<p class="text-muted">© Strolch / <a href="mailto:eitch@eitchnet.ch">Robert von Burg</a> / Hosting by
|
||||
<a href="http://www.eitchnet.ch">eitchnet.ch</a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- /.container -->
|
||||
|
||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
|
||||
<!-- Include all compiled plugins (below), or include individual xsd as needed -->
|
||||
<script src="js/bootstrap.min.js"></script>
|
||||
|
||||
<!-- Piwik -->
|
||||
<script type="text/javascript">
|
||||
var _paq = _paq || [];
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function () {
|
||||
var u = (("https:" == document.location.protocol) ? "https" : "http") + "://piwik.eitchnet.ch/";
|
||||
_paq.push(['setTrackerUrl', u + 'piwik.php']);
|
||||
_paq.push(['setSiteId', 2]);
|
||||
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
|
||||
g.type = 'text/javascript';
|
||||
g.defer = true;
|
||||
g.async = true;
|
||||
g.src = u + 'piwik.js';
|
||||
s.parentNode.insertBefore(g, s);
|
||||
})();
|
||||
</script>
|
||||
<noscript><p><img src="http://piwik.eitchnet.ch/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
|
||||
<!-- End Piwik Code -->
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -51,16 +51,19 @@
|
|||
</div>
|
||||
|
||||
<div class="content">
|
||||
<a href="tutorial-configuration.html" class="pull-left">Previous: Configuration</a><a href="tutorial-.html"
|
||||
class="pull-right">Next: </a>
|
||||
<a href="tutorial-configuration.html" class="pull-left">Previous:
|
||||
Configuration</a><a href="tutorial-crud-book.html"
|
||||
class="pull-right">Next: CRUD
|
||||
Books</a>
|
||||
<br><br>
|
||||
|
||||
<p>Looking back at our functionality, we can list the following entities that need to be modelled:</p>
|
||||
<p>Looking back at our functionality, we can list the following entities that need to be modelled (We'll go into
|
||||
detail further down):</p>
|
||||
<ul>
|
||||
<li>Book → books can be orderd</li>
|
||||
<li>UserCart → we want to store the cart of the user</li>
|
||||
<li>Account → we need to know where to send the orders</li>
|
||||
<li>Order → we need to know what was ordered and keep track of its state</li>
|
||||
<li>PurchaseOrder → we need to know what was ordered and keep track of its state</li>
|
||||
<li>FromStock → we want to use activities to implement the process of an order</li>
|
||||
</ul>
|
||||
|
||||
|
@ -70,85 +73,162 @@
|
|||
<b>Book</b>
|
||||
<pre class="pre-scrollable">
|
||||
<Resource Id="Book" Name="Book Template" Type="Template">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="description" Name="Description" Type="String" Value="" />
|
||||
<Parameter Id="quantity" Name="Quantity in Stock" Type="Integer" Value="0" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
</pre>
|
||||
|
||||
<b>UserCart</b>
|
||||
<pre class="pre-scrollable">
|
||||
<Resource Id="UserCart" Name="UserCart Template" Type="Template">
|
||||
<ParameterBag Id="books" Name="Books" Type="Book">
|
||||
<!-- Parameter Id="bookId" Name="Book reference" Type="Float" Value="0" / -->
|
||||
</ParameterBag>
|
||||
<ParameterBag Id="relations" Name="Relations" Type="Parameters">
|
||||
<Parameter Id="account" Name="Account" Type="String" Interpretation="Resource-Ref" Uom="Account" Value="" />
|
||||
</ParameterBag>
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="description" Name="Description" Type="String" Value="" />
|
||||
<Parameter Id="quantity" Name="Quantity in Stock" Type="Integer" Value="0" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
</pre>
|
||||
|
||||
<b>Account</b>
|
||||
<pre class="pre-scrollable">
|
||||
<Resource Id="Account" Name="Account Template" Type="Template">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="user" Name="User" Type="String" Value="" />
|
||||
<Parameter Id="firstName" Name="First Name" Type="String" Value="" />
|
||||
<Parameter Id="lastName" Name="Last Name" Type="String" Value="" />
|
||||
<Parameter Id="email" Name="E-Mail" Type="String" Value="" />
|
||||
</ParameterBag>
|
||||
<ParameterBag Name="Address" Id="address" Type="Address">
|
||||
<Parameter Id="phone" Name="Telephone Number" Type="String" Value="" />
|
||||
<Parameter Id="street" Name="Street" Type="String" Value="" />
|
||||
<Parameter Id="city" Name="City" Type="String" Value="" />
|
||||
<Parameter Id="zip" Name="Postal Code" Type="String" Value="" />
|
||||
<Parameter Id="country" Name="Country" Type="String" Value="" />
|
||||
</ParameterBag>
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="user" Name="User" Type="String" Value="" />
|
||||
<Parameter Id="firstName" Name="First Name" Type="String" Value="" />
|
||||
<Parameter Id="lastName" Name="Last Name" Type="String" Value="" />
|
||||
<Parameter Id="email" Name="E-Mail" Type="String" Value="" />
|
||||
</ParameterBag>
|
||||
<ParameterBag Name="Address" Id="address" Type="Address">
|
||||
<Parameter Id="phone" Name="Telephone Number" Type="String" Value="" />
|
||||
<Parameter Id="street" Name="Street" Type="String" Value="" />
|
||||
<Parameter Id="city" Name="City" Type="String" Value="" />
|
||||
<Parameter Id="zip" Name="Postal Code" Type="String" Value="" />
|
||||
<Parameter Id="country" Name="Country" Type="String" Value="" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
</pre>
|
||||
|
||||
<b>Order</b>
|
||||
<b>UserCart</b>
|
||||
<pre class="pre-scrollable">
|
||||
<Order Id="Order" Name="Order Template" Type="Template" State="Created">
|
||||
<ParameterBag Id="books" Name="Books" Type="Book">
|
||||
<!-- Parameter Id="bookId" Name="Book reference" Type="Float" Value="0" / -->
|
||||
</ParameterBag>
|
||||
<ParameterBag Id="relations" Name="Relations" Type="Parameters">
|
||||
<Parameter Id="account" Name="Account" Type="String" Interpretation="Resource-Ref" Uom="Account" Value="" />
|
||||
</ParameterBag>
|
||||
<Resource Id="UserCart" Name="UserCart Template" Type="Template">
|
||||
<ParameterBag Id="books" Name="Books" Type="Book">
|
||||
<!-- Parameter Id="bookId" Name="Book reference" Type="Float" Value="0" / -->
|
||||
</ParameterBag>
|
||||
<ParameterBag Id="relations" Name="Relations" Type="Parameters">
|
||||
<Parameter Id="account" Name="Account" Type="String" Interpretation="Resource-Ref" Uom="Account" Value="" />
|
||||
</ParameterBag>
|
||||
</Resource>
|
||||
</pre>
|
||||
|
||||
<b>PurchaseOrder</b>
|
||||
<pre class="pre-scrollable">
|
||||
<Order Id="PurchaseOrder" Name="PurchaseOrder Template" Type="Template" State="Created">
|
||||
<ParameterBag Id="books" Name="Books" Type="Book">
|
||||
<!-- Parameter Id="bookId" Name="Book reference" Type="Float" Value="0" / -->
|
||||
</ParameterBag>
|
||||
<ParameterBag Id="relations" Name="Relations" Type="Parameters">
|
||||
<Parameter Id="account" Name="Account" Type="String" Interpretation="Resource-Ref" Uom="Account" Value="" />
|
||||
</ParameterBag>
|
||||
</Order>
|
||||
</pre>
|
||||
|
||||
<b>FromStock</b>
|
||||
<pre class="pre-scrollable">
|
||||
<Activity Id="FromStock" Name="From Stock Template" Type="FromStock" TimeOrdering="Series">
|
||||
<ParameterBag Name="objectives" Id="Objectives" Type="Objectives">
|
||||
<Parameter Name="Duration" Id="duration" Value="PT1MS" Type="Duration" />
|
||||
</ParameterBag>
|
||||
|
||||
<Action Id="Validate" Name="Validation of order" Type="Use" ResourceType="Validation" ResourceId="validation" />
|
||||
|
||||
<!-- for each book we do a consume, i.e. reduce the stock quantity -->
|
||||
<Action Id="Consume" Name="Consume Template for book" Type="Template">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="quantity" Name="Quantity" Type="Float" Value="0" />
|
||||
<ParameterBag Name="objectives" Id="Objectives" Type="Objectives">
|
||||
<Parameter Name="Duration" Id="duration" Value="PT1MS" Type="Duration" />
|
||||
</ParameterBag>
|
||||
</Action>
|
||||
|
||||
<Action Id="Package" Name="Packaging of Order" Type="Use" ResourceType="Packaging" ResourceId="packaging" />
|
||||
<Action Id="Send" Name="Sending of package" Type="Use" ResourceType="Sending" ResourceId="sending" />
|
||||
<Action Id="validate" Name="Validation of order" Type="Use" ResourceType="Validation" ResourceId="validation" />
|
||||
|
||||
<!-- for each book we do a consume, i.e. reduce the stock quantity -->
|
||||
<Action Id="Consume" Name="Consume Template for book" Type="Template">
|
||||
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
||||
<Parameter Id="quantity" Name="Quantity" Type="Float" Value="0" />
|
||||
</ParameterBag>
|
||||
</Action>
|
||||
|
||||
<Action Id="package" Name="Packaging of PurchaseOrder" Type="Use" ResourceType="Packaging" ResourceId="packaging" />
|
||||
<Action Id="send" Name="Sending of package" Type="Use" ResourceType="Sending" ResourceId="sending" />
|
||||
|
||||
</Activity>
|
||||
</pre>
|
||||
|
||||
<p>Let's explain a few things:</p>
|
||||
<ul>
|
||||
<li></li>
|
||||
<li>The <code>Book</code> entity is a <code>Resource</code> object and only contains the description and the
|
||||
current quantity in stock.
|
||||
</li>
|
||||
<li>The <code>Account</code> entity is a Resource and contains the address and further details of the user,
|
||||
and with the <code>user</code> parameter the username is defined, thus referencing the real user.
|
||||
</li>
|
||||
<li>The <code>UserCart</code> entity is a Resource and has a reference to the account Resource. Note how the
|
||||
reference is done using a StringParameter, where Interpretation, UOM and the value is set in a specific
|
||||
manner.
|
||||
</li>
|
||||
<li>The <code>UserCart</code> entity is a Resource and references books using a special
|
||||
<code>ParameterBag</code> with the type set to <code>Book</code>, the actual type of the book entity.
|
||||
Each Parameter is of type <code>Float</code> and the ID of the parameter is the ID of the book, and the
|
||||
value is the quantity that the user would like to purchase. There will only be one cart per
|
||||
user/account.
|
||||
</li>
|
||||
<li>The <code>PurchaseOrder</code> entity is an <code>Order</code> object, and is basically a copy of the
|
||||
UserCart entity. This is the confirmed purchase order for the contents of a cart, and can then be used
|
||||
for reports on how much of which book was sold.
|
||||
</li>
|
||||
<li>The <code>FromStock</code> entity is an <code>Activity</code> object and defines the process we will go
|
||||
through when delivering a purchase to a user. Note how the activity has a ParameterBag
|
||||
<code>objectives</code> with a <code>duration</code> parameter. This defines globally for this activity
|
||||
how long each <code>Action</code> should execute. This can be overridden in each Action and can help to
|
||||
plan how much effort goes into the delivering of each PurchaseOrder.
|
||||
</li>
|
||||
<li>Further note how the activity has three special actions (<code>validate</code>, <code>package</code> and
|
||||
<code>send</code>) on which a <code>ResourceType</code> and <code>ResourceId</code> are defined. Actions
|
||||
are always performed on a Resource, as the referenced Resource defines the behaviour of the action
|
||||
through defined <code>Policy</code> objects.
|
||||
</li>
|
||||
<li>For each book which will be purchased, an Action will be created of type <code>Consume</code>. In the
|
||||
template this is defined by a template Action with the id <code>Consume</code> and will later be changed
|
||||
accordingly.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<a href="tutorial-configuration.html" class="pull-left">Previous: Configuration</a><a href="tutorial-.html"
|
||||
class="pull-right">Next: </a>
|
||||
<p>Since we are referencing resources from actions in the activity, we need to add these as well, but not as
|
||||
templates. They can be added to the <code>defaultModel.xml</code> file:</p>
|
||||
<pre>
|
||||
<Resource Id="validation" Name="Validation Resource" Type="Validation">
|
||||
<Policies>
|
||||
<Policy Type="ExecutionPolicy" Value="key:ValidationExecution" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:DefaultConfirmation" />
|
||||
</Policies>
|
||||
</Resource>
|
||||
|
||||
<Resource Id="packaging" Name="Packaging Resource" Type="Packaging">
|
||||
<Policies>
|
||||
<Policy Type="ExecutionPolicy" Value="key:PackagingExecution" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:DefaultConfirmation" />
|
||||
</Policies>
|
||||
</Resource>
|
||||
|
||||
<Resource Id="sending" Name="Sending Resource" Type="Sending">
|
||||
<Policies>
|
||||
<Policy Type="ExecutionPolicy" Value="key:SendingExecution" />
|
||||
<Policy Type="ConfirmationPolicy" Value="key:DefaultConfirmation" />
|
||||
</Policies>
|
||||
</Resource>
|
||||
</pre>
|
||||
|
||||
<p>What should now be noted by these three new Resources is that they have Policy definitions:</p>
|
||||
<ul>
|
||||
<li><code>ExecutionPolicy</code> → defines how an action on this resource is executed by
|
||||
referencing an ExecutionPolicy implementation.
|
||||
</li>
|
||||
<li><code>ConfirmationPolicy</code> → defines behaviour to be performed on every state change of
|
||||
an action being performed on this resource by referencing an
|
||||
ConfirmationPolicy implementation.
|
||||
</li>
|
||||
</ul>
|
||||
<p>Currently these resources reference policies which don't exist. We will resolve this issue later, when we
|
||||
implement the execution of the activity.</p>
|
||||
|
||||
<p>This concludes the model definition. In the next step we'll start creating services and commands for our
|
||||
model.</p>
|
||||
|
||||
<a href="tutorial-configuration.html" class="pull-left">Previous:
|
||||
Configuration</a><a href="tutorial-crud-book.html"
|
||||
class="pull-right">Next: CRUD
|
||||
Books</a>
|
||||
<!-- content here -->
|
||||
|
||||
<a href="tutorial-model.html"></a>
|
||||
|
|
|
@ -68,13 +68,16 @@
|
|||
<li>Notify the user when the order is sent</li>
|
||||
</ul>
|
||||
|
||||
<p>Navigation:</p>
|
||||
<ul>
|
||||
<li><a href="tutorial-configuration.html">Configuration</a></li>
|
||||
<li><a href="tutorial-model.html">Model</a></li>
|
||||
</ul>
|
||||
<p>Navigation:</p>
|
||||
<ul>
|
||||
<li><a href="tutorial-configuration.html">Configuration</a></li>
|
||||
<li><a href="tutorial-model.html">Model</a></li>
|
||||
</ul>
|
||||
|
||||
<a href="tutorial-configuration.html" class="pull-right">Next: Configuration</a>
|
||||
<p>The code to the book can be downloaded from <a href="https://github.com/4treesCH/strolch-bookshop">GitHub</a>
|
||||
and will be updated as this tutorial is updated.</p>
|
||||
|
||||
<a href="tutorial-configuration.html" class="pull-right">Next: Configuration</a>
|
||||
|
||||
</div>
|
||||
<!-- /.content -->
|
||||
|
|
Loading…
Reference in New Issue