掲示板

Adding article programmatically with Liferay 6.1

thumbnail
11年前 に Alfredo Larotonda によって更新されました。

Adding article programmatically with Liferay 6.1

Junior Member 投稿: 84 参加年月日: 08/06/18 最新の投稿
Hi,
I developed a portlet that added articles porgtrammatically using liferay 6.0.6 and all worked perfectly.
Now we are upgrading to Liferay 6.1 and the method addArticle of the class JournalArticleServiceUtil is changed and nothing works at all !!
In particular the parameters to set page title and page description that were String before , now become java.util.Map.
How do I have to manage these fields?

Thanks

Alfredo
11年前 に Gwowen Fu によって更新されました。

RE: Adding article programmatically with Liferay 6.1

Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
Map<Locale,String> titleMap, Map<Locale,String> descriptionMap,

titleMap.put(Locale.ENGLISH, "Title");
titleMap.put(Locale.CHINESE, "Title");

descriptionMap.put(Locale.ENGLISH, "Description");
descriptionMap.put(Locale.CHINESE, "Description");
11年前 に Daniel Wilmes によって更新されました。

RE: Adding article programmatically with Liferay 6.1

Regular Member 投稿: 164 参加年月日: 11/05/23 最新の投稿

Map<locale, string> titleMap = getNameMap(title);


	protected Map<locale, string> getNameMap(String name) {
		Map<locale, string> nameMap = new HashMap<locale, string>();

		Locale locale = LocaleUtil.getDefault();

		nameMap.put(locale, name);

		return nameMap;
	}

</locale,></locale,></locale,></locale,>
thumbnail
11年前 に Alfredo Larotonda によって更新されました。

RE: Adding article programmatically with Liferay 6.1

Junior Member 投稿: 84 参加年月日: 08/06/18 最新の投稿
Thanks a lot.
I tried as you suggested but I have an eception like this:
java.lang.NullPointerException
at com.liferay.portal.kernel.util.Tuple.hashCode(Tuple.java:63)
at java.util.HashMap.get(HashMap.java:300)
at com.liferay.portal.util.LocalizationImpl._getCachedValue(LocalizationImpl.java:879)
at com.liferay.portal.util.LocalizationImpl.getLocalization(LocalizationImpl.java:143)
at com.liferay.portal.util.LocalizationImpl.getLocalization(LocalizationImpl.java:137)
at com.liferay.portal.kernel.util.LocalizationUtil.getLocalization(LocalizationUtil.java:69)
at com.liferay.portlet.journal.model.impl.JournalArticleModelImpl.getTitle(JournalArticleModelImpl.java:748)
at com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.notifySubscribers(JournalArticleLocalServiceImpl.java:3221)
at com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.updateStatus(JournalArticleLocalServiceImpl.java:2534)
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)

Does anyone have a complete code example about using JournalArticleServiceUtil with Liferay 6.1 to add an article?

Alfredo
11年前 に Gwowen Fu によって更新されました。

RE: Adding article programmatically with Liferay 6.1

Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
I use JournalArticleLocalServiceUtil to add article. Hope this helps.

public JournalArticle addJournalArticle(final long userId, final long groupId, final String title, final String content, final String structureId, final String templateId,
final ServiceContext serviceContext) {

JournalArticle journalArticle = null;

Map<Locale, String> titleMap = new HashMap<Locale, String>();
setLocalizedValue(titleMap, title);

try {
journalArticle = JournalArticleLocalServiceUtil.addArticle(userId, groupId, 0, 0, title.replaceAll(" ", "_"), false, JournalArticleConstants.VERSION_DEFAULT, titleMap, null,
content, "general", structureId, templateId, StringPool.BLANK, 1, 1, 2008, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, StringPool.BLANK, null,
null, StringPool.BLANK, serviceContext);
}
catch (PortalException e) {
System.err.println("Failed to add aticle.");
LOG.debug(e.getMessage());
}
catch (Exception e) {
System.err.println("Failed to add aticle.");
LOG.debug(e.getMessage());
}

return journalArticle;
}


protected void setLocalizedValue(final Map<Locale, String> map, final String value) {
Locale locale = LocaleUtil.getDefault();

map.put(locale, value);

if (!locale.equals(Locale.US)) {
map.put(Locale.US, value);
}
}
thumbnail
11年前 に Alfredo Larotonda によって更新されました。

RE: Adding article programmatically with Liferay 6.1

Junior Member 投稿: 84 参加年月日: 08/06/18 最新の投稿
Gwowen Fu:
I use JournalArticleLocalServiceUtil to add article. Hope this helps.

public JournalArticle addJournalArticle(final long userId, final long groupId, final String title, final String content, final String structureId, final String templateId,
final ServiceContext serviceContext) {

JournalArticle journalArticle = null;

Map<Locale, String> titleMap = new HashMap<Locale, String>();
setLocalizedValue(titleMap, title);

try {
journalArticle = JournalArticleLocalServiceUtil.addArticle(userId, groupId, 0, 0, title.replaceAll(" ", "_"), false, JournalArticleConstants.VERSION_DEFAULT, titleMap, null,
content, "general", structureId, templateId, StringPool.BLANK, 1, 1, 2008, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, StringPool.BLANK, null,
null, StringPool.BLANK, serviceContext);
}
catch (PortalException e) {
System.err.println("Failed to add aticle.");
LOG.debug(e.getMessage());
}
catch (Exception e) {
System.err.println("Failed to add aticle.");
LOG.debug(e.getMessage());
}

return journalArticle;
}


protected void setLocalizedValue(final Map<Locale, String> map, final String value) {
Locale locale = LocaleUtil.getDefault();

map.put(locale, value);

if (!locale.equals(Locale.US)) {
map.put(Locale.US, value);
}
}


Thanks a lot.
I tried but I had always the same exception.
I'm really disappointed. I think is not a good practice to change completely an interface without preserving old method , also with deprecation, for backwards compatibility.
Very bad.

Alfredo
thumbnail
11年前 に guru prasad によって更新されました。

Adding article programmatically with Liferay 6.1 from custom portlet

New Member 投稿: 15 参加年月日: 12/01/30 最新の投稿
Hi
i have to add the article from my custom portlet .
i am using JournalArticleLocalServiceUtil.addArticle () method .
How i will proceed with this ? i am using liferay 6.1.20 EE