EXIM script for updating - problems using HstQueryBuilder

33 views
Skip to first unread message

Brian Street

unread,
Nov 29, 2017, 6:33:21 PM11/29/17
to Hippo Community
I want to write an EXIM script to update documents/node properties based on some queries.

When I attempted to write a script based on the Fluent Search API, I discovered several classpaths aren't available to the script.

Code Example:
import com.xxxxx.beans.Article
import org.apache.jackrabbit.util.*
import org.hippoecm.repository.api.*
import org.hippoecm.repository.util.JcrUtils
import org.onehippo.repository.update.BaseNodeUpdateVisitor
import org.onehippo.forge.content.pojo.model.*
import org.onehippo.forge.content.exim.core.*
import org.onehippo.forge.content.exim.core.impl.*
import org.onehippo.forge.content.exim.core.util.*
import org.hippoecm.hst.content.beans.query.*
import org.hippoecm.hst.content.beans.query.exceptions.*;
import org.hippoecm.hst.site.HstServices
import java.io.*
import javax.jcr.*
...
private List<Article> queryArticles() {
final Node scope = JcrUtils.getNodeIfExists(SCOPE_PATH, eximSession)
//final ContentBeansTool cbt = HstServices.componentManager.getComponent(ContentBeansTool.class.name)
//final HstQueryManager queryManager = cbt.createQueryManager(eximSession)
final HstQuery hstQuery = HstQueryBuilder.create(scope)
.ofTypes(Article.class)
.build()
final String queryString = hstQuery.getQueryAsString(false)

try {
HstQueryResult result = hstQuery.execute()
log.info "article query found ${result.totalSize} with ${queryString}"
return result.hippoBeans.collect { it as Article }
} catch (QueryException qe) {
log.error "QueryException(${qe.message}) from ${queryString}"
} catch (Exception e) {
log.error("kerblooey", e)
}
return []
} 
 
However, the logs show compilation errors of unavailable classes:
[INFO] [talledLocalContainer] 29.11.2017 16:08:54 ERROR ObservationManager [UpdaterRegistry.buildRegistry:88] Failed to register updater 'set-article-author': org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[INFO] [talledLocalContainer] updater: 15: unable to resolve class org.hippoecm.hst.site.HstServices
[INFO] [talledLocalContainer]  @ line 15, column 1.
[INFO] [talledLocalContainer]    import org.hippoecm.hst.site.HstServices
[INFO] [talledLocalContainer]    ^
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] updater: 3: unable to resolve class com.dhi.efc.beans.Article
[INFO] [talledLocalContainer]  @ line 3, column 1.
[INFO] [talledLocalContainer]    import com.xxxxx.beans.Article
[INFO] [talledLocalContainer]    ^
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] updater: 79: unable to resolve class QueryException
[INFO] [talledLocalContainer]  @ line 79, column 11.
[INFO] [talledLocalContainer]            } catch (QueryException qe) {
[INFO] [talledLocalContainer]              ^
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] 3 errors
 
Which of the following options should I pursue?
* HstQueryBuilder
* javax.jcr.Query
* forget querying & walk the node tree

Also, can I leverage any of my bean classes from the main project, or do I need to replace with low-level javax.jcr.Node/javax.jcr.Property ?


Woonsan Ko

unread,
Nov 29, 2017, 7:00:53 PM11/29/17
to hippo-c...@googlegroups.com
Hi Brian,

Please see my comments inline.

On Wed, Nov 29, 2017 at 6:33 PM, Brian Street <brian.c...@gmail.com> wrote:
I want to write an EXIM script to update documents/node properties based on some queries.

When I attempted to write a script based on the Fluent Search API, I discovered several classpaths aren't available to the script.

You cannot use HST API in an updater script because the updater script is being executed by a groovy script engine in cms.war application, not in HST-2 based site.war application. In CMS web application context, HST-2 runtime is not available. You should stick with JCR (Query) API, unfortunately.
You cannot use HST-2 Content Beans unfortunately for the same reason. You need to stick with JCR APIs or Hippo Repository APIs, Hippo Repository Utilities, etc., but no HST-2 APIs in groovy scripts.

Regards,

Woonsan
 


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--

Brian Street

unread,
Nov 30, 2017, 11:08:37 AM11/30/17
to Hippo Community
Thanks, that makes sense & saved experimentation time.
Hi Brian,

To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.

Brian Street

unread,
Nov 30, 2017, 11:46:56 AM11/30/17
to Hippo Community
For reference, an example EXIM script with queries is the ImageSetUpdater

QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery("hippo:namespaces//element(*,hippogallery:imageset)", "xpath");
QueryResult queryResult = query.execute();
NodeIterator nodeIterator = queryResult.getNodes();

if you look at the example, there are some groovy simplifications that could be done, but  this is immensely helpful getting started.
Reply all
Reply to author
Forward
0 new messages