SlideShare une entreprise Scribd logo
1  sur  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”

Contenu connexe

Tendances (7)

Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Introduction to Sightly
Introduction to SightlyIntroduction to Sightly
Introduction to Sightly
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
 
Experience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsExperience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - Highlights
 
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)
 
Wt unit 5 client &amp; server side framework
Wt unit 5 client &amp; server side frameworkWt unit 5 client &amp; server side framework
Wt unit 5 client &amp; server side framework
 
Les11
Les11Les11
Les11
 

Similaire à XML Business Rules Validation with Schematron

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
 

Similaire à XML Business Rules Validation with Schematron (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
 

Dernier

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Dernier (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

XML Business Rules Validation with Schematron

  • 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”