Foren

Add articles to Liferay programmatically?

Marc Vanderstraeten, geändert vor 15 Jahren.

Add articles to Liferay programmatically?

New Member Beiträge: 4 Beitrittsdatum: 04.06.08 Neueste Beiträge
I am a newbie to Liferay. I would like to add programmatically articles (or other content) to liferay using php or via other means (xml, http, rest, soap...), or even directly in MySQL? Is this possible?

I need to run a program that monitors a directory on a ftp server where xml files (articles form a new site) are posted on a daily basis, and should be imported regularly (cron job) and put in Liferay as articles, and then deleted (the .xml files of course).

The articles put in Liferay this way are in draft mode (not yet published) and can then be reviewed/changed and finally be published.

How can I accomplish this?

I have some articles attached...

Please help... or do I have to go back to a php based solution?
thumbnail
Björn Ryding, geändert vor 15 Jahren.

RE: Add articles to Liferay programmatically?

Liferay Master Beiträge: 582 Beitrittsdatum: 16.05.07 Neueste Beiträge
Hi Marc,

Have a look at Liferay's Journal Article Service:
http://content.liferay.com/4.3/api/portal-service/com/liferay/portlet/journal/service/JournalArticleService.html

When updating the articles, the journal portlet's webdav interface may also be an option.

Cheers,
Björn
thumbnail
Björn Ryding, geändert vor 15 Jahren.

RE: Add articles to Liferay programmatically?

Liferay Master Beiträge: 582 Beitrittsdatum: 16.05.07 Neueste Beiträge
I forgot to mention that you can access Liferay's services in a number of ways.

For example, to access a service using SOAP use:
http://localhost:8080/tunnel-web/secure/axis/someServiceOfYourChoice

The Web Service Deployment Descriptor with the service names is located at:
webapps/tunnel-web/WEB-INF/server-config.wsdd

For some introductory information about how Liferay's services are built, see:
http://www.liferay.com/web/guest/products/tech_specs/architecture/soa
navkalp varshney, geändert vor 15 Jahren.

RE: Add articles to Liferay programmatically?

New Member Beiträge: 8 Beitrittsdatum: 27.06.08 Neueste Beiträge
for articles seems there are no webdav URLs. Is it possible to create htmls from portlets programmatically, or save article programmatically in html format
Radu Banica, geändert vor 15 Jahren.

RE: Add articles to Liferay programmatically?

New Member Beiträge: 11 Beitrittsdatum: 19.06.08 Neueste Beiträge
I have successfully used the function JournalArticleServiceUtil.addArticle in a portlet to add a new article.
The portlet parse an XML file with a list of article content and calls this function. You can also load images to the article by playing with the "Map<String, byte[]> images" parameter.

You can approve the article automatically by calling the function JournalArticleServiceUtil.approveArticle
Edgar Tanaka, geändert vor 13 Jahren.

RE: Add articles to Liferay programmatically?

New Member Beiträge: 4 Beitrittsdatum: 24.11.10 Neueste Beiträge
Radu B:
I have successfully used the function JournalArticleServiceUtil.addArticle in a portlet to add a new article.
The portlet parse an XML file with a list of article content and calls this function. You can also load images to the article by playing with the "Map<String, byte[]> images" parameter.

You can approve the article automatically by calling the function JournalArticleServiceUtil.approveArticle


This approveArticle method is not available after version 6. I spent a lot of time trying to figure out how to add article programatically and make them approved right away. The way to do it if you are using version 6.0.5 is set a workflow aciton in your ServiceContext object:

		JournalArticleServiceSoapServiceLocator locator = new JournalArticleServiceSoapServiceLocator();
		ServiceContext serviceContext = new ServiceContext();
		serviceContext.setScopeGroupId(GROUP_ID);
		serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); //so that the article is added as published and not draft
		JournalArticleServiceSoap soap = locator.getPortlet_Journal_JournalArticleService(LifeRayUtils.getURL(remoteUser, remotePassword, ARTICLE_ENTRY_SERVICE_NAME, server, port));
			

				JournalArticleSoap jas = soap.addArticle(GROUP_ID, 
								b.getBlogId().toString(), 
								true, //autoArticleId 
								b.getTitle(), //title
								null, //description
								b.getBody(), //content
								"news", //type: General, news, blogs, test, press release
								"", // structure id 
								"", //template id
								displayDateMonth,
								displayDateDay, 
								displayDateYear,
								displayDateHour,
								displayDateMinute, 
								0, //expirationDateMonth
								0, //expirationDateDay
								0, //expirationDateYear
								0, //expirationDateHour
								0, //expirationDateMinute
								true, //never expire 
								0, //reviewDateMonth
								0, //reviewDateDay
								0, //reviewDateYear
								0, //reviewDateHour
								0, //reviewDateMinute
								true, //neverReview
								true, //indexable
								"", //articleURL
								serviceContext);


I hope this help someone save time in the future.
thumbnail
Suraj Bihari, geändert vor 12 Jahren.

RE: Add articles to Liferay programmatically?

Junior Member Beiträge: 41 Beitrittsdatum: 20.05.11 Neueste Beiträge
Thanks from the future!

Edgar Tanaka:


I hope this help someone save time in the future.
thumbnail
Jacques Traore, geändert vor 11 Jahren.

RE: Add articles to Liferay programmatically?

Junior Member Beiträge: 49 Beitrittsdatum: 21.01.13 Neueste Beiträge
Hi Edgar,
What about translation?
My contents (with a custom structure) have both English and French versions.
How to construct the XML content to achieve this?

Thanks
Anirudh Joshi, geändert vor 8 Jahren.

RE: Add articles to Liferay programmatically?

New Member Beiträge: 7 Beitrittsdatum: 11.11.05 Neueste Beiträge
were you able to achieve this? We also want to do the same and create translated content which come to back to us from a 3rd party in a XML format

Thanks
Ani
thumbnail
Olaf Kock, geändert vor 8 Jahren.

RE: Add articles to Liferay programmatically?

Liferay Legend Beiträge: 6403 Beitrittsdatum: 23.09.08 Neueste Beiträge
A very stupid version (just by concatenating strings - the way you shouldn't construct xml in production) was demonstrated in my Ridiculously simple plugins session on dev.life - code is linked from the article. Just use proper xml construction and assume that the individual string snippets are safe to concatenate when you look at my code. At least it's easy to understand that way.
thumbnail
mallepula narayanagoud, geändert vor 14 Jahren.

RE: Add articles to Liferay programmatically?

Junior Member Beiträge: 95 Beitrittsdatum: 18.06.09 Neueste Beiträge
Hi Marc,

i have the same issues,can u help me to resolve the problem.
if possible send me code or approach.

Thanks,
Mallepula.
thumbnail
Victor Zorin, geändert vor 14 Jahren.

RE: Add articles to Liferay programmatically?

Liferay Legend Beiträge: 1228 Beitrittsdatum: 14.04.08 Neueste Beiträge
you may also read this link: How to use liferay for Larger Sites, it was in v5.1.* but the approach is still relevant.