392 lines
18 KiB
HTML
392 lines
18 KiB
HTML
<!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: Model</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 class="active"><a href="documentation.html">Documentation</a></li>
|
|
<li><a href="plc.html">PLC</a></li>
|
|
<li><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">Documentation: Model</h1>
|
|
|
|
<p class="lead page-description">This page discusses Strolch's model</p>
|
|
</div>
|
|
|
|
<div class="content">
|
|
|
|
<p>Before we dive into the entire model, let's show an example and how it would be modelled in Strolch and use
|
|
in Strolch:</p>
|
|
<img class="image" src="images/strolch-model-example.png" alt="Strolch model example">
|
|
<p>A possible model would look as follows:</p>
|
|
<pre>
|
|
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<StrolchModel xmlns="https://strolch.li/xsd/StrolchModel-1.6.xsd">
|
|
|
|
<Resource Id="Product" Name="Product Template" Type="Template">
|
|
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
|
<Parameter Id="description" Name="Description" Type="String" Value=""/>
|
|
<Parameter Id="color" Name="Color" Type="String" Value=""/>
|
|
<Parameter Id="form" Name="Form" Type="String" Value=""/>
|
|
</ParameterBag>
|
|
<ParameterBag Id="relations" Name="Relations" Type="Relations">
|
|
<Parameter Id="articles" Name="Articles" Type="StringList" Interpretation="Resource-Ref" Uom="Article" Value=""/>
|
|
</ParameterBag>
|
|
</Resource>
|
|
|
|
<Resource Id="Article" Name="Article Template" Type="Template">
|
|
<ParameterBag Id="parameters" Name="Parameters" Type="Parameters">
|
|
<Parameter Id="description" Name="Description" Type="String" Value=""/>
|
|
<Parameter Id="barcode" Name="Barcode" Type="String" Value=""/>
|
|
</ParameterBag>
|
|
<ParameterBag Id="relations" Name="Relations" Type="Relations">
|
|
<Parameter Id="product" Name="Product" Type="String" Interpretation="Resource-Ref" Uom="Product" Value=""/>
|
|
</ParameterBag>
|
|
</Resource>
|
|
|
|
<Resource Id="Customer" Name="Customer Template" Type="Template">
|
|
<ParameterBag Id="address" Name="Address" Type="Address">
|
|
<Parameter Id="street" Name="Street" Type="String" Value=""/>
|
|
<Parameter Id="zip" Name="Zip" Type="String" Value=""/>
|
|
<Parameter Id="city" Name="City" Type="String" Value=""/>
|
|
<Parameter Id="country" Name="Country" Type="String" Value=""/>
|
|
</ParameterBag>
|
|
</Resource>
|
|
|
|
<Order Id="Order" Name="Order" Type="Template">
|
|
<ParameterBag Id="quantities" Name="Quantities per Article Id" Type="Quantities">
|
|
<Parameter Id="quantity" Name="Quantity" Type="Float" Value="0"/>
|
|
</ParameterBag>
|
|
<ParameterBag Id="relations" Name="Relations" Type="Relations">
|
|
<Parameter Id="articles" Name="Articles" Type="StringList" Interpretation="Resource-Ref" Uom="Article" Value=""/>
|
|
<Parameter Id="customer" Name="Customer" Type="String" Interpretation="Resource-Ref" Uom="Customer" Value=""/>
|
|
</ParameterBag>
|
|
</Order>
|
|
|
|
</StrolchModel></pre>
|
|
<p>Let's go through this model:</p>
|
|
<ul>
|
|
<li><p>In the above model we see that the <code>id</code> and <code>name</code> fields are always on the
|
|
element, and thus aren't added as parameters. Further most elements have a <code>parameters</code>
|
|
ParameterBag, with one or more parameters, modelling the fields.</p></li>
|
|
<li><p>Note that in this example the <code>Type</code> of all the elements is <code>Template</code>. Strolch
|
|
has API support to create a clone of these elements, so that they have a unique ID, and the proper
|
|
type for persistence.</p>
|
|
</li>
|
|
<li><p>The <code>Product</code> element has three parameters: <code>description</code>, <code>color</code>
|
|
and <code>form</code>. In this case they are all of type String. Further the <code>relations</code>
|
|
ParameterBag defines the relationships, i.e. the product knows its articles. Note how the relation is
|
|
first defined in a <code>relations</code> ParameterBag and that the Parameter has <code>Interpretation="Resource-Ref"
|
|
Uom="Product"</code>
|
|
attributes. Strolch has API support for this, making it trivial to retrieve a dependency.</p></li>
|
|
<li><p>The <code>Article</code> element has two parameters <code>description</code> and <code>barcode</code>.
|
|
Further it has a reference to its Product.</p></li>
|
|
<li>The <code>Order</code> element doesn't model the <code>date</code> and <code>state</code> fields as
|
|
parameters, as these are inherently part of an Order element. The Order does define two references to
|
|
<code>customer</code> and <code>articles</code>. A special case is the <code>quantities</code>
|
|
ParameterBag. This bag of parameters is used to store the per article quantity for this order. With
|
|
ParameterBags, you can eliminate the use of simple aggregate classes, as is commonly used in
|
|
object-oriented programming.
|
|
</li>
|
|
<li>The <code>Customer</code> element models a <code>address</code> ParameterBag to store the address of a
|
|
customer. Using a separate bag allows for further more direct fields to stored on the default <code>parameters</code>
|
|
bag.
|
|
</li>
|
|
</ul>
|
|
|
|
<p>Now that we have a basic understanding of te model, it is of far more interest in how to create and interact
|
|
with these elements at runtime. The following listing will perform simple operations:</p>
|
|
<pre>
|
|
try (StrolchTransaction tx = runtimeMock.openUserTx(certificate, false)) {
|
|
|
|
/*
|
|
* create a new product
|
|
*/
|
|
Resource dafalgan = tx.getResourceTemplate("Product", true);
|
|
dafalgan.setName("Dafalgan 100mg");
|
|
dafalgan.getParameter("description", true).setValue("Dafalgan is for pain.");
|
|
dafalgan.getParameter("color", true).setValue("Yellow");
|
|
dafalgan.getParameter("form", true).setValue("flat");
|
|
|
|
StringListParameter articlesP = dafalgan.getRelationsParam("articles", true);
|
|
|
|
/*
|
|
* create articles
|
|
*/
|
|
Resource dafalgan1 = tx.getResourceTemplate("Article", true);
|
|
dafalgan1.setName("Dafalgan 100mg 10 pce");
|
|
dafalgan1.getParameter("description", true).setValue("This is pack with 10 pieces.");
|
|
dafalgan1.getParameter("barcode", true).setValue("654654");
|
|
|
|
Resource dafalgan2 = tx.getResourceTemplate("Article", true);
|
|
dafalgan2.setName("Dafalgan 100mg 20 pce");
|
|
dafalgan2.getParameter("description", true).setValue("This is pack with 20 pieces.");
|
|
dafalgan2.getParameter("barcode", true).setValue("654655");
|
|
|
|
/*
|
|
* add reference to product
|
|
*/
|
|
dafalgan1.getRelationParam("product").setValue(dafalgan.getId());
|
|
articlesP.addValue(dafalgan1.getId());
|
|
dafalgan2.getRelationParam("product").setValue(dafalgan.getId());
|
|
articlesP.addValue(dafalgan2.getId());
|
|
|
|
/*
|
|
* create a new customer
|
|
*/
|
|
Resource customer1 = tx.getResourceTemplate("Customer", true);
|
|
customer1.setName("John Doe");
|
|
|
|
// set address
|
|
ParameterBag addressBag = customer1.getParameterBag("address", true);
|
|
addressBag.getParameter("street", true).setValue("Main Str. 1");
|
|
addressBag.getParameter("zip", true).setValue("1234");
|
|
addressBag.getParameter("city", true).setValue("Hometown");
|
|
addressBag.getParameter("country", true).setValue("Switzerland");
|
|
|
|
/*
|
|
* create a new order
|
|
*/
|
|
Order order = tx.getOrderTemplate("Order", true);
|
|
order.setName("Order for " + customer1.getName());
|
|
order.setDate(LocalDate.of(2021, 2, 1));
|
|
order.setState(State.PLANNED);
|
|
|
|
// store reference to customer
|
|
order.getRelationParam("customer", true).setValue(customer1.getId());
|
|
|
|
StringListParameter orderArticlesP = order.getRelationsParam("articles", true);
|
|
ParameterBag quantitiesBag = order.getParameterBag("quantities", true);
|
|
FloatParameter quantityT = quantitiesBag.removeParameter("quantity");
|
|
|
|
// order quantity of 20 for Dafalgan 1
|
|
FloatParameter q1P = quantityT.getClone();
|
|
q1P.setId(dafalgan1.getId());
|
|
q1P.setValue(20);
|
|
quantitiesBag.addParameter(q1P);
|
|
orderArticlesP.addValue(dafalgan1.getId());
|
|
|
|
// set order quantity of 10 for Dafalgan 2
|
|
FloatParameter q2P = quantityT.getClone();
|
|
orderArticlesP.addValue(dafalgan2.getId());
|
|
q2P.setId(dafalgan2.getId());
|
|
q2P.setValue(20);
|
|
quantitiesBag.addParameter(q2P);
|
|
|
|
// keep IDs for later use
|
|
dafalganId = dafalgan.getId();
|
|
dafalgan1Id = dafalgan1.getId();
|
|
dafalgan2Id = dafalgan2.getId();
|
|
customerId = customer1.getId();
|
|
orderId = order.getId();
|
|
|
|
/*
|
|
* persist
|
|
*/
|
|
tx.add(dafalgan);
|
|
tx.add(dafalgan1);
|
|
tx.add(dafalgan2);
|
|
tx.add(customer1);
|
|
tx.add(order);
|
|
|
|
// commit
|
|
tx.commitOnClose();
|
|
}
|
|
|
|
try (StrolchTransaction tx = runtimeMock.openUserTx(certificate, true)) {
|
|
|
|
// get order
|
|
Order order = tx.getOrderBy("Order", orderId, true);
|
|
assertNotNull(orderId);
|
|
assertEquals("Order for John Doe", order.getName());
|
|
|
|
// get customer
|
|
Resource customer = tx.getResourceByRelation(order, "customer", true);
|
|
assertNotNull(customer);
|
|
assertEquals("John Doe", customer.getName());
|
|
|
|
// get articles
|
|
List<Resource> articles = tx.getResourcesByRelation(order, "articles", true);
|
|
assertEquals(2, articles.size());
|
|
|
|
// get products
|
|
List<Resource> products = articles.stream().map(a -> tx.getResourceByRelation(a, "product", true))
|
|
.distinct().collect(Collectors.toList());
|
|
assertEquals(1, products.size());
|
|
|
|
// search for all orders in state PLANNED and with customer
|
|
List<Order> orders = new OrderSearch().types("Order").stateIsIn(State.PLANNED)
|
|
.where(ExpressionsSupport.relationParam("customer").isEqualTo(customerId)).search(tx).toList();
|
|
assertEquals(1, orders.size());
|
|
}</pre>
|
|
|
|
<p><b>Note:</b> Checkout
|
|
<a href="https://github.com/4treesCH/strolch/blob/develop/li.strolch.service/src/test/resources/transienttest/data/example-model.xml">example-model.xml</a>
|
|
and
|
|
<a href="https://github.com/4treesCH/strolch/blob/develop/li.strolch.service/src/test/java/li/strolch/service/SimpleModelTest.java">SimpleModelTest.java</a>
|
|
for these examples. </p>
|
|
|
|
<p>There is a XML Schema which defines the model in XML:
|
|
<a href="xsd/StrolchModel-1.6.xsd">StrolchModel-1.6.xsd</a>
|
|
</p>
|
|
|
|
Here is an example of all the possible elements in Strolch:
|
|
<pre>
|
|
<StrolchModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xmlns="https://strolch.li/xsd/StrolchModel-1.6.xsd"
|
|
xsi:schemaLocation="https://strolch.li/xsd/StrolchModel-1.6.xsd StrolchModel-1.6.xsd">
|
|
|
|
<IncludeFile file="Include1.xml"/>
|
|
|
|
<Order Id="@test1" Name="Test Order" Type="Order">
|
|
<Version Version="0" CreatedBy="test" CreatedAt="2012-11-30T18:12:05.628+01:00" Deleted="false"/>
|
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true"/>
|
|
</ParameterBag>
|
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true"/>
|
|
</ParameterBag>
|
|
<Policies>
|
|
<Policy Type="PlanningPolicy" Value="key:SimplePlanning"/>
|
|
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation"/>
|
|
</Policies>
|
|
</Order>
|
|
|
|
<Resource Id="MyTestResource" Name="Test Name" Type="TestType">
|
|
<Version Version="0" CreatedBy="test" CreatedAt="2012-11-30T18:12:05.628+01:00" Deleted="false"/>
|
|
<ParameterBag Id="@bag01" Name="Test Bag 01" Type="TestBag">
|
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true"/>
|
|
</ParameterBag>
|
|
<ParameterBag Id="@bag02" Name="Test Bag 02" Type="TestBag">
|
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true"/>
|
|
</ParameterBag>
|
|
<TimedState Id="@booleanState" Name="Boolean State" Type="Boolean">
|
|
<Value Time="1970-01-01T00:02:00.000+01:00" Value="false"/>
|
|
</TimedState>
|
|
<Policies>
|
|
<Policy Type="PlanningPolicy" Value="key:SimplePlanning"/>
|
|
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation"/>
|
|
</Policies>
|
|
</Resource>
|
|
|
|
<Activity Id="activity_1" Name="Activity" Type="parentType" TimeOrdering="Series">
|
|
<Version Version="0" CreatedBy="test" CreatedAt="2012-11-30T18:12:05.628+01:00" Deleted="false"/>
|
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true"/>
|
|
</ParameterBag>
|
|
<Policies>
|
|
<Policy Type="PlanningPolicy" Value="key:SimplePlanning"/>
|
|
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation"/>
|
|
</Policies>
|
|
<Action Id="action_1" Name="Action 1" ResourceId="dummyId" ResourceType="dummyType" State="Created" Type="Use">
|
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true"/>
|
|
</ParameterBag>
|
|
<Policies>
|
|
<Policy Type="PlanningPolicy" Value="key:SimplePlanning"/>
|
|
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation"/>
|
|
</Policies>
|
|
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:05.628+01:00" Value="5" Type="Integer"/>
|
|
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:06.628+01:00" Value="6" Type="Integer"/>
|
|
</Action>
|
|
<Activity Id="child_activity" Name="Child Activity" Type="childType" TimeOrdering="Series">
|
|
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
|
|
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true"/>
|
|
</ParameterBag>
|
|
<Policies>
|
|
<Policy Type="PlanningPolicy" Value="key:SimplePlanning"/>
|
|
<Policy Type="ConfirmationPolicy" Value="key:NoConfirmation"/>
|
|
</Policies>
|
|
<Action Id="action_2" Name="Action 2" ResourceId="dummyId" ResourceType="dummyType" State="Planned"
|
|
Type="Use">
|
|
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:05.628+01:00" Value="5" Type="Integer"/>
|
|
<ValueChange StateId="dummyId" Time="2012-11-30T18:12:06.628+01:00" Value="6" Type="Integer"/>
|
|
</Action>
|
|
<Action Id="action_3" Name="Action 3" ResourceId="dummyId" ResourceType="dummyType" State="Created"
|
|
Type="Use"/>
|
|
</Activity>
|
|
</Activity>
|
|
|
|
</StrolchModel></pre>
|
|
|
|
<!-- content here -->
|
|
|
|
</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>
|