« Back to Web Services

Web Service samples

Introduction #

When initially installing Liferay in an environment without a LDAP, it often takes time to enter master data such as user and organization from Liferay's Control Panel page. In such a circumstance, it is often easier to upload a csv file in bulk from a command line. Liferay offers a web service interface to make this possible. This page will try to present an actually working program to add users and organization to Liferay v6.0.5 from a batch file. Note, that this is just a sample program written so that it would be easier to read. In actual production environment, it is recommended to modify the sample source code to make it more effiecient.

Obtaining the Sample Web Service Tools #

Sample tool to add users may be downloaded from here. Just download the file and extract it to some folder to use it.

Caution: The tool will not work with Liferay v5.x because it has a different web service interface

Using the tool #

First, the tool is written is Java so it requires Java to be installed. Second, the tool requires Liferay to be running and requires Liferay's administrative credentials (aka admin user/password).

Open up the ws-settings.properties from using a text editor and edit the username, password, host, and port fields with values from your Liferay installation. Example:

username=test
password=test
host=http://localhost
port=8080

Retrieving User Information #

If you are using Liferay's bundled download with the demo pages, try retrieving user data using the sample batch command (Linux users would have to create a .sh script): Edit the userGetSample.bat file and comment out row 3 and uncomment row 9.

echo off
rem get user information by screen name
rem userGet.bat -output users.csv -type screen -value "10131,test"

rem get user information by userid
rem userGet.bat -output users.csv -type userid -value 10134

rem get user information by email
userGet.bat -output users.csv -type email -value "10131,test@liferay.com"

Executing this script will create a csv file users.csv in the local folder. This file should contain user data for the test user if the program was able to connect properly to Liferay. If there was an error, it should display in the console.

Adding User Information #

To bulk add users, create a csv file with user information. The tools uses format matching Liferay's web service interface which unfortunately has different interface format for getting user information and adding user information. The format used to add users is provided in the data\Template folder - usersTemplate.xls. A sample of a csv file is provided in the \data folder. Fill out the necessary information for each user to add. Edit the usersImport.bat file to point to the csv file.

java jp.co.ogis.liferay.util.UsersImport data\users.csv

Execute this batch file and users will be added with information provided in the csv file with other default settings provided in the portal.properties and portal-ext.properties files. Login as an administrator to check if users have been added.

2 Attachments
6719 Views
Average (3 Votes)
Comments

Showing 8 Comments

Tetsuya Zama
7/19/11 11:16 PM

Thank you for great information and sample codes!
This is that I've been looking for.

Shripad Bharde
10/4/11 2:07 AM

hi ,

I am trying to add bulk users in liferay using web service 'liferay-wstools_20110119' (http://www.liferay.com/community/wiki/-/wiki/Main/Web+Service+samples)
but when I try to load users with already present users.csv I get exception


Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateCo­nverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)­
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(Abstract­FlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListe­ner.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at com.liferay.portal.dao.orm.hibernate.SessionImpl.flush(SessionImpl.java:108)
... 92 more
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xE3\x82\x88\xE3\x81\x86...' for column 'greeting' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:125­7)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPrepared­Statement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 98 more


is there any problem in given sample user.csv or do you have sample user.csv which can add users using web service .



Thanks & Regards ,

Shripad Bharde

Ivano Carrara
10/24/11 2:35 PM

Hi,

The link to the sample code under "Obtaining the Sample Web Service Tool" is broken ...

Ken Barron
12/20/11 5:05 AM

The sample code is also available as an attachment to this article.

Ken Barron
12/20/11 6:48 AM

Thanks very much for making this available! Saved me a day of coding, exactly what I need.
P.S. one tip, make sure you have tunnel-web installed as a webapp otherwise the servcice calls will not work.

Iseng Dong
4/25/12 3:27 AM

help.... it doesn't work in my laptop.

I've tried at Liferay 6.1. I could see the process that the datas are being moved. But, when I took a look at user and organization menu and also in my mysql, there was nothing. It is still the default data.

and, I also have tried in Liferay 6.0. In the process, it says "skipped". The system skipped all of the row.

what should I do? thanks in advance emoticon

iq6rb iq6rb
5/19/12 12:31 AM

Michael Bowers
http://www.iq6rb.com
http://www.iq6rb.com/vb/forumdisplay.php?f=204
http://w­ww.iq6rb.com/vb/forumdispl­ay.php?f=207
http://www.iq6rb.com/vb/forumdisplay.php?­f=208
http://www.iq6rb.com/vb/forumdisplay.php?f=123
http://www.iq6rb.com/vb/showthread­.php?t=43712
http://www.iq6rb.com/vb/showthread.php?t=43719

iq6rb iq6rb
5/19/12 12:31 AM

Michael Bowers
http://www.iq6rb.com
http://www.iq6rb.com/vb/forumdisplay.php?f=204
http://w­ww.iq6rb.com/vb/forumdispl­ay.php?f=207
http://www.iq6rb.com/vb/forumdisplay.php?­f=208
http://www.iq6rb.com/vb/forumdisplay.php?f=123
http://www.iq6rb.com/vb/showthread­.php?t=43712
http://www.iq6rb.com/vb/showthread.php?t=43719