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