Creating your own Automation Action ( deprecated )
You can create your own Automation Action.
Conditions:
- The new Automation Action class must implement the “Action” interface.
- The new Automation Action class must be declared under the package “com.openkm.automation.action”.
Validation interface:
package com.openkm.automation;
import java.util.HashMap;
public interface Action { public static final String METHOD_PRE = "executePre"; public static final String METHOD_POST = "executePost";
public void executePre(HashMap<String, Object> env, Object... params); public void executePost(HashMap<String, Object> env, Object... params);}Methods description
Section titled “Methods description”| Method | Type | Description |
|---|---|---|
| executePre(Map<String, Object> env, Object… params) | void | The method executed by the Automation event when the validation conditions succeed, on “pre” stage. |
| executePost(Map<String, Object> env, Object… params) | void | The method executed by the Automation event when the validation conditions succeed, on “post” stage. |
Understanding env variable
Section titled “Understanding env variable”The env variable is present on isValid method, it is a Map of values injected by automation. These map values provide information about the node involved on the event and other related information.
For example to retrieve the uuid of the node that caused the event.
String uuid = AutomationUtils.getUuid(env);Understanding params variable
Section titled “Understanding params variable”The env variable is present on isValid method, it is an array of Objects. This array is filled by Automation event based on the number of parameters set on Validation class.
The array can have serveral Objects with a distinct type, it is necessary retrieve the parameters to the correct object type.
For example to retrieve the first parameters as String object.
String param00 = AutomationUtils.getString(0, params);Preventing recursion
Section titled “Preventing recursion”When you create your automation actions, should consider recursion case. For example if your action goes linked with “CREATE_DOCUMENT” event and into the action you create a new document you can go into an infinite loop. For it when you create a new Action should take special care of this cases.
Register
Section titled “Register”Once you have created the new Automation Action, build the OpenKM.war file and deployed into the tomcat, it must be registered into the OKM_AUTO_METADATA table;
The OKM_AUTO_METADATA colums description:
| Column | Description |
|---|---|
| AMD_ID | Autoincremental unique Id |
| AMD_AT | Indicates when the Automation Action can be executed, the values are: - “pre” indicate can be execute inmediatelly before the action who has fired it. - “post” indicate can be execute after the action who has fired it. |
| AMD_CLASS_NAME | Java class name. |
| AMD_DESC00 | Description of the parameter 0. |
| AMD_DESC01 | Description of the parameter 1. |
| AMD_DESC02 | Description of the parameter 2. |
| AMD_GROUP | Type of automation, allowed values are: - “action”. |
| AMD_NAME | Name. |
| AMD_SRC00 | Source, allowed values are: - “” default value. - “okm:folder” indicate the value is a folder uuid. When type “okm:folder” is applied will be shown a folder selector popup. |
| AMD_SRC01 | Source, allowed values are: - “” default value. - “okm:folder” indicate the value is a folder uuid. When type “okm:folder” is applied will be shown a folder selector popup. |
| AMD_SRC02 | Source, allowed values are: - “” default value. - “okm:folder” indicate the value is a folder uuid. When type “okm:folder” is applied will be shown a folder selector popup. |
| AMD_TYPE01 | Allowed type of values are: - “” default value. - “text”. - “textarea”. - “integer”. - “boolean”. The type will take effect on widget shown from UI. |
| AMD_TYPE02 | Allowed type of values are: - “” default value. - “text”. - “textarea”. - “integer”. - “boolean”. The type will take effect on widget shown from UI. |
| AMD_TYPE03 | Allowed type of values are: - “” default value. - “text”. - “textarea”. - “integer”. - “boolean”. The type will take effect on widget shown from UI. |
Example
Section titled “Example”AddKeyword class:
package com.openkm.automation.action;
import java.util.HashMap;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import com.openkm.automation.Action;import com.openkm.automation.AutomationUtils;import com.openkm.core.Config;import com.openkm.dao.NodeBaseDAO;
public class AddKeyword implements Action { private static Logger log = LoggerFactory.getLogger(AddKeyword.class);
@Override public void executePre(HashMap<String, Object> env, Object... params) { }
@Override public void executePost(HashMap<String, Object> env, Object... params) { String keyword = AutomationUtils.getString(0, params); String uuid = AutomationUtils.getUuid(env);
try { if (uuid != null) { if (Config.SYSTEM_KEYWORD_LOWERCASE && keyword != null) { keyword = keyword.toLowerCase(); }
NodeBaseDAO.getInstance().addKeyword(uuid, keyword); } } catch (Exception e) { log.error(e.getMessage(), e); } }}Go to Administration > Database query and execute the sql:
INSERT INTO OKM_AUTO_METADATA (AMD_AT, AMD_CLASS_NAME, AMD_NAME, AMD_GROUP, AMD_TYPE00, AMD_SRC00, AMD_DESC00, AMD_TYPE01, AMD_SRC01, AMD_DESC01) VALUES ('post', 'com.openkm.automation.action.AddKeyword', 'AddKeyword', 'action', 'text', '', 'Keyword', '', '', '');The OKM_AUTO_METADATA colums values for AddKeyword Automation Action:
| Column | Description |
|---|---|
| AMD_ID | Unique Id |
| AMD_AT | “post” |
| AMD_CLASS_NAME | “com.openkm.automation.action.AddKeyword” |
| AMD_DESC00 | “Keyword” |
| AMD_DESC01 | “” |
| AMD_DESC02 | “” |
| AMD_GROUP | “action”. |
| AMD_NAME | “AddKeyword”. |
| AMD_SRC00 | “”. |
| AMD_SRC01 | “”. |
| AMD_SRC02 | “”. |
| AMD_TYPE01 | “text”. |
| AMD_TYPE02 | “”. |
| AMD_TYPE03 | “”. |