Creating your own Automation Validation ( deprecated )
Esta página aún no está disponible en tu idioma.
You can create your own Automation Validation.
Conditions:
- The new Automation Validation class must implement the “Validation” interface.
- The new Automation Validation class must be declared under the package “com.openkm.automation.validation”.
Validation interface:
package com.openkm.automation;
import java.util.HashMap;
public interface Validation { public static final String METHOD = "isValid";
boolean isValid(HashMap<String, Object> env, Object... params);}Methods description
Section titled “Methods description”| Method | Type | Description |
|---|---|---|
| isValid(Map<String, Object> env, Object… params) | boolean | The method executed by the Automation event to evaluate if conditions are true or false. |
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 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 to retrieve the parameters to the correct object type.
For example to retrive the first parameters as String object.
String param00 = AutomationUtils.getString(0, params);Register
Section titled “Register”Once you have created the new Automation Validation, 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: - “validation”. |
| 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”PathContains class:
package com.openkm.automation.validation;
import java.util.HashMap;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import com.openkm.api.OKMRepository;import com.openkm.automation.AutomationUtils;import com.openkm.automation.Validation;
/** * Check if the current parent path contains a designed one. The only * parameter is a path and will test if this one is included in the * actual parent. * */public class PathContains implements Validation { private static Logger log = LoggerFactory.getLogger(PathContains.class);
@Override public boolean isValid(HashMap<String, Object> env, Object... params) { try { String uuid = AutomationUtils.getString(0, params); String parentPath = AutomationUtils.getParentPath(env); String path = OKMRepository.getInstance().getNodePath(null, uuid);
if (parentPath.startsWith(path)) { return true; } else { return false; } } catch (Exception e) { log.error(e.getMessage(), e); }
return false; }}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.validation.PathContains', 'PathContains', 'validation', 'text', 'okm:folder', 'String', '', '', '');The OKM_AUTO_METADATA colums values for PathContains Automation Validation:
| Column | Description |
|---|---|
| AMD_ID | Unique Id |
| AMD_AT | “post” |
| AMD_CLASS_NAME | “com.openkm.automation.validation.PathContains” |
| AMD_DESC00 | “String” |
| AMD_DESC01 | “” |
| AMD_DESC02 | “” |
| AMD_GROUP | “validation”. |
| AMD_NAME | “PathContains”. |
| AMD_SRC00 | “okm:folder”. |
| AMD_SRC01 | “”. |
| AMD_SRC02 | “”. |
| AMD_TYPE01 | “text”. |
| AMD_TYPE02 | “”. |
| AMD_TYPE03 | “”. |