• Bulk Import of users - 6.3.2 Community

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
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.
 #42621  by wwbarn007
 
I'm new to OpenKM so just trying to work out how best to do things. I have a requirement to bulk upload users into OpenKM version 6.3.2 with Community Extension - the build number is 8289. The user details are in a CSV file and I found a previous post https://forum.openkm.com/viewtopic.php?t=5186 which suggests that the correct way to do it is by using the OKMAuth method 'createUser' but it seems that it doesn't exist in OKMAuth in the Community version. I did use the CSV_importer script mentioned in that post as a template to read my CSV file in, but when i tried to call OKMAuth.getInstance().createUser i get the message "Method createUser() not found in class'com.openkm.api.OKMAuth' ". I could use SQL to insert my users directly into the database but can't see a way of doing this whilst recursively reading the CSV file. Is there a method I can call from scripting to execute an SQL statement i construct within the script? Alternatively, has anyone a solution to the bulk adding of a user from a CSV file that doesn't use the createUser method?

Thanks in advance for any assistance.
 #42638  by jllort
 
It's a punctual problem - now - or this is a periodical one and you will need to create users periodically ?
 #42642  by wwbarn007
 
Effectively just the once as it will be an initial load. We have a potential user community of 600+ and don't want to have to add them all manually. Because we were having issues with the CreateUser method I've written a little VB to take my CSV and create SQL insert statements for OKM_USER and OKM_USER_ROLE which I can then paste into the SQL query feature. I haven't run it for the 600+ users yet, but it does seem to work OK. I would like to understand what the preferred method of bulk user load is though, so I'd appreciate your comments/advice.
 #42648  by jllort
 
In your case I suggest scripting ( Administration > Scripting feature ).
Set all your user data in a xls and transform the rows for getting a string like this:
Code: Select all
import com.openkm.api.*;
OKMAuth.getInstance().createUser(null, "User ID", "password", "electronic mail", "User name", true);
OKMAuth.getInstance().createUser(null, "User ID", "password", "electronic mail", "User name", true);
etc...
Create and xls for roles
Code: Select all
import com.openkm.api.*;
OKMAuth.getInstance().createRole(null, "Role name", true);
OKMAuth.getInstance().createRole(null, "Role name", true);
etc...

Also create an xls for user roles, remember the users must have - at least - one of these roles "ROLE_USER" or "ROLE_ADMIN"
Code: Select all
import com.openkm.api.*;
OKMAuth.getInstance().assignRole(null, "User ID", "Role name");
OKMAuth.getInstance().assignRole(null, "User ID", "Role name");
etc...
 #42657  by wwbarn007
 
Thanks for the response. I did try to use the 'creatUser' method as you suggest, but got a error message saying 'Error in method invocation: Method createUser(null, java.lang.String, java.lang.String, java.lang.String, java.lang.String, int) not found in class'com.openkm.api.OKMAuth'

I think I'm getting this because I'm using the Community version. The code I was playing around with is as follows:-
Code: Select all
import java.io.FileReader;
import java.io.Reader;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
 
import com.googlecode.jcsv.CSVStrategy;
import com.googlecode.jcsv.reader.CSVReader;
import com.googlecode.jcsv.reader.internal.CSVReaderBuilder;
import com.googlecode.jcsv.reader.internal.DefaultCSVEntryParser;
 
import com.openkm.bean.QueryResult;
import com.openkm.api.*;
import com.openkm.util.FileLogger;
import com.openkm.util.PathUtils;
 
String INPUT_PATH = "/home/test/";
String INPUT_FILE_NAME = "users.csv";
int usid = 0;
int psswd = 1;
int em = 2;
int uname = 3;
 
// Format defintion
char delimiter = ',';
char quoteCharacter = '"';
char commentIndicator = '#';
boolean skipHeader = false;
boolean ignoreEmptyLines = true;
CSVStrategy strategy = new CSVStrategy(delimiter, quoteCharacter, commentIndicator, skipHeader, ignoreEmptyLines);

// File reader
Reader reader = new FileReader(INPUT_PATH + INPUT_FILE_NAME);

// CSV reader		
CSVReader csvParser = new CSVReaderBuilder(reader).strategy(strategy).entryParser(new DefaultCSVEntryParser()).build();
List data = csvParser.readAll();
int count = 0;
 
for (Iterator it = data.listIterator(); it.hasNext();) {
	String[] row = (String[]) it.next();
	String s_usid = '"' + row[usid] + '"';
	String s_psswd = '"' + row[psswd] + '"';
	String s_em = '"' + row[em] + '"';
	String s_uname = '"' + row[uname] + '"';
	count++;
	print ("User ID = " + s_usid + "</br>");
	print ("Password = " + s_psswd + "</br>");
	print ("Email Address = " + s_em + "</br>");
	print ("User name = " + s_uname + "</br>");
	OKMAuth.getInstance().createUser(null,s_usid, s_psswd ,s_em,s_uname,true);
}
 
print("Total:" + count + "</br>");
Regardless of the above, I think I'm going to use my VB script to generate the SQL to insert the users and assign their roles. I tested with 600 users and it works fine and is pretty quick. Using VB also gives me the ability to construct and send out email notifications to the users with their user_id and password details. If anyone is interested I can post the code for that too, but it's pretty straightforward.
 #42671  by jllort
 
The method ends with boolean not int. I do not know if it's your problem, you get this error.
Code: Select all
createUser(null, java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)
I have checked in the source code and also in the javadoc https://docs.openkm.com/apidoc/com/okm/ ... MAuth.html

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.