Mariusz
Mariusz

Reputation: 1985

How to find group by group name

How to find com.liferay.portal.model.Group object by group name? Also how to find com.liferay.portal.model.Role by role name?

=============EDIT===============

I have testGroup: enter image description here

Group group = GroupServiceUtil.getGroup(themeDisplay.getCompanyId(), "testGroup");

results:

11:09:09,858 ERROR [RuntimePageImpl-15][render_portlet_jsp:132] null
com.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=10157, name=testGroup}
    at com.liferay.portal.service.persistence.GroupPersistenceImpl.findByC_N(GroupPersistenceImpl.java:3253)
    at com.liferay.portal.service.impl.GroupLocalServiceImpl.loadGetGroup(GroupLocalServiceImpl.java:2054)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
    at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
    at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
    at com.liferay.portal.service.impl.GroupLocalServiceImpl.getGroup(GroupLocalServiceImpl.java:1196)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
    at com.liferay.portal.service.impl.GroupServiceImpl.getGroup(GroupServiceImpl.java:329)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
    at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
    at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
    at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
    at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
    at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)

Upvotes: 1

Views: 2618

Answers (1)

Pankaj Kathiriya
Pankaj Kathiriya

Reputation: 4210

You can find group and role by its name using below API methods:

  GroupLocalServiceUtil.getGroup(long companyId, java.lang.String name)

  RoleLocalServiceUtil.getRole(long companyId, java.lang.String name)

Upvotes: 4

Related Questions