SlideShare a Scribd company logo
1 of 32
Business Rules Validation
  in the SOA Suite with
       Schematron
PROGRAM
• XML, XSD, X-Path, XSLT

• XML (Business Rule) Validation

• Validation Gap: Schematron

• Examples

• Schematron in the SOA Suite

• Business Rules Case

• Discussion
XML
XML: eXtensible Markup Language

Store almost any kind of data in a structured form
that applications running on any platform can
easily import and process and is human
readable.

XML became the underlying standard for many
new Software standards:
  • Web: XHTML, RSS, Atom, XMPP (chat), AJAX
  • Web Services: WSDL, SOAP (Simple Object
    Access Protocol)
  • Documents: ODF (Open Document Format), MS
    Office OOXML (docx), Apple iWork
  • Etc., etc
XML EXAMPLE
<?xml version="1.0"?>
<dining-room>
  <manufacturer>The WoodShop</manufacturer>
  <table type="round" wood="maple">
    <price>$199.99</price>
  </table>
  <chair wood="maple">
    <quantity>6</quantity>
    <price>$39.99</price>
  </chair>
</dining-room>
XSD
XML Schema:
• Define structure of xml including data type of elements
  and contstraints

• Schema is also in XML format
   So there is a XML schema that defines an XML
  schema

• Can be seen as the “ERD” or “DB Design” for XML
XSD EXAMPLE
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://amis.nl/schematrondemo/common"
            targetNamespace="http://amis.nl/schematrondemo/common"
            elementFormDefault="qualified">
  <xsd:element name="Employees" type="tEmployees"/>
  <xsd:complexType name="tEmployees">
    <xsd:sequence>
      <xsd:element name="Employee" type="tEmployee"
                   minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="tEmployee">
    <xsd:sequence>
      <xsd:element name="Name" type="xsd:string"/>
      <xsd:element name="Salary" type="xsd:decimal"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:long" use="required"/>
    <xsd:attribute name="manager_id" type="xsd:long" use="optional"/>
  </xsd:complexType>
</xsd:schema>
XPATH

XML Path Language (XPath):
  • Is primarily used to address the nodes of an
    XML document modeled as a tree of nodes
  • Is named after its use of a path notation for
    navigating through the hierarchical structure
    of an XML document
  • Uses a compact, non-XML syntax to form
    expressions for use in Uniform Resource
    Identifier (URI) and XML attribute values
  • Fully supports XML Namespaces
  • Is designed to be used by XML applications
    and XSLT (and XQuery)
XPATH EXAMPLES




//price                              2 element nodes
/*/*/@wood                           2 attribute nodes
//@wood/..                           2 nodes (table and chair)
/dining-room/*[price > 100]/@wood  1 attribute node
//price[1]/text()                    2 text values! (both price are first)
(//price)[1]/text()              1 text value (first from result collection)
XML STYLESHEET (XSLT/XSL)
XSLT processing takes an XML source document and an
XSLT stylesheet, and produces an output document
The XSLT stylesheet:
    • Is an XML document itself
    • Contains rules that map patterns in the input to
      static XML to send into the output
    • Uses XPath expressions to get data from the XML
      source
    • Can contain XSLT logic (if, choose) and operators
      (for-each) to process the XML source
The output document is typically another XML
document, but XSLT can be used to create other plain-
text documents as well.
XSLT EXAMPLE *
XML (BUSINESS RULE) VALIDATION

Three types of XML Validation

• On data / element itself:
    Data type & Constraints

• XML Structure:
    Element names & Child/Parent Constraints

• Between data elements:
    Business Rules
XML (BUSINESS RULE) VALIDATION
Three types of XML Validation

•   On data / element itself:
       Data type & Constraints
                  XSD

•   XML Structure:
      Element names & Child/Parent Constraints
                 XSD partially! (no conditional)

•   Between data elements:
       Business Rules
                 ??
SCHEMATRON
• Used for validating an XML Document

• Validation of Business Rules

• Validation of conditional structure

• Rules are defined in Schematron format which
  is also XML

• Is built on XPath expressions

• Is an ISO/IEC Standard

• Basically is a double XSTL transformation
SCHEMATRON
Usage:

• Define your Business Rules in an XML
  document in a fixed format and structure
  (Schematron) with the usage of XPath
  expressions

• Transform your Business Rules XML using the
  Schematron XSLT to create your Business
  Rules XSLT.

• Use your Business Rules XSLT to validate your
  XML data (Transformation). Output are the
  errors, so no output means the data is valid.
SCHEMATRON
• Double XSLT transformation:
   • 1. Rules.xml with Schematron.xslt =>
     Rules.xslt
   • 2. Data.xml with Rules.xslt => Result
SCHEMATRON FILE
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">

 <pattern name="patternName">
   <rule context="x-path">
     <assert test="x-path condition">Error message</assert>
     <report test="x-path condition">Error message</report>
     ...
   </rule>
 </pattern>

 <pattern name="patternName">
 ...

</schema>
SCHEMATRON EXAMPLE 1
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron" >
  <pattern name="Number of characters in an abbreviation">
    <rule context="Afdeling">
      <report test="string-length(@afk) &lt; 2">There are not enough
   letters in the abbreviation</report>

      <report test="string-length(@afk) > 3">There are too much
   letters in the abbreviation</report>
    </rule>
  </pattern>
</schema>
SCHEMATRON EXAMPLE 2
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron" >
  <pattern name="Sum equals 100%.">
    <rule context="Total">
      <assert test="sum(//Percent) = 100">Sum percentage is not
   100%.</assert>
    </rule>
  </pattern>
</schema>
SCHEMATRON IN THE SOA SUITE
• Default filename extension “sch”
• No report, so only assert tag!  not(report)
• Define namespace prefixes with uri tag:
   <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" />

• Implemented in Mediator:




• „Feature‟: Generate HTTP error (e.g. return error with FireForget)
BUSINESS RULES CASE

Company HRM XML file company containing departments
containing employees:
• An employee may not be the manager of himself.
• All normal employees (so not a manager) must have a
  manager.
• There is only one manager without a manager
  (only one president).
• All employees should have less salary than any
  manager
  (manager = employee in department “Managers”).
• The relation manager and employee is a valid one, so
  the manager of an employee must exist.
CASE EXAMPLE DATA
<Company><Department name="Ground Two" abbr="GR1">...</Department>
  <Department name="Ground Two" abbr="GR2">
     <Employees>
        <Employee id="13" manager_id="20">
           <Name>P. Pietersen</Name>
           <Salary>1550</Salary>
        </Employee>
        <Employee id="14" manager_id="20">
           <Name>S. Smit</Name>
           <Salary>1600</Salary>
        </Employee>
     </Employees>
  </Department>
  <Department name="Managers" abbr="MAN">
     <Employees>
        <Employee id="15">
           <Name>M.A. Nager</Name>
           <Salary>1700</Salary>
        </Employee>
        <Employee id="20" manager_id="25">
           <Name>L.E. Ader</Name>
           <Salary>1600</Salary>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     An employee may not be the manager of himself.


<pattern name="Employee may not be the manager of himself">
  <rule context="//com:Employee[@manager_id]">
    <assert test="@manager_id != @id">Employee may not manage himself</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     All normal employees (so not a manager) must
     have a manager.

<pattern name="All normal employees have a manager">
  <rule context=
"//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
    <assert test="@manager_id">Employee must have a manager</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     There is only one manager without a manager
     (only one president).

<pattern name="Only one manager without manager, mr president">
  <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees">
    <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be
only one president</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     All employees should have less salary than any
     manager
     (manager = employee in department “Managers”).
<pattern name="Managers earn more than normal employees">
  <rule
context="//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
    <assert test="com:Salary &lt;
min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">
Employee earns too much</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     The relation manager and employee is a valid
     one, so the manager of an employee must exist.

<pattern name="Manager does not exist">
  <rule context="//com:Employee[@manager_id]">
    <assert test=
"//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees/com:Employee[@id=c
urrent()/@manager_id]">No valid manager</assert>
  </rule>
</pattern>
TOTAL SCHEMATRON BUSINESS RULE
                IMPLEMENTATION
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">
  <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" />
  <ns uri="http://amis.nl/schematrondemo/common" prefix="com" />
  <pattern name="Managers earn more than normal employees">
    <rule context= "//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
      <assert test="com:Salary &lt;
min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">Employee
earns too much: <value-of select="com:Salary"/></assert>
    </rule>
  </pattern>
  <pattern name="Employee may not be the manager of himself">
    <rule context="//com:Employee[@manager_id]">
      <assert test="@manager_id != @id">Employee may not manage himself</assert>
    </rule>
  </pattern>
  <pattern name="All normal employees have a manager">
    <rule context=
"//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
      <assert test="@manager_id">Employee must have a manager</assert>
    </rule>
  </pattern>
  <pattern name="Only one manager without manager, the president">
    <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees">
      <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be only one
president</assert>
...
DEMO
PERFORMANCE

When there are
1. a lot (hundreds) of Schematron rules and/or
2. your input data (payload) is huge
performance problems can arise.
PERFORMANCE

1. A lot (hundreds) of Schematron rules

This problem is the easiest to handle:
Split the Schematron file up in more files and
serialize them with Mediators.
Place the Schematron rules which fail most in the
first Mediator and the ones which fail least in the last
Mediator.
PERFORMANCE

2. Huge input data (payload)

This problem is quite tricky. Not only for Schematron
validation, but the SOA Suite in common!
Advise for Schematron validation is to split up the
payload (BPEL / OSB) in multiple chunks.
This can be a „vertical split‟, so divide at certain
elements.
But also an „horizontal‟ split, so ommit data which is
not necessary for the (chunk of) Schematron
validation rules.
Even a combination is possible!
With a split-join in the OSB or in BPEL with parallel
processing the output can be merged.
DISCUSSION
                Statement:
“No Business Rules in the Middleware”

More Related Content

What's hot

Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Gheyath M. Othman
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4Gheyath M. Othman
 
Web Design Course: CSS lecture 2
Web Design Course: CSS  lecture 2Web Design Course: CSS  lecture 2
Web Design Course: CSS lecture 2Gheyath M. Othman
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and htmlKevin DeRudder
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Vidyasagar Mundroy
 
Web Design Course: CSS lecture 5
Web Design Course: CSS  lecture 5Web Design Course: CSS  lecture 5
Web Design Course: CSS lecture 5Gheyath M. Othman
 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone ApplicationNguyen Tuan
 
Ôn tập KTTMDT
Ôn tập KTTMDTÔn tập KTTMDT
Ôn tập KTTMDTmrcoffee282
 

What's hot (10)

Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
Web Design Course: CSS lecture 2
Web Design Course: CSS  lecture 2Web Design Course: CSS  lecture 2
Web Design Course: CSS lecture 2
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and html
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
 
Web Design Course: CSS lecture 5
Web Design Course: CSS  lecture 5Web Design Course: CSS  lecture 5
Web Design Course: CSS lecture 5
 
02.Designing Windows Phone Application
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone Application
 
html
htmlhtml
html
 
Ôn tập KTTMDT
Ôn tập KTTMDTÔn tập KTTMDT
Ôn tập KTTMDT
 

Similar to OOW 2012 XML Business Rules Validation Schematron - Emiel Paasschens

Xml part5
Xml part5Xml part5
Xml part5NOHA AW
 
Xml part1
Xml part1  Xml part1
Xml part1 NOHA AW
 
Caracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmCaracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmMaria S Rivera
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIRoselin Mary S
 
Xml and databases
Xml and databasesXml and databases
Xml and databasesRaghu nath
 
Spring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring BatchSpring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring BatchEberhard Wolff
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
[Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment][Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment]Azam Charaniya
 
Android de la A a la Z XML Ulises Gonzalez
Android de la A a la Z  XML Ulises GonzalezAndroid de la A a la Z  XML Ulises Gonzalez
Android de la A a la Z XML Ulises GonzalezAndroid UNAM
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)Serhii Kartashov
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Documentyht4ever
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template LanguageGabriel Walt
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLTMalintha Adikari
 
ORACLE SOA SUIT BASIC XML FORMATS
ORACLE SOA SUIT  BASIC XML FORMATS ORACLE SOA SUIT  BASIC XML FORMATS
ORACLE SOA SUIT BASIC XML FORMATS xavier john
 

Similar to OOW 2012 XML Business Rules Validation Schematron - Emiel Paasschens (20)

Xml part5
Xml part5Xml part5
Xml part5
 
Xml part1
Xml part1  Xml part1
Xml part1
 
Caracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmCaracteristicas Basicas De Htlm
Caracteristicas Basicas De Htlm
 
Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
 
DB2 Native XML
DB2 Native XMLDB2 Native XML
DB2 Native XML
 
Xml and databases
Xml and databasesXml and databases
Xml and databases
 
Spring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring BatchSpring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring Batch
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Xml 2
Xml  2 Xml  2
Xml 2
 
[Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment][Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment]
 
Android de la A a la Z XML Ulises Gonzalez
Android de la A a la Z  XML Ulises GonzalezAndroid de la A a la Z  XML Ulises Gonzalez
Android de la A a la Z XML Ulises Gonzalez
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
Xml
XmlXml
Xml
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
Soa suite doc
Soa suite docSoa suite doc
Soa suite doc
 
ORACLE SOA SUIT BASIC XML FORMATS
ORACLE SOA SUIT  BASIC XML FORMATS ORACLE SOA SUIT  BASIC XML FORMATS
ORACLE SOA SUIT BASIC XML FORMATS
 

More from Getting value from IoT, Integration and Data Analytics

More from Getting value from IoT, Integration and Data Analytics (20)

AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
AMIS Oracle OpenWorld en Code One Review 2018 - Blockchain, Integration, Serv...
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaSAMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: SaaS
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: DataAMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Data
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 1: Cloud Infrastructure
 
10 tips voor verbetering in je Linkedin profiel
10 tips voor verbetering in je Linkedin profiel10 tips voor verbetering in je Linkedin profiel
10 tips voor verbetering in je Linkedin profiel
 
Iot in de zorg the next step - fit for purpose
Iot in de zorg   the next step - fit for purpose Iot in de zorg   the next step - fit for purpose
Iot in de zorg the next step - fit for purpose
 
Iot overview .. Best practices and lessons learned by Conclusion Conenct
Iot overview .. Best practices and lessons learned by Conclusion Conenct Iot overview .. Best practices and lessons learned by Conclusion Conenct
Iot overview .. Best practices and lessons learned by Conclusion Conenct
 
IoT Fit for purpose - how to be successful in IOT Conclusion Connect
IoT Fit for purpose - how to be successful in IOT Conclusion Connect IoT Fit for purpose - how to be successful in IOT Conclusion Connect
IoT Fit for purpose - how to be successful in IOT Conclusion Connect
 
Industry and IOT Overview of protocols and best practices Conclusion Connect
Industry and IOT Overview of protocols and best practices  Conclusion ConnectIndustry and IOT Overview of protocols and best practices  Conclusion Connect
Industry and IOT Overview of protocols and best practices Conclusion Connect
 
IoT practical case using the people counter sensing traffic density build usi...
IoT practical case using the people counter sensing traffic density build usi...IoT practical case using the people counter sensing traffic density build usi...
IoT practical case using the people counter sensing traffic density build usi...
 
R introduction decision_trees
R introduction decision_treesR introduction decision_trees
R introduction decision_trees
 
Introduction overviewmachinelearning sig Door Lucas Jellema
Introduction overviewmachinelearning sig Door Lucas JellemaIntroduction overviewmachinelearning sig Door Lucas Jellema
Introduction overviewmachinelearning sig Door Lucas Jellema
 
IoT and the Future of work
IoT and the Future of work IoT and the Future of work
IoT and the Future of work
 
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
Oracle OpenWorld 2017 Review (31st October 2017 - 250 slides)
 
Ethereum smart contracts - door Peter Reitsma
Ethereum smart contracts - door Peter ReitsmaEthereum smart contracts - door Peter Reitsma
Ethereum smart contracts - door Peter Reitsma
 
Blockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
Blockchain - Techniek en usecases door Robert van Molken - AMIS - ConclusionBlockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
Blockchain - Techniek en usecases door Robert van Molken - AMIS - Conclusion
 
kennissessie blockchain - Wat is Blockchain en smart contracts @Conclusion
kennissessie blockchain -  Wat is Blockchain en smart contracts @Conclusion kennissessie blockchain -  Wat is Blockchain en smart contracts @Conclusion
kennissessie blockchain - Wat is Blockchain en smart contracts @Conclusion
 
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
Internet of Things propositie - Enterprise IOT - AMIS - Conclusion
 
Omc AMIS evenement 26012017 Dennis van Soest
Omc AMIS evenement 26012017 Dennis van SoestOmc AMIS evenement 26012017 Dennis van Soest
Omc AMIS evenement 26012017 Dennis van Soest
 

OOW 2012 XML Business Rules Validation Schematron - Emiel Paasschens

  • 1. Business Rules Validation in the SOA Suite with Schematron
  • 2. PROGRAM • XML, XSD, X-Path, XSLT • XML (Business Rule) Validation • Validation Gap: Schematron • Examples • Schematron in the SOA Suite • Business Rules Case • Discussion
  • 3. XML XML: eXtensible Markup Language Store almost any kind of data in a structured form that applications running on any platform can easily import and process and is human readable. XML became the underlying standard for many new Software standards: • Web: XHTML, RSS, Atom, XMPP (chat), AJAX • Web Services: WSDL, SOAP (Simple Object Access Protocol) • Documents: ODF (Open Document Format), MS Office OOXML (docx), Apple iWork • Etc., etc
  • 4. XML EXAMPLE <?xml version="1.0"?> <dining-room> <manufacturer>The WoodShop</manufacturer> <table type="round" wood="maple"> <price>$199.99</price> </table> <chair wood="maple"> <quantity>6</quantity> <price>$39.99</price> </chair> </dining-room>
  • 5. XSD XML Schema: • Define structure of xml including data type of elements and contstraints • Schema is also in XML format  So there is a XML schema that defines an XML schema • Can be seen as the “ERD” or “DB Design” for XML
  • 6. XSD EXAMPLE <?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://amis.nl/schematrondemo/common" targetNamespace="http://amis.nl/schematrondemo/common" elementFormDefault="qualified"> <xsd:element name="Employees" type="tEmployees"/> <xsd:complexType name="tEmployees"> <xsd:sequence> <xsd:element name="Employee" type="tEmployee" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="tEmployee"> <xsd:sequence> <xsd:element name="Name" type="xsd:string"/> <xsd:element name="Salary" type="xsd:decimal"/> </xsd:sequence> <xsd:attribute name="id" type="xsd:long" use="required"/> <xsd:attribute name="manager_id" type="xsd:long" use="optional"/> </xsd:complexType> </xsd:schema>
  • 7. XPATH XML Path Language (XPath): • Is primarily used to address the nodes of an XML document modeled as a tree of nodes • Is named after its use of a path notation for navigating through the hierarchical structure of an XML document • Uses a compact, non-XML syntax to form expressions for use in Uniform Resource Identifier (URI) and XML attribute values • Fully supports XML Namespaces • Is designed to be used by XML applications and XSLT (and XQuery)
  • 8. XPATH EXAMPLES //price  2 element nodes /*/*/@wood  2 attribute nodes //@wood/..  2 nodes (table and chair) /dining-room/*[price > 100]/@wood  1 attribute node //price[1]/text()  2 text values! (both price are first) (//price)[1]/text()  1 text value (first from result collection)
  • 9. XML STYLESHEET (XSLT/XSL) XSLT processing takes an XML source document and an XSLT stylesheet, and produces an output document The XSLT stylesheet: • Is an XML document itself • Contains rules that map patterns in the input to static XML to send into the output • Uses XPath expressions to get data from the XML source • Can contain XSLT logic (if, choose) and operators (for-each) to process the XML source The output document is typically another XML document, but XSLT can be used to create other plain- text documents as well.
  • 11. XML (BUSINESS RULE) VALIDATION Three types of XML Validation • On data / element itself: Data type & Constraints • XML Structure: Element names & Child/Parent Constraints • Between data elements: Business Rules
  • 12. XML (BUSINESS RULE) VALIDATION Three types of XML Validation • On data / element itself: Data type & Constraints  XSD • XML Structure: Element names & Child/Parent Constraints  XSD partially! (no conditional) • Between data elements: Business Rules  ??
  • 13. SCHEMATRON • Used for validating an XML Document • Validation of Business Rules • Validation of conditional structure • Rules are defined in Schematron format which is also XML • Is built on XPath expressions • Is an ISO/IEC Standard • Basically is a double XSTL transformation
  • 14. SCHEMATRON Usage: • Define your Business Rules in an XML document in a fixed format and structure (Schematron) with the usage of XPath expressions • Transform your Business Rules XML using the Schematron XSLT to create your Business Rules XSLT. • Use your Business Rules XSLT to validate your XML data (Transformation). Output are the errors, so no output means the data is valid.
  • 15. SCHEMATRON • Double XSLT transformation: • 1. Rules.xml with Schematron.xslt => Rules.xslt • 2. Data.xml with Rules.xslt => Result
  • 16. SCHEMATRON FILE <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron"> <pattern name="patternName"> <rule context="x-path"> <assert test="x-path condition">Error message</assert> <report test="x-path condition">Error message</report> ... </rule> </pattern> <pattern name="patternName"> ... </schema>
  • 17. SCHEMATRON EXAMPLE 1 <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron" > <pattern name="Number of characters in an abbreviation"> <rule context="Afdeling"> <report test="string-length(@afk) &lt; 2">There are not enough letters in the abbreviation</report> <report test="string-length(@afk) > 3">There are too much letters in the abbreviation</report> </rule> </pattern> </schema>
  • 18. SCHEMATRON EXAMPLE 2 <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron" > <pattern name="Sum equals 100%."> <rule context="Total"> <assert test="sum(//Percent) = 100">Sum percentage is not 100%.</assert> </rule> </pattern> </schema>
  • 19. SCHEMATRON IN THE SOA SUITE • Default filename extension “sch” • No report, so only assert tag!  not(report) • Define namespace prefixes with uri tag: <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" /> • Implemented in Mediator: • „Feature‟: Generate HTTP error (e.g. return error with FireForget)
  • 20. BUSINESS RULES CASE Company HRM XML file company containing departments containing employees: • An employee may not be the manager of himself. • All normal employees (so not a manager) must have a manager. • There is only one manager without a manager (only one president). • All employees should have less salary than any manager (manager = employee in department “Managers”). • The relation manager and employee is a valid one, so the manager of an employee must exist.
  • 21. CASE EXAMPLE DATA <Company><Department name="Ground Two" abbr="GR1">...</Department> <Department name="Ground Two" abbr="GR2"> <Employees> <Employee id="13" manager_id="20"> <Name>P. Pietersen</Name> <Salary>1550</Salary> </Employee> <Employee id="14" manager_id="20"> <Name>S. Smit</Name> <Salary>1600</Salary> </Employee> </Employees> </Department> <Department name="Managers" abbr="MAN"> <Employees> <Employee id="15"> <Name>M.A. Nager</Name> <Salary>1700</Salary> </Employee> <Employee id="20" manager_id="25"> <Name>L.E. Ader</Name> <Salary>1600</Salary>
  • 22. SCHEMATRON BUSINESS RULE IMPLEMENTATION An employee may not be the manager of himself. <pattern name="Employee may not be the manager of himself"> <rule context="//com:Employee[@manager_id]"> <assert test="@manager_id != @id">Employee may not manage himself</assert> </rule> </pattern>
  • 23. SCHEMATRON BUSINESS RULE IMPLEMENTATION All normal employees (so not a manager) must have a manager. <pattern name="All normal employees have a manager"> <rule context= "//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="@manager_id">Employee must have a manager</assert> </rule> </pattern>
  • 24. SCHEMATRON BUSINESS RULE IMPLEMENTATION There is only one manager without a manager (only one president). <pattern name="Only one manager without manager, mr president"> <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees"> <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be only one president</assert> </rule> </pattern>
  • 25. SCHEMATRON BUSINESS RULE IMPLEMENTATION All employees should have less salary than any manager (manager = employee in department “Managers”). <pattern name="Managers earn more than normal employees"> <rule context="//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="com:Salary &lt; min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)"> Employee earns too much</assert> </rule> </pattern>
  • 26. SCHEMATRON BUSINESS RULE IMPLEMENTATION The relation manager and employee is a valid one, so the manager of an employee must exist. <pattern name="Manager does not exist"> <rule context="//com:Employee[@manager_id]"> <assert test= "//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees/com:Employee[@id=c urrent()/@manager_id]">No valid manager</assert> </rule> </pattern>
  • 27. TOTAL SCHEMATRON BUSINESS RULE IMPLEMENTATION <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron"> <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" /> <ns uri="http://amis.nl/schematrondemo/common" prefix="com" /> <pattern name="Managers earn more than normal employees"> <rule context= "//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="com:Salary &lt; min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">Employee earns too much: <value-of select="com:Salary"/></assert> </rule> </pattern> <pattern name="Employee may not be the manager of himself"> <rule context="//com:Employee[@manager_id]"> <assert test="@manager_id != @id">Employee may not manage himself</assert> </rule> </pattern> <pattern name="All normal employees have a manager"> <rule context= "//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="@manager_id">Employee must have a manager</assert> </rule> </pattern> <pattern name="Only one manager without manager, the president"> <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees"> <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be only one president</assert> ...
  • 28. DEMO
  • 29. PERFORMANCE When there are 1. a lot (hundreds) of Schematron rules and/or 2. your input data (payload) is huge performance problems can arise.
  • 30. PERFORMANCE 1. A lot (hundreds) of Schematron rules This problem is the easiest to handle: Split the Schematron file up in more files and serialize them with Mediators. Place the Schematron rules which fail most in the first Mediator and the ones which fail least in the last Mediator.
  • 31. PERFORMANCE 2. Huge input data (payload) This problem is quite tricky. Not only for Schematron validation, but the SOA Suite in common! Advise for Schematron validation is to split up the payload (BPEL / OSB) in multiple chunks. This can be a „vertical split‟, so divide at certain elements. But also an „horizontal‟ split, so ommit data which is not necessary for the (chunk of) Schematron validation rules. Even a combination is possible! With a split-join in the OSB or in BPEL with parallel processing the output can be merged.
  • 32. DISCUSSION Statement: “No Business Rules in the Middleware”