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