Creating your own Automation Validation ( deprecated )
Automation architecture from version 6.3.7 has been changed instead of plugin architecture. This documentation section is for OpenKM 6.3.6 and older.
Users from version 6.3.7 should use this documentation section Creating your own Automation Validation.
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".
The new Automation Action class must be within the OpenKM source code. You might be interested in OpenKM portable dev environment for it.
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
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
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.
It takes some time, until you take control of AutomationUtils class, because they are centralized, the methods for retrieve data.
For example to retrieve the uuid of the node that caused the event.
String uuid = AutomationUtils.getUuid(env);
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.
It takes some time, until you take control of AutomationUtils class, because they are centralized, the methods to retrieve parameters.
For example to retrive the first parameters as String object.
String param00 = AutomationUtils.getString(0, params);
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:
|
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:
|
AMD_NAME |
Name. |
AMD_SRC00 |
Source, allowed values are:
When type "okm:folder" is applied will be shown a folder selector popup. |
AMD_SRC01 |
Source, allowed values are:
When type "okm:folder" is applied will be shown a folder selector popup. |
AMD_SRC02 |
Source, allowed values are:
When type "okm:folder" is applied will be shown a folder selector popup. |
AMD_TYPE01 |
Allowed type of values are:
The type will take effect on widget shown from UI. |
AMD_TYPE02 |
Allowed type of values are:
The type will take effect on widget shown from UI. |
AMD_TYPE03 |
Allowed type of values are:
The type will take effect on widget shown from UI. |
In case your Automation Validation can be executed from "pre" and "post" stages, you must do an insert for each one. |
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', '', '', '');
Depending on your database the query might have minimal changes.
Oracle:
INSERT INTO OKM_AUTO_METADATA (AMD_ID, AMD_AT, AMD_CLASS_NAME, AMD_NAME, AMD_GROUP, AMD_TYPE00, AMD_SRC00, AMD_DESC00, AMD_TYPE01, AMD_SRC01, AMD_DESC01) VALUES (HIBERNATE_SEQUENCE.nextval, 'post', 'com.openkm.automation.validation.PathContains', 'PathContains', 'validation', 'text', 'okm:folder', 'String', '', '', '');
PostgreSQL:
INSERT INTO OKM_AUTO_METADATA (AMD_ID, AMD_AT, AMD_CLASS_NAME, AMD_NAME, AMD_GROUP, AMD_TYPE00, AMD_SRC00, AMD_DESC00, AMD_TYPE01, AMD_SRC01, AMD_DESC01) VALUES (nextval('hibernate_sequence'), '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 |
"". |