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

Difference between revisions of "Stardust/Knowledge Base/API/ExamplesofAPIUsage/LinkProcesses"

(Created page with "__NOTOC__ == Linking Processes == ==== Purpose ==== To link two processes using the API. ==== Pre Defined Link Types ==== SWITCH("Peer Process Instance"), JOIN("Joi...")
 
 
Line 28: Line 28:
  
 
<source lang="java">
 
<source lang="java">
package com.sungard.infinity;
+
 
  
 
import java.io.Serializable;
 
import java.io.Serializable;

Latest revision as of 10:39, 15 March 2016

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");
   }   
}

Back to the top