Difference between revisions of "Extend automation 6.0"

From OpenKM Documentation
Jump to: navigation, search
Line 11: Line 11:
 
 
 
boolean isValid(HashMap<String, Object> env, Object... params);
 
boolean isValid(HashMap<String, Object> env, Object... params);
 +
}
 +
</source>
 +
 +
* Refer to AutomationUtils class to get variables from HashMap<String, Object> env, take a look at the latest doxygen class reference at [[Developer_Guide]].
 +
* Values set at validator form are stored to String params[].
 +
 +
<source lang="java">
 +
public class PathContains implements Validation {
 +
private static Logger log = LoggerFactory.getLogger(PathContains.class);
 +
 +
@Override
 +
public boolean isValid(HashMap<String, Object> env, Object... params) {
 +
String path = AutomationUtils.getString(0, params);
 +
String parentPath = AutomationUtils.getParentPath(env);
 +
 +
try {
 +
if (parentPath.startsWith(path)) {
 +
return true;
 +
} else {
 +
return false;
 +
}
 +
} catch (Exception e) {
 +
log.error(e.getMessage(), e);
 +
}
 +
 +
return false;
 +
}
 
}
 
}
 
</source>
 
</source>

Revision as of 21:12, 1 November 2012

Refer to Enable automation section to know how enable automation. By default automation is not enabled.

Refer to Automation section to configure automation rules in your OpenKM and get full explanation of available validators and actions.

Create a new validator

Any validator should implements interface Validation:

public interface Validation {
	public static final String METHOD = "isValid";
	
	boolean isValid(HashMap<String, Object> env, Object... params);
}
  • Refer to AutomationUtils class to get variables from HashMap<String, Object> env, take a look at the latest doxygen class reference at Developer_Guide.
  • Values set at validator form are stored to String params[].
public class PathContains implements Validation {
	private static Logger log = LoggerFactory.getLogger(PathContains.class);
	
	@Override
	public boolean isValid(HashMap<String, Object> env, Object... params) {
		String path = AutomationUtils.getString(0, params);
		String parentPath = AutomationUtils.getParentPath(env);
		
		try {
			if (parentPath.startsWith(path)) {
				return true;
			} else {
			 return false;
			}
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		
		return false;
	}
}