├── .gitignore ├── README.md ├── business-resource-planner └── README.md ├── contributor-settings.xml ├── decision-table ├── README.md ├── pom.xml └── src │ └── test │ └── java │ └── org │ └── jboss │ └── quickstarts │ └── brms │ └── DecisionTableTest.java ├── dist ├── pom.xml ├── release-utils.sh ├── release.sh └── src │ └── main │ └── assembly │ └── assembly.xml ├── helloworld-bpmsuite ├── README.md ├── pom.xml └── src │ └── test │ └── java │ └── org │ └── jboss │ └── quickstarts │ └── brms │ └── HelloworldProcessTest.java ├── helloworld-brms ├── README.md ├── pom.xml └── src │ └── test │ └── java │ └── org │ └── jboss │ └── quickstarts │ └── brms │ └── HelloWorldBRMSTest.java ├── helloworld-cep ├── README.md ├── kmodule │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── jboss │ │ │ └── quickstarts │ │ │ └── brms │ │ │ └── cep │ │ │ └── model │ │ │ ├── Transaction.java │ │ │ └── TransactionType.java │ │ └── resources │ │ ├── META-INF │ │ └── kmodule.xml │ │ └── fraud-detection-rules.drl ├── pom.xml └── web │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── jboss │ │ │ └── quickstarts │ │ │ └── brms │ │ │ └── cep │ │ │ ├── controller │ │ │ └── TransactionController.java │ │ │ └── util │ │ │ └── Resources.java │ └── webapp │ │ ├── WEB-INF │ │ ├── beans.xml │ │ └── faces-config.xml │ │ ├── index.html │ │ └── transactions.xhtml │ └── test │ ├── java │ └── org │ │ └── jboss │ │ └── quickstarts │ │ └── brms │ │ └── cep │ │ └── TransactionsTest.java │ └── resources │ └── arquillian.xml ├── helloworld-drl ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── jboss │ │ │ └── quickstarts │ │ │ └── brms │ │ │ └── helloworlddrl │ │ │ ├── Customer.java │ │ │ ├── CustomerType.java │ │ │ └── Sale.java │ └── resources │ │ ├── META-INF │ │ └── kmodule.xml │ │ └── helloworld.drl │ └── test │ └── java │ └── org │ └── jboss │ └── quickstarts │ └── brms │ └── helloworlddrl │ └── HelloWorldDRLTest.java ├── pom.xml ├── settings.xml ├── stateful-ksession ├── README.md ├── kmodule │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── jboss │ │ │ └── quickstarts │ │ │ └── brms │ │ │ └── sfksession │ │ │ └── model │ │ │ ├── Alarm.java │ │ │ ├── Fire.java │ │ │ ├── House.java │ │ │ ├── Room.java │ │ │ └── Sprinkler.java │ │ └── resources │ │ ├── META-INF │ │ ├── beans.xml │ │ └── kmodule.xml │ │ └── houserules.drl ├── pom.xml └── web │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── jboss │ │ │ └── quickstarts │ │ │ └── brms │ │ │ └── sfksession │ │ │ └── controller │ │ │ └── HouseController.java │ └── webapp │ │ ├── WEB-INF │ │ ├── beans.xml │ │ └── faces-config.xml │ │ ├── housedashboard.xhtml │ │ └── index.html │ └── test │ ├── java │ └── org │ │ └── jboss │ │ └── quickstarts │ │ └── brms │ │ └── sfksession │ │ └── HouseFireTest.java │ └── resources │ └── arquillian.xml ├── store-brms ├── README.md ├── pom.xml └── src │ └── test │ └── java │ └── org │ └── jboss │ └── quickstarts │ └── brms │ └── StoreBRMSTest.java └── tasks-bpmsuite ├── README.md ├── pom.xml └── src └── test ├── java └── org │ └── jboss │ └── quickstarts │ └── brms │ └── ApprovalProcessTest.java └── resources ├── META-INF └── persistence.xml └── usergroups.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | target 3 | bin 4 | .* 5 | */.gitignore 6 | .gitkeep 7 | MANIFEST.MF 8 | .classpath 9 | .project 10 | .settings 11 | .metadata 12 | out 13 | *.log 14 | *.tlog 15 | 16 | # IntelliJ specific files/directories 17 | .idea 18 | *.iml 19 | -------------------------------------------------------------------------------- /business-resource-planner/README.md: -------------------------------------------------------------------------------- 1 | **Important**: Quickstart was removed in favor of other web-examples coming directly with Business Resource Planner distribution. 2 | 3 | Download the Business Resource Planner Distribution 4 | ------------------------------------------------------ 5 | * Option 1 6 | * Login to the Customer Portal at 7 | * Select `BRMS` from the product list. 8 | * Find `Red Hat JBoss BRMS 6.2.0 Business Resource Planner` in the file list and click `Download`. 9 | * This downloads the BRMS 6.2.0 Business Resource Planner distribution to a directory of your choice. 10 | 11 | * Option 2 12 | * Visit the JBoss BRMS page at 13 | * Select `Download JBoss BRMS`, login or create an account, and agree to the download terms and conditions. 14 | * Click on `Optaplanner` for version 6.2.0.GA. 15 | * This downloads the JBoss BRMS 6.2.0 Business Resource Planner to a directory of your choice. 16 | 17 | Web examples are located in the directory `jboss-brms-bpmsuite-6.2-planner-engine/webexamples`. You can directly use the WAR 18 | file located in `binaries` directory or explore the sources which are located under `sources` directory. 19 | 20 | Please see [documentation](https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_BRMS) for more details on how to install 21 | and use the examples. 22 | -------------------------------------------------------------------------------- /contributor-settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | jboss-public-repository 28 | 29 | 30 | jboss-public-repository 31 | https://repository.jboss.org/nexus/content/groups/public/ 32 | 33 | true 34 | 35 | 36 | true 37 | 38 | 39 | 40 | 41 | 42 | jboss-public-plugin-repository 43 | https://repository.jboss.org/nexus/content/groups/public/ 44 | 45 | true 46 | 47 | 48 | true 49 | 50 | 51 | 52 | 53 | 54 | 55 | jboss-ga-repository 56 | 57 | 58 | jboss-ga-repository 59 | http://maven.repository.redhat.com/techpreview/all 60 | 61 | true 62 | 63 | 64 | false 65 | 66 | 67 | 68 | 69 | 70 | jboss-ga-plugin-repository 71 | http://maven.repository.redhat.com/techpreview/all 72 | 73 | true 74 | 75 | 76 | false 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | jboss-earlyaccess-repository 85 | 86 | 87 | jboss-earlyaccess-repository 88 | http://maven.repository.redhat.com/earlyaccess/all/ 89 | 90 | true 91 | 92 | 93 | false 94 | 95 | 96 | 97 | 98 | 99 | jboss-earlyaccess-plugin-repository 100 | http://maven.repository.redhat.com/earlyaccess/all/ 101 | 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | jboss-developer-repository 114 | 115 | 116 | jboss-developer-repository 117 | http://jboss-developer.github.io/temp-maven-repo/ 118 | 119 | true 120 | 121 | 122 | false 123 | 124 | 125 | 126 | 127 | 128 | jboss-developer-plugin-repository 129 | http://jboss-developer.github.io/temp-maven-repo/ 130 | 131 | true 132 | 133 | 134 | false 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | jboss-public-repository 145 | jboss-ga-repository 146 | jboss-earlyaccess-repository 147 | jboss-developer-repository 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /decision-table/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 4.0.0 21 | org.jboss.quickstarts.brms 22 | brms-decision-table 23 | 6.2.0-SNAPSHOT 24 | 25 | JBoss BRMS Quickstart: decision-table 26 | 27 | 28 | Apache License, Version 2.0 29 | repo 30 | http://www.apache.org/licenses/LICENSE-2.0.html 31 | 32 | 33 | 34 | 6.2.0-SNAPSHOT 35 | true 36 | 37 | 38 | 39 | 40 | 42 | 43 | org.jboss.bom.brms 44 | jboss-brms-bpmsuite-platform-bom 45 | pom 46 | ${version.org.jboss.bom.brms} 47 | import 48 | 49 | 50 | 51 | 52 | 53 | org.kie 54 | kie-api 55 | 56 | 57 | 58 | org.drools 59 | drools-compiler 60 | runtime 61 | 62 | 63 | 64 | org.drools 65 | drools-decisiontables 66 | runtime 67 | 68 | 69 | 70 | ch.qos.logback 71 | logback-classic 72 | runtime 73 | 74 | 75 | 76 | 77 | junit 78 | junit 79 | test 80 | 81 | 82 | 83 | 84 | ${project.artifactId} 85 | 86 | 87 | 88 | 89 | enable-test 90 | 91 | 92 | false 93 | 94 | 95 | 96 | 97 | 98 | brms 99 | 100 | 101 | 102 | brms-m2-repo 103 | BRMS M2 Repo 104 | http://localhost:8080/business-central/maven2/ 105 | 106 | 107 | 108 | 109 | 110 | 111 | org.jboss.quickstarts.brms 112 | decision-table-kmodule 113 | 1.0.0 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | redhat-product-repo 124 | Red Hat Product Repository 125 | https://maven.repository.redhat.com/ga 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /dist/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | org.jboss.quickstarts.brms 21 | jboss-brms-bpmsuite-quickstarts-dist 22 | 6.2.0-SNAPSHOT 23 | pom 24 | JBoss BRMS/BPM Suite Quickstarts :: Distribution 25 | http://www.jboss.org/jdf/quickstarts/get-started/ 26 | 27 | 28 | Apache License, Version 2.0 29 | repo 30 | http://www.apache.org/licenses/LICENSE-2.0.html 31 | 32 | 33 | 34 | 35 | 2.4 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-assembly-plugin 43 | ${version.assembly.plugin} 44 | 45 | 46 | make-assembly 47 | package 48 | 49 | single 50 | 51 | 52 | false 53 | jboss-brms-bpmsuite-quickstarts 54 | 55 | ${basedir}/src/main/assembly/assembly.xml 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /dist/release-utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # JBoss, Home of Professional Open Source 4 | # Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual 5 | # contributors by the @authors tag. See the copyright.txt in the 6 | # distribution for a full listing of individual contributors. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | 20 | REQUIRED_BASH_VERSION=3.0.0 21 | 22 | if [[ $BASH_VERSION < $REQUIRED_BASH_VERSION ]]; then 23 | echo "You must use Bash version 3 or newer to run this script" 24 | exit 25 | fi 26 | 27 | 28 | DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) 29 | 30 | # DEFINE 31 | 32 | ARCHETYPES=("jboss-javaee6-webapp-archetype" "jboss-javaee6-webapp-ear-archetype") 33 | QUICKSTARTS=("kitchensink" "kitchensink-ear") 34 | VERSIONS_MAVEN_PLUGIN_VERSION=1.3.1 35 | 36 | # SCRIPT 37 | 38 | HUMAN_READABLE_ARCHETYPES="" 39 | i=0 40 | element_count=${#ARCHETYPES[@]} 41 | index=0 42 | while [ "$index" -lt "$element_count" ] 43 | do 44 | if [ $index -ne 0 ] 45 | then 46 | HUMAN_READABLE_ARCHETYPES="${HUMAN_READABLE_ARCHETYPES}, " 47 | fi 48 | HUMAN_READABLE_ARCHETYPES="${HUMAN_READABLE_ARCHETYPES}${ARCHETYPES[index]}" 49 | ((index++)) 50 | done 51 | 52 | 53 | usage() 54 | { 55 | cat << EOF 56 | usage: $0 options 57 | 58 | This script aids in releasing the quickstarts 59 | 60 | OPTIONS: 61 | -u Updates version numbers in all POMs, used with -o and -n 62 | -o Old version number to update from 63 | -n New version number to update to 64 | -r Regenerate the various quickstarts based on archetypes ${HUMAN_READABLE_ARCHETYPES} 65 | -m Generate html versions of markdown readmes 66 | -h Shows this message 67 | EOF 68 | } 69 | 70 | update() 71 | { 72 | cd $DIR/../ 73 | echo "Updating versions from $OLDVERSION TO $NEWVERSION for all Java files under $PWD" 74 | perl -pi -e "s/${OLDVERSION}/${NEWVERSION}/g" `find . -name \*.java` 75 | 76 | echo "Performing updates to POMs" 77 | poms=`find . -type f -iname "pom.xml" -maxdepth 2 | sort` 78 | for pom in $poms 79 | do 80 | echo "Updating ${pom}" 81 | mvn org.codehaus.mojo:versions-maven-plugin:${VERSIONS_MAVEN_PLUGIN_VERSION}:set -DnewVersion=${NEWVERSION} -f ${pom} -q 82 | mvn org.codehaus.mojo:versions-maven-plugin:${VERSIONS_MAVEN_PLUGIN_VERSION}:commit -f ${pom} -q 83 | done 84 | } 85 | 86 | markdown_to_html() 87 | { 88 | cd $DIR/../ 89 | 90 | # Clear the contents from toc.html file 91 | rm dist/target/toc.html 92 | touch dist/target/toc.html 93 | 94 | # Loop through the sorted quickstart directories and process them 95 | # Exclude the template directory since it's not a quickstart 96 | subdirs=`find . -maxdepth 1 -type d ! -iname ".*" ! -iname "template" | sort` 97 | for subdir in $subdirs 98 | do 99 | readmes=`find $subdir -iname readme.md` 100 | for readme in $readmes 101 | do 102 | echo "Processing $readme" 103 | output_filename=${readme//.md/.html} 104 | output_filename=${output_filename//.MD/.html} 105 | $DIR/github-flavored-markdown.rb $readme > $output_filename 106 | done 107 | done 108 | # Now process the root readme 109 | cd $DIR/../ 110 | readme=README.md 111 | echo "Processing $readme" 112 | output_filename=${readme//.md/.html} 113 | output_filename=${output_filename//.MD/.html} 114 | $DIR/github-flavored-markdown.rb $readme > $output_filename 115 | 116 | # Now process the contributing markdown 117 | cd $DIR/../ 118 | markdown_filename=CONTRIBUTING.md 119 | echo "Processing $markdown_filename" 120 | output_filename=${markdown_filename//.md/.html} 121 | output_filename=${output_filename//.MD/.html} 122 | $DIR/github-flavored-markdown.rb $markdown_filename > $output_filename 123 | 124 | # Now process the release procedure markdown 125 | cd $DIR/../ 126 | markdown_filename=RELEASE_PROCEDURE.md 127 | echo "Processing $markdown_filename" 128 | output_filename=${markdown_filename//.md/.html} 129 | output_filename=${output_filename//.MD/.html} 130 | $DIR/github-flavored-markdown.rb $markdown_filename > $output_filename 131 | } 132 | 133 | regenerate() 134 | { 135 | TMPDIR="$DIR/target/regen" 136 | ROOTDIR="$DIR/../" 137 | 138 | rm -rf $TMPDIR 139 | 140 | mkdir -p $TMPDIR 141 | 142 | cd $TMPDIR 143 | 144 | element_count=${#ARCHETYPES[@]} 145 | index=0 146 | while [ "$index" -lt "$element_count" ] 147 | do 148 | archetype=${ARCHETYPES[index]} 149 | quickstart=${QUICKSTARTS[index]} 150 | package=${quickstart//-/_} 151 | name="JBoss AS Quickstarts: $quickstart" 152 | echo "**** Regenerating $quickstart from $archetype" 153 | mvn archetype:generate -DarchetypeGroupId=org.jboss.spec.archetypes -DarchetypeArtifactId=$archetype -DarchetypeVersion=$VERSION -DartifactId=jboss-as-$quickstart -DgroupId=org.jboss.as.quickstarts -Dpackage=org.jboss.as.quickstarts.$package -Dversion=$VERSION -DinteractiveMode=false -Dname="${name}" 154 | ((index++)) 155 | rm -rf $ROOTDIR/$quickstart 156 | mv $TMPDIR/jboss-as-$quickstart $ROOTDIR/$quickstart 157 | done 158 | 159 | } 160 | 161 | OLDVERSION="1.0.0-SNAPSHOT" 162 | NEWVERSION="1.0.0-SNAPSHOT" 163 | VERSION="1.0.0-SNAPSHOT" 164 | CMD="usage" 165 | 166 | while getopts “muo:n:r:” OPTION 167 | 168 | do 169 | case $OPTION in 170 | u) 171 | CMD="update" 172 | ;; 173 | h) 174 | usage 175 | exit 176 | ;; 177 | o) 178 | OLDVERSION=$OPTARG 179 | ;; 180 | n) 181 | NEWVERSION=$OPTARG 182 | ;; 183 | r) 184 | CMD="regenerate" 185 | VERSION=$OPTARG 186 | ;; 187 | m) 188 | CMD="markdown_to_html" 189 | ;; 190 | [?]) 191 | usage 192 | exit 193 | ;; 194 | esac 195 | done 196 | 197 | $CMD 198 | 199 | -------------------------------------------------------------------------------- /dist/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # JBoss, Home of Professional Open Source 4 | # Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual 5 | # contributors by the @authors tag. See the copyright.txt in the 6 | # distribution for a full listing of individual contributors. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | 20 | REQUIRED_BASH_VERSION=3.0.0 21 | 22 | if [[ $BASH_VERSION < $REQUIRED_BASH_VERSION ]]; then 23 | echo "You must use Bash version 3 or newer to run this script" 24 | exit 25 | fi 26 | 27 | DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) 28 | 29 | # DEFINE 30 | 31 | VERSION_REGEX='([0-9]*)\.([0-9]*)([a-zA-Z0-9\.]*)' 32 | 33 | # EAP team email subject 34 | EMAIL_SUBJECT="\${RELEASEVERSION} of JBoss Quickstarts released, please merge with https://github.com/jboss-eap/quickstart, tag and add to EAP maven repo build" 35 | # EAP team email To ? 36 | EMAIL_TO="pgier@redhat.com kpiwko@redhat.com" 37 | EMAIL_FROM="\"JDF Publish Script\" " 38 | 39 | 40 | # SCRIPT 41 | 42 | usage() 43 | { 44 | cat << EOF 45 | usage: $0 options 46 | 47 | This script performs a release of the Quickstarts 48 | 49 | OPTIONS: 50 | -s Snapshot version number to update from 51 | -n New snapshot version number to update to, if undefined, defaults to the version number updated from 52 | -r Release version number 53 | EOF 54 | } 55 | 56 | notify_email() 57 | { 58 | echo "***** Performing JBoss Quickstarts release notifications" 59 | echo "*** Notifying JBoss EAP team" 60 | subject=`eval echo $EMAIL_SUBJECT` 61 | echo "Email from: " $EMAIL_FROM 62 | echo "Email to: " $EMAIL_TO 63 | echo "Subject: " $subject 64 | # send email using sendmail 65 | printf "Subject: $subject\nSee \$subject :)\n" | /usr/bin/env sendmail -f "$EMAIL_FROM" "$EMAIL_TO" 66 | } 67 | 68 | release() 69 | { 70 | BRANCH=$(parse_git_branch) 71 | git checkout -b $RELEASEVERSION 72 | echo "Regenerating html from markdown" 73 | $DIR/release-utils.sh -m 74 | echo "Releasing JBoss AS Quickstarts version $RELEASEVERSION" 75 | $DIR/release-utils.sh -u -o $SNAPSHOTVERSION -n $RELEASEVERSION 76 | echo "Removing unnecessary files" 77 | git rm --cached -r dist/ 78 | git rm --cached -r template/ 79 | git commit -a -m "Prepare for $RELEASEVERSION release" 80 | echo "Creating tag for $RELEASEVERSION" 81 | git tag $RELEASEVERSION 82 | mvn clean install -f $DIR/pom.xml 83 | echo "Your zip file was generated at $DIR/target/jboss-eap-quickstarts-$RELEASEVERSION-dist.zip" 84 | $DIR/release-utils.sh -u -o $RELEASEVERSION -n $NEWSNAPSHOTVERSION 85 | echo "Adding unnecessary files again..." 86 | git add dist/ 87 | git add template/ 88 | git commit -a -m "Prepare for development of $NEWSNAPSHOTVERSION" 89 | git checkout $BRANCH 90 | #echo "Building Distribution zip" 91 | #git checkout $RELEASEVERSION 92 | #echo "Uploading distribution to http://download.jboss.org/jbossas/$MAJOR_VERSION.$MINOR_VERSION/jboss-as-$RELEASEVERSION/jboss-eap-quickstarts-$RELEASEVERSION-dist.zip" 93 | #rsync -Pv --protocol=28 $DIR/target/jboss-eap-quickstarts-$RELEASEVERSION-dist.zip jbossas@filemgmt.jboss.org:downloads_htdocs/jbossas/$MAJOR_VERSION.$MINOR_VERSION/jboss-eap-$RELEASEVERSION/ 94 | read -p "Do you want to send release notifcations to $EAP_EMAIL_TO[y/N]?" yn 95 | case $yn in 96 | [Yy]* ) notify_email;; 97 | esac 98 | echo "Don't forget to push the tag and the branch" 99 | #echo " git push --tags upstream refs/heads/$RELEASEVERSION master" 100 | echo " git push --tags upstream $BRANCH" 101 | } 102 | 103 | parse_git_branch() { 104 | git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' 105 | } 106 | 107 | 108 | SNAPSHOTVERSION="UNDEFINED" 109 | RELEASEVERSION="UNDEFINED" 110 | NEWSNAPSHOTVERSION="UNDEFINED" 111 | MAJOR_VERSION="UNDEFINED" 112 | MINOR_VERSION="UNDEFINED" 113 | 114 | while getopts “n:r:s:” OPTION 115 | 116 | do 117 | case $OPTION in 118 | h) 119 | usage 120 | exit 121 | ;; 122 | s) 123 | SNAPSHOTVERSION=$OPTARG 124 | ;; 125 | r) 126 | RELEASEVERSION=$OPTARG 127 | ;; 128 | n) 129 | NEWSNAPSHOTVERSION=$OPTARG 130 | ;; 131 | [?]) 132 | usage 133 | exit 134 | ;; 135 | esac 136 | done 137 | 138 | if [[ $RELEASEVERSION =~ $VERSION_REGEX ]]; then 139 | MAJOR_VERSION=${BASH_REMATCH[1]} 140 | MINOR_VERSION=${BASH_REMATCH[2]} 141 | fi 142 | 143 | if [ "$NEWSNAPSHOTVERSION" == "UNDEFINED" ] 144 | then 145 | NEWSNAPSHOTVERSION=$SNAPSHOTVERSION 146 | fi 147 | 148 | if [ "$MAJOR_VERSION" == "UNDEFINED" -o "$MINOR_VERSION" == "UNDEFINED" ] 149 | then 150 | echo "\nUnable to extract major and minor versions\n" 151 | usage 152 | exit 153 | fi 154 | 155 | if [ "$SNAPSHOTVERSION" == "UNDEFINED" -o "$RELEASEVERSION" == "UNDEFINED" ] 156 | then 157 | echo "\nMust specify -r and -s\n" 158 | usage 159 | exit 160 | fi 161 | 162 | release 163 | 164 | -------------------------------------------------------------------------------- /dist/src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | Quickstarts 22 | true 23 | 24 | zip 25 | 26 | 27 | 28 | 29 | ../ 30 | 31 | **/target 32 | **/target/**/* 33 | 34 | 644 35 | 755 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /helloworld-bpmsuite/README.md: -------------------------------------------------------------------------------- 1 | helloworld-bpmsuite: A Basic BPM Suite example 2 | ============================================== 3 | Author: Rafael Benevides 4 | Level: Beginner 5 | Technologies: Drools, BRMS 6 | Summary: The `helloworld-bpmsuite` quickstart shows how to run a Process that was defined on a JBoss BPM Suite server 7 | Target Product: BPM Suite 8 | Source: 9 | 10 | What is it? 11 | ----------- 12 | 13 | This project demonstrates how to use BPM Suite to manage and deploy business processes. 14 | 15 | * The `HelloworldProcessTest` class starts a process that was defined in BPM Suite 16 | 17 | _Note_: The bpms-project.helloworld process is defined in the following dependency: org.jboss.quickstarts.brms:bpms_project:1.0.0. It is available in this git repository: 18 | 19 | 20 | The Maven dependency is available in the following Maven Repository: 21 | 22 | This quickstart does not contain a user interface layer. 23 | 24 | System requirements 25 | ------------------- 26 | 27 | All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later. 28 | 29 | The application this project produces is designed to be run on BPM Suite 6 30 | 31 | 32 | Configure Maven 33 | --------------- 34 | 35 | If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstarts. 36 | 37 | 38 | Start the JBoss Server 39 | ----------- 40 | 41 | If you have not yet done so, you must [Configure BPM Suite](../README.md#configure-bpm-suite) before testing the quickstart. 42 | 43 | 1. Open a command line and navigate to the root of the BRMS directory. 44 | 2. The following shows the command line to start the server: 45 | 46 | For Linux: EAP_HOME/bin/standalone.sh 47 | For Windows: EAP_HOME\bin\standalone.bat 48 | 49 | 50 | Import the BRMS Repository 51 | ---------------------- 52 | 53 | If you have not yet done so, you must [Import the BRMS repository](../README.md#import-the-brms-repository) before testing the quickstart. 54 | 55 | 56 | Deploy the BPM Suite Process Project 57 | ---------------------------- 58 | 59 | 1. [Start the JBoss Server](#start-the-jboss-server) as instructed above. 60 | 61 | 2. Open a browser and access the following URL: 62 | 63 | 2. Log in with the following credentials: 64 | 65 | Username: quickstartUser 66 | Password: quickstartPwd1! 67 | 68 | 3. Choose menu option `Authoring` -> `Project Authoring` 69 | 70 | 4. Choose the following options under `Project Explorer`: 71 | 72 | Organizational Unit: example 73 | Repository Name: jboss-brms-repository 74 | BRMS Kmodule: bpms-project 75 | 76 | 5. Next, click on `Tools` and `Project Editor` 77 | 78 | 6. In the tab on the right, click on `Build & Deploy`. 79 | * It will prompt you with a message: "Also save possible changes to project?". Click `Yes`. 80 | * You are prompted for a comment. Add a comment and click on `Save` button. 81 | 82 | This deploys the `org.jboss.quickstarts.brms:bpms_project:1.0.0` artifact to the BRMS Maven repository. You can verify the deployment choosing menu option `Deploy` --> `Deployments`. 83 | 84 | 85 | Run the Tests 86 | ------------- 87 | 88 | 1. Open a command prompt and navigate to the root directory of this quickstart. 89 | 2. Type the following command to run the test goal with the following profile activated: 90 | 91 | mvn clean test -Penable-test,bpms 92 | 93 | The `bpms` profile enables the repository and adds the `org.jboss.quickstarts.brms:bpms_project:1.0.0` as a project dependency. 94 | 95 | The tests should complete successfully. 96 | 97 | Investigate the Console Output 98 | ---------------------------- 99 | 100 | When you run the tests, JUnit will present you test report summary: 101 | 102 | ------------------------------------------------------- 103 | T E S T S 104 | ------------------------------------------------------- 105 | Running org.jboss.quickstarts.brms.HelloworldProcessTest 106 | ================================ 107 | = Starting Process Helloworld. = 108 | ================================ 109 | Hello World! 110 | Hello World from rule! 111 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.482 sec 112 | 113 | Results : 114 | 115 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 116 | 117 | Test the Quickstart in JBoss Developer Studio or Eclipse 118 | ------------------------------------- 119 | 120 | You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts) 121 | 122 | 123 | Debug the Application 124 | ------------------------------------ 125 | 126 | If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them. 127 | 128 | mvn dependency:sources 129 | mvn dependency:resolve -Dclassifier=javadoc 130 | 131 | -------------------------------------------------------------------------------- /helloworld-bpmsuite/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 4.0.0 21 | org.jboss.quickstarts.brms 22 | brms-helloworld-bpmsuite 23 | 6.2.0-SNAPSHOT 24 | 25 | JBoss BPM Suite Quickstart: helloworld-bpmsuite 26 | 27 | 28 | Apache License, Version 2.0 29 | repo 30 | http://www.apache.org/licenses/LICENSE-2.0.html 31 | 32 | 33 | 34 | 6.2.0-SNAPSHOT 35 | true 36 | 37 | 38 | 39 | 41 | 42 | org.jboss.bom.brms 43 | jboss-brms-bpmsuite-platform-bom 44 | pom 45 | ${version.org.jboss.bom.brms} 46 | import 47 | 48 | 49 | 50 | 51 | 52 | org.kie 53 | kie-api 54 | 55 | 56 | 57 | org.drools 58 | drools-compiler 59 | runtime 60 | 61 | 62 | 63 | 64 | 65 | org.jbpm 66 | jbpm-bpmn2 67 | runtime 68 | 69 | 70 | 71 | org.jbpm 72 | jbpm-test 73 | test 74 | 75 | 76 | 77 | ch.qos.logback 78 | logback-classic 79 | runtime 80 | 81 | 82 | 83 | 84 | junit 85 | junit 86 | test 87 | 88 | 89 | 90 | 91 | ${project.artifactId} 92 | 93 | 94 | 95 | 96 | enable-test 97 | 98 | 99 | false 100 | 101 | 102 | 103 | 104 | 105 | bpms 106 | 107 | 108 | 109 | bpms-m2-repo 110 | BRMS M2 Repo 111 | http://localhost:8080/business-central/maven2/ 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.jboss.quickstarts.brms 119 | bpms_project 120 | 1.0.0 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | redhat-product-repo 131 | Red Hat Product Repository 132 | https://maven.repository.redhat.com/ga 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /helloworld-bpmsuite/src/test/java/org/jboss/quickstarts/brms/HelloworldProcessTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.jbpm.test.JbpmJUnitBaseTestCase; 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.kie.api.io.ResourceType; 27 | import org.kie.api.runtime.KieSession; 28 | import org.kie.api.runtime.manager.RuntimeEngine; 29 | import org.kie.api.runtime.process.ProcessInstance; 30 | import org.kie.internal.runtime.manager.context.ProcessInstanceIdContext; 31 | 32 | /** 33 | * @author rafaelbenevides 34 | * 35 | */ 36 | public class HelloworldProcessTest extends JbpmJUnitBaseTestCase { 37 | 38 | private static RuntimeEngine runtime; 39 | 40 | @Before 41 | public void setUp() { 42 | Map resources = new HashMap(); 43 | resources.put("helloworld.bpmn2", ResourceType.BPMN2); 44 | resources.put("helloworldrule.drl", ResourceType.DRL); 45 | 46 | createRuntimeManager(Strategy.SINGLETON, resources); 47 | runtime = getRuntimeEngine(ProcessInstanceIdContext.get()); 48 | } 49 | 50 | @After 51 | public void tearDown() { 52 | disposeRuntimeManager(); 53 | } 54 | 55 | @Test 56 | public void testProcess() { 57 | 58 | KieSession kSession = runtime.getKieSession(); 59 | 60 | // Fire it up! 61 | System.out.println("================================"); 62 | System.out.println("= Starting Process Helloworld. ="); 63 | System.out.println("================================"); 64 | 65 | // start the process 66 | ProcessInstance processInstance = kSession.startProcess("bpms-project.helloworld"); 67 | 68 | // check whether the process instance has completed successfully 69 | assertProcessInstanceActive(processInstance.getId(), kSession); 70 | kSession.insert(processInstance); 71 | kSession.fireAllRules(); 72 | 73 | // check whether the given nodes were executed during the process execution 74 | assertNodeTriggered(processInstance.getId(), "StartProcess", "ScriptTask", "BusinessRules"); 75 | 76 | assertNodeActive(processInstance.getId(), kSession, "Timer"); 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /helloworld-brms/README.md: -------------------------------------------------------------------------------- 1 | helloworld-brms: A Basic BRMS example 2 | ====================================== 3 | Author: Rafael Benevides 4 | Level: Beginner 5 | Technologies: Drools, BRMS 6 | Summary:The `helloworld-brms` quickstart shows how to use a KModule from a BRMS server 7 | Target Product: BRMS 8 | Source: 9 | 10 | What is it? 11 | ----------- 12 | 13 | This project demonstrates how to use BRMS to manage and deploy modules that contain model classes and rules. 14 | 15 | * The `HelloWorldBRMSTest` class creates 3 Sales object instances: `vipSale`, `regularSale`, and `badSale`. 16 | * These Sales objects are passed to the `StatelessKieSession` class, which runs the rules against them to verify and apply discounts. 17 | 18 | _Note:_ The Sale, Customer and CustomerType classes are defined on the following dependency: org.jboss.quickstarts.brms:helloworld-brms-kmodule:1.0.0. This dependency is a BRMS Kmodule that contains the model classes and the rules that were previously built. It is available on the the git repository: 19 | 20 | 21 | The Maven dependency is available at the following Maven Repository: `http://localhost:8080/business-central/maven2/` 22 | 23 | This quickstart does not contain a user interface layer. 24 | 25 | System requirements 26 | ------------------- 27 | 28 | All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later. 29 | 30 | The application this project produces is designed to be run on BRMS 6 31 | 32 | 33 | Configure Maven 34 | --------------- 35 | 36 | If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstarts. 37 | 38 | 39 | Start the JBoss Server 40 | ----------- 41 | 42 | If you have not yet done so, you must [Configure BRMS](../README.md#configure-brms) before testing the quickstart. 43 | 44 | 1. Open a command line and navigate to the root of the BRMS directory. 45 | 2. The following shows the command line to start the server: 46 | 47 | For Linux: EAP_HOME/bin/standalone.sh 48 | For Windows: EAP_HOME\bin\standalone.bat 49 | 50 | 51 | Import the BRMS Repository 52 | ---------------------- 53 | 54 | If you have not yet done so, you must [Import the BRMS repository](../README.md#import-the-brms-repository) before testing the quickstart. 55 | 56 | 57 | Deploy BRMS kmodule 58 | ------------------- 59 | 60 | 1. [Start the JBoss Server](#start-the-jboss-server) as instructed above. 61 | 62 | 2. Open a browser and access the following URL: 63 | 64 | 2. Log in with the following credentials: 65 | 66 | Username: quickstartUser 67 | Password: quickstartPwd1! 68 | 69 | 3. Choose menu option `Authoring` -> `Project Authoring` 70 | 71 | 4. Choose the following options under `Project Explorer`: 72 | 73 | Organizational Unit: example 74 | Repository Name: jboss-brms-repository 75 | BRMS Kmodule: helloworld-brms-kmodule 76 | 77 | 5. Next, click on `Tools` and `Project Editor` 78 | 79 | 6. In the tab on the right, click on `Build & Deploy`. 80 | * It will prompt you with a message: "Also save possible changes to project?". Click `Yes`. 81 | * You are prompted for a comment. Add a comment and click on `Save` button. 82 | 83 | This deploys the `org.jboss.quickstarts.brms:helloworld-brms-kmodule:1.0.0` artifact to the BRMS Maven repository. You can verify the deployment choosing menu option `Deployment` --> `Artifact Repository`. 84 | 85 | 86 | Run the Tests 87 | ------------- 88 | 89 | 1. Open a command prompt and navigate to the root directory of this quickstart. 90 | 2. Type the following command to run the test goal with the following profile activated: 91 | 92 | mvn clean test -Penable-test 93 | 94 | The tests fail with compilation errors because the project does not have the necessary dependencies. 95 | 96 | 4. Now run the following command to run the test goal with the following profiles activated: 97 | 98 | mvn clean test -Penable-test,brms 99 | 100 | The `brms` profile enables the `http://localhost:8080/business-central/maven2/` repository and adds the `org.jboss.quickstarts.brms:helloworld-brms-kmodule:1.0.0` as a project dependency. 101 | 102 | Now the tests complete successfully. 103 | 104 | Investigate the Console Output 105 | ---------------------------- 106 | 107 | When you run the tests, JUnit will present you test report summary: 108 | 109 | ------------------------------------------------------- 110 | T E S T S 111 | ------------------------------------------------------- 112 | Running org.jboss.quickstarts.brms.HelloWorldBRMSTest 113 | 17:02:10.317 [main] INFO o.d.c.k.b.impl.ClasspathKieProject - Found kmodule: jar:file:/Users/rafaelbenevides/.m2/repository/org/jboss/quickstarts/brms/helloworld-brms-kmodule/1.0.0/helloworld-brms-kmodule-1.0.0.jar!/META-INF/kmodule.xml 114 | 17:02:10.322 [main] DEBUG o.d.c.k.b.impl.ClasspathKieProject - KieModule URL type=jar url=/Users/rafaelbenevides/.m2/repository/org/jboss/quickstarts/brms/helloworld-brms-kmodule/1.0.0/helloworld-brms-kmodule-1.0.0.jar 115 | 17:02:10.461 [main] DEBUG o.d.c.k.b.impl.ClasspathKieProject - Found and used pom.properties META-INF/maven/org.jboss.quickstarts.brms/helloworld-brms-kmodule/pom.properties 116 | 17:02:10.466 [main] DEBUG o.d.c.k.b.impl.ClasspathKieProject - Discovered classpath module org.jboss.quickstarts.brms:helloworld-brms-kmodule:1.0.0 117 | 17:02:10.469 [main] INFO o.d.c.k.b.impl.KieRepositoryImpl - KieModule was added:ZipKieModule[ ReleaseId=org.jboss.quickstarts.brms:helloworld-brms-kmodule:1.0.0file=/Users/rafaelbenevides/.m2/repository/org/jboss/quickstarts/brms/helloworld-brms-kmodule/1.0.0/helloworld-brms-kmodule-1.0.0.jar] 118 | 17:02:11.132 [main] DEBUG o.drools.core.reteoo.ReteooRuleBase - Starting Engine in PHREAK mode 119 | ** Testing VIP customer ** 120 | VIP discount applied 121 | Sale approved 122 | ** Testing regular customer ** 123 | Sale approved 124 | ** Testing BAD customer ** 125 | Bad customer. Sale denied 126 | Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.548 sec 127 | 128 | Results : 129 | 130 | Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 131 | 132 | 133 | Test the Quickstart in JBoss Developer Studio or Eclipse 134 | ------------------------------------- 135 | 136 | You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts) 137 | 138 | 139 | Debug the Application 140 | ------------------------------------ 141 | 142 | If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them. 143 | 144 | mvn dependency:sources 145 | mvn dependency:resolve -Dclassifier=javadoc 146 | 147 | -------------------------------------------------------------------------------- /helloworld-brms/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 4.0.0 21 | org.jboss.quickstarts.brms 22 | brms-helloworld-brms 23 | 6.2.0-SNAPSHOT 24 | 25 | JBoss BRMS Quickstart: helloworld-brms 26 | 27 | 28 | Apache License, Version 2.0 29 | repo 30 | http://www.apache.org/licenses/LICENSE-2.0.html 31 | 32 | 33 | 34 | 6.2.0-SNAPSHOT 35 | true 36 | 37 | 38 | 39 | 41 | 42 | org.jboss.bom.brms 43 | jboss-brms-bpmsuite-platform-bom 44 | pom 45 | ${version.org.jboss.bom.brms} 46 | import 47 | 48 | 49 | 50 | 51 | 52 | org.kie 53 | kie-api 54 | 55 | 56 | 57 | org.drools 58 | drools-compiler 59 | runtime 60 | 61 | 62 | 63 | ch.qos.logback 64 | logback-classic 65 | runtime 66 | 67 | 68 | 69 | 70 | 71 | junit 72 | junit 73 | test 74 | 75 | 76 | 77 | ${project.artifactId} 78 | 79 | 80 | 81 | 82 | enable-test 83 | 84 | 85 | false 86 | 87 | 88 | 89 | 90 | 91 | brms 92 | 93 | 94 | 95 | brms-m2-repo 96 | BRMS M2 Repo 97 | http://localhost:8080/business-central/maven2/ 98 | 99 | 100 | 101 | 102 | 103 | 104 | org.jboss.quickstarts.brms 105 | helloworld-brms-kmodule 106 | 1.0.0 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | redhat-product-repo 116 | Red Hat Product Repository 117 | https://maven.repository.redhat.com/ga 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /helloworld-brms/src/test/java/org/jboss/quickstarts/brms/HelloWorldBRMSTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertNull; 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import org.junit.BeforeClass; 25 | import org.junit.Test; 26 | import org.kie.api.KieServices; 27 | import org.kie.api.runtime.KieContainer; 28 | import org.kie.api.runtime.StatelessKieSession; 29 | 30 | /** 31 | * @author rafaelbenevides 32 | * 33 | */ 34 | public class HelloWorldBRMSTest { 35 | 36 | private static StatelessKieSession kSession; 37 | 38 | // A sale for a VIP customer 39 | private static Sale vipSale; 40 | // A sale for a regular customer 41 | private static Sale regularSale; 42 | // A sale for a Bad customer 43 | private static Sale badSale; 44 | 45 | @BeforeClass 46 | public static void setup() { 47 | KieServices kieServices = KieServices.Factory.get(); 48 | KieContainer kContainer = kieServices.getKieClasspathContainer(); 49 | kSession = kContainer.newStatelessKieSession(); 50 | 51 | CustomerType regular = new CustomerType(); 52 | regular.setType("regular"); 53 | 54 | CustomerType vip = new CustomerType(); 55 | vip.setType("VIP"); 56 | 57 | CustomerType bad = new CustomerType(); 58 | bad.setType("BAD"); 59 | 60 | Customer vipCustomer = new Customer(); 61 | vipCustomer.setCustomerType(vip); 62 | vipSale = new Sale(); 63 | vipSale.setCustomer(vipCustomer); 64 | 65 | Customer regularCustomer = new Customer(); 66 | regularCustomer.setCustomerType(regular); 67 | regularSale = new Sale(); 68 | regularSale.setCustomer(regularCustomer); 69 | 70 | Customer badCustomer = new Customer(); 71 | badCustomer.setCustomerType(bad); 72 | badSale = new Sale(); 73 | badSale.setCustomer(badCustomer); 74 | } 75 | 76 | @Test 77 | public void testGoodCustomer() { 78 | System.out.println("** Testing VIP customer **"); 79 | kSession.execute(vipSale); 80 | // Sale approved 81 | assertTrue(vipSale.getApproved().booleanValue()); 82 | // Discount of 0.5 83 | assertEquals(vipSale.getDiscount(), 0.50F, 0.0); 84 | } 85 | 86 | @Test 87 | public void testRegularCustomer() { 88 | System.out.println("** Testing regular customer **"); 89 | kSession.execute(regularSale); 90 | // Sale approved 91 | assertTrue(regularSale.getApproved().booleanValue()); 92 | // No Discount 93 | assertNull(regularSale.getDiscount()); 94 | } 95 | 96 | @Test 97 | public void testBadCustomer() { 98 | System.out.println("** Testing BAD customer **"); 99 | kSession.execute(badSale); 100 | // Sale denied 101 | assertFalse(badSale.getApproved().booleanValue()); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /helloworld-cep/README.md: -------------------------------------------------------------------------------- 1 | helloworld-cep: A Complex Event Processing Hello World 2 | ====================================================== 3 | Author: Rafael Benevides 4 | Level: Intermediate 5 | Technologies: CDI, JSF, Drools 6 | Summary: The `helloworld-cep` quickstart shows a basic example for CEP 7 | Target Product: BRMS 8 | Source: 9 | 10 | What is it? 11 | ----------- 12 | 13 | The `helloworld-cep` quickstarts demonstrates a basic example of CEP - Complex Event Processing. Each financial transaction, for example `Credit Card`, `Deposit` or `Withdrawal`, is an event that occurs on the user account. 14 | 15 | For demonstration purposes, 3 rules are defined to evaluate and detect the following fraudulent transactions: 16 | 17 | 1. More than 3 transactions occur in less than 5 seconds from any entry point. 18 | 2. A transaction amount is more than twice the average of the last 4 Credit Card transactions 19 | 3. A withdrawal occurs less than 10 seconds after a Credit card transaction 20 | 21 | 22 | This Quickstarts contains two modules: 23 | 24 | - The Kmodule project contains the model classes `Transaction` and `TransactionType`. It also contains the rules file `fraud-detection-rules.drl`. 25 | 26 | - The Web project contains a web application that allows you to simulate Credit Card, withdrawal, and deposit transactions. 27 | 28 | _Note: You do not need to download and configure BRMS to run this quickstart._ 29 | 30 | 31 | System requirements 32 | ------------------- 33 | 34 | The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later. 35 | 36 | All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later. 37 | 38 | 39 | Configure Maven 40 | --------------- 41 | 42 | If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstart. 43 | 44 | 45 | Start the JBoss EAP Server 46 | ---------------------- 47 | 48 | 1. Open a command prompt and navigate to the root of the JBoss EAP directory. 49 | 2. The following shows the command line to start the server: 50 | 51 | For Linux: JBOSS_HOME/bin/standalone.sh 52 | For Windows: JBOSS_HOME\bin\standalone.bat 53 | 54 | 55 | Build and Deploy the Quickstart 56 | ------------------------- 57 | 58 | _NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line._ 59 | 60 | 1. Make sure you have started the JBoss EAP server as described above. 61 | 2. Open a command prompt and navigate to the root directory of this quickstart. 62 | 3. Type this command to build and deploy the archive: 63 | 64 | mvn clean install jboss-as:deploy 65 | 66 | 4. This deploys `web/target/brms-helloworld-cep-web.war` to the running instance of the server. 67 | 68 | 69 | Access the application 70 | --------------------- 71 | 72 | 73 | Access the running application in a browser at the following URL: 74 | 75 | You are presented to a form that allows you to create finance transactions. Test the rules by doing the following: 76 | 77 | - Leave the default values (10, CREDIT_CARD) and click on the `Register Transaction` button. 78 | A message `CREDIT_CARD transaction of USD 10 registered!` is displayed. 79 | 80 | - Click more 4 times in less than 5 seconds on the `Register Transaction` button. 81 | A message `Transaction Denied! More than 3 transactions in less than 5 seconds` is displayed. This demonstrates the first rule was applied to this transaction event. 82 | 83 | - Now set the amount to 100 and click on the `Register Transaction` button. 84 | A message `Transaction Denied! This Credit Card transaction amount of USD 100 is more than twice the average amount ( USD 32.5 ) of the last 4 Credit Card Transactions` is displayed. This demonstrates that the second rule was applied to this transaction event. 85 | 86 | - Click again on `Register Transaction` and in less than 10 seconds change the type to `WITHDRAW` and click on the `Register Transaction` button. 87 | A message `Transaction Denied! A withdrawal transaction is not allowed less than 10 seconds after a Credit Card transaction` is displayed. This demonstrates that the third rule was applied to the WITHDRAW transaction event. 88 | 89 | 90 | Undeploy the Archive 91 | -------------------- 92 | 93 | 1. Make sure you have started the JBoss Server as described above. 94 | 2. Open a command line and navigate to the root directory of this quickstart. 95 | 3. When you are finished testing, type this command to undeploy the archive: 96 | 97 | mvn jboss-as:undeploy 98 | 99 | 100 | Run the Arquillian Tests 101 | ------------------------- 102 | 103 | This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. 104 | 105 | _NOTE: The following commands assume you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Run the Arquillian Tests](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/RUN_ARQUILLIAN_TESTS.md#run-the-arquillian-tests) for complete instructions and additional options._ 106 | 107 | 1. Make sure you have started the JBoss Server as described above. 108 | 2. Open a command prompt and navigate to the root directory of this quickstart. 109 | 3. Type the following command to run the test goal with the following profile activated: 110 | 4. Because Arquillian Test need to access customer settings.xml, please make sure your customermized settings.xml was copied into ~/.m2/settings.xml or ../settings.xml was copied into ~/.m2/settings.xml by default. 111 | 112 | mvn clean install test -Parq-jbossas-remote 113 | 114 | 115 | Run the Quickstart in JBoss Developer Studio or Eclipse 116 | ------------------------------------- 117 | 118 | You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts) 119 | 120 | Debug the Application 121 | ------------------------------------ 122 | 123 | If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them. 124 | 125 | mvn dependency:sources 126 | mvn dependency:resolve -Dclassifier=javadoc 127 | -------------------------------------------------------------------------------- /helloworld-cep/kmodule/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.jboss.quickstarts.brms 22 | brms-helloworld-cep 23 | 6.2.0-SNAPSHOT 24 | 25 | brms-helloworld-cep-kmodule 26 | JBoss BRMS Quickstart: helloworld-cep - kmodule 27 | 28 | 29 | Apache License, Version 2.0 30 | repo 31 | http://www.apache.org/licenses/LICENSE-2.0.html 32 | 33 | 34 | 35 | 1.6 36 | 1.6 37 | 38 | 39 | ${project.artifactId} 40 | 41 | 42 | -------------------------------------------------------------------------------- /helloworld-cep/kmodule/src/main/java/org/jboss/quickstarts/brms/cep/model/Transaction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.cep.model; 18 | 19 | import java.math.BigInteger; 20 | 21 | /** 22 | * @author rafaelbenevides 23 | * 24 | */ 25 | public class Transaction { 26 | 27 | private BigInteger value = new BigInteger("10"); 28 | 29 | private boolean denied; 30 | 31 | private String deniedCause; 32 | 33 | private TransactionType type; 34 | 35 | public Transaction() { 36 | 37 | } 38 | 39 | /** 40 | * @param value 41 | * @param type 42 | */ 43 | public Transaction(BigInteger value, TransactionType type) { 44 | this.value = value; 45 | this.type = type; 46 | } 47 | 48 | /** 49 | * @return the value 50 | */ 51 | public BigInteger getValue() { 52 | return value; 53 | } 54 | 55 | /** 56 | * @param value the value to set 57 | */ 58 | public void setValue(BigInteger value) { 59 | this.value = value; 60 | } 61 | 62 | /** 63 | * @return the denied 64 | */ 65 | public boolean isDenied() { 66 | return denied; 67 | } 68 | 69 | /** 70 | * @param denied the denied to set 71 | */ 72 | public void setDenied(boolean denied) { 73 | this.denied = denied; 74 | } 75 | 76 | /** 77 | * @return the deniedCause 78 | */ 79 | public String getDeniedCause() { 80 | return deniedCause; 81 | } 82 | 83 | /** 84 | * @param deniedCause the deniedCause to set 85 | */ 86 | public void setDeniedCause(String deniedCause) { 87 | this.deniedCause = deniedCause; 88 | } 89 | 90 | /** 91 | * @return the type 92 | */ 93 | public TransactionType getType() { 94 | return type; 95 | } 96 | 97 | /** 98 | * @param type the type to set 99 | */ 100 | public void setType(TransactionType type) { 101 | this.type = type; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /helloworld-cep/kmodule/src/main/java/org/jboss/quickstarts/brms/cep/model/TransactionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.cep.model; 18 | 19 | /** 20 | * @author rafaelbenevides 21 | * 22 | * This enum represents the types of {@link Transaction} 23 | * 24 | */ 25 | public enum TransactionType { 26 | 27 | CREDIT_CARD, 28 | WITHDRAW, 29 | DEPOSIT, 30 | 31 | } 32 | -------------------------------------------------------------------------------- /helloworld-cep/kmodule/src/main/resources/META-INF/kmodule.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /helloworld-cep/kmodule/src/main/resources/fraud-detection-rules.drl: -------------------------------------------------------------------------------- 1 | package houserules 2 | 3 | import org.jboss.quickstarts.brms.cep.model.Transaction 4 | import org.jboss.quickstarts.brms.cep.model.TransactionType 5 | 6 | declare Transaction 7 | @role ( event ) 8 | end 9 | 10 | rule "Transaction is suspect if more than 3 transactions occur in less than 5 seconds" 11 | when 12 | $transaction: Transaction( ) 13 | Number( intValue > 3) from accumulate ( 14 | $t: Transaction( ) over window:time ( 5s ), 15 | count($t) 16 | ) 17 | then 18 | $transaction.setDenied(true); 19 | $transaction.setDeniedCause("Transaction Denied! More than 3 transactions in less than 5 seconds"); 20 | System.out.println("Transaction Denied! More than 3 transactions in less than 5 seconds"); 21 | end 22 | 23 | rule "Transaction is suspect if the amount is more than twice the average of the last 4 Credit Card transactions" 24 | when 25 | $transaction: Transaction( $transactionValue: value ) from entry-point "Credit Card" 26 | $average: Number( (intValue * 2) < $transactionValue) from accumulate ( 27 | Transaction( $value: value ) over window:length ( 4 ) from entry-point "Credit Card", 28 | average($value) 29 | ) 30 | then 31 | $transaction.setDenied(true); 32 | $transaction.setDeniedCause("Transaction Denied! This Credit Card transaction amount of USD " + $transaction.getValue() + " is more than twice the average amount ( USD " + $average + ") of the last 4 Credit Card Transactions"); 33 | System.out.println("Transaction Denied! This Credit Card transaction amount of USD " + $transaction.getValue() + " is more than twice the average amount ( USD " + $average + ") of the last 4 Credit Card Transactions"); 34 | end 35 | 36 | rule "Withdrawal transaction is suspect if it occurs less than 10 seconds after a credit card transaction" 37 | when 38 | $creditCardTransaction: Transaction( ) from entry-point "Credit Card" 39 | $withDrawTransaction: Transaction( this after [0s, 10s] $creditCardTransaction, type == TransactionType.WITHDRAW ) 40 | then 41 | $withDrawTransaction.setDenied(true); 42 | $withDrawTransaction.setDeniedCause("Transaction Denied! A withdrawal transaction is not allowed less than 10 seconds after a Credit Card transaction"); 43 | System.out.println("Transaction Denied! A withdrawal transaction is not allowed less than 10 seconds after a Credit Card transaction"); 44 | end 45 | -------------------------------------------------------------------------------- /helloworld-cep/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | org.jboss.quickstarts.brms 21 | brms-helloworld-cep 22 | 6.2.0-SNAPSHOT 23 | 24 | pom 25 | JBoss BRMS Quickstart: helloworld-cep 26 | http://jboss.org/jbossas 27 | 28 | 29 | Apache License, Version 2.0 30 | repo 31 | http://www.apache.org/licenses/LICENSE-2.0.html 32 | 33 | 34 | 35 | 36 | 6.2.0-SNAPSHOT 37 | 6.4.4.GA 38 | 2.4 39 | 2.10 40 | 7.4.Final 41 | 42 | 43 | 44 | kmodule 45 | web 46 | 47 | 48 | 49 | 50 | 52 | 53 | org.jboss.bom.brms 54 | jboss-brms-bpmsuite-bom 55 | pom 56 | ${version.org.jboss.bom.brms} 57 | import 58 | 59 | 63 | 64 | org.jboss.bom.eap 65 | jboss-javaee-6.0-with-tools 66 | ${version.org.jboss.bom.eap} 67 | pom 68 | import 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | javax.enterprise 79 | cdi-api 80 | provided 81 | 82 | 83 | 84 | 85 | org.jboss.spec.javax.annotation 86 | jboss-annotations-api_1.1_spec 87 | provided 88 | 89 | 90 | 91 | 92 | org.jboss.spec.javax.ws.rs 93 | jboss-jaxrs-api_1.1_spec 94 | provided 95 | 96 | 97 | 98 | 99 | 100 | org.jboss.spec.javax.ejb 101 | jboss-ejb-api_3.1_spec 102 | provided 103 | 104 | 105 | 106 | 107 | 108 | org.jboss.spec.javax.faces 109 | jboss-jsf-api_2.1_spec 110 | provided 111 | 112 | 113 | 114 | 115 | org.kie 116 | kie-api 117 | 118 | 119 | org.drools 120 | drools-compiler 121 | runtime 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | junit 130 | junit 131 | test 132 | 133 | 134 | 135 | org.jboss.shrinkwrap.resolver 136 | shrinkwrap-resolver-depchain 137 | pom 138 | test 139 | 140 | 141 | 142 | 143 | 144 | org.jboss.arquillian.junit 145 | arquillian-junit-container 146 | test 147 | 148 | 149 | 150 | org.jboss.arquillian.protocol 151 | arquillian-protocol-servlet 152 | test 153 | 154 | 155 | 156 | 157 | 158 | 159 | 162 | 163 | org.jboss.as.plugins 164 | jboss-as-maven-plugin 165 | ${version.jboss.maven.plugin} 166 | 167 | true 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | redhat-product-repo 177 | Red Hat Product Repository 178 | https://maven.repository.redhat.com/ga 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /helloworld-cep/web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.jboss.quickstarts.brms 22 | brms-helloworld-cep 23 | 6.2.0-SNAPSHOT 24 | 25 | brms-helloworld-cep-web 26 | war 27 | JBoss BRMS Quickstart: helloworld-cep - web 28 | http://jboss.org/jbossas 29 | 30 | 31 | Apache License, Version 2.0 32 | repo 33 | http://www.apache.org/licenses/LICENSE-2.0.html 34 | 35 | 36 | 37 | 1.6 38 | 1.6 39 | 40 | 41 | 42 | 43 | org.jboss.quickstarts.brms 44 | brms-helloworld-cep-kmodule 45 | ${project.version} 46 | 47 | 48 | 49 | 50 | 51 | org.jboss.quickstarts.brms 52 | brms-helloworld-cep-kmodule 53 | compile 54 | 55 | 56 | 57 | 59 | ${project.artifactId} 60 | 61 | 62 | maven-war-plugin 63 | ${version.war.plugin} 64 | 65 | 66 | false 67 | 68 | 69 | 70 | 71 | 72 | org.jboss.as.plugins 73 | jboss-as-maven-plugin 74 | ${version.jboss.maven.plugin} 75 | 76 | false 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | default 86 | 87 | true 88 | 89 | 90 | 91 | 92 | maven-surefire-plugin 93 | ${version.surefire.plugin} 94 | 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | arq-jbossas-managed 107 | 108 | 109 | org.jboss.as 110 | jboss-as-arquillian-container-managed 111 | test 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | arq-jbossas-remote 120 | 121 | 122 | org.jboss.as 123 | jboss-as-arquillian-container-remote 124 | test 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | openshift 134 | 135 | 136 | 137 | maven-war-plugin 138 | ${version.war.plugin} 139 | 140 | deployments 141 | ROOT 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/main/java/org/jboss/quickstarts/brms/cep/controller/TransactionController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.cep.controller; 18 | 19 | import java.io.Serializable; 20 | 21 | import javax.enterprise.inject.Model; 22 | import javax.faces.application.FacesMessage; 23 | import javax.faces.context.FacesContext; 24 | import javax.inject.Inject; 25 | 26 | import org.jboss.quickstarts.brms.cep.model.Transaction; 27 | import org.kie.api.cdi.KSession; 28 | import org.kie.api.runtime.KieSession; 29 | import org.kie.api.runtime.rule.EntryPoint; 30 | 31 | /** 32 | * @author rafaelbenevides 33 | * 34 | */ 35 | // The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an 36 | // EL name 37 | // Read more about the @Model stereotype in this FAQ: 38 | // http://www.cdi-spec.org/faq/#accordion6 39 | @Model 40 | public class TransactionController implements Serializable { 41 | 42 | private static final long serialVersionUID = 1L; 43 | 44 | @Inject 45 | private FacesContext facesContext; 46 | 47 | private Transaction transaction = new Transaction(); 48 | 49 | @Inject 50 | @KSession("myKSession") 51 | // use configured myKSession 52 | private KieSession kieSession; 53 | 54 | /** 55 | * @return the transaction 56 | */ 57 | public Transaction getTransaction() { 58 | return transaction; 59 | } 60 | 61 | public void registerTransaction() { 62 | // Select an entry point based on transaction type 63 | EntryPoint entryPoint = null; 64 | switch (transaction.getType()) { 65 | case CREDIT_CARD: 66 | entryPoint = kieSession.getEntryPoint("Credit Card"); 67 | break; 68 | case DEPOSIT: 69 | entryPoint = kieSession.getEntryPoint("Deposit"); 70 | case WITHDRAW: 71 | entryPoint = kieSession.getEntryPoint("Withdraw"); 72 | break; 73 | } 74 | 75 | // If the entry point exists, place the transaction on entry point also 76 | if (entryPoint != null) { 77 | entryPoint.insert(transaction); 78 | } 79 | // Always place the object in kieSession for rules that doesn't declare an entry point 80 | kieSession.insert(transaction); 81 | // Fire the rules 82 | kieSession.fireAllRules(); 83 | 84 | // Check if the transaction was denied 85 | if (transaction.isDenied()) { 86 | facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, transaction.getDeniedCause(), null)); 87 | } else { 88 | facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, transaction.getType() + " transaction of USD " + transaction.getValue() + " registered!", 89 | null)); 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/main/java/org/jboss/quickstarts/brms/cep/util/Resources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.cep.util; 18 | 19 | import javax.enterprise.inject.Produces; 20 | import javax.faces.context.FacesContext; 21 | import javax.faces.model.SelectItem; 22 | import javax.inject.Named; 23 | 24 | import org.jboss.quickstarts.brms.cep.model.TransactionType; 25 | 26 | /** 27 | * This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans 28 | * 29 | *

30 | * Example injection on a managed bean field: 31 | *

32 | * 33 | *
34 |  * @Inject
35 |  * private EntityManager em;
36 |  * 
37 | */ 38 | public class Resources { 39 | 40 | @Produces 41 | @Named("transactionsType") 42 | public SelectItem[] getTransactionsType() { 43 | SelectItem[] items = new SelectItem[TransactionType.values().length]; 44 | int i = 0; 45 | for (TransactionType type : TransactionType.values()) { 46 | items[i] = new SelectItem(type, type.name()); 47 | i++; 48 | } 49 | return items; 50 | } 51 | 52 | @Produces 53 | public FacesContext getFacesContext() { 54 | return FacesContext.getCurrentInstance(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/main/webapp/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/main/webapp/WEB-INF/faces-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/main/webapp/transactions.xhtml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 22 | 23 | 24 | Transactions simulator 25 | 52 | 53 | 54 | 55 | 57 | 58 | 59 | 60 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 105 | 106 | 107 | 108 | 110 | 111 | 112 |
Transactions Simulation
69 | 71 | 72 | 73 | 90 | 91 | 92 | 101 | 102 | 103 |
74 | 75 | 76 | 77 | Value (default to 10 USD): 78 | 79 | 80 | 81 |
82 | Type: 83 | 84 | 85 | 86 |
87 | 88 |
89 |
93 |
94 | Rules: 95 |
    96 |
  1. A transaction is suspect if more than 3 transactions occur in less than 5 seconds
  2. 97 |
  3. A transaction is suspect if the amount is twice the average of the last 4 Credit Card transactions
  4. 98 |
  5. A withdrawal transaction is suspect if it occurs less than 10 seconds after a Credit Card transaction
  6. 99 |
100 |
104 |
113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/test/java/org/jboss/quickstarts/brms/cep/TransactionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.cep; 18 | 19 | import java.io.File; 20 | import java.math.BigInteger; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | import javax.inject.Inject; 24 | 25 | import org.drools.core.time.SessionPseudoClock; 26 | import org.jboss.arquillian.container.test.api.Deployment; 27 | import org.jboss.arquillian.junit.Arquillian; 28 | import org.jboss.quickstarts.brms.cep.model.Transaction; 29 | import org.jboss.quickstarts.brms.cep.model.TransactionType; 30 | import org.jboss.shrinkwrap.api.Archive; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.spec.WebArchive; 33 | import org.jboss.shrinkwrap.resolver.api.maven.Maven; 34 | import org.junit.Assert; 35 | import org.junit.Test; 36 | import org.junit.runner.RunWith; 37 | import org.kie.api.cdi.KSession; 38 | import org.kie.api.runtime.KieSession; 39 | import org.kie.api.runtime.rule.EntryPoint; 40 | 41 | /** 42 | * @author rafaelbenevides 43 | * 44 | */ 45 | @RunWith(Arquillian.class) 46 | public class TransactionsTest { 47 | 48 | /** 49 | * The location of the WebApp source folder so we know where to find the web.xml when deploying using Arquillian. 50 | */ 51 | private static final String WEBAPP_SRC = "src/main/webapp"; 52 | 53 | @Inject 54 | @KSession("myKSessionTest") 55 | // use configured myKSession 56 | private KieSession kieSession; 57 | 58 | @Deployment 59 | public static Archive getDeployment() { 60 | File pom = new File("pom.xml"); 61 | File[] libs = Maven.resolver() 62 | .loadPomFromFile(pom) 63 | .resolve("org.kie:kie-api", "org.drools:drools-compiler", "org.jboss.quickstarts.brms:brms-helloworld-cep-kmodule") 64 | // Avoid using org.jboss.quickstarts.brms:brms-stateful-ksession-kmodule from reactor 65 | .withClassPathResolution(false) 66 | .withTransitivity().asFile(); 67 | 68 | Archive archive = ShrinkWrap 69 | .create(WebArchive.class, "test.war") 70 | .addAsLibraries(libs) 71 | .addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/beans.xml")); 72 | return archive; 73 | } 74 | 75 | @Test 76 | public void test3TransactionsIn5Seconds() { 77 | System.out.println("** Placing more than 3 transactions in less than 5 seconds **"); 78 | Transaction t1 = new Transaction(); 79 | Transaction t2 = new Transaction(); 80 | Transaction t3 = new Transaction(); 81 | Transaction t4 = new Transaction(); 82 | kieSession.insert(t1); 83 | kieSession.insert(t2); 84 | kieSession.insert(t3); 85 | kieSession.insert(t4); 86 | kieSession.fireAllRules(); 87 | // t4 should be denied 88 | Assert.assertTrue(t4.isDenied()); 89 | System.out.println("* Transaction denied: " + t4.isDenied()); 90 | } 91 | 92 | @Test 93 | public void test3TransactionsIn10Seconds() { 94 | System.out.println("** Placing more than 3 transaction is more than 5 seconds **"); 95 | Transaction t1 = new Transaction(); 96 | Transaction t2 = new Transaction(); 97 | Transaction t3 = new Transaction(); 98 | Transaction t4 = new Transaction(); 99 | kieSession.insert(t1); 100 | kieSession.insert(t2); 101 | kieSession.insert(t3); 102 | 103 | // here we use a pseudoclock so we can forward session clock in 10 seconds before inserting t4 104 | SessionPseudoClock clock = kieSession.getSessionClock(); 105 | clock.advanceTime(10, TimeUnit.SECONDS); 106 | 107 | kieSession.insert(t4); 108 | kieSession.fireAllRules(); 109 | // t4 is not denied because it was inserted after 10 seconds 110 | Assert.assertFalse(t4.isDenied()); 111 | System.out.println("* Transaction denied: " + t4.isDenied()); 112 | } 113 | 114 | @Test 115 | public void test4CreditCardTransactions() { 116 | System.out.println("** Placing a Credit Card where its value is twice the medium of last 4 **"); 117 | Transaction t1 = new Transaction(new BigInteger("10"), TransactionType.CREDIT_CARD); 118 | Transaction t2 = new Transaction(new BigInteger("10"), TransactionType.CREDIT_CARD); 119 | Transaction t3 = new Transaction(new BigInteger("10"), TransactionType.CREDIT_CARD); 120 | Transaction t4 = new Transaction(new BigInteger("10"), TransactionType.CREDIT_CARD); 121 | Transaction t5 = new Transaction(new BigInteger("100"), TransactionType.CREDIT_CARD); 122 | kieSession.insert(t1); 123 | kieSession.insert(t2); 124 | kieSession.insert(t3); 125 | kieSession.insert(t4); 126 | kieSession.insert(t5); 127 | kieSession.fireAllRules(); 128 | // t5 is denied because it is twice the medium of last 4 transactions (t1, t2, t3, t4) 129 | Assert.assertTrue(t5.isDenied()); 130 | System.out.println("* Transaction denied: " + t5.isDenied()); 131 | } 132 | 133 | @Test 134 | public void testWithdrawIn10SecondAfterCreditCard() { 135 | System.out.println("** Placing a Withdraw after a Credit Card transaction in less than 10 seconds **"); 136 | Transaction t1 = new Transaction(new BigInteger("10"), TransactionType.CREDIT_CARD); 137 | Transaction t2 = new Transaction(new BigInteger("10"), TransactionType.WITHDRAW); 138 | EntryPoint entryPoint = kieSession.getEntryPoint("Credit Card"); 139 | entryPoint.insert(t1); 140 | kieSession.insert(t2); 141 | kieSession.fireAllRules(); 142 | Assert.assertTrue(t2.isDenied()); 143 | System.out.println("* Transaction denied: " + t2.isDenied()); 144 | } 145 | 146 | @Test 147 | public void testWithdrawIn20SecondAfterCreditCard() { 148 | System.out.println("** Placing a Withdraw after a Credit Card transaction in more than 10 seconds **"); 149 | Transaction t1 = new Transaction(new BigInteger("10"), TransactionType.CREDIT_CARD); 150 | Transaction t2 = new Transaction(new BigInteger("10"), TransactionType.WITHDRAW); 151 | EntryPoint entryPoint = kieSession.getEntryPoint("Credit Card"); 152 | entryPoint.insert(t1); 153 | // here we use a pseudoclock so we can forward session clock in 20 seconds before inserting t2 154 | SessionPseudoClock clock = kieSession.getSessionClock(); 155 | clock.advanceTime(20, TimeUnit.SECONDS); 156 | 157 | kieSession.insert(t2); 158 | kieSession.fireAllRules(); 159 | Assert.assertFalse(t2.isDenied()); 160 | System.out.println("* Transaction denied: " + t2.isDenied()); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /helloworld-cep/web/src/test/resources/arquillian.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /helloworld-drl/README.md: -------------------------------------------------------------------------------- 1 | helloworld-drl: BRMS Basic DRL example 2 | ====================================== 3 | Author: Rafael Benevides 4 | Level: Beginner 5 | Technologies: Drools 6 | Summary: The `helloworld-drl` quickstart shows how to use Drools 6 7 | Target Product: BRMS 8 | Source: 9 | 10 | What is it? 11 | ----------- 12 | 13 | This project demonstrates how to use Drools 6 to execute rules. The rules are used to approve and apply discounts on a sale based on the customer type. This example applies a 50% discount for VIP customers and denies the sale for BAD customers. 14 | 15 | The `HelloworldDRLTest` class creates 3 Sales object instances: `vipSale`, `regularSale`, and `badSale`. These Sales objects are passed to the `StatelessKieSession` class, which runs the rules against them to verify, apply discounts, or deny the sale. 16 | 17 | This quickstart does not contain a user interface layer. The rules are described in `src/main/resource/META-INF/helloworld.drl`. 18 | 19 | 20 | System requirements 21 | ------------------- 22 | 23 | All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later. 24 | 25 | 26 | Configure Maven 27 | --------------- 28 | 29 | If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstarts. 30 | 31 | 32 | Run the Tests 33 | ------------- 34 | 35 | 1. Open a command prompt and navigate to the root directory of this quickstart. 36 | 2. Type the following command to run the test goal with the following profile activated: 37 | 38 | mvn clean test 39 | 40 | 41 | Investigate the Console Output 42 | ---------------------------- 43 | 44 | When you run the tests, JUnit will present you test report summary: 45 | 46 | ------------------------------------------------------- 47 | T E S T S 48 | ------------------------------------------------------- 49 | Running org.jboss.quickstarts.brms.helloworlddrl.HelloWorldDRLTest 50 | 17:35:06.378 [main] INFO o.d.c.k.b.impl.ClasspathKieProject - Found kmodule: file:/Users/rafaelbenevides/projetos/jdf/Quickstarts/jboss-brms-quickstarts/helloworld-drl/target/classes/META-INF/kmodule.xml 51 | 17:35:06.384 [main] DEBUG o.d.c.k.b.impl.ClasspathKieProject - KieModule URL type=file url=/Users/rafaelbenevides/projetos/jdf/Quickstarts/jboss-brms-quickstarts/helloworld-drl/target/classes 52 | 17:35:06.571 [main] WARN o.d.c.k.b.impl.ClasspathKieProject - Unable to load pom.properties tried recursing down from/Users/rafaelbenevides/projetos/jdf/Quickstarts/jboss-brms-quickstarts/helloworld-drl/target/classes 53 | null 54 | 17:35:06.595 [main] INFO o.d.c.k.b.impl.ClasspathKieProject - Recursed up folders, found and used pom.xml /Users/rafaelbenevides/projetos/jdf/Quickstarts/jboss-brms-quickstarts/helloworld-drl/pom.xml 55 | 17:35:06.599 [main] DEBUG o.d.c.k.b.impl.ClasspathKieProject - Discovered classpath module org.jboss.quickstarts.brms:brms-helloworld-drl:1.0.0-build-SNAPSHOT 56 | 17:35:06.610 [main] INFO o.d.c.k.b.impl.KieRepositoryImpl - KieModule was added:FileKieModule[ ReleaseId=org.jboss.quickstarts.brms:brms-helloworld-drl:1.0.0-build-SNAPSHOTfile=/Users/rafaelbenevides/projetos/jdf/Quickstarts/jboss-brms-quickstarts/helloworld-drl/target/classes] 57 | 17:35:07.716 [main] DEBUG o.drools.core.reteoo.ReteooRuleBase - Starting Engine in PHREAK mode 58 | ** Testing VIP customer ** 59 | VIP discount applied 60 | Sale approved 61 | ** Testing regular customer ** 62 | Sale approved 63 | ** Testing BAD customer ** 64 | BAD customer. Sale denied 65 | Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.105 sec 66 | 67 | Results : 68 | 69 | Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 70 | 71 | Test the Quickstart in JBoss Developer Studio or Eclipse 72 | ------------------------------------- 73 | 74 | You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts) 75 | 76 | 77 | Debug the Application 78 | ------------------------------------ 79 | 80 | If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them. 81 | 82 | mvn dependency:sources 83 | mvn dependency:resolve -Dclassifier=javadoc 84 | 85 | -------------------------------------------------------------------------------- /helloworld-drl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 4.0.0 21 | org.jboss.quickstarts.brms 22 | brms-helloworld-drl 23 | 6.2.0-SNAPSHOT 24 | 25 | JBoss BRMS Quickstart: helloworld-drl 26 | 27 | 28 | Apache License, Version 2.0 29 | repo 30 | http://www.apache.org/licenses/LICENSE-2.0.html 31 | 32 | 33 | 34 | 35 | 6.2.0-SNAPSHOT 36 | 37 | 38 | 39 | 40 | 42 | 43 | org.jboss.bom.brms 44 | jboss-brms-bpmsuite-platform-bom 45 | pom 46 | ${version.org.jboss.bom.brms} 47 | import 48 | 49 | 50 | 51 | 52 | 53 | org.kie 54 | kie-api 55 | 56 | 57 | 58 | org.drools 59 | drools-compiler 60 | runtime 61 | 62 | 63 | 64 | ch.qos.logback 65 | logback-classic 66 | runtime 67 | 68 | 69 | 70 | 71 | 72 | junit 73 | junit 74 | test 75 | 76 | 77 | 78 | ${project.artifactId} 79 | 80 | 81 | 82 | 83 | 84 | redhat-product-repo 85 | Red Hat Product Repository 86 | https://maven.repository.redhat.com/ga 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /helloworld-drl/src/main/java/org/jboss/quickstarts/brms/helloworlddrl/Customer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.helloworlddrl; 18 | 19 | public class Customer { 20 | 21 | private String name; 22 | 23 | private CustomerType type; 24 | 25 | public Customer(String name, CustomerType type) { 26 | super(); 27 | this.name = name; 28 | this.type = type; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public CustomerType getType() { 36 | return type; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /helloworld-drl/src/main/java/org/jboss/quickstarts/brms/helloworlddrl/CustomerType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.helloworlddrl; 18 | 19 | public enum CustomerType { 20 | 21 | VIP, 22 | REGULAR, 23 | BAD 24 | 25 | } 26 | -------------------------------------------------------------------------------- /helloworld-drl/src/main/java/org/jboss/quickstarts/brms/helloworlddrl/Sale.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.helloworlddrl; 18 | 19 | import java.math.BigDecimal; 20 | 21 | public class Sale { 22 | 23 | private Customer customer; 24 | 25 | private BigDecimal value; 26 | 27 | private double discount; 28 | 29 | private boolean approved; 30 | 31 | public Sale(Customer customer, BigDecimal value) { 32 | this.customer = customer; 33 | this.value = value; 34 | } 35 | 36 | public double getDiscount() { 37 | return discount; 38 | } 39 | 40 | public void setDiscount(double discount) { 41 | this.discount = discount; 42 | } 43 | 44 | public boolean isApproved() { 45 | return approved; 46 | } 47 | 48 | public void setApproved(boolean approved) { 49 | this.approved = approved; 50 | } 51 | 52 | public Customer getCustomer() { 53 | return customer; 54 | } 55 | 56 | public BigDecimal getValue() { 57 | return value; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /helloworld-drl/src/main/resources/META-INF/kmodule.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | -------------------------------------------------------------------------------- /helloworld-drl/src/main/resources/helloworld.drl: -------------------------------------------------------------------------------- 1 | package helloworlddrl; 2 | import org.jboss.quickstarts.brms.helloworlddrl.Sale; 3 | import org.jboss.quickstarts.brms.helloworlddrl.Customer 4 | import org.jboss.quickstarts.brms.helloworlddrl.CustomerType 5 | 6 | rule "Apply 50% discount to VIP customers" 7 | when 8 | $s: Sale( customer.type == CustomerType.VIP ) 9 | then 10 | $s.setDiscount(0.50); 11 | System.out.println("VIP discount applied"); 12 | end 13 | 14 | rule "Apply no discount to Regular customers but approves the Sale" 15 | when 16 | $s: Sale( customer.type != CustomerType.BAD ) 17 | then 18 | $s.setApproved(true); 19 | System.out.println("Sale approved"); 20 | end 21 | 22 | rule "Deny sales to BAD customers" 23 | when 24 | $s: Sale( customer.type == CustomerType.BAD ) 25 | then 26 | $s.setApproved(false); 27 | System.out.println("BAD customer. Sale denied"); 28 | end -------------------------------------------------------------------------------- /helloworld-drl/src/test/java/org/jboss/quickstarts/brms/helloworlddrl/HelloWorldDRLTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.helloworlddrl; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import java.math.BigDecimal; 24 | 25 | import org.junit.BeforeClass; 26 | import org.junit.Test; 27 | import org.kie.api.KieServices; 28 | import org.kie.api.runtime.KieContainer; 29 | import org.kie.api.runtime.StatelessKieSession; 30 | 31 | public class HelloWorldDRLTest { 32 | 33 | private static StatelessKieSession kSession; 34 | 35 | private Customer vipCustomer = new Customer("Mr. Good Customer", CustomerType.VIP); 36 | private Customer regularCustomer = new Customer("Mr. Typical Customer", CustomerType.REGULAR); 37 | private Customer badCustomer = new Customer("Mr. Bad Customer", CustomerType.BAD); 38 | 39 | // A sale for a VIP customer 40 | private Sale vipSale = new Sale(vipCustomer, new BigDecimal(1000)); 41 | // A sale for a regular customer 42 | private Sale regularSale = new Sale(regularCustomer, new BigDecimal(1000)); 43 | // A sale for a Bad customer 44 | private Sale badSale = new Sale(badCustomer, new BigDecimal(50)); 45 | 46 | @BeforeClass 47 | public static void setup() { 48 | KieServices kieServices = KieServices.Factory.get(); 49 | KieContainer kContainer = kieServices.getKieClasspathContainer(); 50 | kSession = kContainer.newStatelessKieSession(); 51 | } 52 | 53 | @Test 54 | public void testGoodCustomer() { 55 | System.out.println("** Testing VIP customer **"); 56 | kSession.execute(vipSale); 57 | // Sale approved 58 | assertTrue(vipSale.isApproved()); 59 | // Discount of 0.5 60 | assertEquals(vipSale.getDiscount(), 0.50F, 0.0); 61 | } 62 | 63 | @Test 64 | public void testRegularCustomer() { 65 | System.out.println("** Testing regular customer **"); 66 | kSession.execute(regularSale); 67 | // Sale approved 68 | assertTrue(regularSale.isApproved()); 69 | // No Discount 70 | assertEquals(regularSale.getDiscount(), 0.0, 0.0); 71 | } 72 | 73 | @Test 74 | public void testBadCustomer() { 75 | System.out.println("** Testing BAD customer **"); 76 | kSession.execute(badSale); 77 | // Sale denied 78 | assertFalse(badSale.isApproved()); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.jboss 22 | jboss-parent 23 | 11 24 | 25 | 26 | org.jboss.quickstarts.brms 27 | jboss-brms-bpmsuite-quickstarts-parent 28 | 6.2.0-SNAPSHOT 29 | pom 30 | JBoss BRMS/BPM Suite Quickstarts Parent 31 | JBoss BRMS Quickstarts Parent 32 | http://www.jboss.org/jdf/quickstarts/get-started/ 33 | 34 | 35 | Apache License, Version 2.0 36 | repo 37 | http://www.apache.org/licenses/LICENSE-2.0.html 38 | 39 | 40 | 41 | 42 | 43 | UTF-8 44 | 45 | 46 | 1.6 47 | 1.6 48 | 49 | 50 | 51 | https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/ 52 | 53 | 54 | https://repository.jboss.org/nexus/content/repositories/snapshots/ 55 | 56 | 57 | 58 | decision-table 59 | helloworld-bpmsuite 60 | helloworld-brms 61 | helloworld-cep 62 | helloworld-drl 63 | stateful-ksession 64 | store-brms 65 | tasks-bpmsuite 66 | dist 67 | 68 | 69 | 70 | 71 | 72 | jboss-public-repository-group 73 | JBoss Public Repository Group 74 | https://repository.jboss.org/nexus/content/groups/public-jboss 75 | 76 | 77 | 78 | Red Hat Product Repository 79 | https://maven.repository.redhat.com/techpreview/all/ 80 | 81 | 82 | 83 | 84 | jboss-releases-repository 85 | JBoss Releases Repository 86 | ${jboss.releases.repo.url} 87 | 88 | 89 | jboss-snapshots-repository 90 | JBoss Snapshots Repository 91 | ${jboss.snapshots.repo.url} 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | jboss-ga-repository 27 | 28 | 29 | jboss-ga-repository 30 | http://maven.repository.redhat.com/techpreview/all 31 | 32 | true 33 | 34 | 35 | false 36 | 37 | 38 | 39 | 40 | 41 | jboss-ga-plugin-repository 42 | http://maven.repository.redhat.com/techpreview/all 43 | 44 | true 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | brms-m2-repo 58 | quickstartUser 59 | quickstartPwd1! 60 | 61 | httpclient 62 | 63 | 64 | true 65 | 66 | 67 | 68 | 69 | 70 | bpms-m2-repo 71 | quickstartUser 72 | quickstartPwd1! 73 | 74 | httpclient 75 | 76 | 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | jboss-ga-repository 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /stateful-ksession/README.md: -------------------------------------------------------------------------------- 1 | stateful-ksession: Stateful Kie Session Quickstart 2 | ================================================== 3 | Author: Rafael Benevides 4 | Level: Intermediate 5 | Technologies: CDI, JSF, Drools 6 | Summary: The `stateful-ksession` quickstart shows how to use Stateful Kie Session 7 | Target Product: BRMS 8 | Source: 9 | 10 | What is it? 11 | ----------- 12 | 13 | The `stateful-ksession` project demonstrates the use of Drools Stateful KIE session. Stateful KIE sessions are longer lived and allow iterative changes over time. 14 | 15 | In this use case we see a 'House' with a fire alarm. The house contains 'Rooms' with fire 'Sprinklers' in each room. 16 | 17 | This Quickstarts contains two modules: 18 | 19 | - The Kmodule project contains the model classes (House, Room, Alarm, Sprinkler, and Fire) and the rules file (houserules.drl). 20 | 21 | - The Web project contains a web application that allows you to simulate a fire in each room. 22 | 23 | System requirements 24 | ------------------- 25 | 26 | All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later. 27 | 28 | The application this project produces is designed to be run on BRMS 6. 29 | 30 | 31 | Configure Maven 32 | --------------- 33 | 34 | If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstarts. 35 | 36 | 37 | 38 | Start the JBoss Server 39 | ---------------------- 40 | 41 | 1. Open a command prompt and navigate to the root of the JBoss server directory. 42 | 2. The following shows the command line to start the server: 43 | 44 | For Linux: EAP_HOME/bin/standalone.sh 45 | For Windows: EAP_HOME\bin\standalone.bat 46 | 47 | 48 | Build and Deploy the Quickstart 49 | ------------------------- 50 | 51 | _NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line._ 52 | 53 | 1. Make sure you have started the JBoss Server as described above. 54 | 2. Open a command prompt and navigate to the root directory of this quickstart. 55 | 3. Type this command to build and deploy the archive: 56 | 57 | mvn clean install jboss-as:deploy 58 | 59 | 4. This deploys `web/target/brms-stateful-ksession-web.war` to the running instance of the server. 60 | 61 | 62 | Access the application 63 | --------------------- 64 | 65 | 66 | Access the running application in a browser at the following URL: 67 | 68 | You are presented to a Dashboard that shows two tables: 69 | 70 | - The action table on the left lists the rooms in the house and provides buttons to initiate or extinguish a fire in each room. 71 | 72 | - The status table on the right lists the sprinklers in the rooms and the current status for each sprinkler. The green sprinkler status 'OFF' indicates there is no fire in the room. 73 | 74 | To simulate a fire in a room, click the `Initiate Fire` button. The text 'FIRE ALARM RINGING' appears below the action table to indicate a room is on fire. Also notice the status for that room's sprinklers turn red and change to 'ON' in the status table on the right. 75 | 76 | To put out the fire, click the `Extinguish Fire` button for the room. The status for the sprinklers in that room are set to 'OFF' and the color changes to green. 77 | 78 | If there no fire in any room, the 'FIRE ALARM RINGING' text disappears. 79 | 80 | 81 | Undeploy the Archive 82 | -------------------- 83 | 84 | 1. Make sure you have started the JBoss Server as described above. 85 | 2. Open a command line and navigate to the root directory of this quickstart. 86 | 3. When you are finished testing, type this command to undeploy the archive: 87 | 88 | mvn jboss-as:undeploy 89 | 90 | 91 | Run the Arquillian Tests 92 | ------------------------- 93 | 94 | This quickstart provides Arquillian tests. By default, these tests are configured to be skipped as Arquillian tests require the use of a container. 95 | 96 | _NOTE: The following commands assume you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Run the Arquillian Tests](../README.md#run-the-arquillian-tests) for complete instructions and additional options._ 97 | 98 | 1. Make sure you have started the JBoss Server as described above. 99 | 2. Open a command prompt and navigate to the root directory of this quickstart. 100 | 3. Type the following command to run the test goal with the following profile activated: 101 | 4. Because Arquillian Test need to access customer settings.xml, please make sure your customermized settings.xml was copied into ~/.m2/settings.xml or ../settings.xml was copied into ~/.m2/settings.xml by default. 102 | 103 | mvn clean install test -Parq-jbossas-remote 104 | 105 | 106 | Run the Quickstart in JBoss Developer Studio or Eclipse 107 | ------------------------------------- 108 | 109 | You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts) 110 | 111 | Debug the Application 112 | ------------------------------------ 113 | 114 | If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them. 115 | 116 | mvn dependency:sources 117 | mvn dependency:resolve -Dclassifier=javadoc 118 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.jboss.quickstarts.brms 22 | brms-stateful-ksession 23 | 6.2.0-SNAPSHOT 24 | 25 | brms-stateful-ksession-kmodule 26 | JBoss BRMS Quickstart: stateful-ksession - kmodule 27 | 28 | 29 | Apache License, Version 2.0 30 | repo 31 | http://www.apache.org/licenses/LICENSE-2.0.html 32 | 33 | 34 | 35 | 1.6 36 | 1.6 37 | 38 | 39 | ${project.artifactId} 40 | 41 | 42 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/java/org/jboss/quickstarts/brms/sfksession/model/Alarm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.sfksession.model; 18 | 19 | public class Alarm { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/java/org/jboss/quickstarts/brms/sfksession/model/Fire.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.sfksession.model; 18 | 19 | public class Fire { 20 | 21 | private Room room; 22 | 23 | /** 24 | * @param room 25 | */ 26 | public Fire(Room room) { 27 | this.room = room; 28 | } 29 | 30 | /** 31 | * @return the room 32 | */ 33 | public Room getRoom() { 34 | return room; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/java/org/jboss/quickstarts/brms/sfksession/model/House.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.sfksession.model; 18 | 19 | import java.io.Serializable; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import javax.annotation.PostConstruct; 24 | import javax.enterprise.context.SessionScoped; 25 | import javax.inject.Named; 26 | 27 | @Named 28 | @SessionScoped 29 | public class House implements Serializable { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | private List rooms = new ArrayList(); 34 | private List sprinklers = new ArrayList(); 35 | 36 | private boolean alarmOn; 37 | 38 | @PostConstruct 39 | public void buildHouse() { 40 | Room kitchen = new Room("kitchen"); 41 | Room bedroom = new Room("bedroom"); 42 | Room office = new Room("office"); 43 | Room livingroom = new Room("livingroom"); 44 | 45 | Sprinkler sprinklerKitchen1 = new Sprinkler(kitchen); 46 | Sprinkler sprinklerKitchen2 = new Sprinkler(kitchen); 47 | Sprinkler sprinklerKitchen3 = new Sprinkler(kitchen); 48 | Sprinkler sprinklerBedroom1 = new Sprinkler(bedroom); 49 | Sprinkler sprinklerBedroom2 = new Sprinkler(bedroom); 50 | Sprinkler sprinklerBedroom3 = new Sprinkler(bedroom); 51 | Sprinkler sprinklerOffice1 = new Sprinkler(office); 52 | Sprinkler sprinklerOffice2 = new Sprinkler(office); 53 | Sprinkler sprinklerOffice3 = new Sprinkler(office); 54 | Sprinkler sprinklerLivingRoom1 = new Sprinkler(livingroom); 55 | Sprinkler sprinklerLivingRoom2 = new Sprinkler(livingroom); 56 | Sprinkler sprinklerLivingRoom3 = new Sprinkler(livingroom); 57 | 58 | rooms.add(office); 59 | rooms.add(bedroom); 60 | rooms.add(kitchen); 61 | rooms.add(livingroom); 62 | 63 | sprinklers.add(sprinklerOffice1); 64 | sprinklers.add(sprinklerOffice2); 65 | sprinklers.add(sprinklerOffice3); 66 | sprinklers.add(sprinklerBedroom1); 67 | sprinklers.add(sprinklerBedroom2); 68 | sprinklers.add(sprinklerBedroom3); 69 | sprinklers.add(sprinklerKitchen1); 70 | sprinklers.add(sprinklerKitchen2); 71 | sprinklers.add(sprinklerKitchen3); 72 | sprinklers.add(sprinklerLivingRoom1); 73 | sprinklers.add(sprinklerLivingRoom2); 74 | sprinklers.add(sprinklerLivingRoom3); 75 | } 76 | 77 | /** 78 | * @return the sprinklers 79 | */ 80 | public List getSprinklers() { 81 | return sprinklers; 82 | } 83 | 84 | /** 85 | * @return the rooms 86 | */ 87 | public List getRooms() { 88 | return rooms; 89 | } 90 | 91 | /** 92 | * @return the alarmOn 93 | */ 94 | public boolean isAlarmOn() { 95 | return alarmOn; 96 | } 97 | 98 | /** 99 | * @param alarmOn the alarmOn to set 100 | */ 101 | public void setAlarmOn(boolean alarmOn) { 102 | this.alarmOn = alarmOn; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/java/org/jboss/quickstarts/brms/sfksession/model/Room.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.sfksession.model; 18 | 19 | public class Room { 20 | 21 | private String name; 22 | 23 | public Room(String name) { 24 | this.name = name; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/java/org/jboss/quickstarts/brms/sfksession/model/Sprinkler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.sfksession.model; 18 | 19 | public class Sprinkler { 20 | 21 | private boolean on; 22 | 23 | private Room room; 24 | 25 | private int serialNumber; 26 | 27 | private static int serialCount; 28 | 29 | public Sprinkler(Room room) { 30 | this.room = room; 31 | this.serialNumber = serialCount++; 32 | } 33 | 34 | public int getSerialNumber() { 35 | return serialNumber; 36 | } 37 | 38 | public Room getRoom() { 39 | return room; 40 | } 41 | 42 | public boolean isOn() { 43 | return on; 44 | } 45 | 46 | public void turnOn() { 47 | this.on = true; 48 | } 49 | 50 | public void turnOff() { 51 | this.on = false; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/resources/META-INF/kmodule.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | -------------------------------------------------------------------------------- /stateful-ksession/kmodule/src/main/resources/houserules.drl: -------------------------------------------------------------------------------- 1 | package houserules 2 | 3 | import org.jboss.quickstarts.brms.sfksession.model.Fire 4 | import org.jboss.quickstarts.brms.sfksession.model.Sprinkler 5 | import org.jboss.quickstarts.brms.sfksession.model.House 6 | import org.jboss.quickstarts.brms.sfksession.model.Room 7 | import org.jboss.quickstarts.brms.sfksession.model.Alarm 8 | 9 | 10 | rule "When there is a fire turn on the sprinkler" 11 | when 12 | $house : House( ) 13 | Fire( $room : room) 14 | $sprinkler : Sprinkler( room == $room, on == false ) 15 | then 16 | modify( $sprinkler ) { turnOn(); }; 17 | System.out.println("Sprinkler turned on"); 18 | end 19 | 20 | rule "When the fire is gone turn off the sprinkler" 21 | when 22 | $house : House( ) 23 | $room : Room( ) 24 | $sprinkler : Sprinkler( room == $room, on == true ) 25 | not Fire( room == $room ) 26 | then 27 | modify( $sprinkler ) { turnOff(); }; 28 | System.out.println("Sprinkler turned off"); 29 | end 30 | 31 | rule "Raise the alarm when we have one or more fires" 32 | when 33 | $house: House( ) 34 | exists Fire() 35 | then 36 | insert( new Alarm() ); 37 | $house.setAlarmOn(true); 38 | System.out.println("Alarm fired"); 39 | end 40 | 41 | rule "Cancel the alarm when all the fires have gone" 42 | when 43 | $house: House( ) 44 | not Fire() 45 | $alarm : Alarm() 46 | then 47 | delete( $alarm ); 48 | $house.setAlarmOn(false); 49 | System.out.println("Alarm disabed"); 50 | end 51 | -------------------------------------------------------------------------------- /stateful-ksession/web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.jboss.quickstarts.brms 22 | brms-stateful-ksession 23 | 6.2.0-SNAPSHOT 24 | 25 | brms-stateful-ksession-web 26 | war 27 | JBoss BRMS Quickstart: stateful-ksession - web 28 | http://jboss.org/jbossas 29 | 30 | 31 | Apache License, Version 2.0 32 | repo 33 | http://www.apache.org/licenses/LICENSE-2.0.html 34 | 35 | 36 | 37 | 1.6 38 | 1.6 39 | 40 | 41 | 42 | 43 | org.jboss.quickstarts.brms 44 | brms-stateful-ksession-kmodule 45 | ${project.version} 46 | 47 | 48 | 49 | 50 | 51 | org.jboss.quickstarts.brms 52 | brms-stateful-ksession-kmodule 53 | compile 54 | 55 | 56 | 57 | 59 | ${project.artifactId} 60 | 61 | 62 | maven-war-plugin 63 | ${version.war.plugin} 64 | 65 | 66 | false 67 | 68 | 69 | 70 | 71 | 72 | org.jboss.as.plugins 73 | jboss-as-maven-plugin 74 | ${version.jboss.maven.plugin} 75 | 76 | false 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | default 86 | 87 | true 88 | 89 | 90 | 91 | 92 | maven-surefire-plugin 93 | ${version.surefire.plugin} 94 | 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | arq-jbossas-managed 107 | 108 | 109 | org.jboss.as 110 | jboss-as-arquillian-container-managed 111 | test 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | arq-jbossas-remote 120 | 121 | 122 | org.jboss.as 123 | jboss-as-arquillian-container-remote 124 | test 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | openshift 134 | 135 | 136 | 137 | maven-war-plugin 138 | ${version.war.plugin} 139 | 140 | deployments 141 | ROOT 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /stateful-ksession/web/src/main/java/org/jboss/quickstarts/brms/sfksession/controller/HouseController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.sfksession.controller; 18 | 19 | import java.io.Serializable; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import javax.annotation.PostConstruct; 24 | import javax.enterprise.context.SessionScoped; 25 | import javax.inject.Inject; 26 | import javax.inject.Named; 27 | 28 | import org.jboss.quickstarts.brms.sfksession.model.Fire; 29 | import org.jboss.quickstarts.brms.sfksession.model.House; 30 | import org.jboss.quickstarts.brms.sfksession.model.Room; 31 | import org.jboss.quickstarts.brms.sfksession.model.Sprinkler; 32 | import org.kie.api.runtime.KieSession; 33 | import org.kie.api.runtime.rule.FactHandle; 34 | 35 | /** 36 | * @author rafaelbenevides 37 | * 38 | */ 39 | @Named 40 | @SessionScoped 41 | public class HouseController implements Serializable { 42 | 43 | private static final long serialVersionUID = 1L; 44 | 45 | @Inject 46 | private KieSession kieSession; 47 | 48 | @Inject 49 | private House house; 50 | 51 | private Map roomFactHandles = new HashMap(); 52 | 53 | @PostConstruct 54 | public void init() { 55 | kieSession.insert(house); 56 | for (Room room : house.getRooms()) { 57 | kieSession.insert(room); 58 | } 59 | for (Sprinkler sprinkler : house.getSprinklers()) { 60 | kieSession.insert(sprinkler); 61 | } 62 | } 63 | 64 | public void initiateFire(Room room) { 65 | // insert a new fire instance if there isn't any fire yet 66 | if (roomFactHandles.get(room.getName()) == null) { 67 | FactHandle factHandle = kieSession.insert(new Fire(room)); 68 | // store room's FactHandle 69 | roomFactHandles.put(room.getName(), factHandle); 70 | } 71 | kieSession.fireAllRules(); 72 | } 73 | 74 | public void extinguishFire(Room room) { 75 | FactHandle handle = roomFactHandles.get(room.getName()); 76 | if (handle != null) { 77 | // remove fire factHandle from KieSession 78 | kieSession.delete(handle); 79 | // remove room's FactHandle 80 | roomFactHandles.remove(room.getName()); 81 | } 82 | kieSession.fireAllRules(); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /stateful-ksession/web/src/main/webapp/WEB-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /stateful-ksession/web/src/main/webapp/WEB-INF/faces-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /stateful-ksession/web/src/main/webapp/housedashboard.xhtml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 22 | 23 | 24 | House Dashboard 25 | 53 | 54 | 55 | 56 | 58 | 59 | 60 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 110 | 111 | 112 | 113 | 115 | 116 | 117 |
House Dashboard
70 | 71 | 72 | 73 | 106 | 107 | 108 |
74 | 75 |
76 | 77 | 78 | Room 79 | #{varRoom.name} 80 | 81 | 82 | Perform Actions 83 | 84 | 85 | 86 | 87 | 88 |
89 | 90 | 91 | 92 | Sprinkler 93 | Sprinkle Serial Num: #{varSprinkler.serialNumber} 94 | 95 | 96 | Sprinkler Room 97 | #{varSprinkler.room.name} 98 | 99 | 100 | Sprinkler Status 101 | 102 | 103 | 104 | 105 |
109 |
118 | 119 | 120 | -------------------------------------------------------------------------------- /stateful-ksession/web/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /stateful-ksession/web/src/test/java/org/jboss/quickstarts/brms/sfksession/HouseFireTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms.sfksession; 18 | 19 | import static org.junit.Assert.assertFalse; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import java.io.File; 23 | import java.util.logging.Level; 24 | import java.util.logging.Logger; 25 | 26 | import javax.inject.Inject; 27 | 28 | import org.jboss.arquillian.container.test.api.Deployment; 29 | import org.jboss.arquillian.junit.Arquillian; 30 | import org.jboss.quickstarts.brms.sfksession.model.Fire; 31 | import org.jboss.quickstarts.brms.sfksession.model.House; 32 | import org.jboss.quickstarts.brms.sfksession.model.Room; 33 | import org.jboss.quickstarts.brms.sfksession.model.Sprinkler; 34 | import org.jboss.shrinkwrap.api.Archive; 35 | import org.jboss.shrinkwrap.api.ShrinkWrap; 36 | import org.jboss.shrinkwrap.api.spec.WebArchive; 37 | import org.jboss.shrinkwrap.resolver.api.maven.Maven; 38 | import org.junit.Test; 39 | import org.junit.runner.RunWith; 40 | import org.kie.api.runtime.KieSession; 41 | import org.kie.api.runtime.rule.FactHandle; 42 | 43 | /** 44 | * @author rafaelbenevides 45 | * 46 | */ 47 | @RunWith(Arquillian.class) 48 | public class HouseFireTest { 49 | 50 | /** 51 | * The location of the WebApp source folder so we know where to find the web.xml when deploying using Arquillian. 52 | */ 53 | private static final String WEBAPP_SRC = "src/main/webapp"; 54 | 55 | @Inject 56 | private KieSession kieSession; 57 | 58 | @Inject 59 | private House house; 60 | 61 | @Deployment 62 | public static Archive getDeployment() { 63 | Logger.getLogger("org.jboss.shrinkwrap.resolver").setLevel(Level.SEVERE); 64 | File pom = new File("pom.xml"); 65 | File[] libs = Maven.resolver() 66 | .loadPomFromFile(pom) 67 | .resolve("org.kie:kie-api", "org.drools:drools-compiler", "org.jboss.quickstarts.brms:brms-stateful-ksession-kmodule") 68 | // Avoid using org.jboss.quickstarts.brms:brms-stateful-ksession-kmodule from reactor 69 | .withClassPathResolution(false) 70 | .withTransitivity().asFile(); 71 | 72 | Archive archive = ShrinkWrap 73 | .create(WebArchive.class, "test.war") 74 | .addAsLibraries(libs) 75 | .addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/beans.xml")); 76 | return archive; 77 | } 78 | 79 | @Test 80 | public void assertAlarmWorkingAndSprinklerWorkingOnFire() { 81 | System.out.println("** Testing if Sprinkler and Alarm is working **"); 82 | Room room = new Room("testRoom"); 83 | Sprinkler sprinkler = new Sprinkler(room); 84 | kieSession.insert(house); 85 | kieSession.insert(sprinkler); 86 | kieSession.insert(room); 87 | // Put fire in the room 88 | FactHandle fireHandle = kieSession.insert(new Fire(room)); 89 | kieSession.fireAllRules(); 90 | // Sprinkler should be On 91 | assertTrue(sprinkler.isOn()); 92 | // Alarm should be On 93 | assertTrue(house.isAlarmOn()); 94 | 95 | //Remove the fire 96 | kieSession.delete(fireHandle); 97 | // There's no fire on the House 98 | kieSession.fireAllRules(); 99 | // Sprinkler should be Off 100 | assertFalse(sprinkler.isOn()); 101 | // Alarm should be Off 102 | assertFalse(house.isAlarmOn()); 103 | 104 | } 105 | 106 | @Test 107 | public void assertSprinklerOffWihoutFire() { 108 | System.out.println("** Testing if Sprinkler and Alarm is off without fire **"); 109 | Room room = new Room("testRoom"); 110 | Sprinkler sprinkler = new Sprinkler(room); 111 | kieSession.insert(house); 112 | kieSession.insert(sprinkler); 113 | kieSession.insert(room); 114 | // There's no fire on the House 115 | kieSession.fireAllRules(); 116 | // Sprinkler should be Off 117 | assertFalse(sprinkler.isOn()); 118 | // Alarm should be Off 119 | assertFalse(house.isAlarmOn()); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /stateful-ksession/web/src/test/resources/arquillian.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /store-brms/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 4.0.0 21 | 22 | org.jboss.quickstarts.brms 23 | brms-store-brms 24 | 6.2.0-SNAPSHOT 25 | 26 | JBoss BRMS Quickstart: store-brms 27 | 28 | 29 | Apache License, Version 2.0 30 | repo 31 | http://www.apache.org/licenses/LICENSE-2.0.html 32 | 33 | 34 | 35 | 6.2.0-SNAPSHOT 36 | true 37 | 38 | 39 | 40 | 41 | 43 | 44 | org.jboss.bom.brms 45 | jboss-brms-bpmsuite-platform-bom 46 | pom 47 | ${version.org.jboss.bom.brms} 48 | import 49 | 50 | 51 | 52 | 53 | 54 | org.kie 55 | kie-api 56 | 57 | 58 | 59 | org.drools 60 | drools-compiler 61 | runtime 62 | 63 | 64 | 65 | ch.qos.logback 66 | logback-classic 67 | runtime 68 | 69 | 70 | 71 | 72 | 73 | junit 74 | junit 75 | test 76 | 77 | 78 | 79 | ${project.artifactId} 80 | 81 | 82 | 83 | 84 | enable-test 85 | 86 | 87 | false 88 | 89 | 90 | 91 | 92 | 93 | brms 94 | 95 | 96 | 97 | brms-m2-repo 98 | BRMS M2 Repo 99 | http://localhost:8080/business-central/maven2/ 100 | 101 | 102 | 103 | 104 | 105 | 106 | org.jboss.quickstarts.brms 107 | my-store-brms-kmodule 108 | 1.0.0 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | redhat-product-repo 119 | Red Hat Product Repository 120 | https://maven.repository.redhat.com/ga 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /store-brms/src/test/java/org/jboss/quickstarts/brms/StoreBRMSTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms; 18 | 19 | import static org.junit.Assert.assertEquals; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertNull; 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import java.util.ArrayList; 25 | import java.util.Date; 26 | import java.util.GregorianCalendar; 27 | 28 | import org.junit.AfterClass; 29 | import org.junit.BeforeClass; 30 | import org.junit.Test; 31 | import org.kie.api.KieServices; 32 | import org.kie.api.runtime.KieContainer; 33 | import org.kie.api.runtime.StatelessKieSession; 34 | 35 | /** 36 | * @author rafaelbenevides 37 | * 38 | */ 39 | public class StoreBRMSTest { 40 | 41 | private static StatelessKieSession kSession; 42 | 43 | // A sale for a VIP customer 44 | private static Sale vipSale; 45 | // A sale for a regular customer 46 | private static Sale regularSale; 47 | // A sale for a Bad customer 48 | private static Sale badSale; 49 | // A sale for a young customer 50 | private static Sale youngSale; 51 | 52 | // The salesMan 53 | private static Salesman salesman = new Salesman(); 54 | 55 | @BeforeClass 56 | public static void setup() { 57 | // A birthDate for a non-young customer 58 | Date oldDate = new GregorianCalendar(1977, 06, 10).getTime(); 59 | // A birthDate for a non legal age customer 60 | Date youngDate = new GregorianCalendar(2010, 06, 10).getTime(); 61 | 62 | KieServices kieServices = KieServices.Factory.get(); 63 | KieContainer kContainer = kieServices.getKieClasspathContainer(); 64 | // Use a specified KSession from org.jboss.quickstarts.brms:my-store-brms-kmodule:1.0.0 65 | kSession = kContainer.newStatelessKieSession("storeKSession"); 66 | // Setup the global variable with the Salesman 67 | salesman.setAllSales(new ArrayList()); 68 | kSession.getGlobals().set("$salesman", salesman); 69 | 70 | CustomerType regular = new CustomerType(); 71 | regular.setType("regular"); 72 | 73 | CustomerType vip = new CustomerType(); 74 | vip.setType("VIP"); 75 | 76 | CustomerType bad = new CustomerType(); 77 | bad.setType("BAD"); 78 | 79 | Customer young = new Customer(); 80 | young.setBirthDate(youngDate); 81 | young.setCustomerType(regular); 82 | youngSale = new Sale(); 83 | youngSale.setCustomer(young); 84 | 85 | Customer vipCustomer = new Customer(); 86 | vipCustomer.setCustomerType(vip); 87 | vipCustomer.setBirthDate(oldDate); 88 | vipSale = new Sale(); 89 | vipSale.setCustomer(vipCustomer); 90 | 91 | Customer regularCustomer = new Customer(); 92 | regularCustomer.setCustomerType(regular); 93 | regularCustomer.setBirthDate(oldDate); 94 | regularSale = new Sale(); 95 | regularSale.setCustomer(regularCustomer); 96 | 97 | Customer badCustomer = new Customer(); 98 | badCustomer.setCustomerType(bad); 99 | badCustomer.setBirthDate(oldDate); 100 | badSale = new Sale(); 101 | badSale.setCustomer(badCustomer); 102 | 103 | } 104 | 105 | @Test 106 | public void testGoodCustomer() { 107 | System.out.println("** Testing VIP customer **"); 108 | kSession.execute(vipSale); 109 | // Sale approved 110 | assertTrue(vipSale.getApproved().booleanValue()); 111 | // Discount of 0.5 112 | assertEquals(vipSale.getDiscount(), 0.50F, 0.0); 113 | } 114 | 115 | @Test 116 | public void testRegularCustomer() { 117 | System.out.println("** Testing regular customer **"); 118 | kSession.execute(regularSale); 119 | // Sale approved 120 | assertTrue(regularSale.getApproved().booleanValue()); 121 | // No Discount 122 | assertNull(regularSale.getDiscount()); 123 | } 124 | 125 | @Test 126 | public void testBadCustomer() { 127 | System.out.println("** Testing BAD customer **"); 128 | kSession.execute(badSale); 129 | // Sale denied 130 | assertFalse(badSale.getApproved().booleanValue()); 131 | } 132 | 133 | @Test 134 | public void testYoungCustomer() { 135 | System.out.println("** Testing Young customer **"); 136 | kSession.execute(youngSale); 137 | // Sale denied for young customer 138 | assertFalse(youngSale.getApproved()); 139 | } 140 | 141 | @AfterClass 142 | public static void testSalesfromSalesMan() { 143 | System.out.println("** Testing if all sales were registered to salesman **"); 144 | // Assert that all sales (bad,vip,regular,young) was registered after all 145 | assertEquals(4, salesman.getAllSales().size()); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /tasks-bpmsuite/README.md: -------------------------------------------------------------------------------- 1 | tasks-bpmsuite: A BPM Suite example with User Tasks 2 | ==================================================== 3 | Author: Rafael Benevides 4 | Level: Advanced 5 | Technologies: BPMS 6 | Summary: The `tasks-bpmsuite` quickstart shows how to run a Process with user tasks that was defined on a JBoss BPM Suite server. 7 | Target Product: BPM Suite 8 | Source: 9 | 10 | What is it? 11 | ----------- 12 | 13 | This project demonstrates how to use BPM Suite to manage and deploy business processes. 14 | 15 | * The `ApprovalProcessTest` class starts a process that was defined in BPM Suite 16 | 17 | _Note_: The bpms-project.approval process is defined in the following dependency: org.jboss.quickstarts.brms:bpms_project:1.0.0. It is available in this git repository: 18 | 19 | The process begins by asking for the amount to be approved. If the amount is less than 10.000 USD, it is automatically approved. If the amount is higher than 10.000 USD, it must wait for a user to manually approve or deny the amount. 20 | 21 | The Maven dependency is available in the following Maven Repository: 22 | 23 | This quickstart does not contain a user interface layer. 24 | 25 | System requirements 26 | ------------------- 27 | 28 | All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later. 29 | 30 | The application this project produces is designed to be run on BPM Suite 6 31 | 32 | 33 | Configure Maven 34 | --------------- 35 | 36 | If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstarts. 37 | 38 | 39 | Start the JBoss Server 40 | ----------- 41 | 42 | If you have not yet done so, you must [Configure BPM Suite](../README.md#configure-bpm-suite) before testing the quickstart. 43 | 44 | 1. Open a command line and navigate to the root of the BRMS directory. 45 | 2. The following shows the command line to start the server: 46 | 47 | For Linux: EAP_HOME/bin/standalone.sh 48 | For Windows: EAP_HOME\bin\standalone.bat 49 | 50 | 51 | Import the BRMS Repository 52 | ---------------------- 53 | 54 | If you have not yet done so, you must [Import the BRMS repository](../README.md#import-the-brms-repository) before testing the quickstart. 55 | 56 | 57 | Deploy the BPM Suite Process Project 58 | ---------------------------- 59 | 60 | 1. [Start the JBoss Server](#start-the-jboss-server) as instructed above. 61 | 62 | 2. Open a browser and access the following URL: 63 | 64 | 2. Log in with the following credentials: 65 | 66 | Username: quickstartUser 67 | Password: quickstartPwd1! 68 | 69 | 3. Choose menu option `Authoring` -> `Project Authoring` 70 | 71 | 4. Choose the following options under `Project Explorer`: 72 | 73 | Organizational Unit: example 74 | Repository Name: jboss-brms-repository 75 | BRMS Kmodule: bpms-project 76 | 77 | 5. Next, click on `Tools` and `Project Editor` 78 | 79 | 6. In the tab on the right, click on `Build & Deploy`. 80 | * It will prompt you with a message: "Also save possible changes to project?". Click `Yes`. 81 | * You are prompted for a comment. Add a comment and click on `Save` button. 82 | 83 | This deploys the `org.jboss.quickstarts.brms:bpms_project:1.0.0` artifact to the BRMS Maven repository. You can verify the deployment choosing menu option `Deploy` --> `Deployments`. 84 | 85 | 86 | Run the Tests 87 | ------------- 88 | 89 | 1. Open a command prompt and navigate to the root directory of this quickstart. 90 | 2. Type the following command to run the test goal with the following profile activated: 91 | 92 | mvn clean test -Penable-test,bpms 93 | 94 | The `bpms` profile enables the repository and adds the `org.jboss.quickstarts.brms:bpms_project:1.0.0` as a project dependency. 95 | 96 | The tests should complete successfully. 97 | 98 | Investigate the Console Output 99 | ---------------------------- 100 | 101 | When you run the tests, JUnit will present you test report summary: 102 | 103 | ------------------------------------------------------- 104 | T E S T S 105 | ------------------------------------------------------- 106 | Running org.jboss.quickstarts.brms.ApprovalProcessTest 107 | Amount asked: 10500 USD 108 | ============================== 109 | = Starting Process Approval. = 110 | ============================== 111 | Approval process started. Value: 10500.0 112 | Waiting for Approval 113 | There's a Task Assigned 114 | Task Claimed 115 | Task Started 116 | Task completed 117 | Not approved 118 | Amount asked: 10500 USD 119 | ============================== 120 | = Starting Process Approval. = 121 | ============================== 122 | Approval process started. Value: 10500.0 123 | Waiting for Approval 124 | There's a Task Assigned 125 | Task Claimed 126 | Task Started 127 | Task completed 128 | Approved 129 | Amount asked: 100 USD 130 | ============================== 131 | = Starting Process Approval. = 132 | ============================== 133 | Approval process started. Value: 100.0 134 | Auto approved 135 | Approved 136 | Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.232 sec 137 | 138 | Results : 139 | 140 | Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 141 | 142 | 143 | Test the Quickstart in JBoss Developer Studio or Eclipse 144 | ------------------------------------- 145 | 146 | You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts) 147 | 148 | 149 | Debug the Application 150 | ------------------------------------ 151 | 152 | If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them. 153 | 154 | mvn dependency:sources 155 | mvn dependency:resolve -Dclassifier=javadoc 156 | 157 | -------------------------------------------------------------------------------- /tasks-bpmsuite/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.jboss.quickstarts.brms 22 | brms-tasks-bpmsuite 23 | 6.2.0-SNAPSHOT 24 | 25 | JBoss BPM Suite Quickstart: tasks-bpmsuite 26 | 27 | 28 | Apache License, Version 2.0 29 | repo 30 | http://www.apache.org/licenses/LICENSE-2.0.html 31 | 32 | 33 | 34 | 35 | 6.2.0-SNAPSHOT 36 | true 37 | 38 | 39 | 40 | 41 | 43 | 44 | org.jboss.bom.brms 45 | jboss-brms-bpmsuite-platform-bom 46 | pom 47 | ${version.org.jboss.bom.brms} 48 | import 49 | 50 | 51 | 52 | 53 | 54 | org.kie 55 | kie-api 56 | 57 | 58 | 59 | org.drools 60 | drools-compiler 61 | runtime 62 | 63 | 64 | 65 | 66 | org.jbpm 67 | jbpm-bpmn2 68 | runtime 69 | 70 | 71 | 72 | org.jbpm 73 | jbpm-test 74 | test 75 | 76 | 77 | 78 | 79 | ch.qos.logback 80 | logback-classic 81 | 82 | 83 | 84 | 85 | junit 86 | junit 87 | test 88 | 89 | 90 | 91 | 92 | ${project.artifactId} 93 | 94 | 95 | 96 | 97 | enable-test 98 | 99 | 100 | false 101 | 102 | 103 | 104 | 105 | 106 | bpms 107 | 108 | 109 | 110 | bpms-m2-repo 111 | BRMS M2 Repo 112 | http://localhost:8080/business-central/maven2/ 113 | 114 | 115 | 116 | 117 | 118 | 119 | org.jboss.quickstarts.brms 120 | bpms_project 121 | 1.0.0 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | redhat-product-repo 132 | Red Hat Product Repository 133 | https://maven.repository.redhat.com/ga 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /tasks-bpmsuite/src/test/java/org/jboss/quickstarts/brms/ApprovalProcessTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | * contributors by the @authors tag. See the copyright.txt in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jboss.quickstarts.brms; 18 | 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import org.jbpm.test.JbpmJUnitBaseTestCase; 24 | import org.junit.Test; 25 | import org.kie.api.runtime.KieSession; 26 | import org.kie.api.runtime.manager.RuntimeEngine; 27 | import org.kie.api.runtime.process.ProcessInstance; 28 | import org.kie.api.task.TaskService; 29 | import org.kie.api.task.model.TaskSummary; 30 | import org.kie.internal.runtime.manager.context.ProcessInstanceIdContext; 31 | 32 | /** 33 | * @author rafaelbenevides 34 | * 35 | */ 36 | public class ApprovalProcessTest extends JbpmJUnitBaseTestCase { 37 | 38 | public ApprovalProcessTest() { 39 | // to execute with persistent process management with human tasks persistence 40 | super(true, true); 41 | } 42 | 43 | @Test 44 | public void testProcessLowAmmountApproved() { 45 | createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "approval.bpmn2"); 46 | RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get()); 47 | 48 | KieSession kSession = runtime.getKieSession(); 49 | 50 | // Map to be passed to the startProcess. 51 | Map params = new HashMap(); 52 | System.out.println("Amount asked: 100 USD"); 53 | params.put("amount", 100F); 54 | 55 | // Fire it up! 56 | System.out.println("=============================="); 57 | System.out.println("= Starting Process Approval. ="); 58 | System.out.println("=============================="); 59 | 60 | // start the process 61 | ProcessInstance processInstance = kSession.startProcess("bpms-project.approval", params); 62 | 63 | // check whether the process instance has completed successfully 64 | assertProcessInstanceCompleted(processInstance.getId(), kSession); 65 | // Finished. 66 | assertNodeTriggered(processInstance.getId(), "Approved"); 67 | 68 | disposeRuntimeManager(); 69 | } 70 | 71 | @Test 72 | public void testProcessHighAmmountApproved() { 73 | createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "approval.bpmn2"); 74 | RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get()); 75 | 76 | KieSession kSession = runtime.getKieSession(); 77 | 78 | // Map to be passed to the startProcess. 79 | Map params = new HashMap(); 80 | System.out.println("Amount asked: 10500 USD"); 81 | params.put("amount", 10500F); 82 | 83 | // Fire it up! 84 | System.out.println("=============================="); 85 | System.out.println("= Starting Process Approval. ="); 86 | System.out.println("=============================="); 87 | 88 | // start the process 89 | ProcessInstance processInstance = kSession.startProcess("bpms-project.approval", params); 90 | 91 | assertNodeTriggered(processInstance.getId(), "Amount approval"); 92 | 93 | // Process should be active waiting for user to approve 94 | assertProcessInstanceActive(processInstance.getId(), kSession); 95 | 96 | TaskService taskService = runtime.getTaskService(); 97 | List list = taskService.getTasksAssignedAsPotentialOwner("rafaelbenevides", "en-UK"); 98 | for (TaskSummary taskSummary : list) { 99 | System.out.println("There's a Task Assigned"); 100 | // Claim Task 101 | System.out.println("Task Claimed"); 102 | taskService.claim(taskSummary.getId(), "rafaelbenevides"); 103 | // Start Task 104 | System.out.println("Task Started"); 105 | taskService.start(taskSummary.getId(), "rafaelbenevides"); 106 | 107 | params.put("approvedOut", true); 108 | System.out.println("Task completed"); 109 | taskService.complete(taskSummary.getId(), "rafaelbenevides", params); 110 | } 111 | 112 | // check whether the process instance has completed successfully 113 | assertProcessInstanceCompleted(processInstance.getId(), kSession); 114 | // Finished. 115 | assertNodeTriggered(processInstance.getId(), "Approved"); 116 | 117 | } 118 | 119 | @Test 120 | public void testProcessHighAmmountDenied() { 121 | createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "approval.bpmn2"); 122 | RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get()); 123 | 124 | KieSession kSession = runtime.getKieSession(); 125 | 126 | // Map to be passed to the startProcess. 127 | Map params = new HashMap(); 128 | System.out.println("Amount asked: 10500 USD"); 129 | params.put("amount", 10500F); 130 | 131 | // Fire it up! 132 | System.out.println("=============================="); 133 | System.out.println("= Starting Process Approval. ="); 134 | System.out.println("=============================="); 135 | 136 | // start the process 137 | ProcessInstance processInstance = kSession.startProcess("bpms-project.approval", params); 138 | 139 | assertNodeTriggered(processInstance.getId(), "Amount approval"); 140 | 141 | // Process should be active waiting for user to approve 142 | assertProcessInstanceActive(processInstance.getId(), kSession); 143 | 144 | TaskService taskService = runtime.getTaskService(); 145 | List list = taskService.getTasksAssignedAsPotentialOwner("rafaelbenevides", "en-UK"); 146 | for (TaskSummary taskSummary : list) { 147 | System.out.println("There's a Task Assigned"); 148 | // Claim Task 149 | System.out.println("Task Claimed"); 150 | taskService.claim(taskSummary.getId(), "rafaelbenevides"); 151 | // Start Task 152 | System.out.println("Task Started"); 153 | taskService.start(taskSummary.getId(), "rafaelbenevides"); 154 | 155 | params.put("approvedOut", false); 156 | System.out.println("Task completed"); 157 | taskService.complete(taskSummary.getId(), "rafaelbenevides", params); 158 | } 159 | 160 | // check whether the process instance has completed successfully 161 | assertProcessInstanceCompleted(processInstance.getId(), kSession); 162 | // Finished. 163 | assertNodeTriggered(processInstance.getId(), "Not approved"); 164 | 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /tasks-bpmsuite/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | 23 | 24 | org.hibernate.ejb.HibernatePersistence 25 | 26 | 27 | jdbc/jbpm-ds 28 | 29 | META-INF/JBPMorm.xml 30 | META-INF/Taskorm.xml 31 | META-INF/TaskAuditorm.xml 32 | 33 | org.jbpm.persistence.processinstance.ProcessInstanceInfo 34 | org.drools.persistence.info.SessionInfo 35 | org.drools.persistence.info.WorkItemInfo 36 | 37 | org.jbpm.process.audit.ProcessInstanceLog 38 | org.jbpm.process.audit.NodeInstanceLog 39 | org.jbpm.process.audit.VariableInstanceLog 40 | 41 | org.jbpm.persistence.correlation.CorrelationKeyInfo 42 | org.jbpm.persistence.correlation.CorrelationPropertyInfo 43 | 44 | 45 | org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo 46 | 47 | org.jbpm.services.task.impl.model.AttachmentImpl 48 | org.jbpm.services.task.impl.model.ContentImpl 49 | org.jbpm.services.task.impl.model.BooleanExpressionImpl 50 | org.jbpm.services.task.impl.model.CommentImpl 51 | org.jbpm.services.task.impl.model.DeadlineImpl 52 | org.jbpm.services.task.impl.model.CommentImpl 53 | org.jbpm.services.task.impl.model.DeadlineImpl 54 | org.jbpm.services.task.impl.model.DelegationImpl 55 | org.jbpm.services.task.impl.model.EscalationImpl 56 | org.jbpm.services.task.impl.model.GroupImpl 57 | org.jbpm.services.task.impl.model.I18NTextImpl 58 | org.jbpm.services.task.impl.model.NotificationImpl 59 | org.jbpm.services.task.impl.model.EmailNotificationImpl 60 | org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl 61 | org.jbpm.services.task.impl.model.PeopleAssignmentsImpl 62 | org.jbpm.services.task.impl.model.ReassignmentImpl 63 | 64 | org.jbpm.services.task.impl.model.TaskImpl 65 | org.jbpm.services.task.impl.model.TaskDataImpl 66 | org.jbpm.services.task.impl.model.UserImpl 67 | 68 | 69 | org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl 70 | 71 | 72 | org.jbpm.services.task.audit.impl.model.AuditTaskImpl 73 | 74 | 75 | org.jbpm.services.task.audit.impl.model.TaskEventImpl 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /tasks-bpmsuite/src/test/resources/usergroups.properties: -------------------------------------------------------------------------------- 1 | # 2 | # JBoss, Home of Professional Open Source 3 | # Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual 4 | # contributors by the @authors tag. See the copyright.txt in the 5 | # distribution for a full listing of individual contributors. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | rafaelbenevides=admin,analyst 19 | --------------------------------------------------------------------------------