|
3 | 3 | import de.hybris.platform.core.Initialization; |
4 | 4 | import de.hybris.platform.core.PK; |
5 | 5 | import de.hybris.platform.core.Registry; |
| 6 | +import de.hybris.platform.core.system.InitializationLockHandler; |
| 7 | +import de.hybris.platform.core.system.impl.DefaultInitLockDao; |
6 | 8 | import de.hybris.platform.regioncache.CacheController; |
7 | 9 | import de.hybris.platform.servicelayer.event.EventService; |
8 | 10 | import de.hybris.platform.util.JspContext; |
|
13 | 15 | import org.springframework.mock.web.MockHttpServletResponse; |
14 | 16 | import org.springframework.stereotype.Component; |
15 | 17 |
|
| 18 | +import java.lang.reflect.Method; |
| 19 | +import java.util.concurrent.Callable; |
| 20 | + |
| 21 | +import static java.lang.String.format; |
| 22 | + |
16 | 23 |
|
17 | 24 | @Component |
18 | 25 | @Scope("prototype") |
19 | 26 | public class HybrisAdapter { |
20 | 27 | private static final Logger LOG = Logger.getLogger(HybrisAdapter.class); |
| 28 | + private static final String SYSTEM_UPDATE = "System update"; |
| 29 | + private static final String HMC_RESET = "HMC Reset"; |
21 | 30 | @Autowired EventService eventService; |
22 | 31 | @Autowired CacheController cacheController; |
23 | 32 |
|
@@ -53,12 +62,34 @@ private void doInitialize(boolean update) throws Exception { |
53 | 62 | request.addParameter("clearHMC", "true"); |
54 | 63 |
|
55 | 64 | JspContext jspContext = new JspContext(jspWriter, request, new MockHttpServletResponse()); |
56 | | - Initialization.doInitialize(jspContext); |
| 65 | + |
| 66 | + try { |
| 67 | + InitializationLockHandler handler = new InitializationLockHandler(new DefaultInitLockDao()); |
| 68 | + String operationName = update ? SYSTEM_UPDATE : HMC_RESET; |
| 69 | + |
| 70 | + handler.performLocked(Registry.getCurrentTenant(), |
| 71 | + createInitializeCallable(jspContext), |
| 72 | + operationName); |
| 73 | + } catch (NoSuchMethodException e) { |
| 74 | + LOG.info(format("Internal reflection unsuccessful: system is not locked while performing '%s only' change.", HMC_RESET)); |
| 75 | + Initialization.doInitialize(jspContext); |
| 76 | + } |
57 | 77 | } finally { |
58 | 78 | LOG.debug(de.hybris.platform.util.Utilities.filterOutHTMLTags(jspWriter.getString())); |
59 | 79 | } |
60 | 80 | } |
61 | 81 |
|
| 82 | + private Callable<Boolean> createInitializeCallable(final JspContext jspContext) { |
| 83 | + return new Callable<Boolean>() { |
| 84 | + public Boolean call() throws Exception { |
| 85 | + Method m = Initialization.class.getDeclaredMethod("doInitializeImpl", JspContext.class); |
| 86 | + m.setAccessible(true); |
| 87 | + m.invoke(null, jspContext); |
| 88 | + return Boolean.TRUE; |
| 89 | + } |
| 90 | + }; |
| 91 | + } |
| 92 | + |
62 | 93 | public void clearHmcConfiguration(PK migration) throws Exception { |
63 | 94 | doInitialize(false); |
64 | 95 | eventService.publishEvent(new HmcResetEvent(getTenantId(), migration)); |
|
0 commit comments