001/** 002 * Copyright 2015 DuraSpace, Inc. 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 */ 016package org.fcrepo.kernel.impl.utils.iterators; 017 018import static org.slf4j.LoggerFactory.getLogger; 019 020import javax.jcr.RepositoryException; 021import javax.jcr.Session; 022 023import org.fcrepo.kernel.models.FedoraResource; 024import org.fcrepo.kernel.identifiers.IdentifierConverter; 025import org.fcrepo.kernel.utils.iterators.RdfStream; 026import org.slf4j.Logger; 027 028import com.hp.hpl.jena.rdf.model.Resource; 029import com.hp.hpl.jena.rdf.model.Statement; 030 031/** 032 * Consumes an {@link org.fcrepo.kernel.utils.iterators.RdfStream} by removing its contents from the 033 * JCR. 034 * 035 * @see RdfAdder 036 * @author ajs6f 037 * @since Oct 24, 2013 038 */ 039public class RdfRemover extends PersistingRdfStreamConsumer { 040 041 private static final Logger LOGGER = getLogger(RdfRemover.class); 042 043 /** 044 * Ordinary constructor. 045 * 046 * @param idTranslator the id translator 047 * @param session the session 048 * @param stream the stream 049 */ 050 public RdfRemover(final IdentifierConverter<Resource, FedoraResource> idTranslator, final Session session, 051 final RdfStream stream) { 052 super(idTranslator, session, stream); 053 } 054 055 @Override 056 protected void operateOnMixin(final Resource mixinResource, 057 final FedoraResource resource) throws RepositoryException { 058 059 jcrRdfTools().removeMixin(resource, mixinResource, stream().namespaces()); 060 } 061 062 @Override 063 protected void operateOnProperty(final Statement t, final FedoraResource resource) 064 throws RepositoryException { 065 LOGGER.debug("Trying to remove property from triple: {} on resource: {}.", t, resource 066 .getPath()); 067 jcrRdfTools().removeProperty(resource, t.getPredicate(), t.getObject(), stream().namespaces()); 068 069 } 070}