<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Filip_Drools_-_DSL</id>
	<title>Filip Drools - DSL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Filip_Drools_-_DSL"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Filip_Drools_-_DSL&amp;action=history"/>
	<updated>2026-05-13T23:42:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Filip_Drools_-_DSL&amp;diff=68892&amp;oldid=prev</id>
		<title>Fstachecki at 09:48, 14 September 2018</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Filip_Drools_-_DSL&amp;diff=68892&amp;oldid=prev"/>
		<updated>2018-09-14T09:48:54Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Drools Filip|095]]&lt;br /&gt;
&lt;br /&gt;
== What is Domain Specific Language ==&lt;br /&gt;
[[File:ClipCapIt-160929-194441.PNG]]&lt;br /&gt;
* &amp;quot;A  way of creating a rule language that is dedicated to your problem domain&amp;quot;&lt;br /&gt;
* DSL is a way non-technical people can write executable rules in Drools environment&lt;br /&gt;
* DSL is ultimately transformed to rules (mvel or java)&lt;br /&gt;
* .dsl file contain the transformations (mapping)&lt;br /&gt;
* DSLs have no impact on the rule engine at runtime, they are just a compile time feature&lt;br /&gt;
&lt;br /&gt;
== When to use DSL ==&lt;br /&gt;
* Your requirements should be executable and always in sync with what is actually executed&lt;br /&gt;
* Analysts can focus on &amp;quot;logic proper&amp;quot;&lt;br /&gt;
* You already have rules written in SBVR or other standard (which is consistent and detailed enough to be easily translated into executable rules)&lt;br /&gt;
* You need &amp;quot;templates&amp;quot; for conditional elements and consequence actions that are used repeatedly in your rules (with minor variations)&lt;br /&gt;
&lt;br /&gt;
== DSL in KIE Workbench==&lt;br /&gt;
Create New -&amp;gt; New DSL&lt;br /&gt;
 [when]Order is greater than {totalOrder} = sc :ShoppingCart( $totalPrice : totalPrice &amp;gt; {totalOrder})&lt;br /&gt;
 [then]Set discount to {discount} = sc.setTotalPrice( $totalPrice * (1-{discount}) ); update(sc); &lt;br /&gt;
&lt;br /&gt;
# Create New -&amp;gt; New Rule&lt;br /&gt;
# Type (format) of rule: DSL or Guided Rule&lt;br /&gt;
 dilect &amp;quot;mvel&amp;quot;&lt;br /&gt;
 when&lt;br /&gt;
  Order is greater than 10000&lt;br /&gt;
 then&lt;br /&gt;
  Set discount to 0.1&lt;br /&gt;
&lt;br /&gt;
Use the test created for tall order discount&lt;br /&gt;
&lt;br /&gt;
== Eclipse ==&lt;br /&gt;
See 08.1DSL folder&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DSLR&amp;#039;&amp;#039;&amp;#039; file contains rules defined using business context&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;DSL&amp;#039;&amp;#039;&amp;#039; file contains the translations between business context and drools language&lt;br /&gt;
&lt;br /&gt;
=== Connecting DSL file with DSRL file===&lt;br /&gt;
[[File:ClipCapIt-150716-052324.PNG]]&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;It&amp;#039;s not required to use expander to refer to DSL file in Drools 6.4 if all DSL files included in KIE Base are going to be used.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
===DSL file===&lt;br /&gt;
* The DSL file is a text file containing DSL entries.&lt;br /&gt;
* Entry syntax&lt;br /&gt;
&amp;lt;source&amp;gt;# This is a comment to be ignored&amp;lt;/source&amp;gt;&lt;br /&gt;
[[File:ClipCapIt-160916-132246.PNG]]&lt;br /&gt;
* Examples&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
[condition][]There is a Shopping Cart that=$sc : ShoppingCart()&lt;br /&gt;
[consequence][]Show price=System.out.println($sc.totalPrice)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
* &amp;lt;text expression&amp;gt; can contain Java regular expressions &amp;lt;br/&amp;gt;https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
[&amp;lt; entry scope &amp;gt;][ &amp;lt; object &amp;gt;] &amp;lt; text expression &amp;gt; = &amp;lt; replacement text &amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 [condition]      description    text to replace      matching expression&lt;br /&gt;
[consequence]&lt;br /&gt;
     [*]&lt;br /&gt;
  [keyword]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
====Nesting entries====&lt;br /&gt;
*Starting new entry with a hyphen sign &amp;quot;-&amp;quot; allows to add this expression to the last pattern&lt;br /&gt;
*Examples&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
[condition][]There is a Shopping Cart that=$sc : ShoppingCart()&lt;br /&gt;
[condition][]- total price is greater than 1000 =totalPrice &amp;gt; 1000&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
*Result&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
$sc : ShoppingCart(totalPrice &amp;gt; 1000)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
* Hyphens can be used in consequence entries as part of a modify statement&lt;br /&gt;
&lt;br /&gt;
====Variables====&lt;br /&gt;
*Variables can be defined using curly brackets { and }&lt;br /&gt;
*Examples&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
[condition][]There is a Shopping Cart that=$sc : ShoppingCart()&lt;br /&gt;
[condition][]- total price is greater than {price}=totalPrice &amp;gt;{price}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
====Keywords====&lt;br /&gt;
* Keyword is valid in any part of DSLR file&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
[keyword] no loops = no-loop true&lt;br /&gt;
[keyword][]regula=rule&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====String transformation functions====&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot; cellspacing=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr bgcolor=&amp;quot;#BDBDBD&amp;quot;&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;uc&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Converts all letters to upper case.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;lc&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Converts all letters to lower case.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;ucfirst&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Converts the first letter to upper case, and all other letters to lower case.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;num&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Extracts all digits and &amp;quot;-&amp;quot; from the string. &amp;lt;br/&amp;gt;If the last two digits in the original string are preceded by &amp;quot;.&amp;quot; or &amp;quot;,&amp;quot;, a decimal period is inserted in the corresponding position.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;a&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;?&amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;b&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;/&amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;c&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Compares the string with string &amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;a&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;, and if they are equal, replaces it with &amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;b&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;, otherwise with &amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;c&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;.&amp;lt;br/&amp;gt;But &amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;c&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt; can be another triplet &amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;a&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;b&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;, &amp;lt;span class=&amp;quot;emphasis&amp;quot;&amp;gt;&amp;lt;em&amp;gt;c&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;, so that the entire structure is, in fact, a translation table.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&lt;br /&gt;
===== Examples=====&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
# definitions for conditions&lt;br /&gt;
[when][]There is an? {entity}=${entity!lc}: {entity!ucfirst}()&lt;br /&gt;
[when][]- with an? {attr} greater than {amount}={attr} &amp;gt;= {amount!num}&lt;br /&gt;
[when][]- with a {what} {attr}={attr} {what!positive?&amp;gt;0/negative?%lt;0/zero?==0/ERROR}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Debug options for DSL expansion====&lt;br /&gt;
* Drools can log a DSL translation process&lt;br /&gt;
* To get access to those details use special type of statement starting with &amp;quot;#/ debug display&amp;quot;&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;10&amp;quot; cellspacing=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr bgcolor=&amp;quot;#BDBDBD&amp;quot;&amp;gt;&amp;lt;th&amp;gt;Word&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;result&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Prints the resulting DRL text, with line numbers.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;steps&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Prints each expansion step of condition and consequence lines.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;keyword&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Dumps the internal representation of all DSL entries with scope &amp;quot;keyword&amp;quot;.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;when&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Dumps the internal representation of all DSL entries with scope &amp;quot;when&amp;quot; or &amp;quot;*&amp;quot;.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;then&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Dumps the internal representation of all DSL entries with scope &amp;quot;then&amp;quot; or &amp;quot;*&amp;quot;.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;usage&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Displays a usage statistic of all DSL entries.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&lt;br /&gt;
===== Examples=====&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
#/ debug display result, steps and usage&lt;br /&gt;
#/ debug display result and usage&lt;br /&gt;
#/ debug display steps&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fstachecki</name></author>
	</entry>
</feed>