001/** 002 * Copyright 2014 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.rdf.impl; 017 018import static com.google.common.base.Predicates.not; 019import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isInternalProperty; 020import static org.slf4j.LoggerFactory.getLogger; 021 022import java.util.Iterator; 023 024import javax.jcr.Property; 025import javax.jcr.RepositoryException; 026 027import com.hp.hpl.jena.rdf.model.Resource; 028import org.fcrepo.kernel.models.FedoraResource; 029import org.fcrepo.kernel.identifiers.IdentifierConverter; 030import org.fcrepo.kernel.impl.rdf.impl.mappings.PropertyToTriple; 031import org.fcrepo.kernel.utils.iterators.PropertyIterator; 032import org.slf4j.Logger; 033 034import com.google.common.collect.Iterators; 035import com.google.common.collect.UnmodifiableIterator; 036import com.hp.hpl.jena.graph.Triple; 037 038/** 039 * {@link NodeRdfContext} for RDF that derives from JCR properties on a Resource 040 * 041 * @author ajs6f 042 * @since Oct 10, 2013 043 */ 044public class PropertiesRdfContext extends NodeRdfContext { 045 046 private PropertyToTriple property2triple; 047 048 private static final Logger LOGGER = getLogger(PropertiesRdfContext.class); 049 050 /** 051 * Default constructor. 052 * 053 * @param resource 054 * @throws RepositoryException 055 */ 056 057 public PropertiesRdfContext(final FedoraResource resource, 058 final IdentifierConverter<Resource, FedoraResource> idTranslator) 059 throws RepositoryException { 060 super(resource, idTranslator); 061 property2triple = new PropertyToTriple(resource.getNode().getSession(), idTranslator); 062 concat(triplesFromProperties(resource())); 063 } 064 065 private Iterator<Triple> triplesFromProperties(final FedoraResource n) 066 throws RepositoryException { 067 LOGGER.trace("Creating triples for node: {}", n); 068 final UnmodifiableIterator<Property> properties = 069 Iterators.filter(new PropertyIterator(n.getNode().getProperties()), not(isInternalProperty)); 070 071 return Iterators.concat(Iterators.transform(properties, property2triple)); 072 073 } 074 075}