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