001/* 002 * (C) Copyright 2015 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 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.quota; 020 021import static org.nuxeo.ecm.core.versioning.VersioningService.DISABLE_AUTO_CHECKOUT; 022import static org.nuxeo.ecm.core.versioning.VersioningService.VERSIONING_OPTION; 023import static org.nuxeo.ecm.platform.audit.service.NXAuditEventsService.DISABLE_AUDIT_LOGGER; 024import static org.nuxeo.ecm.platform.dublincore.listener.DublinCoreListener.DISABLE_DUBLINCORE_LISTENER; 025import static org.nuxeo.ecm.platform.ec.notification.NotificationConstants.DISABLE_NOTIFICATION_SERVICE; 026import static org.nuxeo.ecm.platform.htmlsanitizer.HtmlSanitizerListener.DISABLE_HTMLSANITIZER_LISTENER; 027import static org.nuxeo.ecm.platform.publisher.listeners.DomainEventsListener.DISABLE_DOMAIN_LISTENER; 028import static org.nuxeo.ecm.quota.size.DocumentsSizeUpdater.DISABLE_QUOTA_CHECK_LISTENER; 029 030import java.util.Arrays; 031import java.util.List; 032 033import org.nuxeo.ecm.core.api.DocumentModel; 034import org.nuxeo.ecm.core.api.VersioningOption; 035 036public class QuotaUtils { 037 038 private QuotaUtils() { 039 } 040 041 protected static final List<String> FLAGS = Arrays.asList( // 042 DISABLE_QUOTA_CHECK_LISTENER, // 043 DISABLE_AUDIT_LOGGER, // 044 DISABLE_DUBLINCORE_LISTENER, // 045 DISABLE_NOTIFICATION_SERVICE, // 046 DISABLE_AUTO_CHECKOUT, // 047 DISABLE_DOMAIN_LISTENER, // 048 DISABLE_HTMLSANITIZER_LISTENER); 049 050 /** 051 * Disables listeners and options when saving a value in a quota facet. 052 * 053 * @param doc the document 054 * @since 7.4 055 */ 056 public static void disableListeners(DocumentModel doc) { 057 for (String flag : FLAGS) { 058 doc.putContextData(flag, Boolean.TRUE); 059 } 060 doc.putContextData(VERSIONING_OPTION, VersioningOption.NONE); 061 } 062 063 /** 064 * Clears the context data of the various flags used to disable listeners. 065 * 066 * @param doc the document 067 * @since 7.4 068 */ 069 public static void clearContextData(DocumentModel doc) { 070 for (String flag : FLAGS) { 071 doc.putContextData(flag, null); 072 } 073 doc.putContextData(VERSIONING_OPTION, null); 074 } 075 076}