Web Service samples
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,firstname.lastname@example.org"
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.