This sample shows a web application calling a decision service built into Decision Intelligence. It provides code for a web-based client application which calls a decision service archive to process loan requests using the decision runtime.
- Deploy a decision service to the decision runtime.
- Configure a web application to call a decision service using the decision runtime REST API.
- Run the web application with representative data.
- Explore the execution trace.
- Monitor the execution in a Decision Insights dashboard.
This sample is for anyone who wants to call a decision service deployed to the decision runtime.
15 minutes
- Decision Intelligence: You should have access to Decision Intelligence. Decision Intelligence includes Decision Designer, a comprehensive authoring environment where you can develop, test, and deploy decision services.
- API key: To call the decision services you deployed from Decision Intelligence, you must use an API key. For more information about API keys, see Creating API keys
- Websphere Application Server Liberty: A Java application server that you can download from Download WAS Liberty. This sample was tested with WebSphere Liberty Web Profile 8 26.0.0.6.
- Apache Maven: A software project management tool that you can download from Welcome to Apache Maven.
It is recommended that you go through the tutorial Creating and deploying a decision service before using this sample.
The web application defined in this sample calls a decision service that returns a decision about approving a loan or not. It is based on the Loan Approval decision service defined in the Banking sample project. You start by exploring the decision service in Decision Designer. Then, you deploy the web application and execute it with the appropriate parameters.
You use Decision Designer to explore and deploy a decision service.
- Sign in to Decision Intelligence using your instance credentials.
- Create a decision automation.
- Click
New decision +. - Click
Industry samplesand selectBanking. Then, click Import. Open theLoan Approvaldecision service. - Explore the imported decision service:
- Go to the
Datatab and open theLoan Validation Datadata model to review the defined types. - Navigate back to the decision service name in the breadcrumbs and open the
Approval Decision Model. This model determines whether a loan can be approved. - Go to the
Runtab to run the predefined test data sets.
- Go to the
- When you are finished exploring the decision service, click the
Share changesicon in the top toolbar. Keep onlyLoan approvalselected and click onShare. - Go to the
Deploytab. Create a new version1.0.0and deploy it. - When the deployment has completed, click on
Manage deploymentto open theDecision deploymentsview. - Open the
Metadatatab and copy the decision ID. You will need this parameter in the next step. - Open the
Overviewtab and setBusiness monitoring is activeto be able to monitor the executions in Decision Insights.
You execute the decision service to get a first execution.
- Click on the
Swagger UIto open the Swagger UI dedicated to the Loan Approval decision service. - Expand the
POST approval/executecommand. - Click on
Try it out, keep the proposed Input data. - Click
Execute. The loan is rejected because the borrower's ZIP code is incorrectly formatted.
You use Decision Insights to monitor executions of the decision service through a dashboard.
You create a monitoring source:
- Open the side navigation menu and click
Dashboards. - Open the
Monitoring Sourcestab and click theCreate +button. - Enter
Sample loan approvalas the name. - Select the decision service that you just deployed as the
Scope. Its name ends withLoan Approval (User Id). - Keep
Privateselected, then clickAdd.
You import a predefined dashboard and associate it with your monitoring source:
- Open the
Dashboardstab and clickImport. - Browse to
samples/LoanApplicationSample/dashboard/LoanApproval.json, then clickOpenandImportto load the predefined dashboard. - Click on the
Edit detailsicon. - In
Monitoring sources used in charts, clickBulk edit. - Select the monitoring source that you just created, then click
Donetwice. - Click on the
Saveicon.
Explore the dashboard: it currently shows only one execution. To generate more data, run additional executions using the Sample details section below. Keep the dashboard open in your browser to observe updates in real time.
In this section, you download the repository for the sample application, set properties to match your decision service deployment, and build the application WAR file.
- Download a compressed file of the
decision-intelligence-samplesGit repository. - Set the values noted as
TO BE SETin the filesamples/LoanApplicationSample/src/main/webapp/resources/config.js:- SERVER_NAME: The name of the host server on which you run Decision Intelligence, you just copy the first part of the URL used in the previous step, for example
ibm.decision-intelligence.decision.saas.com. Only the name is required, not the complete URL. - DI_API_KEY: The credentials you need to call the decision runtime REST API. For more about API keys, see Creating API keys
- DECISION_SERVICE_ID: The decision ID of the decision service you deployed in the previous step.
- SERVER_NAME: The name of the host server on which you run Decision Intelligence, you just copy the first part of the URL used in the previous step, for example
- Edit the
samples/LoanApplicationSample/pom.xmlfile to set the<liberty-path>property to the path of your Liberty application server. - Run the following command in the
samples/LoanApplicationSampledirectory:
mvn clean install
The command:
- Creates the client application WAR file.
- Creates and starts a Liberty server.
- Deploys the client application to the server.
You can use the application when you see the message BUILD SUCCESS.
Note: If you want to modify and build the application again, follow the instructions in the section Modifying this sample at the end of this readme.
- In a browser, open the URL
http://localhost:9080/loanApplicationSample-1.0-SNAPSHOT/:
-
Switch to the
Execution Detailstab: the values for the server name (called host name in the application) and the decision service ID are the ones you entered in theconfig.jsfile. -
Click Request loan, and look at the results.
-
Select Trace Enabled, and click Request loan again to get more details on the execution trace. You can choose between viewing the formatted output or the complete JSON response. You can play with the input values to change the results. For example, in the
Applicationtab, if you change the amount to 2000000, you get the messageThe loan cannot exceed 1000000.
Note Each time, you run the application, the dashboard is updated with the new results. Change the execution count to 5 and get more data to monitor.
Here is the dashboard with some data.
When you want to modify the application or stop using it, follow these instructions:
- To stop the Liberty server, run the following command in the
<path to Liberty>/bindirectory:./server stop testDI - To remove the Liberty server, delete the
<path to Liberty>/usr/servers/testDIdirectory. - To rebuild the sample and create the Liberty server again, run the following command in the
samples/LoanApplicationSampledirectory:mvn clean install
When you modify the decision automation or stop using it, follow these instructions:
- To modify the decision automation:
- Open Decision Intelligence.
- Make and test your changes.
- Share your changes, create and deploy a new version.
- Use the decision service id newly deployed in the
Loan application.


