Fórum

PermissionChecker not initialized while updating the journal article statu

Pankaj Kumar, modificado 8 Anos atrás.

PermissionChecker not initialized while updating the journal article statu

Regular Member Postagens: 101 Data de Entrada: 27/07/14 Postagens Recentes
Hi All,

I have written scheduler which will update the journal article status.While updating the status i am getting PermissionChecker not initialized exception.

Below is my code

ServiceContext serviceContext = new ServiceContext();
for(JournalArticle articles :expsAds){
JournalArticle jrnl = null;

try
{
jrnl = JournalArticleLocalServiceUtil.getArticle(articles.getGroupId(), articles.getArticleId());
final String content = setJournalSpecificFields(jrnl, AdSchedulerStatusConstants.CONTENT_XML_FIELD_COMMENT, "comment");
jrnl = JournalArticleLocalServiceUtil.updateContent(jrnl.getGroupId(), jrnl.getArticleId(), jrnl.getVersion(), content);
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
JournalArticleLocalServiceUtil.updateJournalArticle(jrnl);
LOG.info("Article id "+jrnl.getArticleId()+ " status going to be changed");
jrnl = JournalArticleServiceUtil.updateStatus(jrnl.getGroupId(), jrnl.getArticleId(), Double.parseDouble(String.valueOf(jrnl.getVersion())), WorkflowConstants.STATUS_EXPIRED, jrnl.getUrlTitle(), serviceContext);
LOG.info("Article id "+jrnl.getArticleId() + "status changed");
listOfExpAds.add(jrnl);

}

Please tell me how can i overcome on this error.
com.liferay.portal.security.auth.PrincipalException: PermissionChecker not initialized
at com.liferay.portal.service.BaseServiceImpl.getPermissionChecker(BaseServiceImpl.java:82)
at com.liferay.portlet.journal.service.impl.JournalArticleServiceImpl.updateStatus(JournalArticleServiceImpl.java:2295)
at sun.reflect.GeneratedMethodAccessor639.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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)
thumbnail
Amos Fong, modificado 8 Anos atrás.

RE: PermissionChecker not initialized while updating the journal article st

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Because you're in a scheduled job and you know exactly what you're doing, you probably don't need to check permission on who is executing the update. So you can simply use JournalArticleLocalServiceUtil.updateStatus() instead which does not check any permissions.
Pankaj Kumar, modificado 8 Anos atrás.

RE: PermissionChecker not initialized while updating the journal article st

Regular Member Postagens: 101 Data de Entrada: 27/07/14 Postagens Recentes
Thanks Amos for your reply.

I did like this and it works for me.

User user = UserLocalServiceUtil.getUserById(jrnl.getUserId());
PermissionChecker permissionChecker;
permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);

.