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.rdf.impl; 019 020import org.apache.jena.rdf.model.Resource; 021import org.fcrepo.kernel.api.models.FedoraResource; 022import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 023import org.slf4j.Logger; 024 025import javax.jcr.RepositoryException; 026 027import static org.apache.jena.graph.Triple.create; 028import static org.fcrepo.kernel.api.RdfLexicon.CONTAINS; 029import static org.fcrepo.kernel.modeshape.utils.FedoraTypesUtils.getJcrNode; 030import static org.slf4j.LoggerFactory.getLogger; 031 032/** 033 * @author cabeer 034 * @author ajs6f 035 * @since 9/16/14 036 */ 037public class ChildrenRdfContext extends NodeRdfContext { 038 039 private static final Logger LOGGER = getLogger(ChildrenRdfContext.class); 040 041 /** 042 * Default constructor. 043 * 044 * @param resource the resource 045 * @param idTranslator the idTranslator 046 * @throws javax.jcr.RepositoryException if repository exception occurred 047 */ 048 public ChildrenRdfContext(final FedoraResource resource, 049 final IdentifierConverter<Resource, FedoraResource> idTranslator) 050 throws RepositoryException { 051 super(resource, idTranslator); 052 053 if (getJcrNode(resource).hasNodes()) { 054 LOGGER.trace("Found children of this resource: {}", resource.getPath()); 055 056 concat(resource().getChildren().peek(child -> LOGGER.trace("Creating triple for child node: {}", child)) 057 .map(child -> create(subject(), CONTAINS.asNode(), uriFor(child)))); 058 } 059 } 060 061}