Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Stardust/Knowledge Base/Java API/Process Instance Queries

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.

If you use a process data for such queries then you should consider making it a descriptor. Process data (fields) that are used as descriptors are stored in an index. Therefore queries filtered by descriptors are way more efficient than queries using regular process data (fields). To declare a descriptor open the properties of a process definition, add a data path with direction IN, check the descriptor check box and specify the process data (field and access path).
package test;
 
import java.util.Iterator;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import ag.carnot.workflow.query.DataFilter;
import ag.carnot.workflow.query.DescriptorPolicy;
import ag.carnot.workflow.query.ProcessInstanceQuery;
import ag.carnot.workflow.query.ProcessInstances;
import ag.carnot.workflow.runtime.ProcessInstance;
import ag.carnot.workflow.runtime.QueryService;
import ag.carnot.workflow.runtime.ServiceFactory;
import ag.carnot.workflow.runtime.ServiceFactoryLocator;
import ag.carnot.workflow.runtime.details.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();
	}
}

Back to the top