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