Receiving Parent Process Instance OID for Specific Details Policy Option

You can use the enumeration ProcessInstanceDetailsOptions.html to set more details options for process instance objects.

public enum ProcessInstanceDetailsOptions

WITH_HIERARCHY_INFO determines, that the process instance details will contain information about the parent process instance.

To set the details options for a specific level of detail, you can use the constructor of class ProcessInstanceDetailsPolicy.

public ProcessInstanceDetailsPolicy(ProcessInstanceDetailsLevel level,
        EnumSet<ProcessInstanceDetailsOptions> options)
    this.level = level;
    this.options = options.clone();

To get the options used for details creation for a process instance, use method

EnumSet<ProcessInstanceDetailsOptions> getDetailsOptions();

of the ProcessInstance class.


The following code snippet shows an example on how to receive the parent process instance oid for a process instance object depending on a specific details policy option.

import java.util.EnumSet;
import java.util.Iterator;

import org.eclipse.stardust.engine.api.query.ProcessInstanceDetailsPolicy;
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.runtime.dto.ProcessInstanceDetailsLevel;
import org.eclipse.stardust.engine.api.runtime.dto.ProcessInstanceDetailsOptions;

public class Main
   private static final String PROCESS_DEFINITION_1 = "ProcessDefinition_1";

   public static void main(String[] args)
      ServiceFactory sf = ServiceFactoryLocator.get("motu", "motu");
      QueryService qs = sf.getQueryService();

      ProcessInstanceQuery piq = ProcessInstanceQuery.findAll();

      // create new policy... here default level
      ProcessInstanceDetailsPolicy policy = new ProcessInstanceDetailsPolicy(ProcessInstanceDetailsLevel.Default);
      // ... and additionally set more details options 
      // alternative approach: create policy by constructor only
      // ProcessInstanceDetailsPolicy policy = new ProcessInstanceDetailsPolicy(ProcessInstanceDetailsLevel.Default, EnumSet.of(ProcessInstanceDetailsOptions.WITH_HIERARCHY_INFO));
      // setting this extended policy
      ProcessInstances processInstances = qs.getAllProcessInstances(piq);

      // iterate over all PIs
      for (Iterator iterator = processInstances.iterator(); iterator.hasNext();)
         ProcessInstance pi = (ProcessInstance);
         // retrieve the oid of parentProcessInstance
         // can be ProcessInstance.UNKNOWN_OID, 0 or >0.
         // ProcessInstance.UNKNOWN_OID: not requested or an error occurred during fetch
         // 0: no parent PI
         // >0: the oid
         long parentProcessInstanceOid = pi.getParentProcessInstanceOid();
         // check the details options the PI has queries with
         EnumSet<ProcessInstanceDetailsOptions> detailsOptions = pi.getDetailsOptions();