-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
7e1a7e9
commit 4a612b4
Showing
5 changed files
with
653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
Oops, something went wrong.