Can a PropertyInterceptor detect that a site import is running?
Question
Can a PropertyInterceptor detect that a site import is running?
Answer
Yes. In a Jahia rule you can write - not in operation import. The equivalent
inside a PropertyInterceptor is:
JCRObservationManager.getCurrentOperationType() == JCRObservationManager.IMPORT
Both read the same signal. The rules engine turns it into the string "import"
for the DSL; from Java you compare against the constant directly.
Using it
Override canApplyOnProperty and decline while an import is running:
public class MyInterceptor extends BaseInterceptor {
@Override
public boolean canApplyOnProperty(JCRNodeWrapper node, ExtendedPropertyDefinition definition)
throws RepositoryException {
Integer op = JCRObservationManager.getCurrentOperationType();
if (op != null && op == JCRObservationManager.IMPORT) {
return false; // a site import is in progress - stand down
}
return super.canApplyOnProperty(node, definition);
}
}
Calling super.canApplyOnProperty(...) keeps whatever propertyNames,
requiredTypes, selectors and nodeTypes filters you configured on the bean.
Why it works
ImportExportBaseService wraps the whole site-import callback in
JCRObservationManager.doWithOperationType(session, JCRObservationManager.IMPORT, ...),
which sets a thread-local for the duration. Your interceptor runs on that same
thread, so it can read it.
Measured on Jahia 8.2.3.2, importing the Digitall demo site with a recording
interceptor: every property write under /sites/digitall that reached the
interceptor chain - 2735 of 2735 - reported operation type 13, which is
JCRObservationManager.IMPORT. Not a sample: all of them.
Four things to know before relying on it
It is a thread-local. It is visible only on the thread performing the import. Work you hand to another thread, a scheduled job or an async task will not see it.
Not everything around an import carries it. In the same measured run, writes
outside the site import itself reported null or 1 instead - module
installation (j:version, j:bundlesPersistentState) and some post-import
bookkeeping (jcr:lastModifiedBy, j:originWS). The signal is reliable inside
the site import, not for everything happening nearby. Always null-check before
comparing.
A nested caller can shadow it. doWithOperationType only sets the
thread-local if it is not already set, and restores it afterwards. If an outer
operation has already set a different type, you will read the outer one.
It only governs an interceptor you own. It cannot suppress Jahia's own
URLInterceptor or HtmlFilteringInterceptor - there is no supported way to do
that, and it is usually unnecessary anyway, because most imported content
properties never reach the interceptor chain at all. See
How do I stop property interceptors from running during a site import? for the
measurement behind that.
Other operation types
The same call distinguishes a few other contexts. The rules engine maps only three of them to DSL strings:
| Constant | Rules DSL value |
|---|---|
JCRObservationManager.IMPORT | import |
JCRObservationManager.SESSION_SAVE | session |
JCRObservationManager.WORKSPACE_CLONE | clone |
Anything else is null in a rule. In particular there is no copy operation
value, so a rule condition such as - not in operation copy is always true and
does nothing.
This article was drafted with AI assistance, then reviewed and curated by Jahia Customer Support engineers before publication.