001/* 002 * (C) Copyright 2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.ecm.platform.importer.filter; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.core.event.EventServiceAdmin; 024import org.nuxeo.runtime.api.Framework; 025 026public class EventServiceConfiguratorFilter implements ImporterFilter { 027 028 private static final Log log = LogFactory.getLog(EventServiceConfiguratorFilter.class); 029 030 protected boolean blockSyncPostCommitProcessing = false; 031 032 protected boolean blockAsyncProcessing = false; 033 034 protected boolean blockMimeTypeDetection = false; 035 036 protected boolean blockNotifications = true; 037 038 // @since 8.3 039 protected boolean blockIndexing = false; 040 041 protected boolean bulkMode = false; 042 043 protected static final String NOTIF_LISTENER = "notificationListener"; 044 045 protected static final String MIME_LISTENER = "mimetypeIconUpdater"; 046 047 protected static final String INDEXING_LISTENER = "elasticSearchInlineListener"; 048 049 public EventServiceConfiguratorFilter(Boolean blockSyncPostCommitProcessing, Boolean blockAsyncProcessing, 050 Boolean blockMimeTypeDetection, Boolean blockIndexing, Boolean bulkMode) { 051 if (blockAsyncProcessing != null) { 052 this.blockAsyncProcessing = blockAsyncProcessing; 053 } 054 if (blockSyncPostCommitProcessing != null) { 055 this.blockSyncPostCommitProcessing = blockSyncPostCommitProcessing; 056 } 057 if (blockMimeTypeDetection != null) { 058 this.blockMimeTypeDetection = blockMimeTypeDetection; 059 } 060 if (blockIndexing != null) { 061 this.blockIndexing = blockIndexing; 062 } 063 if (bulkMode != null) { 064 this.bulkMode = bulkMode; 065 } 066 } 067 068 @Override 069 public void handleBeforeImport() { 070 EventServiceAdmin eventAdmin = Framework.getService(EventServiceAdmin.class); 071 if (eventAdmin == null) { 072 log.error("EventServiceAdmin service was not found ... Possible that the import process will not proceed ok"); 073 return; 074 } 075 eventAdmin.setBulkModeEnabled(bulkMode); 076 eventAdmin.setBlockAsyncHandlers(blockAsyncProcessing); 077 eventAdmin.setBlockSyncPostCommitHandlers(blockSyncPostCommitProcessing); 078 if (blockMimeTypeDetection) { 079 eventAdmin.setListenerEnabledFlag(MIME_LISTENER, false); 080 } 081 if (blockNotifications) { 082 eventAdmin.setListenerEnabledFlag(NOTIF_LISTENER, false); 083 } 084 if (blockIndexing) { 085 eventAdmin.setListenerEnabledFlag(INDEXING_LISTENER, false); 086 } 087 } 088 089 @Override 090 public void handleAfterImport(Exception e) { 091 EventServiceAdmin eventAdmin = Framework.getService(EventServiceAdmin.class); 092 if (eventAdmin != null) { 093 log.info("Restoring default event listeners and bulk mode"); 094 eventAdmin.setBulkModeEnabled(false); 095 eventAdmin.setBlockAsyncHandlers(false); 096 eventAdmin.setBlockSyncPostCommitHandlers(false); 097 eventAdmin.setListenerEnabledFlag(NOTIF_LISTENER, true); 098 eventAdmin.setListenerEnabledFlag(MIME_LISTENER, true); 099 eventAdmin.setListenerEnabledFlag(INDEXING_LISTENER, true); 100 } 101 } 102 103 public boolean getBlockNotifications() { 104 return blockNotifications; 105 } 106 107 public void setBlockNotifications(boolean blockNotifications) { 108 this.blockNotifications = blockNotifications; 109 } 110 111 @Override 112 public String toString() { 113 return String.format( 114 "blockSyncPostCommitProcessing set %b, blockAsyncProcessing set %b, blockMimeTypeDetection set %b, blockNotifications set %b, blockIndexing set %b, bulkMode set %b", 115 blockSyncPostCommitProcessing, blockAsyncProcessing, blockMimeTypeDetection, blockNotifications, blockIndexing, bulkMode); 116 } 117}