Fetch corda transaction from Ledger based on query condition


(Jayant) #1

Hi ,
I want to fetch corda transaction from ledger based on some condition.
e.g. my transaction contains property like userId or Date .
so how can I fetch transaction or filter the data based on date or userId or any perperty of my transacion.

I can see only below code in purchase order example which actually fetches all the data.
I want to apply filter here …

services.networkMapUpdates().getFirst()

Can anyone help in this regard.


(Srinidhi) #2

@GET
@Path(“purchase-orders/{conditionField}”)
@Produces(MediaType.APPLICATION_JSON)
public List getPurchaseOrdersOnCondition(@PathParam(“conditionField”) String conditionField) {
List matchedStates= new ArrayList();
services.vaultAndUpdates().getFirst().forEach(contractStateStateAndRef -> {
YourStatestate = (YourState) contractStateStateAndRef.getState().getData();
if(state.getPurchaseOrders().getId().equals(conditionField)){
matchedStates.add(state);
}
});
return matchedStates;
}