<!doctype html><htmllang=enclass="js csstransforms3d"><head><metacharset=utf-8><metaname=viewportcontent="width=device-width,initial-scale=1"><metaname=generatorcontent="Hugo 0.80.0"><metaname=descriptioncontent="Strolch is a parameterized framework for use on servers and IoT"><metaname=authorcontent="Robert von Burg"><linkrel=iconhref=/favicon.icotype=image/ico><title>Model - Strolch</title><linkhref=/css/nucleus.css?1678977092rel=stylesheet><linkhref=/css/fontawesome-all.min.css?1678977092rel=stylesheet><linkhref=/css/hybrid.css?1678977092rel=stylesheet><linkhref=/css/featherlight.min.css?1678977092rel=stylesheet><linkhref=/css/perfect-scrollbar.min.css?1678977092rel=stylesheet><linkhref=/css/auto-complete.css?1678977092rel=stylesheet><linkhref=/css/atom-one-dark-reasonable.css?1678977092rel=stylesheet><linkhref=/css/theme.css?1678977092rel=stylesheet><linkhref=/css/hugo-theme.css?1678977092rel=stylesheet><linkhref=/css/theme-green.css?1678977092rel=stylesheet><scriptsrc=/js/jquery-3.3.1.min.js?1678977092></script><style>:root#header+#content>#left>#rlblock_left{display:none!important}</style></head><bodydata-url=/tutorial/model/><navid=sidebar><divid=header-wrapper><divid=header><aid=logohref=/><imgsrc=/logo.png></a></div><divclass=searchbox><labelfor=search-by><iclass="fas fa-search"></i></label><inputdata-search-inputid=search-bytype=searchplaceholder=Search...>
<spandata-search-clear><iclass="fas fa-times"></i></span></div><scripttype=text/javascriptsrc=/js/lunr.min.js?1678977092></script><scripttype=text/javascriptsrc=/js/auto-complete.js?1678977092></script><scripttype=text/javascript>varbaseurl="https:\/\/strolch.li\/";</script><scripttype=text/javascriptsrc=/js/search.js?1678977092></script></div><sectionid=homelinks><ul><li><aclass=paddinghref=/><iclass="fas fa-home"></i>Home</a></li></ul></section><divclass=highlightable><ulclass=topics><lidata-nav-id=/api/title=APIclass=dd-item><ahref=/api/>API</a></li><lidata-nav-id=/documentation/title=Documentationclass=dd-item><ahref=/documentation/>Documentation</a><ul><lidata-nav-id=/documentation/architecture/title=Architectureclass=dd-item><ahref=/documentation/architecture/>Architecture</a></li><lidata-nav-id=/documentation/model/title=Modelclass=dd-item><ahref=/documentation/model/>Model</a></li><lidata-nav-id=/documentation/do-and-donts/title="Do and Don't"class=dd-item><ahref=/documentation/do-and-donts/>Do and Don't</a></li><lidata-nav-id=/documentation/runtime-configuration/title="Runtime Configuration"class=dd-item><ahref=/documentation/runtime-configuration/>Runtime Configuration</a></li><lidata-nav-id=/documentation/realms/title=Realmsclass=dd-item><ahref=/documentation/realms/>Realms</a></li><lidata-nav-id=/documentation/components/title=Componentsclass=dd-item><ahref=/documentation/components/>Components</a></li><lidata-nav-id=/documentation/services-and-commands/title="Services and Commands"class=dd-item><ahref=/documentation/services-and-commands/>Services and Commands</a></li><lidata-nav-id=/documentation/searches/title=Searchesclass=dd-item><ahref=/documentation/searches/>Searches</a></li><lidata-nav-id=/documentation/queries/title=Queriesclass=dd-item><ahref=/documentation/queries/>Queries</a></li><lidata-nav-id=/documentation/transactions/title=Transactionsclass=dd-item><ahref=/documentation/transactions/>Transactions</a></li><lidata-nav-id=/documentation/policies/title=Policiesclass=dd-item><ahref=/documentation/policies/>Policies</a></li><lidata-nav-id=/documentation/observers/title=Observersclass=dd-item><ahref=/documentation/observers/>Observers</a></li><lidata-nav-id=/documentation/versioning/title=Versioningclass=dd-item><ahref=/documentation/versioning/>Versioning</a></li><lidata-nav-id=/documentation/reports/title=Reportsclass=dd-item><ahref=/documentation/reports/>Reports</a></li><lidata-nav-id=/documentation/priviles/title=Privilegesclass=dd-item><ahref=/documentation/priviles/>Privileges</a></li></ul></li><lidata-nav-id=/plc/title=PLCclass=dd-item><ahref=/plc/>PLC</a><ul><lidata-nav-id=/plc/architecture/title=Architectureclass=dd-item><ahref=/plc/architecture/>Architecture</a></li><lidata-nav-id=/plc/example-set-up/title="Example Set-Up"class=dd-item><ahref=/plc/example-set-up/>Example Set-Up</a></li></ul></li><lidata-nav-id=/tutorial/title=Tutorialclass="dd-item
parent"><ahref=/tutorial/>Tutorial</a><ul><lidata-nav-id=/tutorial/configuration/title=Configurationclass=dd-item><ahref=/tutorial/configuration/>Configuration</a></li><lidata-nav-id=/tutorial/model/title=Modelclass="dd-item active"><ahref=/tutorial/model/>Model</a></li><lidata-nav-id=/tutorial/crud-book/title="CRUD Book"class=dd-item><ahref=/tutorial/crud-book/>CRUD Book</a></li></ul></li><lidata-nav-id=/download/title=Downloadclass=dd-item><ahref=/download/>Download</a></li><lidata-nav-id=/development/title=Developmentclass=dd-item><ahref=/development/>Development</a><ul><lidata-nav-id=/development/prerequisites/title=Prerequisitesclass=dd-item><ahref=/development/prerequisites/>Prerequisites</a></li><lidata-nav-id=/development/building/title="Building Strolch"class=dd-item><ahref=/development/building/>Building Strolch</a></li><lidata-nav-id=/development/maven-archetypes/title="Maven Archetypes"class=dd-item><ahref=/development/maven-archetypes/>Maven Archetypes</a></li><lidata-nav-id=/development/web-app/title="Web App"class=dd-item><ahref=/development/web-app/>Web App</a></li><lidata-nav-id=/development/main-class-app/title="Main Class App"class=dd-item><ahref=/development/main-class-app/>Main Class App</a></li><lidata-nav-id=/development/converting-existing/title="Converting Existing App"class=dd-item><ahref=/development/converting-existing/>Converting Existing App</a></li></ul></li><lidata-nav-id=/blog/title=Blogclass=dd-item><ahref=/blog/>Blog</a><ul><lidata-nav-id=/blog/post-00018/title="Strolch PLC 1.2.3 released"class=dd-item><ahref=/blog/post-00018/>Strolch PLC 1.2.3 released</a></li><lidata-nav-id=/blog/post-00017/title="Strolch 1.8.5 and PLC 1.2.2 are out"class=dd-item><ahref=/blog/post-00017/>Strolch 1.8.5 and PLC 1.2.2 are out</a></li><lidata-nav-id=/blog/post-00016/title="Strolch PLC now also on Maven Central"class=dd-item><ahref=/blog/post-00016/>Strolch PLC now also on Maven Central</a></li><lidata-nav-id=/blog/post-00015/title="Release of Strolch 1.6.100"class=dd-item><ahref=/blog/post-00015/>Release of Strolch 1.6.100</a></li><lidata-nav-id=/blog/post-00014/title="Strolch Reports"class=dd-item><ahref=/blog/post-00014/>Strolch Reports</a></li><lidata-nav-id=/blog/post-00013/title="Strolch Searches"class=dd-item><ahref=/blog/post-00013/>Strolch Searches</a></li><lidata-nav-id=/blog/post-00012/title="Wow, the many changes!"class=dd-item><ahref=/blog/post-00012/>Wow, the many changes!</a></li><lidata-nav-id=/blog/post-00011/title="Strolch now on Maven Central"class=dd-item><ahref=/blog/post-00011/>Strolch now on Maven Central</a></li><lidata-nav-id=/blog/post-00010/title="Versioning of objects"class=dd-item><ahref=/blog/post-00010/>Versioning of objects</a></li><lidata-nav-id=/blog/post-00009/title="Release 1.2.0"class=dd-item><ahref=/blog/post-00009/>Release 1.2.0</a></li><lidata-nav-id=/blog/post-00008/title="Strolch Update"class=dd-item><ahref=/blog/post-00008/>Strolch Update</a></li><lidata-nav-id=/blog/post-00007/title="Activities: Beginning of the planning engine"class=dd-item><ahref=/blog/post-00007/>Activities: Beginning of the planning engine</a></li><lidata-nav-id=/blog/post-00006/title="Strolch Documentation"class=dd-item><ahref=/blog/post-00006/>Strolch Documentation</a></li><lidata-nav-id=/blog/post-00005/title="Strolch Release 1.0.0"class=dd-item><ahref=/blog/post-00005/>Strolch Release 1.0.0</a></li><lidata-nav-id=/blog/post-00004/title="DurationParameter and other minor changes: Release 1.0.0-RC4"class=dd-item><ahref=/blog/post-00004/>DurationParameter and other minor changes: Release 1.0.0-RC4</a></li><lidata-nav-id=/blog/post-00003/title="DB Initialization: Release 1.0.0-RC3"class=dd-item><ahref=/blog/post-00003/>DB Initialization: Release 1.0.0-RC3</a></li><lidata-nav-id=/blog/post-00002/title="Release 1.0.0-RC2"class=dd-item><ahref=/blog/post-00002/>Release 1.0.0-RC2</a></li><lidata-nav-id=/blog/post-00001/title="Release 1.0.0-RC1"class=dd-item><ahref=/blog/post-00
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>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><p>In Strolch we model entities by defining the element as a template. Thus in the
<code>templates.xml</code> file we can add the templates with the following content:</p><p><strong>Book</strong></p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-xmldata-lang=xml>
<spanstyle=color:#f92672><Parameter</span><spanstyle=color:#a6e22e>Id=</span><spanstyle=color:#e6db74>"quantity"</span><spanstyle=color:#a6e22e>Name=</span><spanstyle=color:#e6db74>"Quantity in Stock"</span><spanstyle=color:#a6e22e>Type=</span><spanstyle=color:#e6db74>"Integer"</span><spanstyle=color:#a6e22e>Value=</span><spanstyle=color:#e6db74>"0"</span><spanstyle=color:#f92672>/></span>
<spanstyle=color:#f92672><Action</span><spanstyle=color:#a6e22e>Id=</span><spanstyle=color:#e6db74>"validate"</span><spanstyle=color:#a6e22e>Name=</span><spanstyle=color:#e6db74>"Validation of order"</span><spanstyle=color:#a6e22e>Type=</span><spanstyle=color:#e6db74>"Use"</span>
<spanstyle=color:#75715e><!-- for each book we do a consume, i.e. reduce the stock quantity --></span>
<spanstyle=color:#f92672><Action</span><spanstyle=color:#a6e22e>Id=</span><spanstyle=color:#e6db74>"Consume"</span><spanstyle=color:#a6e22e>Name=</span><spanstyle=color:#e6db74>"Consume Template for book"</span><spanstyle=color:#a6e22e>Type=</span><spanstyle=color:#e6db74>"Template"</span><spanstyle=color:#f92672>></span>
<spanstyle=color:#f92672><Action</span><spanstyle=color:#a6e22e>Id=</span><spanstyle=color:#e6db74>"package"</span><spanstyle=color:#a6e22e>Name=</span><spanstyle=color:#e6db74>"Packaging of PurchaseOrder"</span><spanstyle=color:#a6e22e>Type=</span><spanstyle=color:#e6db74>"Use"</span>
<spanstyle=color:#f92672><Action</span><spanstyle=color:#a6e22e>Id=</span><spanstyle=color:#e6db74>"send"</span><spanstyle=color:#a6e22e>Name=</span><spanstyle=color:#e6db74>"Sending of package"</span><spanstyle=color:#a6e22e>Type=</span><spanstyle=color:#e6db74>"Use"</span><spanstyle=color:#a6e22e>ResourceType=</span><spanstyle=color:#e6db74>"Sending"</span>
</code></pre></div><p>Let’s explain a few things:</p><ul><li><p>The <code>Book</code> entity is a <code>Resource</code> object and only contains the description and the
current quantity in stock.</p></li><li><p>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.</p></li><li><p>The <code>UserCart</code> entity is a Resource and has a reference to the <code>account</code> Resource.</p><divclass="notices tip"><p>Note how the reference is done using a StringParameter, where <code>Interpretation</code>,
<code>UOM</code> and the <code>value</code> is set in a specific manner.</p></div></li><li><p>The <code>UserCart</code> entity is a Resource and references <code>books</code> using a special
ParameterBag with the type set to <code>Book</code>, the actual type of the book entity.
Each Parameter is of type Float 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.</p><p>There will only be one cart per user/account.</p></li><li><p>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.</p></li><li><p>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.</p><divclass="notices tip"><p>Note how the activity has a
ParameterBag <code>objectives</code> with a <code>duration</code> parameter. This defines 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.</p></div><divclass="notices tip"><p>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.</p></div></li><li><p>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 <code>Action</code> with the id
<code>Consume</code> and will later be changed accordingly.</p></li></ul><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>
</code></pre></div><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