Try OpenEdge Now
skip to main content
Application Developer's Guide
Developing BPM Workflow adapters : Developing custom adapters : Sample adapter code for BPM Workflow-style adapters
 

Sample adapter code for BPM Workflow-style adapters

Use the following sample Adapter code as a template to create custom BPM Workflow-style Adapters.
package com.savvion.BPM Workflow.beans;
import java.util.Enumeration;
import java.util.Vector;
import com.savvion.BPM Workflow.Server.PublicResources;
import com.savvion.BPM Workflow.Server.BPM WorkflowLog;
import com.tdiinc.userManager.UserManager;
import com.tdiinc.userManager.User;
import com.savvion.common.SBM;
import com.savvion.sbm.bizsolo.util.SBMConf;
public class PAKGetDS
    extends GenericAction
{    public PAKGetDS()
    {
    }
    public String[] getInputList()
    {
Vector names = getAllNames();
Enumeration e=names.elements();
String[] snames = new String[names.size()];
int i=0;
while(e.hasMoreElements()){
    snames[i]=(String)e.nextElement();
    i++;
}return (snames);
    }
    public int commit()
    throws Exception
    {
    String workitemName = getPropString(PublicResources.BL_WORKITEMNAME);
    String ptName = getPropString(PublicResources.BL_PTNAME);
    String mode = getPropString(PublicResources.MODE);
    long workitemId = getPropLong(PublicResources.BL_WORKITEMID);
    String httpSessionId = getPropString(PublicResources.HTTP_SESSION_ID);
if("true".equals(getPropString(PublicResources.IS_BIZSOLO_SUBPROCESS)))
return 0;
if(workitemName==null && ptName != null &&
"SLAVE".equalsIgnoreCase(mode)) {
        workitemId = -1;
    }
    String blsid = getPropString(PublicResources.BL_SID);
    if(blsid == null)
    {
    String msg = "No BP Server connection information received. Aborting ...";
    Log.log(msg, Log.ERROR);
    setError(msg);
    return -1;
    }
    try{
        if (Log.isDebugEnabled())
        Log.log("GetDsPresentationTag :Getting PAKBPM WorkflowBean object using values:httpSessionId ="+httpSessionId+", bLSID="+blsid+",workitem id="+workitemId, Log.DEBUG);
    
    PAKBPM WorkflowBean pakbean = PAKBPM WorkflowBean.getInstance(httpSessionId, blsid, workitemId);
    if(workitemId == -1) {
    pakbean.setStartWorkstepDS(ptName);
    }
    String wiperf = pakbean.getWorkitemPerformer();
    boolean isEmailPerf = isEmailPerformer(wiperf);
    if(wiperf != null && isEmailPerf && (PAKBPM WorkflowBean.WI_ASSIGNED ==
        pakbean.getWorkitemStatus())){
    String sessUser = pakbean.getSessionUser();
    boolean isEmailValid = false;
    String userEmailId = this.getEmailAddress(sessUser);
    if(!(wiperf.equals(userEmailId)) && !(wiperf.equals(sessUser))){
    String error = wiperf + " needs to login with the right credentails ";
        setPropString("error",error);
        BPM WorkflowLog.log("BPM Workflow_ERR_091", new Exception(error));
        throw new BPM WorkflowRuntimeException(error);
    }
    }else if(((pakbean.getWorkitemStatus() == PAKBPM WorkflowBean.WI_ASSIGNED) &&
        (pakbean.getSessionUser() != null) &&
!(comparePerformer(pakbean.getSessionUser(),pakbean.getWorkitemPerformer(    &&
!pakbean.isDelegatePerformer())
    || (pakbean.getWorkitemStatus() == PAKBPM WorkflowBean.WI_COMPLETED))
    {
        String error = (pakbean.getWorkitemStatus() ==
PAKBPM WorkflowBean.WI_COMPLETED)?(workitemName+" task has been already
completed."):(workitemName+" task has been already assigned to
"+pakbean.getWorkitemPerformer()+".");
    setPropString("error",error);
    BPM WorkflowLog.log("BPM Workflow_ERR_091", new Exception(error));
    throw new BPM WorkflowRuntimeException(error);
    }
    String[] dsi;
    String[] dso;
    dsi = pakbean.getInputDataslotList();
    dso = pakbean.getOutputDataslotList();
        if(workitemId > 0){
        setPropString(PublicResources.BL_PINAME,pakbean.getPIname());
        setPropString(PublicResources.BL_PTNAME,pakbean.getPTname());
        setPropString(PublicResources.BL_TASK_DUEDATE,pakbean.getDueDate());
        } else if (workitemId == -1){
    setPropString(PublicResources.BL_PTNAME,ptName);
        }
        setPropString(PublicResources.BL_TASK_PRIORITY,pakbean.getPriority());
        setPropString(PublicResources.BL_TASK_STARTDATE,pakbean.getStartDate());
        setPropString(PublicResources.BL_TASK_INSTRUCTION,pakbean.getInstruction());
        for(int i=0;i<dsi.length;i++)
        {
                if (Log.isDebugEnabled())
                Log.log("PAKGetDS Input: "+dsi[i]+" , value:
"+pakbean.getInputDataslotValue(dsi[i]), Log.DEBUG);
                try{
        setPropObject(dsi[i],pakbean.getInputDataslotValue(dsi[i]));
        }catch(Exception e)
        {
        Log.log("Error retrieving input ds name:"+dsi[i]+" error: "+e.toString(), Log.ERROR);
                throw e;
        }
        }
        for(int i=0;i<dso.length;i++)
        {
        if (Log.isDebugEnabled())
        Log.log("PAKGetDS Output: "+dso[i]+" , value:
"+pakbean.getOutputDataslotValue(dso[i]), Log.DEBUG);
                try{
        setPropObject(dso[i],pakbean.getOutputDataslotValue(dso[i]));
        }catch(Exception e)
        {
        Log.log("Error retrieving output ds name:"+dso[i]+" error: "+e.toString(),
Log.ERROR);
        throw e;
        }
    }
    }
    catch(BPM WorkflowRuntimeException bizSoloEx)
    {
        throw bizSoloEx;
    
    catch(Exception ex)
    {
        mode = getPropString(PublicResources.ADAPTER_MODE);
        Log.log("PAKGetDS mode: "+mode, ex, Log.ERROR);
        setError(ex.toString());
        if(PublicResources.BIZSITE_MODE.equalsIgnoreCase(mode))
            throw ex;
        return -1;
    }
    return 0;
    }
    private String getEmailAddress(String userName){
        if(userName == null)
            return null;
        String emailAttribute = null;
        try{
            emailAttribute = SBM.getParameter("umacl.conf", "user.email.attr");
        }catch(Throwable ignore){
        }
        if(emailAttribute == null || emailAttribute.trim().equals(""))
emailAttribute = "email";
        try{
            User user = UserManager.getUser(userName);
            return (String)user.getAttribute(emailAttribute);
    }catch(Throwable ignore){
            return null;
        }
    }
    private boolean isEmailPerformer(String perf){
        try {
            UserManager.getUser(perf);
            return false;
        } catch (Throwable ignore) {
            return true;
        }
    }
    private boolean comparePerformer(String sessionUser, String performer) {
            if("true".equals(SBMConf.SBM_USERMANAGER_CASESENSITIVE)) {
            return sessionUser.equals(performer);
    } else {
            return sessionUser.equalsIgnoreCase(performer);
            }
    }
}