Skip to content

Commit 4a612b4

Browse files
LakshmiMekalarameshpolishetti
authored andcommitted
Feature creditcard example (#59)
* 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
1 parent 7e1a7e9 commit 4a612b4

File tree

5 files changed

+653
-0
lines changed

5 files changed

+653
-0
lines changed

examples/flogo/creditcard/README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Flogo Rules based Creditcard application
2+
3+
4+
This example demonstrates rule based processing of credit card application. In this example three tuples are used, tuples description is given below.
5+
6+
7+
* `UserAccount` tuple is always stored in network, while the other tuples `NewAccount` and `UpdateCreditScore` are removed after usage as ttl is given as 0.
8+
9+
10+
## Usage
11+
12+
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.
13+
14+
#### Conditions
15+
16+
```
17+
cBadUser : Check for new user input data - check if age <18 and >=45, empty address and salary less than 10k
18+
cNewUser : Check for new user input data - check if age >=18 and <= 44, address and salary >= 10k
19+
cUserIdMatch : Check for id match from 'UserAccount' and 'UpdateCreditScore' tuples
20+
cUserCreditScore : Check for CreditScore >= 750 && < 820
21+
cUserLowCreditScore : Check for CreditScore < 750
22+
cUserHighCreditScore : Check for CreditScore >= 820 && <= 900
23+
```
24+
#### Actions
25+
```
26+
aBadUser : Executes when age - < 18 and >=45, address empty, salary less than 10k
27+
aNewUser : Add the newuser info to userAccount tuple
28+
aApproveWithLowerLimit : Provides credit card application status approved with lower credit limit
29+
aApproveWithHigherLimit : Provides credit card application status approved with higher credit limit
30+
aUserReject : Rejects when lower Credit score provided and retracts NewAccount
31+
```
32+
### Direct build and run
33+
```
34+
cd $GOPATH/src/github.com/project-flogo/rules/examples/flogo/creditcard
35+
go build
36+
./creditcard
37+
```
38+
### Create app using flogo cli
39+
```
40+
cd $GOPATH/src/github.com/project-flogo/rules/examples/flogo/creditcard
41+
flogo create -f flogo.json creditcard
42+
cp functions.go creditcard/src
43+
cd creditcard
44+
flogo build
45+
./bin/creditcard
46+
```
47+
48+
* Input new user details
49+
50+
```
51+
$ 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"}'
52+
```
53+
* Update credit score details of the user
54+
55+
```
56+
$ curl -X PUT http://localhost:7777/credit -H 'Content-Type: application/json' -d '{"Id":12312,"creditScore":680}'
57+
```
58+
59+
* Application status will be printed on the console
60+

examples/flogo/creditcard/flogo.json

+276
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"name": "cardapp",
3+
"type": "flogo:app",
4+
"version": "0.0.1",
5+
"description": "Sample Flogo App",
6+
"appModel": "1.0.0",
7+
"imports": [
8+
"github.com/project-flogo/contrib/trigger/rest",
9+
"github.com/project-flogo/rules/ruleaction",
10+
"github.com/project-flogo/legacybridge"
11+
],
12+
"triggers": [
13+
{
14+
"id": "receive_http_message",
15+
"ref": "github.com/project-flogo/contrib/trigger/rest",
16+
"settings": {
17+
"port": "7777"
18+
},
19+
"handlers": [
20+
{
21+
"settings": {
22+
"method": "PUT",
23+
"path": "/newaccount"
24+
},
25+
"actions": [
26+
{
27+
"id": "simple_rule",
28+
"input": {
29+
"tupletype": "NewAccount",
30+
"values": "=$.content"
31+
}
32+
}
33+
]
34+
},
35+
{
36+
"settings": {
37+
"method": "PUT",
38+
"path": "/credit"
39+
},
40+
"actions": [
41+
{
42+
"id": "simple_rule",
43+
"input": {
44+
"tupletype": "UpdateCreditScore",
45+
"values": "=$.content"
46+
}
47+
}
48+
]
49+
}
50+
]
51+
}
52+
],
53+
"resources": [
54+
{
55+
"id": "rulesession:simple",
56+
"data": {
57+
"metadata": {
58+
"input": [
59+
{
60+
"name": "values",
61+
"type": "string"
62+
},
63+
{
64+
"name": "tupletype",
65+
"type": "string"
66+
}
67+
],
68+
"output": [
69+
{
70+
"name": "outputData",
71+
"type": "any"
72+
}
73+
]
74+
},
75+
"rules": [
76+
{
77+
"name": "UserData",
78+
"conditions": [
79+
{
80+
"name": "cBadUser",
81+
"identifiers": [
82+
"NewAccount"
83+
],
84+
"evaluator": "cBadUser"
85+
}
86+
],
87+
"actionFunction": "aBadUser"
88+
},
89+
{
90+
"name": "NewUser",
91+
"conditions": [
92+
{
93+
"name": "cNewUser",
94+
"identifiers": [
95+
"NewAccount"
96+
],
97+
"evaluator": "cNewUser"
98+
}
99+
],
100+
"actionFunction": "aNewUser"
101+
},
102+
{
103+
"name": "NewUser1",
104+
"conditions": [
105+
{
106+
"name": "cUserIdMatch",
107+
"identifiers": [
108+
"UpdateCreditScore",
109+
"UserAccount"
110+
],
111+
"evaluator": "cUserIdMatch"
112+
},
113+
{
114+
"name": "cUserCreditScore",
115+
"identifiers": [
116+
"UpdateCreditScore"
117+
],
118+
"evaluator": "cUserCreditScore"
119+
}
120+
],
121+
"actionFunction": "aApproveWithLowerLimit"
122+
},
123+
{
124+
"name": "NewUser2",
125+
"conditions": [
126+
{
127+
"name": "cUserIdMatch",
128+
"identifiers": [
129+
"UpdateCreditScore",
130+
"UserAccount"
131+
],
132+
"evaluator": "cUserIdMatch"
133+
},
134+
{
135+
"name": "cUserCreditScore",
136+
"identifiers": [
137+
"UpdateCreditScore"
138+
],
139+
"evaluator": "cUserHighCreditScore"
140+
}
141+
],
142+
"actionFunction": "aApproveWithHigherLimit"
143+
},
144+
{
145+
"name": "Rejected",
146+
"conditions": [
147+
{
148+
"name": "cUserIdMatch",
149+
"identifiers": [
150+
"UpdateCreditScore",
151+
"UserAccount"
152+
],
153+
"evaluator": "cUserIdMatch"
154+
},
155+
{
156+
"name": "cUserCreditScore",
157+
"identifiers": [
158+
"UpdateCreditScore"
159+
],
160+
"evaluator": "cUserLowCreditScore"
161+
}
162+
],
163+
"actionFunction": "aUserReject"
164+
}
165+
]
166+
}
167+
}
168+
],
169+
"actions": [
170+
{
171+
"ref": "github.com/project-flogo/rules/ruleaction",
172+
"settings": {
173+
"ruleSessionURI": "res://rulesession:simple",
174+
"tds": [
175+
{
176+
"name": "UserAccount",
177+
"properties": [
178+
{
179+
"name": "Id",
180+
"pk-index": 0,
181+
"type": "int"
182+
},
183+
{
184+
"name": "Name",
185+
"type": "string"
186+
},
187+
{
188+
"name": "Gender",
189+
"type": "string"
190+
},
191+
{
192+
"name": "Age",
193+
"type": "int"
194+
},
195+
{
196+
"name": "Address",
197+
"type": "string"
198+
},
199+
{
200+
"name": "Income",
201+
"type": "int"
202+
},
203+
{
204+
"name": "maritalStatus",
205+
"type": "string"
206+
},
207+
{
208+
"name": "creditScore",
209+
"type": "int"
210+
},
211+
{
212+
"name": "approvedLimit",
213+
"type": "int"
214+
},
215+
{
216+
"name": "appStatus",
217+
"type": "string"
218+
}
219+
]
220+
},
221+
{
222+
"name": "NewAccount",
223+
"ttl": 0,
224+
"properties": [
225+
{
226+
"name": "Id",
227+
"pk-index": 0,
228+
"type": "int"
229+
},
230+
{
231+
"name": "Name",
232+
"type": "string"
233+
},
234+
{
235+
"name": "Gender",
236+
"type": "string"
237+
},
238+
{
239+
"name": "Age",
240+
"type": "int"
241+
},
242+
{
243+
"name": "Address",
244+
"type": "string"
245+
},
246+
{
247+
"name": "Income",
248+
"type": "int"
249+
},
250+
{
251+
"name": "maritalStatus",
252+
"type": "string"
253+
}
254+
]
255+
},
256+
{
257+
"name": "UpdateCreditScore",
258+
"properties": [
259+
{
260+
"name": "Id",
261+
"pk-index": 0,
262+
"type": "int"
263+
},
264+
{
265+
"name": "creditScore",
266+
"type": "int"
267+
}
268+
],
269+
"ttl": 0
270+
}
271+
]
272+
},
273+
"id": "simple_rule"
274+
}
275+
]
276+
}

0 commit comments

Comments
 (0)