Page 1 of 1

Adding my own automation validation

PostPosted:Tue Mar 14, 2017 7:43 am
by nelis
So i want to add my own validation in automation.
I saw something in the wiki entitled "Extend Automation 6.4" (https://www.openkm.com/wiki/index.php/E ... mation_6.4), the steps are the ff:
Step 1 - Create Class
Step 2 - Publish

Can someone help me by elaborating these steps?
How can I create my own class? Suppose I have created a class called UserHasProfile, Should I save it as .java file then compile it to create the .class file?

Re: Adding my own automation validation

PostPosted:Tue Mar 14, 2017 10:08 am
by nelis
Update:
I installed OpenKM dev and successfully generated my .class file, can i just paste it on tomcat\webapps\OpenKM\WEB-INF\classes\com\openkm\automation\validation directory of my openKM?

Re: Adding my own automation validation

PostPosted:Tue Mar 14, 2017 11:45 am
by nelis
Update 2:
Never mind, it works now. I just paste the .class file in my OpenKM directory.
BTW this is the validation I created to check the profile of the user
Code: Select all
package com.openkm.automation.validation;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.openkm.automation.AutomationUtils;
import com.openkm.automation.Validation;
import com.openkm.spring.PrincipalUtils;
import com.openkm.core.DatabaseException;
import com.openkm.dao.ProfileDAO;

public class UserHasProfile implements Validation {
	private static Logger log = LoggerFactory.getLogger(UserHasProfile.class);
	
	@Override
	public boolean isValid(HashMap<String, Object> env, Object... params) {
		String profile = AutomationUtils.getString(0, params);
		
		try {
			return hasProfile(profile);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return false;
		}
	}
	public boolean hasProfile(String profile)
	{
		try 
		{
			return ProfileDAO.findByUser(PrincipalUtils.getUser()).getName().equals(profile);
		} catch (DatabaseException e) {
			log.error(e.getMessage(), e);
			return false;
		}		
	}
}

Re: Adding my own automation validation

PostPosted:Wed Mar 15, 2017 7:25 pm
by jllort
Might be the OpenKM.war file not included the class or was not exploded when openkm started.