Skip interceptor for synchronization process

There is a lot of interceptors, which must be not executed while creating/updating items from sync process.

Unfortunately hybris doesn’t have OOTB functionality to do this, also SyncItemJob doesn’t put any attribute in session, which will indicate, that current execution context is a synchronization job, so the only way, which I found to resolve it, was to iterate via tread execution stack and check the class names.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18

package com.blog.core.utils.impl;

public class BlogThreadInvestigateUtil {

    private BlogThreadInvestigateUtil() {
        throw new UnsupportedOperationException("This is Utility class.");
    }

    public static boolean isRunBySyncProcess() {
        for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
            if (element.getClassName().toLowerCase().contains("catalogversionsync")) {
                return true;
            }
        }
        return false;
    }
}

UPD 2019-01-31

Finally hybris added session attribute, which indicates if interceptor is run from sync process.

1
Boolean isSyncActive = (Boolean) this.sessionService.getCurrentSession().getAttribute("catalog.sync.active");
comments powered by Disqus