Foren

Problem with JournalArticle creation programmatically in Liferay 6.1 EE

thumbnail
Samujjwal Sahu, geändert vor 11 Jahren.

Problem with JournalArticle creation programmatically in Liferay 6.1 EE

Junior Member Beiträge: 31 Beitrittsdatum: 22.05.12 Neueste Beiträge
We are trying to create a JournalArticle from a custom portlet in liferay 6.1.
We were using the below mention method:
JournalArticle com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil.addArticle(long userId, long groupId, long classNameId, long classPK, String articleId, boolean autoArticleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String type, String structureId, String templateId, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile, Map<String, byte[]> images, String articleURL, ServiceContext serviceContext)

this is the exact call:
article = JournalArticleLocalServiceUtil.addArticle(userId, groupId, 0L, 0L, articleId, false, JournalArticleConstants.VERSION_DEFAULT, getNameMap(title), getNameMap(description), contentPre + content + contentPost, type, structureId, templateId, StringPool.BLANK, 01, 21, 2013, 3, 15, 1, 1, 1, 1, 1, true, 1, 1, 1, 1, 1, true, true, false, null, null, null, articleURL, serviceContext);

Although we are providing valid groupID and userID (UserId = 10434 , groupId = 85113 in my case) still the API is throwing this exception as
NoSuchGroupException: No Group exists with the primary key 0
.

Attached is the portlet code.

Exception(Stacktrace) :
[ERROR] No Group exists with the primary key 0
com.liferay.portal.NoSuchGroupException: No Group exists with the primary key 0
at com.liferay.portal.service.persistence.GroupPersistenceImpl.findByPrimaryKey(GroupPersistenceImpl.java:825)
at com.liferay.portal.service.impl.GroupLocalServiceImpl.getGroup(GroupLocalServiceImpl.java:898)
at sun.reflect.GeneratedMethodAccessor235.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:112)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at $Proxy22.getGroup(Unknown Source)
at com.liferay.portal.service.GroupLocalServiceUtil.getGroup(GroupLocalServiceUtil.java:177)
at com.liferay.portal.util.PortalImpl.getControlPanelFullURL(PortalImpl.java:1343)
at com.liferay.portal.util.PortalUtil.getControlPanelFullURL(PortalUtil.java:363)
at com.liferay.portlet.journal.workflow.JournalArticleWorkflowHandler.updateStatus(JournalArticleWorkflowHandler.java:69)
at com.liferay.portlet.journal.workflow.JournalArticleWorkflowHandler.updateStatus(JournalArticleWorkflowHandler.java:1)
at com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil.startWorkflowInstance(WorkflowHandlerRegistryUtil.java:125)
at com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil.startWorkflowInstance(WorkflowHandlerRegistryUtil.java:75)
at com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.addArticle(JournalArticleLocalServiceImpl.java:309)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:112)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at $Proxy205.addArticle(Unknown Source)
at com.liferay.portlet.journal.service.impl.JournalArticleServiceImpl.addArticle(JournalArticleServiceImpl.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:112)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at $Proxy206.addArticle(Unknown Source)
at com.liferay.portlet.journal.service.JournalArticleServiceUtil.addArticle(JournalArticleServiceUtil.java:90)
at com.test.SampleTestPortlet.processAction(SampleTestPortlet.java:86)
thumbnail
Harish Kumar, geändert vor 11 Jahren.

RE: Problem with JournalArticle creation programmatically in Liferay 6.1 EE

Expert Beiträge: 483 Beitrittsdatum: 31.07.10 Neueste Beiträge
I have posted the solution in this thread

you have to set scopeGroupId in serviceContext object.

HTH
thumbnail
Samujjwal Sahu, geändert vor 11 Jahren.

RE: Problem with JournalArticle creation programmatically in Liferay 6.1 EE

Junior Member Beiträge: 31 Beitrittsdatum: 22.05.12 Neueste Beiträge
Thanks Harish ... What I did is something like this:
ServiceContext serviceContext = ServiceContextFactory.getInstance(JournalArticle.class.getName(), actionRequest);


Can you help me in one more thing?
I want to set this newly created journalarticle to a web content display portlet on the newly created page programmatically.

Even if I set this Web content to a display portlet manually its not showing the content on the page, Thats because of the InstanceId. As its not given in our content. So it gets a null.
thumbnail
Samujjwal Sahu, geändert vor 11 Jahren.

RE: Problem with JournalArticle creation programmatically in Liferay 6.1 EE

Junior Member Beiträge: 31 Beitrittsdatum: 22.05.12 Neueste Beiträge
As of now we have been able to Add a Web Content Display portlet to a newly created page.
And have also created a Journal Article from a html file.
But the Article that I have created is not getting displayed in any Web Content Display Portlet. I guess this is due to the Prefix that I am adding before the html content.
<?xml version="1.0"?>

<root available-locales="en_US" default-locale="en_US">
<dynamic-element name="var" type="text_area" index-type="">
<dynamic-content><![CDATA[


And here is the Postfix content:
]]></dynamic-content>
</dynamic-element>
</root>


in between the the html content.
The thing that I compared with other contents is that :
In my content there is no instance-id within the TAG dynamic-element

How to add this instance-id to the JournalArticle through API?

article = JournalArticleLocalServiceUtil.addArticle(
userId, groupId, 0L, 0L, articleId, false,
JournalArticleConstants.VERSION_DEFAULT,
getNameMap(title), getNameMap(description),
contentPre + content + contentPost, type,
structureId, templateId, StringPool.BLANK, 01,
21, 2013, 3, 15, 1, 1, 1, 1, 1, true, 1, 1, 1,
1, 1, true, true, false, null, null, null,
articleURL, serviceContext);
thumbnail
Samujjwal Sahu, geändert vor 11 Jahren.

RE: Problem with JournalArticle creation programmatically in Liferay 6.1 EE

Junior Member Beiträge: 31 Beitrittsdatum: 22.05.12 Neueste Beiträge
Have added the instance-id in the dynamic content using the below code, but still the content is not showing after pointing it through a Web Content Display Portlet:

protected String generateInstanceId() {
StringBuilder instanceId = new StringBuilder(8);

String key = PwdGenerator.KEY1 + PwdGenerator.KEY2 + PwdGenerator.KEY3;

for (int i = 0; i < 8; i++) {
int pos = (int)Math.floor(Math.random() * key.length());

instanceId.append(key.charAt(pos));
}
return instanceId.toString();
}