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 adding its contents to the
033 * JCR.
034 *
035 * @see RdfRemover
036 * @author ajs6f
037 * @since Oct 24, 2013
038 */
039public class RdfAdder extends PersistingRdfStreamConsumer {
040
041    private static final Logger LOGGER = getLogger(RdfAdder.class);
042
043    /**
044     * Ordinary constructor.
045     *
046     * @param idTranslator the id translator
047     * @param session the session
048     * @param stream the rdf stream
049     */
050    public RdfAdder(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, final FedoraResource resource)
057            throws RepositoryException {
058        jcrRdfTools().addMixin(resource, mixinResource, stream().namespaces());
059    }
060
061
062    @Override
063    protected void operateOnProperty(final Statement t, final FedoraResource resource) throws RepositoryException {
064        LOGGER.debug("Adding property from triple: {} to resource: {}.", t, resource
065                .getPath());
066
067        jcrRdfTools().addProperty(resource, t.getPredicate(), t.getObject(), stream().namespaces());
068    }
069}