Skip to content

Commit

Permalink
SWITCHYARD-1607: Decision table support missing from Rules component
Browse files Browse the repository at this point in the history
  • Loading branch information
errantepiphany authored and Keith Babo committed Aug 20, 2013
1 parent acf2bc3 commit 215f69d
Show file tree
Hide file tree
Showing 49 changed files with 1,202 additions and 196 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<module>rules-camel-cbr</module>
<module>rules-interview</module>
<module>rules-interview-container</module>
<module>rules-interview-dtable</module>
<module>soap-addressing</module>
<module>soap-attachment</module>
<module>soap-binding-rpc</module>
Expand Down
27 changes: 15 additions & 12 deletions rules-interview-container/Readme.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
Introduction
============
This quickstart demonstrates the usage of a rules service which performs an age check.
The drl resource is specified using annotations within the InterviewRules interface.
The name of the service in the drl is specified using a Mapping annotation containing an MVEL expression.
This quickstart demonstrates the usage of a rules service which performs an age check.
The input is the incoming message content (an "Applicant").
The output is a boolean, and mapped using the implicit "globals" Map.

This rules-interview-container quickstart differs from the rules-interview quickstart.
A /META-INF/kmodule.xml is used, which is referenced by both the <container> element in switchyard.xml, and the KIE/Drools container.
The rules-interview quickstart, on the other hand, manually lists the required resource.

This quickstart also demonstrates how a domain property can be made available as a global variable inside your DRL.
See references to ${user.name} (system property) mapping to userName (domain property) mapping to userName (global variable) inside switchyard.xml.
Then look at Interview.drl and how the userName global variable is used in the DRL.

This rules-interview-container quickstart differs from the rules-interview quickstart.
A /META-INF/kmodule.xml is used, which is referenced by both the <container> element in switchyard.xml, and the KIE/Drools container.
The rules-interview quickstart, on the other hand, manually lists the required resource.
This quickstart can be executed using either a java interface or a web service interface.

![Rules Interview Container Quickstart](https://github.com/jboss-switchyard/quickstarts/raw/master/rules-interview-container/rules-interview-container.jpg)

Expand All @@ -21,24 +23,25 @@ Maven

Running the quickstart
======================

JBoss AS 7
----------
1. Build the quickstart:

mvn clean install

2. Run the test:

(Using java interface:)
mvn -Dtest=RulesInterviewTest test

(Using web service interface:)
mvn -Dtest=WebServiceTest test

Expected Output:
================
(userName is a placeholder in this Readme.)
```
Running org.switchyard.quickstarts.rules.interview.RulesInterviewTest
********** Twenty is a valid applicant, userName. **********
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.131 sec`
Running org.switchyard.quickstarts.rules.interview.RulesInterviewTest
**** Twenty is an old enough applicant, userName. ****
**** Sixteen is too young of an applicant, userName. ****
```

## Further Reading
Expand Down
164 changes: 93 additions & 71 deletions rules-interview-container/pom.xml
Original file line number Diff line number Diff line change
@@ -1,73 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
-
- Licensed under the Apache License, Version 2.0 (the "License")
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.switchyard.quickstarts</groupId>
<artifactId>switchyard-quickstart-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>switchyard-quickstart-rules-interview-container</artifactId>
<name>Quickstart : Rules Interview Container</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-api</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-test-mixin-cdi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-rules</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.switchyard.quickstarts</groupId>
<artifactId>switchyard-quickstart-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
</parent>
<artifactId>switchyard-quickstart-rules-interview-container</artifactId>
<name>Quickstart : Rules Interview (Container)</name>
<dependencies>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-api</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-rules</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-test-mixin-cdi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-test-mixin-http</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-transform</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-validate</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-soap</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jboss-public-repository</id>
<name>JBoss Public Maven Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-public-repository</id>
<name>JBoss Public Maven Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</pluginRepository>
</pluginRepositories>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
<configuration>
<scannerClassNames>
<param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param>
</scannerClassNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Binary file modified rules-interview-container/rules-interview-container.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public class Applicant {

private String name;
private int age;
private boolean valid;

public Applicant() {
this("", 0);
}

public Applicant(String name, int age) {
setName(name);
Expand All @@ -43,12 +46,4 @@ public void setAge(int age) {
this.age = age;
}

public boolean isValid() {
return valid;
}

public void setValid(boolean valid) {
this.valid = valid;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*/
public interface Interview {

public void verify(Applicant applicant);
public boolean verify(Applicant applicant);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.switchyard.quickstarts.rules.interview;

import java.io.StringReader;

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamSource;

import org.switchyard.annotations.Transformer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
* @author David Ward &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; &copy; 2013 Red Hat Inc.
*/
public class Transformers {

@Transformer(from = "{urn:switchyard-quickstart:rules-interview-container:0.1.0}verify")
public Applicant transformVerifyToApplicant(Element e) {
String name = getElementValue(e, "name");
int age = Integer.valueOf(getElementValue(e, "age")).intValue();
return new Applicant(name, age);
}

@Transformer(to = "{urn:switchyard-quickstart:rules-interview-container:0.1.0}verifyResponse")
public Element transformBooleanToVerifyResponse(boolean b) {
String xml = new StringBuilder()
.append("<urn:verifyResponse xmlns:urn='urn:switchyard-quickstart:rules-interview-container:0.1.0'>")
.append( "<return>").append(b).append("</return>")
.append("</urn:verifyResponse>")
.toString();
return toElement(xml);
}

private String getElementValue(Element parent, String elementName) {
String value = null;
NodeList nodes = parent.getElementsByTagName(elementName);
if (nodes.getLength() > 0) {
value = nodes.item(0).getChildNodes().item(0).getNodeValue();
}
return value;
}

private Element toElement(String xml) {
DOMResult dom = new DOMResult();
try {
TransformerFactory.newInstance().newTransformer().transform(new StreamSource(new StringReader(xml)), dom);
} catch (Exception e) {
e.printStackTrace();
}
return ((Document)dom.getNode()).getDocumentElement();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="Interview" targetNamespace="urn:switchyard-quickstart:rules-interview-container:0.1.0" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:switchyard-quickstart:rules-interview-container:0.1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="urn:switchyard-quickstart:rules-interview-container:0.1.0" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="urn:switchyard-quickstart:rules-interview-container:0.1.0">
<xs:complexType name="applicant">
<xs:sequence>
<xs:element name="age" type="xs:int"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="verify" type="verify"/>
<xs:complexType name="verify">
<xs:sequence>
<xs:element minOccurs="0" name="applicant" type="applicant"/>
</xs:sequence>
</xs:complexType>
<xs:element name="verifyResponse" type="verifyResponse"/>
<xs:complexType name="verifyResponse">
<xs:sequence>
<xs:element name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="verifyResponse">
<wsdl:part name="parameters" element="tns:verifyResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="verify">
<wsdl:part name="parameters" element="tns:verify">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="InterviewPortType">
<wsdl:operation name="verify">
<wsdl:input name="verify" message="tns:verify">
</wsdl:input>
<wsdl:output name="verifyResponse" message="tns:verifyResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="InterviewSoapBinding" type="tns:InterviewPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="verify">
<soap:operation soapAction="verify" style="document"/>
<wsdl:input name="verify">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="verifyResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Interview">
<wsdl:port name="InterviewPort" binding="tns:InterviewSoapBinding">
<soap:address location="http://localhost:8080/rules-interview-container/Interview"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Loading

0 comments on commit 215f69d

Please sign in to comment.