Adding my own automation validation

OpenKM has many interesting features, but requires some configuration process to show its full potential.
Forum rules
Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
Post Reply
nelis
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: Tue Mar 14, 2017 7:34 am

Adding my own automation validation

Post by nelis » Tue Mar 14, 2017 7:43 am

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?

nelis
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: Tue Mar 14, 2017 7:34 am

Re: Adding my own automation validation

Post by nelis » Tue Mar 14, 2017 10:08 am

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?

nelis
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: Tue Mar 14, 2017 7:34 am

Re: Adding my own automation validation

Post by nelis » Tue Mar 14, 2017 11:45 am

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

jllort
Moderator
Moderator
Posts: 9110
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Adding my own automation validation

Post by jllort » Wed Mar 15, 2017 7:25 pm

Might be the OpenKM.war file not included the class or was not exploded when openkm started.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest