Skip to content
Other versions

Loading…

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 Validation class must be annotated with@PluginImplementation”.

Validation interface:

package com.openkm.automation;
import java.util.Map;
import net.xeoh.plugins.base.Plugin;
public interface Validation extends Plugin {
public static final String METHOD = "isValid";
boolean isValid(Map<String, Object> env, Object... params);
public boolean hasPost();
public boolean hasPre();
public String getName();
public String getParamType00();
public String getParamSrc00();
public String getParamDesc00();
public String getParamType01();
public String getParamSrc01();
public String getParamDesc01();
public String getParamType02();
public String getParamSrc02();
public String getParamDesc02();
}
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.
hasPost() boolean When true is returned, this method indicates the isValid(…) method can be used in Automation post stage.
More information about automation stages at Automation.
hasPre() boolean When true is returned, this method indicates the isValid(…) method can be used in Automation pre stage.
More information about automation stages at Automation.
getName() String Sets the name that will be shown in the administrator user interface selector list.
getParamType00
getParamType01
getParamType02
String Sets the parameter type.
Available values:
- Automation.PARAM_TYPE_EMPTY
- Automation.PARAM_TYPE_TEXT
- Automation.PARAM_TYPE_INTEGER
- Automation.PARAM_TYPE_BOOLEAN
- Automation.PARAM_TYPE_TEXTAREA
- Automation.PARAM_TYPE_CODE
- Automation.PARAM_TYPE_USER
- Automation.PARAM_TYPE_ROLE
- Automation.PARAM_TYPE_OMR
When the value is set to Automation.PARAM_TYPE_EMPTY
The parameters work as a logical group.
[ getParamType00 + getParamSrc00 + getParamDesc00 ]
getParamSrc00
getParamSrc01
getParamSrc02
String Set the source type.
Available values:
- Automation.PARAM_SOURCE_EMPTY
- Automation.PARAM_SOURCE_FOLDER
- Automation.PARAM_SOURCE_OMR
getParamDesc00
getParamDesc00
getParamDesc00
String The parameter description.

The env variable is present on the 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);

The params variable is present the on isValid method, it is an array of Objects. This array is filled by an Automation event based on the number of parameters set on the Validation class (which will not be Automation.PARAM_TYPE_EMPTY value).

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);

Description of available ParamType values:

Section titled “Description of available ParamType values:”
Property Description
Automation.PARAM_TYPE_EMPTY Indicates an empty value.
Automation.PARAM_TYPE_TEXT Indicates that a text value will be required.
Automation.PARAM_TYPE_INTEGER Indicates that an integer value will be required.
Automation.PARAM_TYPE_BOOLEAN Indicates that a boolean value will be required.
Automation.PARAM_TYPE_TEXTAREA Indicates that a text area value will be required.
Automation.PARAM_TYPE_CODE Indicates that a code will be required.
Automation.PARAM_TYPE_USER Indicates that a valid application user will be required.
Automation.PARAM_TYPE_ROLE Indicates that a valid application role will be required.
Automation.PARAM_TYPE_OMR Indicates that a valid OMR id - object mark recognition - will be required.
Property Description
PARAM_SOURCE_EMPTY Indicates an empty source.
PARAM_SOURCE_FOLDER Indicates that the source must be a folder.
PARAM_SOURCE_OMR Indicates that the source must be a valid OMR - object mark recognition -.

PathContains class:

package com.openkm.automation.validation;
import java.util.Map;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.api.OKMRepository;
import com.openkm.automation.AutomationUtils;
import com.openkm.automation.Validation;
import com.openkm.dao.bean.Automation;
/**
* PathContains
*
*/
@PluginImplementation
public class PathContains implements Validation {
private static Logger log = LoggerFactory.getLogger(PathContains.class);
@Override
public boolean isValid(Map<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;
}
@Override
public boolean hasPost() {
return true;
}
@Override
public boolean hasPre() {
return false;
}
@Override
public String getName() {
return "PathContains";
}
@Override
public String getParamType00() {
return Automation.PARAM_TYPE_TEXT;
}
@Override
public String getParamSrc00() {
return Automation.PARAM_SOURCE_FOLDER;
}
@Override
public String getParamDesc00() {
return "String";
}
@Override
public String getParamType01() {
return Automation.PARAM_TYPE_EMPTY;
}
@Override
public String getParamSrc01() {
return Automation.PARAM_SOURCE_EMPTY;
}
@Override
public String getParamDesc01() {
return "";
}
@Override
public String getParamType02() {
return Automation.PARAM_TYPE_EMPTY;
}
@Override
public String getParamSrc02() {
return Automation.PARAM_SOURCE_EMPTY;
}
@Override
public String getParamDesc02() {
return "";
}
}