Skip to content

Commit cceec9a

Browse files
authored
Merge pull request #77 from divya-r3/customquery
Sample to demonstrate Custom Queries
2 parents de2729d + cd51a4f commit cceec9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2401
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2016, R3 Limited.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"info": {
3+
"_postman_id": "381497f6-9903-47b2-9d74-7f1578532895",
4+
"name": "Queryable State",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6+
},
7+
"item": [
8+
{
9+
"name": "Vehicle Insurance",
10+
"request": {
11+
"method": "POST",
12+
"header": [
13+
{
14+
"key": "Content-Type",
15+
"name": "Content-Type",
16+
"type": "text",
17+
"value": "application/json"
18+
}
19+
],
20+
"body": {
21+
"mode": "raw",
22+
"raw": "{\n\t\"vehicleInfo\": {\n\t\t\"registrationNumber\": \"MH014343\",\n\t\t\"chasisNumber\": \"C232ND832\",\n\t\t\"make\": \"Hyundai\",\n\t\t\"model\": \"Elantra\",\n\t\t\"variant\": \"SX\",\n\t\t\"color\": \"Black\",\n\t\t\"fuelType\": \"Petrol\"\n\t},\n\t\"policyNumber\": \"8190\",\n\t\"insuredValue\": \"20000\",\n\t\"duration\": 1,\n\t\"premium\": \"3000\"\n}"
23+
},
24+
"url": {
25+
"raw": "http://localhost:8080/vehicleInsurance/Insuree",
26+
"protocol": "http",
27+
"host": [
28+
"localhost"
29+
],
30+
"port": "8080",
31+
"path": [
32+
"vehicleInsurance",
33+
"Insuree"
34+
]
35+
}
36+
},
37+
"response": []
38+
},
39+
{
40+
"name": "Claim",
41+
"request": {
42+
"method": "POST",
43+
"header": [
44+
{
45+
"key": "Content-Type",
46+
"name": "Content-Type",
47+
"value": "application/json",
48+
"type": "text"
49+
}
50+
],
51+
"body": {
52+
"mode": "raw",
53+
"raw": "{\n\t\"claimNumber\":\"C001\",\n\t\"claimDescription\": \"Minor Accident, Bumper Damaged\",\n\t\"claimAmount\": 1000\n}"
54+
},
55+
"url": {
56+
"raw": "http://localhost:8080//vehicleInsurance/claim/8190",
57+
"protocol": "http",
58+
"host": [
59+
"localhost"
60+
],
61+
"port": "8080",
62+
"path": [
63+
"",
64+
"vehicleInsurance",
65+
"claim",
66+
"8190"
67+
]
68+
}
69+
},
70+
"response": []
71+
}
72+
],
73+
"event": [
74+
{
75+
"listen": "prerequest",
76+
"script": {
77+
"type": "text/javascript",
78+
"exec": [
79+
""
80+
]
81+
}
82+
},
83+
{
84+
"listen": "test",
85+
"script": {
86+
"type": "text/javascript",
87+
"exec": [
88+
""
89+
]
90+
}
91+
}
92+
]
93+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Car Insurance -- QueryableState -- Custom Query
2+
3+
This CorDapp demonstrates how [Custom Query](https://docs.r3.com/en/platform/corda/4.8/open-source/api-vault-query.html)
4+
work in Corda. Corda allows developers to have the ability to query the vault using multiple mechanisms such as the
5+
Vault Query API, using a JDBC session, etc. This sample demonstrates how to store your state data to a custom database
6+
using an ORM tool and how to query this vault via Vault Query using some custom field defined in your state (for example
7+
a string property of your state). To use Vault Query to query by a certain property the state must implement
8+
`QueryableState` with a custom mapped schema. This way the DB (and Corda) know what you will be querying By. Please
9+
refer to the flow `InsranceClaimflow` for details.
10+
11+
In this CorDapp we would use an `Insurance` state and persist its properties in a custom table in the database.
12+
The `Insurance` state among other fields also contains an `VehicleDetail` object, which is the asset being insured. We
13+
have used this `VehicleDetail` to demonstrate _One-to-One_ relationship. Similarly we also have a list of `Claim`
14+
objects in the `Insurance` state which represents claims made against the insurance. We use them to demonstrate _
15+
One-to-Many_ relationship.
16+
17+
## Concepts
18+
19+
A spring boot client is provided with the cordapp, which exposes two REST endpoints
20+
(see `Controller` in the clients module) to trigger the flows. Use the command `./gradlew bootRun` in the project root
21+
folder to run the [Spring Boot Server](https://spring.io/projects/spring-boot#overview).
22+
23+
### Flows
24+
25+
There are two flow in this cordapp:
26+
27+
1. IssueInsurance: It creates the insurance state with the associated vehicle information.
28+
29+
2. InsuranceClaim: It creates the claims against the insurance.It uses the Vault Query to perform a custom vault query.
30+
31+
## Usage
32+
33+
## Pre-Requisites
34+
35+
For development environment setup, please refer to: [Setup Guide](https://docs.corda.net/getting-set-up.html).
36+
37+
### Running the CorDapp
38+
39+
Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)
40+
41+
```
42+
./gradlew clean deployNodes
43+
```
44+
45+
Then type: (to run the nodes)
46+
47+
```
48+
./build/nodes/runnodes
49+
```
50+
51+
### Interacting with the nodes
52+
53+
The Postman collection containing API's calls to the REST endpoints can be imported from the
54+
link: https://www.getpostman.com/collections/ddc01c13b8ab4b5e853b. Use the option Import > Import from Link option in
55+
Postman to import the collection. The collection file is also included in this repo for reference.
56+
57+
<p align="center">
58+
<img src="./clients/src/main/resources/static/Postman_screenshot.png" alt="Postman Import Collection" width="400">
59+
</p>
60+
61+
### Connecting to the Database
62+
63+
The JDBC url to connect to the database would be printed in the console in node startup. Use the url to connect to the
64+
database using a suitable client. The default username is 'sa' and password is '' (blank). You could download H2 Console
65+
to connect to h2 database here:
66+
http://www.h2database.com/html/download.html
67+
68+
<p align="center">
69+
<img src="./clients/src/main/resources/static/JDBC-url.png" alt="Database URL" width="400">
70+
</p>
71+
72+
Refer here for more details regarding connecting to the node database.
73+
https://docs.corda.net/head/node-database-access-h2.html
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Corda and the Corda logo are trademarks of R3CEV LLC and its affiliates. All rights reserved.
2+
3+
For R3CEV LLC's trademark and logo usage information, please consult our Trademark Usage Policy at
4+
https://www.r3.com/trademark-policy/.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
buildscript {
2+
Properties constants = new Properties()
3+
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
4+
5+
ext {
6+
corda_release_group = constants.getProperty("cordaReleaseGroup")
7+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
8+
corda_release_version = constants.getProperty("cordaVersion")
9+
corda_core_release_version = constants.getProperty("cordaCoreVersion")
10+
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
11+
kotlin_version = constants.getProperty("kotlinVersion")
12+
junit_version = constants.getProperty("junitVersion")
13+
quasar_version = constants.getProperty("quasarVersion")
14+
log4j_version = constants.getProperty("log4jVersion")
15+
slf4j_version = constants.getProperty("slf4jVersion")
16+
corda_platform_version = constants.getProperty("platformVersion").toInteger()
17+
18+
//springboot
19+
spring_boot_version = '2.0.2.RELEASE'
20+
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
21+
}
22+
23+
repositories {
24+
mavenLocal()
25+
mavenCentral()
26+
27+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
28+
}
29+
30+
dependencies {
31+
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
32+
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
33+
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
34+
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
35+
36+
}
37+
}
38+
39+
allprojects {
40+
apply from: "${rootProject.projectDir}/repositories.gradle"
41+
apply plugin: 'java'
42+
43+
repositories {
44+
mavenLocal()
45+
46+
mavenCentral()
47+
maven { url 'https://software.r3.com/artifactory/corda' }
48+
maven { url 'https://jitpack.io' }
49+
}
50+
51+
tasks.withType(JavaCompile) {
52+
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
53+
}
54+
55+
jar {
56+
// This makes the JAR's SHA-256 hash repeatable.
57+
preserveFileTimestamps = false
58+
reproducibleFileOrder = true
59+
}
60+
}
61+
62+
apply plugin: 'net.corda.plugins.cordapp'
63+
apply plugin: 'net.corda.plugins.cordformation'
64+
apply plugin: 'net.corda.plugins.quasar-utils'
65+
66+
sourceSets {
67+
main {
68+
resources {
69+
srcDir rootProject.file("config/dev")
70+
}
71+
}
72+
}
73+
74+
dependencies {
75+
// Corda dependencies.
76+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
77+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
78+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
79+
80+
// CorDapp dependencies.
81+
cordapp project(":workflows")
82+
cordapp project(":contracts")
83+
84+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
85+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
86+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
87+
}
88+
89+
cordapp {
90+
info {
91+
name "Queryablestate Car Insurance"
92+
vendor "Corda Open Source"
93+
targetPlatformVersion corda_platform_version
94+
minimumPlatformVersion corda_platform_version
95+
}
96+
}
97+
98+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
99+
nodeDefaults {
100+
projectCordapp {
101+
deploy = false
102+
}
103+
cordapp project(":workflows")
104+
cordapp project(":contracts")
105+
runSchemaMigration = true //This configuration is for any CorDapps with custom schema, We will leave this as true to avoid
106+
//problems for developers who are not familiar with Corda. If you are not using custom schemas, you can change
107+
//it to false for quicker project compiling time.
108+
}
109+
110+
node {
111+
name "O=Notary,L=London,C=GB"
112+
notary = [validating : false]
113+
p2pPort 10002
114+
rpcSettings {
115+
address("localhost:10003")
116+
adminAddress("localhost:10043")
117+
}
118+
cordapps.clear()
119+
}
120+
121+
node {
122+
name "O=Insurer,L=London,C=GB"
123+
p2pPort 10005
124+
rpcSettings {
125+
address("localhost:10006")
126+
adminAddress("localhost:10046")
127+
}
128+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
129+
extraConfig = ['h2Settings.address' : 'localhost:20041']
130+
}
131+
132+
node {
133+
name "O=Insuree,L=New York,C=US"
134+
p2pPort 10008
135+
rpcSettings {
136+
address("localhost:10009")
137+
adminAddress("localhost:10049")
138+
}
139+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
140+
extraConfig = ['h2Settings.address' : 'localhost:20042']
141+
}
142+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'org.springframework.boot'
2+
3+
sourceSets {
4+
main {
5+
resources {
6+
srcDir rootProject.file("config/dev")
7+
}
8+
}
9+
}
10+
11+
dependencies {
12+
// Corda dependencies.
13+
compile "$corda_release_group:corda-rpc:$corda_release_version"
14+
15+
// CorDapp dependencies.
16+
compile project(":workflows")
17+
18+
compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") {
19+
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
20+
}
21+
22+
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
23+
compile "org.apache.logging.log4j:log4j-web:${log4j_version}"
24+
compile "org.slf4j:jul-to-slf4j:$slf4j_version"
25+
}
26+
27+
springBoot {
28+
mainClassName = "net.corda.samples.carinsurance.webserver.Starter"
29+
}
30+
31+
// Note that the bootRun task is built into gradle so there is no webserver task defined here.

0 commit comments

Comments
 (0)