001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
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 *     dmetzler
016 */
017package org.nuxeo.ecm.quota.size;
018
019import java.util.Collection;
020import java.util.HashSet;
021import java.util.Set;
022
023import org.slf4j.Logger;
024import org.nuxeo.runtime.model.ComponentInstance;
025import org.nuxeo.runtime.model.DefaultComponent;
026import org.slf4j.LoggerFactory;
027
028/**
029 * @author dmetzler
030 * @since 5.7
031 */
032public class QuotaSizeServiceImpl extends DefaultComponent implements QuotaSizeService {
033
034    private Set<String> excludedPathList = new HashSet<String>();
035
036    private static Logger LOG = LoggerFactory.getLogger(QuotaSizeServiceImpl.class);
037
038    @Override
039    public Collection<String> getExcludedPathList() {
040        return excludedPathList;
041    }
042
043    @Override
044    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
045        if ("exclusions".equals(extensionPoint)) {
046            BlobExcludeDescriptor descriptor = (BlobExcludeDescriptor) contribution;
047            LOG.info(String.format("Adding %s to size quota computation's blacklist", descriptor.getPathRegexp()));
048            excludedPathList.add(descriptor.getPathRegexp());
049        }
050
051    }
052
053    @Override
054    public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
055        if ("exclusions".equals(extensionPoint)) {
056            BlobExcludeDescriptor descriptor = (BlobExcludeDescriptor) contribution;
057            String pathRegexp = descriptor.getPathRegexp();
058            if (excludedPathList.contains(pathRegexp)) {
059                LOG.info(String.format("Removing %s from size quota computation's blacklist", pathRegexp));
060                excludedPathList.remove(pathRegexp);
061
062            }
063        }
064    }
065
066}