Updating JournalArticles programmatically

thumbnail
bernd kopinits, modified 8 Years ago. Junior Member Posts: 28 Join Date: 12/8/14 Recent Posts
Hello, we're using Liferay 6.2 SP17 and creating articles programmatically with this API call

JournalArticle newArticle = JournalArticleLocalServiceUtil.addArticle(userId, groupId, folderId, titleMap, descMap, content, structureKey, templateKey, sc);


Later we're trying to update article's content programmatically with this call

JournalArticle updatedArticle = JournalArticleLocalServiceUtil.updateArticle(userId, groupId, newArticle.getFolderId(), newArticle.getArticleId(), newArticle.getVersion(), newArticle.getTitleMap(), newArticle.getDescriptionMap(), newContent, newArticle.getLayoutUuid(), sc);


While debugging, the content property of the updatedArticle variable shows the new content. In the database a new minorversion is created with the correct content. However when we open the article, we can see the new versionnumber but the content is the old one. Why are we presented with the old content?

Thanks, Bernd
thumbnail
Olaf Kock, modified 8 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
I'm trying to make this code a bit more readable by introducing line breaks
bernd kopinits:

JournalArticle newArticle = JournalArticleLocalServiceUtil.addArticle(
    userId, groupId, folderId, 
    titleMap, descMap, content, 
    structureKey, templateKey, sc);


Later we're trying to update article's content programmatically with this call

JournalArticle updatedArticle = JournalArticleLocalServiceUtil.updateArticle(
    userId, groupId, newArticle.getFolderId(), newArticle.getArticleId(), 
    newArticle.getVersion(), newArticle.getTitleMap(), newArticle.getDescriptionMap(), 
    newContent, newArticle.getLayoutUuid(), sc);


While debugging, the content property of the updatedArticle variable shows the new content. In the database a new minorversion is created with the correct content. However when we open the article, we can see the new versionnumber but the content is the old one. Why are we presented with the old content?


The two easiest points (please check):
  • Validate the interface if you haven't exchanged any ids
  • The new content should be XML and might have multiple languages. You might only update one language version
  • Are you running a cluster, update it on one machine, then access it on the other? In that case this points to a flawed cluster setup


It might be something less (or even more) obvious, but these are the quick-to-check points, assuming that you following the debugger closely, would have caught the easiest cases.
thumbnail
bernd kopinits, modified 8 Years ago. Junior Member Posts: 28 Join Date: 12/8/14 Recent Posts
  • Validate the interface if you haven't exchanged any ids
    Sorry, I'm not sure what you mean by that.

  • The new content should be XML and might have multiple languages. You might only update one language version
    the content before the update looks like
    <!--?xml version="1.0"?-->
     
     <root available-locales="de_DE" default-locale="de_DE">
     	<static-content language-id="de_DE">hello there</static-content>
     </root>

    the content after the update
    <!--?xml version="1.0"?-->
     
     <root available-locales="de_DE" default-locale="de_DE">
     	<static-content language-id="de_DE">hello today</static-content>
     </root>

    all that has changed is the string inside of the cdata.

  • Are you running a cluster, update it on one machine, then access it on the other? In that case this points to a flawed cluster setup
    the process is running an my local dev client, so no clustering.
thumbnail
Olaf Kock, modified 8 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
bernd kopinits:
  • Validate the interface if you haven't exchanged any ids

Sorry, I'm not sure what you mean by that.


I meant: Double-Check that you didn't exchange some parameters - e.g. the different IDs you provide etc. This is one of the easy to miss problems. Look up the interface, be 200% sure that everything is in the right order.

As I said above: Let's start with what's easy to rule out. Sorry, if this all sounds trivial - everything you write sounds like it should work. Seems reasonable to hunt for the easily missed simple things first...
thumbnail
Christoph Rabel, modified 8 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Does deleting the caches in the service administration help? (Or a restart)
Also, please check the database for differences between the new entry and the old one. e.g. a status might be set.