Foros de discusión

Add articles to Liferay programmatically?

Marc Vanderstraeten, modificado hace 15 años.

Add articles to Liferay programmatically?

New Member Mensajes: 4 Fecha de incorporación: 4/06/08 Mensajes recientes
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, modificado hace 15 años.

RE: Add articles to Liferay programmatically?

Liferay Master Mensajes: 582 Fecha de incorporación: 16/05/07 Mensajes recientes
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, modificado hace 15 años.

RE: Add articles to Liferay programmatically?

Liferay Master Mensajes: 582 Fecha de incorporación: 16/05/07 Mensajes recientes
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, modificado hace 15 años.

RE: Add articles to Liferay programmatically?

New Member Mensajes: 8 Fecha de incorporación: 27/06/08 Mensajes recientes
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, modificado hace 15 años.

RE: Add articles to Liferay programmatically?

New Member Mensajes: 11 Fecha de incorporación: 19/06/08 Mensajes recientes
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, modificado hace 13 años.

RE: Add articles to Liferay programmatically?

New Member Mensajes: 4 Fecha de incorporación: 24/11/10 Mensajes recientes
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, modificado hace 12 años.

RE: Add articles to Liferay programmatically?

Junior Member Mensajes: 41 Fecha de incorporación: 20/05/11 Mensajes recientes
Thanks from the future!

Edgar Tanaka:


I hope this help someone save time in the future.
thumbnail
Jacques Traore, modificado hace 11 años.

RE: Add articles to Liferay programmatically?

Junior Member Mensajes: 49 Fecha de incorporación: 21/01/13 Mensajes recientes
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, modificado hace 8 años.

RE: Add articles to Liferay programmatically?

New Member Mensajes: 7 Fecha de incorporación: 11/11/05 Mensajes recientes
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, modificado hace 8 años.

RE: Add articles to Liferay programmatically?

Liferay Legend Mensajes: 6403 Fecha de incorporación: 23/09/08 Mensajes recientes
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, modificado hace 14 años.

RE: Add articles to Liferay programmatically?

Junior Member Mensajes: 95 Fecha de incorporación: 18/06/09 Mensajes recientes
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, modificado hace 14 años.

RE: Add articles to Liferay programmatically?

Liferay Legend Mensajes: 1228 Fecha de incorporación: 14/04/08 Mensajes recientes
you may also read this link: How to use liferay for Larger Sites, it was in v5.1.* but the approach is still relevant.