Skip to content

Commit 2fd7b40

Browse files
committed
update comments
1 parent dfc291c commit 2fd7b40

File tree

1 file changed

+11
-9
lines changed
  • Features/customquery-carinsurance/workflows/src/main/java/net/corda/samples/carinsurance/flows

1 file changed

+11
-9
lines changed

Features/customquery-carinsurance/workflows/src/main/java/net/corda/samples/carinsurance/flows/InsuranceClaimFlow.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,24 @@ public InsuranceClaimInitiator(ClaimInfo claimInfo, String policyNumber) {
4444
@Override
4545
@Suspendable
4646
public SignedTransaction call() throws FlowException{
47-
// Query the vault to fetch list of all Insurance state based on the policy number.
48-
// This state would be used as input to the
49-
// transaction.
50-
QueryCriteria generalCriteria = new QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED);
47+
/*************************************************************************************
48+
* This section is the custom query code. Instead of query out all the insurance state and filter by their policy number,
49+
* custom query will only retrieve the insurance state that matched the policy number. The filtering will happen behind the scene.
50+
* **/
5151
Field valueField = null;
5252
try{
5353
valueField = PersistentInsurance.class.getDeclaredField("policyNumber");
5454
} catch (NoSuchFieldException e) {
5555
e.printStackTrace();
5656
}
57-
CriteriaExpression criteria = Builder.equal(valueField, policyNumber);
58-
QueryCriteria insuranceQuery = new QueryCriteria.VaultCustomQueryCriteria(criteria);
59-
generalCriteria = generalCriteria.and(insuranceQuery);
57+
QueryCriteria insuranceQuery = new QueryCriteria.VaultCustomQueryCriteria(Builder.equal(valueField, policyNumber));
58+
/** And you can have joint custom criteria as well. Simply add additional criteria and add it to the criteria object by using and().
59+
* QueryCriteria insuranceQuery = new QueryCriteria.VaultCustomQueryCriteria(Builder.equal(valueField, insuredValue));
60+
* **/
61+
QueryCriteria generalCriteria = new QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED).and(insuranceQuery);
62+
Vault.Page<InsuranceState> insuranceStateAndRefs = getServiceHub().getVaultService().queryBy(InsuranceState.class, generalCriteria );
63+
/***************************************************************************************/
6064

61-
Vault.Page<InsuranceState> insuranceStateAndRefs;
62-
insuranceStateAndRefs = getServiceHub().getVaultService().queryBy(InsuranceState.class, generalCriteria );
6365
if(insuranceStateAndRefs.getStates().isEmpty()){
6466
throw new IllegalArgumentException("Policy not found");
6567
}

0 commit comments

Comments
 (0)