001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Florent Guillaume 016 */ 017package org.nuxeo.ecm.quota; 018 019import static org.nuxeo.ecm.core.versioning.VersioningService.DISABLE_AUTO_CHECKOUT; 020import static org.nuxeo.ecm.core.versioning.VersioningService.VERSIONING_OPTION; 021import static org.nuxeo.ecm.platform.audit.service.NXAuditEventsService.DISABLE_AUDIT_LOGGER; 022import static org.nuxeo.ecm.platform.dublincore.listener.DublinCoreListener.DISABLE_DUBLINCORE_LISTENER; 023import static org.nuxeo.ecm.platform.ec.notification.NotificationConstants.DISABLE_NOTIFICATION_SERVICE; 024import static org.nuxeo.ecm.platform.htmlsanitizer.HtmlSanitizerListener.DISABLE_HTMLSANITIZER_LISTENER; 025import static org.nuxeo.ecm.platform.publisher.listeners.DomainEventsListener.DISABLE_DOMAIN_LISTENER; 026import static org.nuxeo.ecm.quota.size.QuotaSyncListenerChecker.DISABLE_QUOTA_CHECK_LISTENER; 027 028import java.util.Arrays; 029import java.util.List; 030 031import org.nuxeo.ecm.core.api.DocumentModel; 032import org.nuxeo.ecm.core.api.VersioningOption; 033 034public class QuotaUtils { 035 036 private QuotaUtils() { 037 } 038 039 public static List<String> FLAGS = Arrays.asList( // 040 DISABLE_AUDIT_LOGGER, // 041 DISABLE_DUBLINCORE_LISTENER, // 042 DISABLE_NOTIFICATION_SERVICE, // 043 DISABLE_AUTO_CHECKOUT, // 044 DISABLE_DOMAIN_LISTENER, // 045 DISABLE_HTMLSANITIZER_LISTENER); 046 047 /** 048 * Disables listeners and options when saving a value in a quota facet. 049 * 050 * @param doc the document 051 * @since 7.4 052 */ 053 public static void disableListeners(DocumentModel doc) { 054 for (String flag : FLAGS) { 055 doc.putContextData(flag, Boolean.TRUE); 056 } 057 doc.putContextData(VERSIONING_OPTION, VersioningOption.NONE); 058 } 059 060 /** 061 * Clears the context data of the various flags used to disable listeners. 062 * 063 * @param doc the document 064 * @since 7.4 065 */ 066 public static void clearContextData(DocumentModel doc) { 067 for (String flag : FLAGS) { 068 doc.putContextData(flag, null); 069 } 070 doc.putContextData(VERSIONING_OPTION, null); 071 doc.putContextData(DISABLE_QUOTA_CHECK_LISTENER, null); 072 } 073 074}