Workflow samples
For most examples it has been used the Purchase workflow sample.
Methods
registerProcessDefinition
Description:
Method | Return values | Description |
---|---|---|
registerProcessDefinition(InputStream is) |
void |
Registers a new workflow. |
Example:
package com.openkm;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
InputStream is = new FileInputStream("/opt/files/Purchase.par");
ws.registerProcessDefinition(is);
IOUtils.closeQuietly(is);
} catch (Exception e) {
e.printStackTrace();
}
}
}
deleteProcessDefinition
Description:
Method | Return values | Description |
---|---|---|
deleteProcessDefinition(long pdId) |
void |
Deletes a workflow. |
The parameter pdId value is a valid workflow process definition. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long pdId = 5; // Valid workflow process definition
ws.deleteProcessDefinition(pdId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getProcessDefinition
Description:
Method | Return values | Description |
---|---|---|
getProcessDefinition(long pdId) |
void |
Returns a workflow process definition. |
The parameter pdId value is a valid workflow process definition. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.ProcessDefinition;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long pdId = 5; // Valid workflow process definition
ProcessDefinition pd = ws.getProcessDefinition(pdId);
System.out.println(pd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
runProcessDefinition
Description:
Method | Return values | Description |
---|---|---|
runProcessDefinition(long pdId, String uuid, List<FormElement> values) |
ProcessInstance |
Executes a workflow on a node. |
The parameter pdId value is a valid workflow process definition. The parameter uuid can be any document, mail, folder or record UUID. The parameter values are form element values needed for starting the workflow ( not all workflows need form values for starting ). |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.FormElement;
import com.openkm.sdk4j.bean.form.Input;
import com.openkm.sdk4j.bean.form.TextArea;
import java.util.*;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long pdId = 8041; // Some valid workflow process definition id
List<FormElement> feList = new ArrayList<>(); // Case as part of starting workflow are required form parameter
Input price = new Input();
price.setName("price");
price.setValue("1000");
feList.add(price);
TextArea textArea = new TextArea();
textArea.setName("description");
textArea.setValue("some description here");
feList.add(textArea);
ws.runProcessDefinition(pdId, "f86cc22d-9b50-434f-a940-b04cea9c0048", feList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
findProcessInstances
Description:
Method | Return values | Description |
---|---|---|
findProcessInstances(long pdId) |
List<ProcessInstance> |
Retrieves a list of all process instances of some registered workflows definition. |
The parameter pdId value is a valid workflow process definition. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.ProcessDefinition;
import com.openkm.sdk4j.bean.workflow.ProcessInstance;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
// Get all workflow definitions
for (ProcessDefinition pd : ws.findAllProcessDefinitions()) {
System.out.println("WF definition: "+pd);
// Get all process of some workflow definition
for (ProcessInstance pi : ws.findProcessInstances(pd.getId())) {
System.out.println("PI: "+pi);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findAllProcessDefinitions
Description:
Method | Return values | Description |
---|---|---|
findAllProcessDefinitions() |
List<ProcessDefinition> |
Retrieves a list of all registered workflows definitions. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.ProcessDefinition;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
for (ProcessDefinition pd : ws.findAllProcessDefinitions()) {
System.out.println(pd);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findLatestProcessDefinitions
Description:
Method | Return values | Description |
---|---|---|
findLatestProcessDefinitions() |
List<ProcessDefinition> |
Retrieves a list of the last workflows definitions. |
Several versions of the same workflow can be registered. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.ProcessDefinition;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
// Get all latest workflow definitions
for (ProcessDefinition pd : ws.findLatestProcessDefinitions()) {
System.out.println("WF definition: " + pd);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findLastProcessDefinition
Description:
Method | Return values | Description |
---|---|---|
findLastProcessDefinition(String name) |
ProcessDefinition |
Retrieves last workflow definition of some specific workflow. |
The parameter name identifies an specific workflow definitions group. Several workflow definition versions that have the same name. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.ProcessDefinition;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
ProcessDefinition pd = ws.findLastProcessDefinition("purchase");
System.out.println("WF definition: " + pd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getProcessInstance
Description:
Method | Return values | Description |
---|---|---|
getProcessInstance(long piId) |
ProcessInstance |
Returns the process instance. |
The parameter piId is a valid process instance id. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.ProcessInstance;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long piId = 8108; // Some valid process instance id
ProcessInstance pi = ws.getProcessInstance(piId);
System.out.println("PI: " + pi);
} catch (Exception e) {
e.printStackTrace();
}
}
}
findUserTaskInstances
Description:
Method | Return values | Description |
---|---|---|
findUserTaskInstances() |
List<TaskInstance> |
Retrieves a list of task instances assigned to the user. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.TaskInstance;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
// Get all user task intances
for (TaskInstance ti : ws.findUserTaskInstances()) {
System.out.println(ti);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findTaskInstances
Description:
Method | Return values | Description |
---|---|---|
findTaskInstances(long piId) |
List<TaskInstance> |
Retrieves a list of task instances from a process instance id. |
The parameter piId is a valid process instance id. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.TaskInstance;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
// Get all task instances of some process instance
long piId = 8108; // Some valid process instance id
for (TaskInstance ti : ws.findTaskInstances(piId)) {
System.out.println(ti);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
setTaskInstanceValues
Description:
Method | Return values | Description |
---|---|---|
setTaskInstanceValues(long tiId, String transName, List<FormeElement> values) |
void |
Set a task instance vales. |
The parameter tiId is a valid task instance id. The parameter transName is the choosen transaction. The parameter values are form element values needed for starting the workflow ( not all workflow tasks need form values ). |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.TaskInstance;
import java.util.*;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long tiId = 8110; // Some valid task instance id
List<FormElement> feList = new ArrayList<>();
ws.setTaskInstanceValues(tiId, "approve", feList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getTaskInstance
Description:
Method | Return values | Description |
---|---|---|
getTaskInstance(long tiId) |
TaskInstance |
Returns a task instance. |
The parameter tiId is a valid task instance id. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.workflow.TaskInstance;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long tiId = 8110; // Some valid task instance id
TaskInstance ti = ws.getTaskInstance(tiId);
System.out.println(ti);
} catch (Exception e) {
e.printStackTrace();
}
}
}
startTaskInstance
Description:
Method | Return values | Description |
---|---|---|
startTaskInstance(long tiId) |
void |
Starts a task instance. |
The parameter tiId is a valid task instance id. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long tiId = 8110; // Some valid task instance id
ws.startTaskInstance(tiId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
setTaskInstanceActorId
Description:
Method | Return values | Description |
---|---|---|
setTaskInstanceActorId(long tiId, String actorId) |
void |
Set the actor to a task instance. |
The parameter tiId is a valid task instance id. The parameter actorId must be some valid OpenKM userId. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long tiId = 8110; // Some valid task instance id
ws.setTaskInstanceActorId(tiId, "okmAdmin");
} catch (Exception e) {
e.printStackTrace();
}
}
}
endTaskInstance
Description:
Method | Return values | Description |
---|---|---|
endTaskInstance(long tiId, String transName) |
void |
Ends a task instance. |
The parameter tiId is a valid task instance id. The parameter transName is a transaction name. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
long tiId = 8110; // Some valid task instance id
ws.endTaskInstance(tiId, "end");
} catch (Exception e) {
e.printStackTrace();
}
}
}
getProcessDefinitionForms
Description:
Method | Return values | Description |
---|---|---|
getProcessDefinitionForms(long pdId) |
Map<String, List<FormElement>> |
Return a map with all the process definition forms. |
The parameter pdId value is a valid workflow process definition. |
Example:
package com.openkm;
import java.util.List;
import java.util.Map;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;
public class Test2 {
public static void main(String[] args) {
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {
Map<String, List<FormElement>> forms = ws.getProcessDefinitionForms(12);
for (String key : forms.keySet()) {
System.out.println("Key:"+key);
for (FormElement fe : forms.get(key)) {
System.out.println("Fe:"+fe);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}