Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Stardust/Knowledge Base/Java API/Process Instance Queries
< Stardust | Knowledge Base | Java API
Querying Process Instances filtered by a Field in a Structured Data
(Versions: 5.3.17)
Let us assume you have a
- process definition with the id StockDividend which uses a
- (structured) process date named CorporateAction having a
- field of type String with the id ISIN
To search for all StockDividend process instance where the ISIN field in the data CorporateAction has the value US0378331005 one could use the following code. The findForProcess method limits the query to a specific process definition. The DataFilter then limits the result to process instances having the data with the specified value.
package test; import java.util.Iterator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.stardust.engine.api.query.DataFilter; import org.eclipse.stardust.engine.api.query.DescriptorPolicy; import org.eclipse.stardust.engine.api.query.ProcessInstanceQuery; import org.eclipse.stardust.engine.api.query.ProcessInstances; import org.eclipse.stardust.engine.api.runtime.ProcessInstance; import org.eclipse.stardust.engine.api.runtime.QueryService; import org.eclipse.stardust.engine.api.runtime.ServiceFactory; import org.eclipse.stardust.engine.api.runtime.ServiceFactoryLocator; import org.eclipse.stardust.engine.api.dto.ProcessInstanceDetails; public class QueryTest { public static final Logger log = LoggerFactory.getLogger(QueryTest.class); public static void main(String[] args) { ServiceFactory sf = ServiceFactoryLocator.get("motu", "motu"); QueryService qys = sf.getQueryService(); ProcessInstanceQuery piQuery = ProcessInstanceQuery.findForProcess("StockDividend"); piQuery.setPolicy(DescriptorPolicy.WITH_DESCRIPTORS); piQuery.where(DataFilter.isEqual("CorporateAction","ISIN", "US0378331005")); ProcessInstances pis = qys.getAllProcessInstances(piQuery); for (Iterator iterator = pis.iterator(); iterator.hasNext();) { ProcessInstance pi = (ProcessInstance) iterator.next(); ProcessInstanceDetails details = (ProcessInstanceDetails)pi; log.info("PI:" + pi.getOID() + " ISIN:" + details.getDescriptorValue("ISIN")); } sf.close(); } }