Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
creating new user via API Marian Rosko 3 aprile 2009 5.50
RE: creating new user via API Luc Pons 20 maggio 2009 0.51
RE: creating new user via API Ahamed Hasan 20 maggio 2009 4.22
RE: creating new user via API Ayaz Pasha 20 maggio 2009 5.11
RE: creating new user via API Ayaz Pasha 20 maggio 2009 5.35
RE: creating new user via API Juan M. Gomez 24 giugno 2009 10.42
RE: creating new user via API Amos Fong 24 giugno 2009 10.46
RE: creating new user via API Juan M. Gomez 24 giugno 2009 15.04
RE: creating new user via API Amos Fong 10 settembre 2009 15.43
RE: creating new user via API Anonimo 23 novembre 2009 7.06
RE: creating new user via API Man V K 9 dicembre 2009 0.49
RE: creating new user via API Shankar Baba 30 marzo 2013 4.13
RE: creating new user via API li guicheng 9 agosto 2010 18.10
RE: creating new user via API Michael Angelo dela Cruz 15 settembre 2015 18.20
RE: creating new user via API David H Nebinger 15 settembre 2015 18.26
RE: creating new user via API Michael Angelo dela Cruz 15 settembre 2015 18.33
RE: creating new user via API David H Nebinger 15 settembre 2015 19.20
RE: creating new user via API Suresh Chinna Pillai 14 febbraio 2011 0.55
RE: creating new user via API Siddhartha Bera 15 febbraio 2011 11.21
RE: creating new user via API Suresh Chinna Pillai 16 febbraio 2011 7.45
RE: creating new user via API RathnaDevi Chellaiah 2 aprile 2012 2.51
RE: creating new user via API leo Hudson 22 gennaio 2014 5.31
RE: creating new user via API RathnaDevi Chellaiah 30 marzo 2012 6.50
RE: creating new user via API David H Nebinger 30 marzo 2012 7.08
RE: creating new user via API piyush liferay 31 gennaio 2013 5.50
RE: creating new user via API Shankar Baba 28 marzo 2013 4.28
RE: How to update user organization using java API solomon Merkebu Adamu 4 luglio 2016 23.45
RE: creating new user via API Pepe Laberta 5 novembre 2010 8.04
RE: creating new user via API Rajesh Chaurasia 2 aprile 2012 9.19
RE: creating new user via API Rajesh Chaurasia 2 aprile 2012 9.24
RE: creating new user via API saritha reddy 30 giugno 2014 4.54
RE: creating new user via API David H Nebinger 30 giugno 2014 5.28
Marian Rosko
creating new user via API
3 aprile 2009 5.50
Risposta

Marian Rosko

Punteggio: New Member

Messaggi: 1

Data di Iscrizione: 3 aprile 2009

Messaggi recenti

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 maggio 2009 0.51
Risposta

Luc Pons

Punteggio: Junior Member

Messaggi: 70

Data di Iscrizione: 3 dicembre 2008

Messaggi recenti

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    }
Ahamed Hasan
RE: creating new user via API
20 maggio 2009 4.22
Risposta

Ahamed Hasan

Punteggio: Expert

Messaggi: 306

Data di Iscrizione: 13 aprile 2007

Messaggi recenti

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 maggio 2009 5.11
Risposta

Ayaz Pasha

Punteggio: Junior Member

Messaggi: 78

Data di Iscrizione: 1 agosto 2008

Messaggi recenti

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 maggio 2009 5.35
Risposta

Ayaz Pasha

Punteggio: Junior Member

Messaggi: 78

Data di Iscrizione: 1 agosto 2008

Messaggi recenti

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 giugno 2009 10.42
Risposta

Juan M. Gomez

Punteggio: Junior Member

Messaggi: 69

Data di Iscrizione: 7 novembre 2007

Messaggi recenti

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 giugno 2009 10.46
Risposta

Amos Fong

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 1912

Data di Iscrizione: 7 ottobre 2008

Messaggi recenti

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 giugno 2009 15.04
Risposta

Juan M. Gomez

Punteggio: Junior Member

Messaggi: 69

Data di Iscrizione: 7 novembre 2007

Messaggi recenti

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 settembre 2009 15.43
Risposta

Amos Fong

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 1912

Data di Iscrizione: 7 ottobre 2008

Messaggi recenti

Juan,

Sorry for late response, organizations are not indexed so no.
Anonimo
RE: creating new user via API
23 novembre 2009 7.06
Risposta

Anonimo

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 dicembre 2009 0.49
Risposta

Man V K

Punteggio: Regular Member

Messaggi: 139

Data di Iscrizione: 4 dicembre 2007

Messaggi recenti

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 agosto 2010 18.10
Risposta

li guicheng

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 28 marzo 2010

Messaggi recenti

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 novembre 2010 8.04
Risposta

Pepe Laberta

Punteggio: New Member

Messaggi: 7

Data di Iscrizione: 12 maggio 2010

Messaggi recenti

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 febbraio 2011 0.55
Risposta

Suresh Chinna Pillai

Punteggio: New Member

Messaggi: 16

Data di Iscrizione: 13 febbraio 2011

Messaggi recenti

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 febbraio 2011 11.21
Risposta

Siddhartha Bera

Punteggio: New Member

Messaggi: 2

Data di Iscrizione: 4 febbraio 2011

Messaggi recenti

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 febbraio 2011 7.45
Risposta

Suresh Chinna Pillai

Punteggio: New Member

Messaggi: 16

Data di Iscrizione: 13 febbraio 2011

Messaggi recenti

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 marzo 2012 6.50
Risposta

RathnaDevi Chellaiah

Punteggio: Junior Member

Messaggi: 29

Data di Iscrizione: 26 marzo 2012

Messaggi recenti

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 marzo 2012 7.08
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11793

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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 aprile 2012 2.51
Risposta

RathnaDevi Chellaiah

Punteggio: Junior Member

Messaggi: 29

Data di Iscrizione: 26 marzo 2012

Messaggi recenti

hi Suresh,
can u share ur code.. am unable to create user inthe user_ table..
Rajesh Chaurasia
RE: creating new user via API
2 aprile 2012 9.19
Risposta

Rajesh Chaurasia

Punteggio: Regular Member

Messaggi: 119

Data di Iscrizione: 18 agosto 2011

Messaggi recenti

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 aprile 2012 9.24
Risposta

Rajesh Chaurasia

Punteggio: Regular Member

Messaggi: 119

Data di Iscrizione: 18 agosto 2011

Messaggi recenti

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 gennaio 2013 5.50
Risposta

piyush liferay

Punteggio: Junior Member

Messaggi: 40

Data di Iscrizione: 1 gennaio 2013

Messaggi recenti

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 marzo 2013 4.28
Risposta

Shankar Baba

Punteggio: Regular Member

Messaggi: 144

Data di Iscrizione: 17 ottobre 2012

Messaggi recenti

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 marzo 2013 4.13
Risposta

Shankar Baba

Punteggio: Regular Member

Messaggi: 144

Data di Iscrizione: 17 ottobre 2012

Messaggi recenti

man did u got solution for this problem?
leo Hudson
RE: creating new user via API
22 gennaio 2014 5.31
Risposta

leo Hudson

Punteggio: New Member

Messaggi: 1

Data di Iscrizione: 19 gennaio 2014

Messaggi recenti

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 giugno 2014 4.54
Risposta

saritha reddy

Punteggio: Junior Member

Messaggi: 95

Data di Iscrizione: 27 gennaio 2014

Messaggi recenti

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 giugno 2014 5.28
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11793

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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.
Michael Angelo dela Cruz
RE: creating new user via API
15 settembre 2015 18.20
Risposta

Michael Angelo dela Cruz

Punteggio: New Member

Messaggi: 4

Data di Iscrizione: 14 settembre 2015

Messaggi recenti

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)


Hi guys,

I am new to Liferay and I would like to ask for your help. I'm making a program that will need to use the Liferay API. It's a separate program and I just need to use the Liferay API of another project. I imported all the necessary libraries of Liferay to my application but unfortunately I encountered an error saying "com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set".

I tried to run the code above but the result still the same.

I'm hoping you could me regarding this matter. Thanks in advance.
David H Nebinger
RE: creating new user via API
15 settembre 2015 18.26
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11793

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

What does that have to do with this old thread?
Michael Angelo dela Cruz
RE: creating new user via API
15 settembre 2015 18.33
Risposta

Michael Angelo dela Cruz

Punteggio: New Member

Messaggi: 4

Data di Iscrizione: 14 settembre 2015

Messaggi recenti

David H Nebinger:
What does that have to do with this old thread?


I'm sorry sir I don't know where to post. I'm new to this forum and still exploring.
Can you send me a link where I can post my concern? Thank you.
David H Nebinger
RE: creating new user via API
15 settembre 2015 19.20
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11793

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

Start a new forum thread in the development area.
solomon Merkebu Adamu
RE: How to update user organization using java API
4 luglio 2016 23.45
Risposta

solomon Merkebu Adamu

Punteggio: New Member

Messaggi: 2

Data di Iscrizione: 15 febbraio 2016

Messaggi recenti

I want to update user organization using java api for example if an employee change his/her organization from organization1 to organization2 so how can update using java Api?