Forums de discussion

Add articles to Liferay programmatically?

Marc Vanderstraeten, modifié il y a 15 années.

Add articles to Liferay programmatically?

New Member Publications: 4 Date d'inscription: 04/06/08 Publications récentes
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, modifié il y a 15 années.

RE: Add articles to Liferay programmatically?

Liferay Master Publications: 582 Date d'inscription: 16/05/07 Publications récentes
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, modifié il y a 15 années.

RE: Add articles to Liferay programmatically?

Liferay Master Publications: 582 Date d'inscription: 16/05/07 Publications récentes
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, modifié il y a 15 années.

RE: Add articles to Liferay programmatically?

New Member Publications: 8 Date d'inscription: 27/06/08 Publications récentes
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, modifié il y a 15 années.

RE: Add articles to Liferay programmatically?

New Member Publications: 11 Date d'inscription: 19/06/08 Publications récentes
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, modifié il y a 13 années.

RE: Add articles to Liferay programmatically?

New Member Publications: 4 Date d'inscription: 24/11/10 Publications récentes
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, modifié il y a 12 années.

RE: Add articles to Liferay programmatically?

Junior Member Publications: 41 Date d'inscription: 20/05/11 Publications récentes
Thanks from the future!

Edgar Tanaka:


I hope this help someone save time in the future.
thumbnail
Jacques Traore, modifié il y a 11 années.

RE: Add articles to Liferay programmatically?

Junior Member Publications: 49 Date d'inscription: 21/01/13 Publications récentes
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, modifié il y a 8 années.

RE: Add articles to Liferay programmatically?

New Member Publications: 7 Date d'inscription: 11/11/05 Publications récentes
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, modifié il y a 8 années.

RE: Add articles to Liferay programmatically?

Liferay Legend Publications: 6403 Date d'inscription: 23/09/08 Publications récentes
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, modifié il y a 14 années.

RE: Add articles to Liferay programmatically?

Junior Member Publications: 95 Date d'inscription: 18/06/09 Publications récentes
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, modifié il y a 14 années.

RE: Add articles to Liferay programmatically?

Liferay Legend Publications: 1228 Date d'inscription: 14/04/08 Publications récentes
you may also read this link: How to use liferay for Larger Sites, it was in v5.1.* but the approach is still relevant.