Skeleton URLExternalTask

Posted: 18 May 2009 in CSSDK, Java, Teamsite, UI toolkits, URLExternalTask, Worfklow models, Workflows

If you want to create a new URLExternalTask class, here’s a skeleton that can be re-used. It allows you to run an test the class before having to rebuild the toolkits, therefore reducing the interferences (and also the build times). It also lets you control the workflow when errors have been intercepted and redirect the flow to an error handling task.

/*
 * Author: Laurent Picquet
 */
package com.acme.workflow;

import com.interwoven.cssdk.access.CSAuthenticationException;
import com.interwoven.cssdk.common.CSClient;
import com.interwoven.cssdk.common.CSException;
import com.interwoven.cssdk.common.CSRemoteException;
import com.interwoven.cssdk.factory.CSLocalFactory;
import com.interwoven.cssdk.filesys.CSFile;
import com.interwoven.cssdk.filesys.CSVPath;
import com.interwoven.cssdk.workflow.CSExternalTask;
import com.interwoven.cssdk.workflow.CSURLExternalTask;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Laurent Picquet
 */
public class SkeletonTask implements CSURLExternalTask {

 private CSClient client = null;
 private CSExternalTask task = null;
 private CSFile[] attachedCSFiles=new CSFile[0];
 private StringBuilder executionLog = null;
 private String transitionLinkName = "";
 private static String KEY_ONSUCCESS_TASK_VARIABLE = "onSucess";
 private static String KEY_ONFAILURE_TASK_VARIABLE = "onFailure";

 public void execute(CSClient client, CSExternalTask task, Hashtable params) throws CSException {
 this.client = client;
 this.task=task;
 attachedCSFiles=task.getArea().getFiles(task.getFiles());
 try {
 execute();
 transitionLinkName = task.getVariable(KEY_ONSUCCESS_TASK_VARIABLE);
 } catch (Exception e) {
 transitionLinkName = task.getVariable(KEY_ONFAILURE_TASK_VARIABLE);
 e.printStackTrace();
 } finally {
 if (transitionLinkName == null) {
 transitionLinkName = "";
 }
 task.chooseTransition(transitionLinkName, executionLog.toString());
 }
 }

 private void execute() {
 executionLog = new StringBuilder();
 executionLog.append("SkeletonTask begin execute\r\n");
 /* do the work here. */
 executionLog.append("SkeletonTask end execute\r\n");
 }

 public static void main(String args[]) throws CSException {
 String configFilePath = "/apps/interwoven/teamsite/cssdk/cssdk.cfg";
 Properties localProperties = new Properties();
 localProperties.setProperty("cssdk.cfg.path", configFilePath);
 CSLocalFactory csLocalFactory = (CSLocalFactory) CSLocalFactory.getFactory(localProperties);
 SkeletonTask task = new SkeletonTask();
 try {
 task.client = csLocalFactory.getClientForCurrentUser(Locale.ENGLISH, "SkeletonTask", "localhost");
 } catch (CSAuthenticationException ex) {
 Logger.getLogger(SkeletonTask.class.getName()).log(Level.SEVERE, null, ex);
 } catch (CSRemoteException ex) {
 Logger.getLogger(SkeletonTask.class.getName()).log(Level.SEVERE, null, ex);
 } catch (CSException ex) {
 Logger.getLogger(SkeletonTask.class.getName()).log(Level.SEVERE, null, ex);
 }

 if (task.client != null) {
 System.out.println("connected to TeamSite.");
 task.attachedCSFiles=new CSFile[1];
 task.attachedCSFiles[0]=task.client.getFile(new CSVPath("/default/main/acme/WORKAREA/acme/sites/acme/default.site"));
 task.execute();
 }
 }
}
Advertisements
Comments
  1. Mik says:

    It does look interesting but I’m getting one issue,
    Testing with 7.3(TS), and of course we should be able to test there also except for does:
    It doesnt recognize the import this import:
    import com.interwoven.cssdk.factory.CSLocalFactory; so I don’t have the cssdk of 2009…
    Which create a cascading effect on does 2 line:
    1.CSLocalFactory csLocalFactory = (CSLocalFactory) CSLocalFactory.getFactory(localProperties);
    2.SkeletonTask task = new();

    IS there another class I can try: I did try with :
    import com.interwoven.cssdk.factory.*; ….

    I would like to have my hands on the API….

    If I understand you right, at that poiint I just start the workflow model with this task and the code on
    private void execute() will get executed…

    Thx appreicate your examples.

    Just trying to debug more efficently.

    Mik

  2. CSLOCALFActory has been replaced with a CSJavaFactory. I haven’t looked if this object has the same methods but my guess is it should.

    Regards,
    Laurent

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s