Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
creating new user via API Marian Rosko 3 de abril de 2009 5:50
RE: creating new user via API Luc Pons 20 de mayo de 2009 0:51
RE: creating new user via API Ahmed Hasan 20 de mayo de 2009 4:22
RE: creating new user via API Ayaz Pasha 20 de mayo de 2009 5:11
RE: creating new user via API Ayaz Pasha 20 de mayo de 2009 5:35
RE: creating new user via API Juan M. Gomez 24 de junio de 2009 10:42
RE: creating new user via API Amos Fong 24 de junio de 2009 10:46
RE: creating new user via API Juan M. Gomez 24 de junio de 2009 15:04
RE: creating new user via API Amos Fong 10 de septiembre de 2009 15:43
RE: creating new user via API Anónimo 23 de noviembre de 2009 7:06
RE: creating new user via API Man V K 9 de diciembre de 2009 0:49
RE: creating new user via API Shankar Baba 30 de marzo de 2013 4:13
RE: creating new user via API li guicheng 9 de agosto de 2010 18:10
RE: creating new user via API Suresh Chinna Pillai 14 de febrero de 2011 0:55
RE: creating new user via API Siddhartha Bera 15 de febrero de 2011 11:21
RE: creating new user via API Suresh Chinna Pillai 16 de febrero de 2011 7:45
RE: creating new user via API RathnaDevi Chellaiah 2 de abril de 2012 2:51
RE: creating new user via API leo Hudson 22 de enero de 2014 5:31
RE: creating new user via API RathnaDevi Chellaiah 30 de marzo de 2012 6:50
RE: creating new user via API David H Nebinger 30 de marzo de 2012 7:08
RE: creating new user via API piyush liferay 31 de enero de 2013 5:50
RE: creating new user via API Shankar Baba 28 de marzo de 2013 4:28
RE: creating new user via API Pepe Laberta 5 de noviembre de 2010 8:04
RE: creating new user via API Rajesh Chaurasia 2 de abril de 2012 9:19
RE: creating new user via API Rajesh Chaurasia 2 de abril de 2012 9:24
RE: creating new user via API saritha reddy 30 de junio de 2014 4:54
RE: creating new user via API David H Nebinger 30 de junio de 2014 5:28
Marian Rosko
creating new user via API
3 de abril de 2009 5:50
Respuesta

Marian Rosko

Ranking: New Member

Mensajes: 1

Fecha de incorporación: 3 de abril de 2009

Mensajes recientes

Hello everybody,

I am trying to create a new user via liferay API. The only way how I could create a user who was able to log in into the portal, was to repeat the steps form the create.sql script.

1) creating a new user: User user = UserLocalServiceUtil.createUser(userId);
2) setting properties for this user (password, companyId, screenName, active,.... )
3) creating corresponding contact: Contact contact = ContactLocalServiceUtil.createContact(contactId);
4) setting contact's properties (userId, accountId,...)
5) adding user: UserLocalServiceUtil.addUser(user);
6) adding contact: ContactLocalServiceUtil.addContact(contact);
7) adding user to the group: UserUtil.addGroups(userId, grpIds);
8) adding user to the organization: UserUtil.addOrganizations(userId, orgIds);
9) adding user roles: UserUtil.addRoles(id, roleIds);
10)creating group: GroupLocalServiceUtil.createGroup(groupId);
11)setting properties for the group
12)creating layout sets: LayoutSetLocalServiceUtil.createLayoutSet(layoutId);
13)setting propeties for the sets
14)adding group : GroupLocalServiceUtil.addGroup(group);
15)adding layout sets: LayoutSetLocalServiceUtil.addLayoutSet(ls1);

Isnt there a simpler solution which creates a liferay user with all (default) required dependecies/roles/groups?

Thanks in advance,
Marian
Luc Pons
RE: creating new user via API
20 de mayo de 2009 0:51
Respuesta

Luc Pons

Ranking: Junior Member

Mensajes: 70

Fecha de incorporación: 3 de diciembre de 2008

Mensajes recientes

Here is a method i wrote :


 1public static User addUser(String firstName, String lastName, String email, String password, String screenName) throws CantAddUserException {
 2        try {
 3            
 4
 5            long[] emptyLong = {};
 6            User user = UserLocalServiceUtil.addUser(
 7                    new Long(Constants.ADMIN_ID) /*long creatorUserId*/,
 8                    Constants.COMP_ID /*long companyId*/,
 9                    false /*boolean autoPassword*/,
10                    password /*String password1*/,
11                    password /*String password2*/,
12                    false /*boolean autoScreenName*/,
13                    screenName /* String screenName*/,
14                    email /*String emailAddress*/,
15                    new Locale("fr") /*Locale locale*/,
16                    firstName /*String firstName*/,
17                    null /*String middleName*/,
18                    lastName /*String lastName*/,
19                    0/*int prefixId*/,
20                    0 /*int suffixId*/,
21                    false /*boolean male*/,
22                    1 /*int birthdayMonth*/,
23                    1 /*int birthdayDay*/,
24                    2000 /*int birthdayYear*/,
25                    null /*String jobTitle*/,
26                    emptyLong /*long[] organizationIds*/,
27                    false /*boolean sendEmail*/);
28
29            return user;
30
31        } catch (Exception e) {
32            throw new CantAddUserException(e);
33        }
34    }
Ahmed Hasan
RE: creating new user via API
20 de mayo de 2009 4:22
Respuesta

Ahmed Hasan

Ranking: Expert

Mensajes: 306

Fecha de incorporación: 13 de abril de 2007

Mensajes recientes

Yes, this is the right approach to create a new user using the local service api.

For the unique userId you have to get it as below.

long userId = CounterLocalServiceUtil.increment();

The rest of the code is fine.

For any help feel free to contact me,

Ahmed Hasan
CTO, TransIT mPower Labs (P) Ltd.
info@mpowerglobal.com
mPower Global Inc.
A Liferay expert company.
Ayaz Pasha
RE: creating new user via API
20 de mayo de 2009 5:11
Respuesta

Ayaz Pasha

Ranking: Junior Member

Mensajes: 78

Fecha de incorporación: 1 de agosto de 2008

Mensajes recientes

I have a doubt, is it mandatory to pass the organizationIds as a value? Can it be an empty long[ ]? In short, is it necessary to have an Organization prior to create new user via API? But I can find that a new user can be created manually though he doesn't belong to any organization.

Hope what I am asking is clear?

Thanks !
Ayaz Pasha
RE: creating new user via API
20 de mayo de 2009 5:35
Respuesta

Ayaz Pasha

Ranking: Junior Member

Mensajes: 78

Fecha de incorporación: 1 de agosto de 2008

Mensajes recientes

The response for my previous query is yes we can create user via API by passing all the ids(such as groupIds, organizationIds, roleIds, userGroupIds) as an empty long [ ] untill it requires.
Juan M. Gomez
RE: creating new user via API
24 de junio de 2009 10:42
Respuesta

Juan M. Gomez

Ranking: Junior Member

Mensajes: 69

Fecha de incorporación: 7 de noviembre de 2007

Mensajes recientes

Hello, i have been able to create a new User using the following code..
 1long userId = CounterLocalServiceUtil.increment();
 2            User userToCreate = UserUtil.create(userId);
 3            userToCreate.setFirstName(firstName);
 4            userToCreate.setLastName(lastName);
 5            userToCreate.setEmailAddress(email);
 6            userToCreate.setPassword(password);
 7            userToCreate.setScreenName(screenName);
 8            userToCreate.setActive(true);
 9            userToCreate.setCreateDate(new Date());
10            userToCreate.setGreeting("Hi " + screenName);
11            userToCreate.setJobTitle(job_title);
12            userToCreate.setLanguageId(languageId);
13            userToCreate.setMiddleName(middleName);
14
15            User createdUser = UserLocalServiceUtil.addUser(userToCreate);


The user is persisted on liferay database with all the data i have passed.. but I still cannot login with it, and the User doesn't appear on the Users admin list. What is missing or what am I doing wrong?

I'm using Liferay 5.2.3.

Thanks in advance,
Juan M. Gomez



EDIT: The same happens with organizations.. i successfully create both the organization and the related group from the API, but i can't use them from the Portal.
Amos Fong
RE: creating new user via API
24 de junio de 2009 10:46
Respuesta

Amos Fong

LIFERAY STAFF

Ranking: Liferay Legend

Mensajes: 1855

Fecha de incorporación: 7 de octubre de 2008

Mensajes recientes

Hi Juan,

Try calling this afterward:

1        try {
2            UserIndexer.updateUser(user);
3        }
4        catch (SearchException se) {
5            _log.error("Indexing " + userId, se);
6        }
Juan M. Gomez
RE: creating new user via API
24 de junio de 2009 15:04
Respuesta

Juan M. Gomez

Ranking: Junior Member

Mensajes: 69

Fecha de incorporación: 7 de noviembre de 2007

Mensajes recientes

Hi Amos,

I had to import the portal-impl.jar into my project to use that method.. but after that everything worked perfectly.
Thank you.

Is there any similar method for Organizations??
Thanks again.


Juan M. Gomez
Amos Fong
RE: creating new user via API
10 de septiembre de 2009 15:43
Respuesta

Amos Fong

LIFERAY STAFF

Ranking: Liferay Legend

Mensajes: 1855

Fecha de incorporación: 7 de octubre de 2008

Mensajes recientes

Juan,

Sorry for late response, organizations are not indexed so no.
Anónimo
RE: creating new user via API
23 de noviembre de 2009 7:06
Respuesta

Anónimo

I did:

long userId = CounterLocalServiceUtil.increment();
System.out.println(userId);

and I got some error. Someone could tell me what I did wrong do?

java.lang.NullPointerException
at com.liferay.counter.service.CounterLocalServiceUtil.increment(CounterLocalServiceUtil.java:42)
Man V K
RE: creating new user via API
9 de diciembre de 2009 0:49
Respuesta

Man V K

Ranking: Regular Member

Mensajes: 139

Fecha de incorporación: 4 de diciembre de 2007

Mensajes recientes

Hi,

I have created the user using the above code, it works fine, I checked the user table, it created the record. but i tried to enter with that user id and password but always get an error like this "You have entered invalid data. Please try again."

Any suggession please.

thanks
Vin
li guicheng
RE: creating new user via API
9 de agosto de 2010 18:10
Respuesta

li guicheng

Ranking: Junior Member

Mensajes: 25

Fecha de incorporación: 28 de marzo de 2010

Mensajes recientes

Anonymous:
I did:

long userId = CounterLocalServiceUtil.increment();
System.out.println(userId);

and I got some error. Someone could tell me what I did wrong do?

java.lang.NullPointerException
at com.liferay.counter.service.CounterLocalServiceUtil.increment(CounterLocalServiceUtil.java:42)


Could you tell me the solution if you get it through?
thank you

li_guicheng@hotmail.com
Pepe Laberta
RE: creating new user via API
5 de noviembre de 2010 8:04
Respuesta

Pepe Laberta

Ranking: New Member

Mensajes: 7

Fecha de incorporación: 12 de mayo de 2010

Mensajes recientes

Hi, I have Liferay 5.2.3 and I have tried the following code (firstly in the doView method directly to test it). Its deploys without errors but when I launch the portlet it throws the following error:

com.liferay.portal.kernel.dao.orm.ormexception: could not execute jdbc batch update


long userId = CounterLocalServiceUtil.increment();
User userToCreate = UserUtil.create(userId);

userToCreate.setFirstName("Test Name");
userToCreate.setLastName("Test Last Name");
userToCreate.setEmailAddress("test@liferay.com");
userToCreate.setPassword("password");
userToCreate.setScreenName("Test Name");
userToCreate.setActive(true);
userToCreate.setCreateDate(new Date());
userToCreate.setGreeting("Hi Test Name");
userToCreate.setJobTitle("Job Test");
userToCreate.setLanguageId("en_US");
userToCreate.setMiddleName("Test");

User createdUser = UserLocalServiceUtil.addUser(userToCreate);

try {
UserIndexer.updateUser(createdUser);
}
catch (SearchException se) {
_log.error("Indexing " + userId, se);
}


What can I do to solve the problem?

Also, I am not sure if the installed liferay is using HSQL or MySQL. I have MySQL installed but I have not modified portal-ext.properties (I havent got it in the tomcat folder and I have not modified portal-imp.jar).

Thanks a lot.
Suresh Chinna Pillai
RE: creating new user via API
14 de febrero de 2011 0:55
Respuesta

Suresh Chinna Pillai

Ranking: New Member

Mensajes: 16

Fecha de incorporación: 13 de febrero de 2011

Mensajes recientes

Hi,
I am new to Liferay environment.I am creating a User management in Liferay with the API. but it throws the following Exception.
06:59:22,671 ERROR [JDBCExceptionReporter:101] ORA-00001: unique constraint (EBMS.IX_5ADBE171) violated

com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update



That constraint was set to the contactId of the User_ table.I created a contact of my own(manually)
and then executed the application the new user was added to the database.
1) The Process of creating the contactId of our own is good(or)not.If this process is bad.How can we overcome this problem?

and the user details was not displayed in the User list page of Liferay.As you mentioned in this forum append the following code.
1
2try {
32            UserIndexer.updateUser(user);
43        }
54        catch (SearchException se) {
65            _log.error("Indexing " + userId, se);
76        }

and we have to import the import "portal-impl.jar". I imported that jar.then it shows the error that "the method updateUser(User) is undefined for the type UserIndexer".How can I solve this one..?Where can I get the correct jar file..?
Pls help me..
I am Using Liferay 6.0.5 bundled with Tomcat.
Siddhartha Bera
RE: creating new user via API
15 de febrero de 2011 11:21
Respuesta

Siddhartha Bera

Ranking: New Member

Mensajes: 2

Fecha de incorporación: 4 de febrero de 2011

Mensajes recientes

IndexerRegistryUtil.register(new UserIndexer()); - In Liferay 6.0.5



You can do others too ....

IndexerRegistryUtil.register(new BookmarksIndexer());
IndexerRegistryUtil.register(new DLIndexer());
IndexerRegistryUtil.register(new IGIndexer());
IndexerRegistryUtil.register(new MBIndexer());
IndexerRegistryUtil.register(new AssetIndexer());
IndexerRegistryUtil.register(new JournalIndexer());
Suresh Chinna Pillai
RE: creating new user via API
16 de febrero de 2011 7:45
Respuesta

Suresh Chinna Pillai

Ranking: New Member

Mensajes: 16

Fecha de incorporación: 13 de febrero de 2011

Mensajes recientes

Hi friend,
Thank you for your quick reply. I found the solution for this issue. I use "UserLocalServiceUtil.addUser(long creatorUserId, long companyId, boolean autoPassword,
String password1, String password2, boolean autoScreenName,
String screenName, String emailAddress, long facebookId, String openId,
Locale locale, String firstName, String middleName, String lastName,
int prefixId, int suffixId, boolean male, int birthdayMonth,
int birthdayDay, int birthdayYear, String jobTitle, long[] groupIds,
long[] organizationIds, long[] roleIds, long[] userGroupIds,
boolean sendEmail, ServiceContext serviceContext)"
method.

It works fine.

Can you have any idea about how to add the user to a group..?

Thanks in advance..

-Suresh.
RathnaDevi Chellaiah
RE: creating new user via API
30 de marzo de 2012 6:50
Respuesta

RathnaDevi Chellaiah

Ranking: Junior Member

Mensajes: 29

Fecha de incorporación: 26 de marzo de 2012

Mensajes recientes

hi
i need ur help....am facing an issue regarding the creation of user using user form data.. my scenario is i have to create a registration form that is used by service builder and based on that it stores the value into db(lportel).. at the same time the value in the form should create a user into the liferay user table.
i have achieved upto storing of db.. but facing issue with creating user.. the form data is not fetched and stored into the predefined attributes of userlocalservice..


public void processAction(ActionRequest request,ActionResponse response) {

try {
long userId=CounterLocalServiceUtil.increment();
User user=UserLocalServiceUtil.createUser(userId);
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long creatorId=0;
long companyId = themeDisplay.getCompanyId();
user.setCompanyId(companyId);
boolean autoPassword = true;

String password1 = "";
user.setPassword(password1);
String password2 = "";
user.setPassword(password2);
boolean autoScreenName = true;
String screenName = "MyProfile1";
user.setScreenName(screenName);
String compemail = request.getParameter("cemail");// from the view.jsp page

user.setEmailAddress(compemail);
long facebookId = 0;
user.setFacebookId(facebookId);
String openId = "";
user.setOpenId(openId);
// Locale locale = themeDisplay.getLocale();
String firstName = request.getParameter("fname");// from the view.jsp page
user.setActive(true);
user.setFirstName(firstName);

String middleName = "";
String lastName = request.getParameter("lname");// from the view.jsp page
user.setLastName(lastName);
int prefixId = 0;
int suffixId = 0;
boolean male = true;
int birthdayMonth = 0;
int birthdayDay = 0;
int birthdayYear = 0;
String designation =request.getParameter("designation");// from the view.jsp page
user.setJobTitle(designation);
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
long[] userGroupIds = null;

boolean sendEmail = true;

com.liferay.portal.service.ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), request);

UserLocalServiceUtil.addUser(creatorId,
themeDisplay.getCompanyId(), autoPassword, password1, password2,
autoScreenName, screenName, compemail, facebookId, openId,
LocaleUtil.getDefault(), firstName, middleName, lastName, prefixId,
suffixId, male, birthdayMonth, birthdayDay, birthdayYear, designation,
groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
serviceContext);

}
catch(Exception e){
e.printStackTrace();
}
}
i have tried many code posted in forum but nothing worked.......... please give me guide on this issue..
David H Nebinger
RE: creating new user via API
30 de marzo de 2012 7:08
Respuesta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensajes: 9424

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

Do not post the same thing in multiple threads. I've posted a response here: http://www.liferay.com/community/forums/-/message_boards/message/13199278
RathnaDevi Chellaiah
RE: creating new user via API
2 de abril de 2012 2:51
Respuesta

RathnaDevi Chellaiah

Ranking: Junior Member

Mensajes: 29

Fecha de incorporación: 26 de marzo de 2012

Mensajes recientes

hi Suresh,
can u share ur code.. am unable to create user inthe user_ table..
Rajesh Chaurasia
RE: creating new user via API
2 de abril de 2012 9:19
Respuesta

Rajesh Chaurasia

Ranking: Junior Member

Mensajes: 98

Fecha de incorporación: 18 de agosto de 2011

Mensajes recientes

I have a scenarion similar to yours but with a difference .I create users when I am creating organisation .we have a use case where some default users be created with certain set of roles when we are trying to create organisation .
As you might be aware that certain entities like orgaisation , user ,etc have model listeners attached to them so that when we create a successful insert in one of these ,simultaneous entries go in associated model listeners.And this is the way liferay behaves.For your custom insert into a liferay db you may be able to insert a user in user_ table but you will not be able to use that user or at least refer to that user unless simulatneos insert sre being made in associated model listeners for user.

I am attaching a create user method that I used in my use case.Hope this answers your query to a certain extent:
private User insertOrgPublisher(ActionRequest actionRequest,Organization organization,ServiceContext serviceContext) throws PortalException, SystemException {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
long groupId= themeDisplay.getLayout().getGroupId();
String password1= "orgpub";//organization.getName().toLowerCase();
String domainName = null;
long facebookId=0;
String openId=null;
String firstName=organization.getName();
String lastName=organization.getName();
int prefixId=123;
int suffixId=234;
String jobTitle="Organization Publisher";
domainName = organization.getName();
domainName= domainName.trim();
if(domainName.contains(" ")) {
domainName = domainName.replaceAll("\\s+", "-");
}
String emailAddress="publisher@"+domainName+".com";
Role role = RoleLocalServiceUtil.getRole(companyId, "Organization Publisher");
User user = null;
if(role != null){
String greeting="Welcome "+role.getName();
long id = CounterLocalServiceUtil.increment(User.class.getName());
user = UserLocalServiceUtil.createUser(id);
user.setCompanyId(companyId);
user.setPassword(password1);
String screenName=organization.getName().toLowerCase()+id;
user.setScreenName(screenName);
user.setGreeting(greeting);
user.setEmailAddress(emailAddress);
user.setFacebookId(facebookId);
user.setOpenId(openId);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setJobTitle(jobTitle);
user.setCreateDate(new Date ());
user.setContactId(id+1);
user.setPasswordReset(true);
user.setPasswordModifiedDate(new Date());
user.setCreateDate(new Date());
user.setModifiedDate(new Date());
user.setLanguageId(themeDisplay.getLanguageId());
user.setTimeZoneId(themeDisplay.getTimeZone().getDisplayName());
UserLocalServiceUtil.addUser(user);

//Associate a role with user
long userid[] = {user.getUserId()};
//UserLocalServiceUtil.addRoleUsers(role.getRoleId(), userid);
long roleids[]={role.getRoleId()};
UserGroupRoleLocalServiceUtil.addUserGroupRoles(user.getUserId(), groupId, roleids);
ClassName clsNameUser = ClassNameLocalServiceUtil.getClassName("com.liferay.portal.model.User");
long classNameId=clsNameUser.getClassNameId();

//Insert Group for a user
long gpId = CounterLocalServiceUtil.increment(Group.class.getName());
Group userGrp = GroupLocalServiceUtil.createGroup(gpId);
userGrp.setClassNameId(classNameId);
userGrp.setClassPK(userid[0]);
userGrp.setCompanyId(companyId);
userGrp.setName("group"+String.valueOf(userid[0]));
userGrp.setFriendlyURL("/group"+gpId);
userGrp.setCreatorUserId(PortalUtil.getUserId(actionRequest));
userGrp.setActive(true);
GroupLocalServiceUtil.addGroup(userGrp);

//Insert Contact for a user
long idContact = user.getUserId() + 1;//CounterLocalServiceUtil.increment(Contact.class.getName());
Contact contact = ContactLocalServiceUtil.createContact(idContact);
contact.setCompanyId(companyId);
contact.setCreateDate(new Date());
contact.setUserName(screenName);
contact.setUserId(user.getUserId());
contact.setModifiedDate(new Date());
contact.setFirstName("contact-"+contact.getContactId());
contact.setLastName("contact-"+contact.getContactId());
contact.setMiddleName("contact-"+contact.getContactId());
contact.setPrefixId(prefixId);
contact.setBirthday(new Date());
contact.setSuffixId(suffixId);
contact.setJobTitle(jobTitle+contact.getContactId());
ContactLocalServiceUtil.addContact(contact);

//Create AssetEntry
long assetEntryId = user.getUserId()+5;//CounterLocalServiceUtil.increment(AssetEntry.class.getName());
AssetEntry ae = AssetEntryLocalServiceUtil.createAssetEntry(assetEntryId);
ae.setCompanyId(companyId);
ae.setClassPK(user.getUserId());
ae.setGroupId(userGrp.getGroupId());
ae.setClassNameId(classNameId);
AssetEntryLocalServiceUtil.addAssetEntry(ae);

//Insert ResourcePermission for a User
long resPermId = CounterLocalServiceUtil.increment(ResourcePermission.class.getName());
ResourcePermission rpEntry = ResourcePermissionLocalServiceUtil.createResourcePermission(resPermId);
rpEntry.setCompanyId(organization.getCompanyId());
rpEntry.setName("com.liferay.portal.model.User");
rpEntry.setRoleId(role.getRoleId());
rpEntry.setScope(4);
ResourcePermissionLocalServiceUtil.addResourcePermission(rpEntry);

//Insert Layoutset for public and private
long layoutSetIdPub = CounterLocalServiceUtil.increment(LayoutSet.class.getName());
LayoutSet layoutSetPub=LayoutSetLocalServiceUtil.createLayoutSet(layoutSetIdPub);
layoutSetPub.setCompanyId(companyId);
layoutSetPub.setPrivateLayout(false);
layoutSetPub.setGroupId(userGrp.getGroupId());
layoutSetPub.setThemeId("classic");
try{
LayoutSetLocalServiceUtil.addLayoutSet(layoutSetPub);
}catch(SystemException se){

}

long layoutSetIdPriv= CounterLocalServiceUtil.increment(LayoutSet.class.getName());
LayoutSet layoutSetPriv=LayoutSetLocalServiceUtil.createLayoutSet(layoutSetIdPriv);
layoutSetPriv.setCompanyId(companyId);
layoutSetPriv.setPrivateLayout(true);
layoutSetPriv.setThemeId("classic");
layoutSetPriv.setGroupId(userGrp.getGroupId());
try{
LayoutSetLocalServiceUtil.addLayoutSet(layoutSetPriv);
}catch(SystemException se){
}
}else{
return null;
}


return user;


}
Rajesh Chaurasia
RE: creating new user via API
2 de abril de 2012 9:24
Respuesta

Rajesh Chaurasia

Ranking: Junior Member

Mensajes: 98

Fecha de incorporación: 18 de agosto de 2011

Mensajes recientes

In my recent post above , you should use CounterLocalServiceUtil to generate the id for an entity rather than evaluating it base don some other id as this might cause failure in inserts as there might be unique constraint violation .
piyush liferay
RE: creating new user via API
31 de enero de 2013 5:50
Respuesta

piyush liferay

Ranking: Junior Member

Mensajes: 40

Fecha de incorporación: 1 de enero de 2013

Mensajes recientes

Ahmed Hasan:
Yes, this is the right approach to create a new user using the local service api.

For the unique userId you have to get it as below.

long userId = CounterLocalServiceUtil.increment();

The rest of the code is fine.

For any help feel free to contact me,

Ahmed Hasan
CTO, TransIT mPower Labs (P) Ltd.
info@mpowerglobal.com
mPower Global Inc.
A Liferay expert company.


but after calling addUser() method gives some error :- Exception occurred inside getter of com.liferay.portal.model.impl.UserImpl.digest
Shankar Baba
RE: creating new user via API
28 de marzo de 2013 4:28
Respuesta

Shankar Baba

Ranking: Regular Member

Mensajes: 144

Fecha de incorporación: 17 de octubre de 2012

Mensajes recientes

Does any body have sample working example for this, if yes please attach the code with your reply.
Shankar Baba
RE: creating new user via API
30 de marzo de 2013 4:13
Respuesta

Shankar Baba

Ranking: Regular Member

Mensajes: 144

Fecha de incorporación: 17 de octubre de 2012

Mensajes recientes

man did u got solution for this problem?
leo Hudson
RE: creating new user via API
22 de enero de 2014 5:31
Respuesta

leo Hudson

Ranking: New Member

Mensajes: 1

Fecha de incorporación: 19 de enero de 2014

Mensajes recientes

Suresh Chinna Pillai:
Hi friend,
Thank you for your quick reply. I found the solution for this issue. I use "UserLocalServiceUtil.addUser(long creatorUserId, long companyId, boolean autoPassword,
String password1, String password2, boolean autoScreenName,
String screenName, String emailAddress, long facebookId, String openId,
Locale locale, String firstName, String middleName, String lastName,
int prefixId, int suffixId, boolean male, int birthdayMonth,
int birthdayDay, int birthdayYear, String jobTitle, long[] groupIds,
long[] organizationIds, long[] roleIds, long[] userGroupIds,
boolean sendEmail, ServiceContext serviceContext)"
method.

It works fine.

Can you have any idea about how to add the user to a group..?

Thanks in advance..

-Suresh.


Hi Suresh
can you explain how did you were able to create users in Liferay Portal
did you used SOAP/JSON or java invocation ??

how did you made a connection ???
saritha reddy
RE: creating new user via API
30 de junio de 2014 4:54
Respuesta

saritha reddy

Ranking: Junior Member

Mensajes: 95

Fecha de incorporación: 27 de enero de 2014

Mensajes recientes

Hi Rajesh

First of all thank you for that code snippet.

Sorry to pick old call but when am trying to implement the the your above mentioned code
am getting error like NoSuchMethodException with the following method.

private User insertOrgPublisher(ActionRequest actionRequest,Organization organization,ServiceContext serviceContext) throws PortalException, SystemException {

}

Could you please help me with this error


Thank you


Regards
Saritha
David H Nebinger
RE: creating new user via API
30 de junio de 2014 5:28
Respuesta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensajes: 9424

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

saritha reddy:
Sorry to pick old call but when am trying to implement the the your above mentioned code
am getting error like NoSuchMethodException with the following method.

private User insertOrgPublisher(ActionRequest actionRequest,Organization organization,ServiceContext serviceContext) throws PortalException, SystemException;


Well that's the thing with picking up dead code to use w/o understanding. This thread is over a year old and most likely talking about a previous version of Liferay than what you're using.

You should be able to adapt the concepts into your code for the version you're using, it will just take a little effort on your part.