Skip to content

Commit

Permalink
Feature creditcard example (#59)
Browse files Browse the repository at this point in the history
* Adding creditcard application example

* adding sanity test file for creditcard example

* Added description for sanity test cases

* removed unwanted package index values

* draft version of improved creditcard example

* Updated new changes as per the review comments

* spell check

* spell check

* refactoring functions.go file

* refactoring functions.go file

* refactoring credit card example

* Fix failing sanity test cases and minor changes in functions.go file
  • Loading branch information
LakshmiMekala authored and rameshpolishetti committed Aug 7, 2019
1 parent 7e1a7e9 commit 4a612b4
Show file tree
Hide file tree
Showing 5 changed files with 653 additions and 0 deletions.
60 changes: 60 additions & 0 deletions examples/flogo/creditcard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Flogo Rules based Creditcard application


This example demonstrates rule based processing of credit card application. In this example three tuples are used, tuples description is given below.


* `UserAccount` tuple is always stored in network, while the other tuples `NewAccount` and `UpdateCreditScore` are removed after usage as ttl is given as 0.


## Usage

Get the repo and in this example main.go, functions.go both are available. We can directly build and run the app or create flogo rule app and run it.

#### Conditions

```
cBadUser : Check for new user input data - check if age <18 and >=45, empty address and salary less than 10k
cNewUser : Check for new user input data - check if age >=18 and <= 44, address and salary >= 10k
cUserIdMatch : Check for id match from 'UserAccount' and 'UpdateCreditScore' tuples
cUserCreditScore : Check for CreditScore >= 750 && < 820
cUserLowCreditScore : Check for CreditScore < 750
cUserHighCreditScore : Check for CreditScore >= 820 && <= 900
```
#### Actions
```
aBadUser : Executes when age - < 18 and >=45, address empty, salary less than 10k
aNewUser : Add the newuser info to userAccount tuple
aApproveWithLowerLimit : Provides credit card application status approved with lower credit limit
aApproveWithHigherLimit : Provides credit card application status approved with higher credit limit
aUserReject : Rejects when lower Credit score provided and retracts NewAccount
```
### Direct build and run
```
cd $GOPATH/src/github.com/project-flogo/rules/examples/flogo/creditcard
go build
./creditcard
```
### Create app using flogo cli
```
cd $GOPATH/src/github.com/project-flogo/rules/examples/flogo/creditcard
flogo create -f flogo.json creditcard
cp functions.go creditcard/src
cd creditcard
flogo build
./bin/creditcard
```

* Input new user details

```
$ curl -X PUT http://localhost:7777/newaccount -H 'Content-Type: application/json' -d '{"Name":"Test","Age":"26","Income":"60100","Address":"TEt","Id":"12312","Gender":"male","maritalStatus":"single"}'
```
* Update credit score details of the user

```
$ curl -X PUT http://localhost:7777/credit -H 'Content-Type: application/json' -d '{"Id":12312,"creditScore":680}'
```

* Application status will be printed on the console

276 changes: 276 additions & 0 deletions examples/flogo/creditcard/flogo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
{
"name": "cardapp",
"type": "flogo:app",
"version": "0.0.1",
"description": "Sample Flogo App",
"appModel": "1.0.0",
"imports": [
"github.com/project-flogo/contrib/trigger/rest",
"github.com/project-flogo/rules/ruleaction",
"github.com/project-flogo/legacybridge"
],
"triggers": [
{
"id": "receive_http_message",
"ref": "github.com/project-flogo/contrib/trigger/rest",
"settings": {
"port": "7777"
},
"handlers": [
{
"settings": {
"method": "PUT",
"path": "/newaccount"
},
"actions": [
{
"id": "simple_rule",
"input": {
"tupletype": "NewAccount",
"values": "=$.content"
}
}
]
},
{
"settings": {
"method": "PUT",
"path": "/credit"
},
"actions": [
{
"id": "simple_rule",
"input": {
"tupletype": "UpdateCreditScore",
"values": "=$.content"
}
}
]
}
]
}
],
"resources": [
{
"id": "rulesession:simple",
"data": {
"metadata": {
"input": [
{
"name": "values",
"type": "string"
},
{
"name": "tupletype",
"type": "string"
}
],
"output": [
{
"name": "outputData",
"type": "any"
}
]
},
"rules": [
{
"name": "UserData",
"conditions": [
{
"name": "cBadUser",
"identifiers": [
"NewAccount"
],
"evaluator": "cBadUser"
}
],
"actionFunction": "aBadUser"
},
{
"name": "NewUser",
"conditions": [
{
"name": "cNewUser",
"identifiers": [
"NewAccount"
],
"evaluator": "cNewUser"
}
],
"actionFunction": "aNewUser"
},
{
"name": "NewUser1",
"conditions": [
{
"name": "cUserIdMatch",
"identifiers": [
"UpdateCreditScore",
"UserAccount"
],
"evaluator": "cUserIdMatch"
},
{
"name": "cUserCreditScore",
"identifiers": [
"UpdateCreditScore"
],
"evaluator": "cUserCreditScore"
}
],
"actionFunction": "aApproveWithLowerLimit"
},
{
"name": "NewUser2",
"conditions": [
{
"name": "cUserIdMatch",
"identifiers": [
"UpdateCreditScore",
"UserAccount"
],
"evaluator": "cUserIdMatch"
},
{
"name": "cUserCreditScore",
"identifiers": [
"UpdateCreditScore"
],
"evaluator": "cUserHighCreditScore"
}
],
"actionFunction": "aApproveWithHigherLimit"
},
{
"name": "Rejected",
"conditions": [
{
"name": "cUserIdMatch",
"identifiers": [
"UpdateCreditScore",
"UserAccount"
],
"evaluator": "cUserIdMatch"
},
{
"name": "cUserCreditScore",
"identifiers": [
"UpdateCreditScore"
],
"evaluator": "cUserLowCreditScore"
}
],
"actionFunction": "aUserReject"
}
]
}
}
],
"actions": [
{
"ref": "github.com/project-flogo/rules/ruleaction",
"settings": {
"ruleSessionURI": "res://rulesession:simple",
"tds": [
{
"name": "UserAccount",
"properties": [
{
"name": "Id",
"pk-index": 0,
"type": "int"
},
{
"name": "Name",
"type": "string"
},
{
"name": "Gender",
"type": "string"
},
{
"name": "Age",
"type": "int"
},
{
"name": "Address",
"type": "string"
},
{
"name": "Income",
"type": "int"
},
{
"name": "maritalStatus",
"type": "string"
},
{
"name": "creditScore",
"type": "int"
},
{
"name": "approvedLimit",
"type": "int"
},
{
"name": "appStatus",
"type": "string"
}
]
},
{
"name": "NewAccount",
"ttl": 0,
"properties": [
{
"name": "Id",
"pk-index": 0,
"type": "int"
},
{
"name": "Name",
"type": "string"
},
{
"name": "Gender",
"type": "string"
},
{
"name": "Age",
"type": "int"
},
{
"name": "Address",
"type": "string"
},
{
"name": "Income",
"type": "int"
},
{
"name": "maritalStatus",
"type": "string"
}
]
},
{
"name": "UpdateCreditScore",
"properties": [
{
"name": "Id",
"pk-index": 0,
"type": "int"
},
{
"name": "creditScore",
"type": "int"
}
],
"ttl": 0
}
]
},
"id": "simple_rule"
}
]
}
Loading

0 comments on commit 4a612b4

Please sign in to comment.