« 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 the attachment to this page. 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.

3 添付ファイル
56072 参照数
平均 (3 投票)
平均評価は5.0星中の5です。
コメント
コメント 作成者 日時
Thank you for great information and sample... Tetsuya Zama 2011/07/19 23:16
hi , I am trying to add bulk users in liferay... Shripad Bharde 2011/10/04 2:07
Hi, The link to the sample code under... Ivano Carrara 2011/10/24 14:35
The sample code is also available as an... Ken Barron 2011/12/20 5:05
Thanks very much for making this available! ... Ken Barron 2011/12/20 6:48
help.... it doesn't work in my laptop. I've... Iseng Dong 2012/04/25 3:27
did you finally get the answers to your... austen xia 2013/07/05 1:35
Hi i do get the same error ... sandeep tripathi 2012/05/28 2:23
I want to create similar web service to... urman parikh 2012/08/08 2:05
Hi.. Thanks for this useful tool.. I have tried... Jo Cern 2013/10/14 16:01
Hi, Some time ago I wrote an article for import... Antonio Musarra 2014/04/16 15:01

Thank you for great information and sample codes!
This is that I've been looking for.
投稿日時:11/07/19 23:16
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
投稿日時:11/10/04 2:07
Hi,

The link to the sample code under "Obtaining the Sample Web Service Tool" is broken ...
投稿日時:11/10/24 14:35
The sample code is also available as an attachment to this article.
Ivano Carraraへのコメント。投稿日時:11/12/20 5:05
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.
投稿日時:11/12/20 6:48
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
投稿日時:12/04/25 3:27
Hi
i do get the same error
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
is there any other setting which we need to do .
thanks and regards
Sandeep
投稿日時:12/05/28 2:23
I want to create similar web service to associate site template to public/private pages to an organization when organization is added.

So when i add organization it's site should be created and its public/private page should have site templete.

can any one help.
投稿日時:12/08/08 2:05
did you finally get the answers to your question? I got the same error
Iseng Dongへのコメント。投稿日時:13/07/05 1:35
Hi..
Thanks for this useful tool..
I have tried to get it to work (user import) with the 6.2s interface by editing the UserInfo.java and UserImport. java accordingly.. no luck so far get the user table updated but with a message unknown element when running the BAT file.. in the logs on the server I have this error
17:48:31,744 ERROR [http-bio-8080-exec-4][UserServiceSoap:92] com.liferay.portal.DuplicateUserEmailAddressException
edited userimport.java with >> UserSoap usoap= soap.addUser(userInfo.getcompanyId(),userInfo.getAutoPassword(),userInfo.getPass­word1(),userInfo.getPassword2(),userInfo.getAutoScreenName(),userInfo.getScreenN­ame(),userInfo.getEmailAddress(),userInfo.getFacebookId(),userInfo.getOpenId(),u­serInfo.getLocale(),userInfo.getFirstName(),userInfo.getMiddleName(),userInfo.ge­tLastName(),userInfo.getPrefixId(),userInfo.getSuffixId(),userInfo.getMale(),use­rInfo.getBirthdayMonth(),userInfo.getBirthdayDay(),userInfo.getBirthdayYear(),us­erInfo.getJobTitle(),userInfo.getGroupIds(),userInfo.getOrganizationIds(),userIn­fo.getRoleIds(),userInfo.getUserGroupIds(),userInfo.getSendEmail(),serviceContex­t);

And also the UserInfo.java with the corresponding values... I am obviously missing something... a little help or hint in the right direction would be much appreciated..
Cheers
投稿日時:13/10/14 16:01
Hi,
Some time ago I wrote an article for import users from an excel sheet using web services liferay. http://www.dontesta.it/blog/blog-2/cms/liferay/liferay-web-services-come-importa­re-utenti/ The source repository at https://github.com/amusarra/ImportUsersLiferayViaWS

Bye,
Antonio.
投稿日時:14/04/16 15:01