001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.kernel.modeshape.observer; 019 020import static com.google.common.collect.ImmutableSet.of; 021import static org.fcrepo.kernel.api.FedoraTypes.FEDORA_BINARY; 022import static org.fcrepo.kernel.api.FedoraTypes.FEDORA_CONTAINER; 023import static org.fcrepo.kernel.api.FedoraTypes.FEDORA_RESOURCE; 024import static org.fcrepo.kernel.modeshape.FedoraJcrConstants.ROOT; 025import static org.fcrepo.kernel.modeshape.observer.FedoraEventImpl.getResourceTypes; 026 027import javax.jcr.observation.Event; 028 029import java.util.Set; 030 031/** 032 * {@link EventFilter} that passes only events emitted from nodes with a Fedora 033 * JCR type, or properties attached to them, except in the case of a node 034 * removal. In that case, since we cannot test the node for its types, we assume 035 * that any non-JCR namespaced node is fair game. 036 * 037 * @author ajs6f 038 * @author barmintor 039 * @since Dec 2013 040 * @author eddies 041 * @since Feb 7, 2013 042 * @author escowles 043 * @since Oct 3, 2013 044 */ 045public class DefaultFilter implements EventFilter { 046 047 private static final Set<String> fedoraMixins = 048 of(FEDORA_BINARY, FEDORA_CONTAINER, FEDORA_RESOURCE, ROOT); 049 050 @Override 051 public boolean test(final Event event) { 052 return getResourceTypes(event).anyMatch(fedoraMixins::contains); 053 } 054}