Skip to main content
Jump to: navigation, search

Stardust/Knowledge Base/API/ExamplesofAPIUsage/LinkProcesses

Linking Processes

Purpose

To link two processes using the API.

Pre Defined Link Types

  SWITCH("Peer Process Instance"),
  JOIN("Join Process Instance"),
  UPGRADE("Upgrade Process Instance"),
  SPAWN("Spawn Process Instance"),
  RELATED("Related Process Instance");

Implementation

    @Override
    public void addProcessLink(long poid, long joinedPoid) {
        try {
            Object object = getWorkflowService().execute(new LinkProcessServiceCommand(poid, joinedPoid));
        } catch (ServiceCommandException e) {
            LOG.warn("Could not link process instance " + poid + " and " + joinedPoid);
        }
    }
import java.io.Serializable;
 
import org.eclipse.stardust.common.error.ObjectNotFoundException;
import org.eclipse.stardust.engine.api.runtime.PredefinedProcessInstanceLinkTypes;
import org.eclipse.stardust.engine.api.runtime.ServiceFactory;
import org.eclipse.stardust.engine.core.runtime.beans.IProcessInstance;
import org.eclipse.stardust.engine.core.runtime.beans.IProcessInstanceLinkType;
import org.eclipse.stardust.engine.core.runtime.beans.ProcessInstanceBean;
import org.eclipse.stardust.engine.core.runtime.beans.ProcessInstanceLinkBean;
import org.eclipse.stardust.engine.core.runtime.beans.ProcessInstanceLinkTypeBean;
import org.eclipse.stardust.engine.core.runtime.command.ServiceCommand;
 
public class LinkProcessServiceCommand implements ServiceCommand
{
	public long poid;
	public long joinedPoid;
 
    public LinkProcessServiceCommand(long poid, long joinedPoid) {
		super();
		this.poid = poid;
		this.joinedPoid = joinedPoid;
	}
 
   public Serializable execute(ServiceFactory sf)
   {
      addProcessLink(poid, joinedPoid);
      return "success";
   }
 
   public void addProcessLink(long poid, long joinedPoid) {
       IProcessInstance originatingProcessInstance = ProcessInstanceBean.findByOID(joinedPoid);
       IProcessInstance targetProcessInstance = ProcessInstanceBean.findByOID(poid);
       IProcessInstanceLinkType linkType = null;
       try {
           linkType = ProcessInstanceLinkTypeBean.findById(PredefinedProcessInstanceLinkTypes.JOIN);
       } catch (ObjectNotFoundException e) {
           linkType = new ProcessInstanceLinkTypeBean(PredefinedProcessInstanceLinkTypes.JOIN.getId(),
                   PredefinedProcessInstanceLinkTypes.RELATED.getDescription());
       }
 
       IProcessInstance linkSource = originatingProcessInstance.getRootProcessInstance().isCaseProcessInstance() ? originatingProcessInstance
               : originatingProcessInstance.getRootProcessInstance();
       new ProcessInstanceLinkBean(linkSource, targetProcessInstance, linkType, "Joined Process Instance");
   }   
}

Copyright © Eclipse Foundation, Inc. All Rights Reserved.