Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Issam B
Unable to find new roles created
April 29, 2013 1:26 AM
Answer

Issam B

Rank: New Member

Posts: 11

Join Date: October 26, 2012

Recent Posts

Hello everyone,

I'm developing a method which adds new roles to a specific user; I took from (http://www.liferay.com/community/forums/-/message_boards/message/9389920 ) some tips

Now, all what I did is fine - I hope- , I mean in database ROLE_, USERS_ROLES and USER_, but the problem is that I can't see these new roles in Liferay control panel.

ps: I did not define permissions for roles I have created

Help please and thakns in advance
Anil Sunkari
RE: Unable to find new roles created
April 26, 2013 1:58 AM
Answer

Anil Sunkari

Rank: Expert

Posts: 427

Join Date: August 11, 2009

Recent Posts

Hi Issam,

I have few queries on your post.

1) Which DB are you pointing to??
2) Is that really in SYNC??
3) Might be you have to enable lazy loading to "true" somewhere.Please cross check.

Correct me if i'm wrong with your understanding.

Regards,
Anil Sunkari
Issam B
RE: Unable to find new roles created
April 26, 2013 2:11 AM
Answer

Issam B

Rank: New Member

Posts: 11

Join Date: October 26, 2012

Recent Posts

Hi Anil,

Thanks for your answer..

I'm pointing to Liferay DB and it is really in SYNC. However, I'm not sure about enabling lazy loading (where can I see this property)

In addition, I still trying to get the role I added in DB and control panel. At present I use :
1Role newRole = RoleLocalServiceUtil.createRole(roleId);
2RoleLocalServiceUtil.addRole(userId, themeDisplay.getCompanyId(), roleName, null, null, 1);
3


instead of

 1Role newRole = RoleLocalServiceUtil.createRole(roleId);
 2
 3    newRole.setClassNameId(classNameId);
 4    newRole.setCompanyId(companyId);
 5    newRole.setClassPK(roleId);
 6    newRole.setDescription(null);
 7    newRole.setTitleMap(null);
 8    newRole.setName(roleName);
 9    newRole.setType(1);
10        RoleLocalServiceUtil.addRole(newRole);
11



Using addRole(userId, ....) method allowed me to see the role in control panel and it is of course saved in DB, BUT the role was not assigned to the user specified in the method


Using addRole(Role) method was the first case (the role is saved in DB but not found in control panel)




Here I can not see the difference between these two methods despite their same aim.


It really ambigous



Regards


Issam
Oliver Bayer
RE: Unable to find new roles created
April 26, 2013 2:14 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 883

Join Date: February 18, 2009

Recent Posts

Hi Issam,

do you try to add new roles manually or are you using liferay services?
Maybe a reindex from within the control panel solves this issue.

HTH Oli
Issam B
RE: Unable to find new roles created
April 26, 2013 2:21 AM
Answer

Issam B

Rank: New Member

Posts: 11

Join Date: October 26, 2012

Recent Posts

Oliver Bayer:
Hi Issam,

do you try to add new roles manually or are you using liferay services?
Maybe a reindex from within the control panel solves this issue.

HTH Oli


Hi Oliver,

I'm trying to do that with Liferay API

Well, how can I perfrom a reindex within the control panel ?


Regards,
Issam
Masroor Khan
RE: Unable to find new roles created
April 26, 2013 2:54 AM
Answer

Masroor Khan

Rank: Regular Member

Posts: 119

Join Date: September 9, 2008

Recent Posts

Hi,

In Control Panel left side you can see "server administration" .


Regards,

Masroor khan
Atif Hussain
RE: Unable to find new roles created
April 26, 2013 3:02 AM
Answer

Atif Hussain

Rank: Junior Member

Posts: 47

Join Date: April 3, 2012

Recent Posts

Some times this happens, a database instance is used by multiple web servers.
If you are doing development in Team, and if multiple developers are using the same Database you will face this data concurrency issue.

Regards,
Atif Hussain
Issam B
RE: Unable to find new roles created
April 26, 2013 4:05 AM
Answer

Issam B

Rank: New Member

Posts: 11

Join Date: October 26, 2012

Recent Posts

Thank you Masroor for the tip

Well, Atif, that will happen eventually when a developement team is working on a central DB. It is not the case for me, I'm working on my own local DB.


Regards,
Issam
Issam B
RE: Unable to find new roles created
April 26, 2013 4:20 AM
Answer

Issam B

Rank: New Member

Posts: 11

Join Date: October 26, 2012

Recent Posts

Hi all,

I think that i find the solution since it worked as I want (as described above).

The old implementation I did to add a new role is like this :
 1
 2long roleId = CounterLocalServiceUtil.increment();
 3long classNameId = CounterLocalServiceUtil.increment();
 4
 5//create the role
 6Role newRole = RoleLocalServiceUtil.createRole(roleId);
 7
 8newRole.setClassNameId(classNameId);
 9newRole.setCompanyId(companyId);
10newRole.setClassPK(roleId);
11newRole.setDescription(null);
12newRole.setTitleMap(null);
13newRole.setName(roleName);
14newRole.setType(1); // regular role type
15
16//add the new role to database
17RoleLocalServiceUtil.addRole(newRole);
18
19//assign the role to a userId specified as input parameter
20RoleLocalServiceUtil.addUserRoles(user.getUserId(),new long[] { newRole1.getRoleId() });


The result I had was a new role created in Database (in ROLE_ table) and relations are created between the created role and the specified user (in USERS_ROLES table). This looks very fine !! But in Roles section within control panel I did not find the created role but I found it assigned to user when I clic on this later to see his roles... very ambigous and I can not understand this point up to now :-(


Now, I'm using another way to implement my needs, directly like this:
1
2
3//create and add the role to database
4Role newRole1 =  RoleLocalServiceUtil.addRole(user.getUserId(), themeDisplay.getCompanyId(), roleName, null, null, 1);
5//assign the created role to user
6RoleLocalServiceUtil.addUserRoles(user.getUserId(),new long[] { newRole1.getRoleId() });


And as a result, the created role appear in database, roles section and user roles within control panel

I still unconvinced by results I got when I used the first way.. and so I would like to know the difference between Liferay API methods I used in the two cases above.

Best regards,
Issam
Anil Sunkari
RE: Unable to find new roles created
April 27, 2013 3:37 AM
Answer

Anil Sunkari

Rank: Expert

Posts: 427

Join Date: August 11, 2009

Recent Posts

@Issam - That's good to see ..finally you have fixed the issue... Congratulations....

So regarding you question on difference.... Problem might exist while indexing because we manually passing the primary key/classpk.....i guess might be.

Regards,
Anil Sunkari