Creating/Updating the CMS documents through scheduler job

My use case is to run a backend Scheduler job in hippo CMS (which is working)
From there, I need to create a new document dynamically or edit an existing document.

I came across EditableWorkflow API (https://onehippo-forge.github.io/jcr-pojo-binding/examples-bindings.html) , where I can create ContentNode and bind it to and editable instance and I see a document getting created as desired.

If a document is already present I want to check it first and update it, instead of creating new document with same name. Now the questions are:

  1. How can I know if document with same name exists already?
  2. If it exists, How can I update the data within the document ? (and not create a new document with same name/id)

Hi,

If you use Content EXIM (which is using the jcr-pojo-binding module internally), your code will be even shorter.
See the following example code lines in https://onehippo-forge.github.io/content-export-import/tutorials-import-docs.html:

// 5. Create or update document at documentLocation from contentNode with locale and localized name.
updatedDocumentLocation =
    importTask.createOrUpdateDocumentFromVariantContentNode(contentNode, primaryTypeName, 
documentLocation, locale, localizedName)

Woonsan

Thanks a lot Woonsan. :slight_smile: This will indeed save me quite some code and time.

Could you please tell me, what is localizedName used for?

localizedName is for display name in CMS.
For example, “The Medusa News” document in a CMS folder is a display name, or to be more precise, a localized display name in English, whereas its physical node name is ‘the-medusa-news’ which is probably inside the contentNode object.

Regards,

Woonsan

Thanks for the update Woonsan.
There are two further questions:

  1. Suppose if I pass ‘Foo Bar’ as localized name, it still creates document with name foo_bar.
    I am passing path as: /content/documents/app/dynamic-documents/foo_bar

  2. I am opening a session (Session session = context.createSystemSession();), Looping through data for creating say 10 documents and saving the session in each iteration and finally doing session.logout() after loop ends.
    , but I see following exception from EXIM plugin for some cases -
    Do you have idea, why is it so? because Data being passed looks fine to me.

[INFO] [talledLocalContainer] #component==GML# #sourcetype==log4j# [13 Jul 2018 14:49:06,704] [ERROR] [org.quartz.core.JobRunShell]: [Job DEFAULT.d055f4a0-f48a-4d9c-bb69-78843aba3947 threw an unhandled Exception: ]
[INFO] [talledLocalContainer] java.lang.NoSuchMethodError: org.hippoecm.repository.standardworkflow.DefaultWorkflow.setDisplayName(Ljava/lang/String;)V
[INFO] [talledLocalContainer] at org.onehippo.forge.content.exim.core.impl.WorkflowDocumentManagerImpl.createDocument(WorkflowDocumentManagerImpl.java:422)
[INFO] [talledLocalContainer] at org.onehippo.forge.content.exim.core.impl.WorkflowDocumentVariantImportTask.createDocument(WorkflowDocumentVariantImportTask.java:153)
[INFO] [talledLocalContainer] at org.onehippo.forge.content.exim.core.impl.WorkflowDocumentVariantImportTask.createOrUpdateDocumentFromVariantContentNode(WorkflowDocumentVariantImportTask.java:86)

That’s how it should work. The physical node name should be always URL-safe string.

It looks like the EXIM version is incompatible with your CMS version. Use the compatible version with your CMS version:

Woonsan

Thanks a lot Woonsan. :slight_smile:
#1 was also happening because of version conflict.
I was seeing URL safe string (foo_bar) instead of the localized name (Foo Bar)

Hi Woonsan,

Can you suggest some way to unit/integration test the related code?
With older plugin , I was redirected to JCRJobStoreTest (based on RepositoryTestCase)

So, Just wanted your inputs on creating the test case and what expected value to look for. (e.g. String path returned by method - createOrUpdateDocumentFromVariantContentNode() to check if document got created? )

I don’t think we have any product support for Mocking with Hippo Workflow API on which Content EXIM depends.
So, RepositoryTestCase is the only way to go for unit/integration tests.

Please see the JavaDoc as well:

Regards,

Woonsan

Hi @woonsanko ,

As we were working on one of the feature, I came across a scenario.
If I am setting 3(a,b,c) out of 4 properties (a,b,c,d) of a document, then
EXIM API clears the property value for d. (Image in my case)

Based on some previous conversations, I had an idea that it doesn’t override and in fact, worked fine for some of the properties like taxonomy values.

Can you suggest , how to prevent overriding of a property which I don’t want to update?

Hi Sarthak,

Could you please start a new thread for the new question? It’s better to create a new post for a new topic wherever possible as not many people can associate the question with the old one.

Regards,

Woonsan

ok Woonsan. I’ll do that, but as it was connected to the same context, I thought it will be easier for you to understand.