Forums de discussion

creating new user via API

Marian Rosko, modifié il y a 14 années.

creating new user via API

New Member Envoyer: 1 Date d'inscription: 03/04/09 Publications récentes
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
thumbnail
Aravind Kumar, modifié il y a 14 années.

RE: creating new user via API

New Member Publications: 2 Date d'inscription: 26/03/09 Publications récentes
Hi Marian,

You can try accessing the UserLocalServiceUtil.addUser of Liferay. I'm not sure about the output as it did not work for me.

Ref Link - http://www.liferay.com/web/guest/community/forums/-/message_boards/message/116444

Also, can you send me your Create.sql. I'm struggling with that currently. Help me pls. You can post your reply here or send me via indaravind@gmail.com.

- AK
thumbnail
Luc Pons, modifié il y a 14 années.

RE: creating new user via API

Junior Member Publications: 70 Date d'inscription: 03/12/08 Publications récentes
Here is a method i wrote :


public static User addUser(String firstName, String lastName, String email, String password, String screenName) throws CantAddUserException {
        try {
            

            long[] emptyLong = {};
            User user = UserLocalServiceUtil.addUser(
                    new Long(Constants.ADMIN_ID) /*long creatorUserId*/,
                    Constants.COMP_ID /*long companyId*/,
                    false /*boolean autoPassword*/,
                    password /*String password1*/,
                    password /*String password2*/,
                    false /*boolean autoScreenName*/,
                    screenName /* String screenName*/,
                    email /*String emailAddress*/,
                    new Locale("fr") /*Locale locale*/,
                    firstName /*String firstName*/,
                    null /*String middleName*/,
                    lastName /*String lastName*/,
                    0/*int prefixId*/,
                    0 /*int suffixId*/,
                    false /*boolean male*/,
                    1 /*int birthdayMonth*/,
                    1 /*int birthdayDay*/,
                    2000 /*int birthdayYear*/,
                    null /*String jobTitle*/,
                    emptyLong /*long[] organizationIds*/,
                    false /*boolean sendEmail*/);

            return user;

        } catch (Exception e) {
            throw new CantAddUserException(e);
        }
    }
thumbnail
Ahmed Hasan, modifié il y a 14 années.

RE: creating new user via API

Expert Publications: 306 Date d'inscription: 13/04/07 Publications récentes
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.
thumbnail
Imran Pasha, modifié il y a 14 années.

RE: creating new user via API

Junior Member Publications: 78 Date d'inscription: 01/08/08 Publications récentes
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 !
thumbnail
Imran Pasha, modifié il y a 14 années.

RE: creating new user via API

Junior Member Publications: 78 Date d'inscription: 01/08/08 Publications récentes
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.
thumbnail
Juan M. Gomez, modifié il y a 14 années.

RE: creating new user via API

Junior Member Publications: 69 Date d'inscription: 07/11/07 Publications récentes
Hello, i have been able to create a new User using the following code..
long userId = CounterLocalServiceUtil.increment();
            User userToCreate = UserUtil.create(userId);
            userToCreate.setFirstName(firstName);
            userToCreate.setLastName(lastName);
            userToCreate.setEmailAddress(email);
            userToCreate.setPassword(password);
            userToCreate.setScreenName(screenName);
            userToCreate.setActive(true);
            userToCreate.setCreateDate(new Date());
            userToCreate.setGreeting("Hi " + screenName);
            userToCreate.setJobTitle(job_title);
            userToCreate.setLanguageId(languageId);
            userToCreate.setMiddleName(middleName);

            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.
thumbnail
Amos Fong, modifié il y a 14 années.

RE: creating new user via API

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
Hi Juan,

Try calling this afterward:

		try {
			UserIndexer.updateUser(user);
		}
		catch (SearchException se) {
			_log.error("Indexing " + userId, se);
		}
thumbnail
Juan M. Gomez, modifié il y a 14 années.

RE: creating new user via API

Junior Member Publications: 69 Date d'inscription: 07/11/07 Publications récentes
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
thumbnail
Amos Fong, modifié il y a 14 années.

RE: creating new user via API

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
Juan,

Sorry for late response, organizations are not indexed so no.
Anonyme, modifié il y a 14 années.

RE: creating new user via API

Envoyer: 1
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)
Vin k k, modifié il y a 14 années.

RE: creating new user via API

Regular Member Publications: 138 Date d'inscription: 04/12/07 Publications récentes
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
thumbnail
Sri Sri, modifié il y a 11 années.

RE: creating new user via API

Regular Member Publications: 143 Date d'inscription: 18/10/12 Publications récentes
man did u got solution for this problem?
li guicheng, modifié il y a 13 années.

RE: creating new user via API

Junior Member Publications: 25 Date d'inscription: 29/03/10 Publications récentes
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
Michael Angelo dela Cruz, modifié il y a 8 années.

RE: creating new user via API

New Member Publications: 4 Date d'inscription: 15/09/15 Publications récentes
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.
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: creating new user via API

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
What does that have to do with this old thread?
Michael Angelo dela Cruz, modifié il y a 8 années.

RE: creating new user via API

New Member Publications: 4 Date d'inscription: 15/09/15 Publications récentes
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.
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: creating new user via API

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Start a new forum thread in the development area.
Suresh Chinna Pillai, modifié il y a 13 années.

RE: creating new user via API

New Member Publications: 16 Date d'inscription: 14/02/11 Publications récentes
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.

try {
2            UserIndexer.updateUser(user);
3        }
4        catch (SearchException se) {
5            _log.error("Indexing " + userId, se);
6        }

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, modifié il y a 13 années.

RE: creating new user via API

New Member Publications: 2 Date d'inscription: 04/02/11 Publications récentes
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, modifié il y a 13 années.

RE: creating new user via API

New Member Publications: 16 Date d'inscription: 14/02/11 Publications récentes
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.
thumbnail
RathnaDevi Chellaiah, modifié il y a 11 années.

RE: creating new user via API

Junior Member Publications: 29 Date d'inscription: 27/03/12 Publications récentes
hi Suresh,
can u share ur code.. am unable to create user inthe user_ table..
leo Hudson, modifié il y a 10 années.

RE: creating new user via API

New Member Envoyer: 1 Date d'inscription: 20/01/14 Publications récentes
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 ???
thumbnail
RathnaDevi Chellaiah, modifié il y a 12 années.

RE: creating new user via API

Junior Member Publications: 29 Date d'inscription: 27/03/12 Publications récentes
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..
thumbnail
David H Nebinger, modifié il y a 12 années.

RE: creating new user via API

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
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
piyush liferay, modifié il y a 11 années.

RE: creating new user via API

Junior Member Publications: 40 Date d'inscription: 02/01/13 Publications récentes
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
thumbnail
Sri Sri, modifié il y a 11 années.

RE: creating new user via API

Regular Member Publications: 143 Date d'inscription: 18/10/12 Publications récentes
Does any body have sample working example for this, if yes please attach the code with your reply.
thumbnail
solomon merkebu, modifié il y a 7 années.

RE: How to update user organization using java API

New Member Publications: 2 Date d'inscription: 15/02/16 Publications récentes
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?
Pepe Laberta, modifié il y a 13 années.

RE: creating new user via API

New Member Publications: 7 Date d'inscription: 12/05/10 Publications récentes
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.
thumbnail
Rajesh Chaurasia, modifié il y a 11 années.

RE: creating new user via API

Regular Member Publications: 183 Date d'inscription: 18/08/11 Publications récentes
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;


}
thumbnail
Rajesh Chaurasia, modifié il y a 11 années.

RE: creating new user via API

Regular Member Publications: 183 Date d'inscription: 18/08/11 Publications récentes
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 .
saritha reddy, modifié il y a 9 années.

RE: creating new user via API

Junior Member Publications: 95 Date d'inscription: 27/01/14 Publications récentes
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
thumbnail
David H Nebinger, modifié il y a 9 années.

RE: creating new user via API

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
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.