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.rdf.impl; 017 018import com.hp.hpl.jena.rdf.model.Resource; 019import org.fcrepo.kernel.api.models.FedoraResource; 020import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 021import org.slf4j.Logger; 022 023import javax.jcr.RepositoryException; 024 025import static java.util.stream.Stream.of; 026import static com.hp.hpl.jena.graph.Triple.create; 027import static org.fcrepo.kernel.api.RdfLexicon.HAS_PARENT; 028import static org.fcrepo.kernel.modeshape.FedoraJcrConstants.VERSIONABLE; 029import static org.slf4j.LoggerFactory.getLogger; 030 031/** 032 * @author cabeer 033 * @author ajs6f 034 * @since 9/16/14 035 */ 036public class ParentRdfContext extends NodeRdfContext { 037 038 private static final Logger LOGGER = getLogger(ParentRdfContext.class); 039 040 /** 041 * Default constructor. 042 * 043 * @param resource the resource 044 * @param idTranslator the id translator 045 * @throws javax.jcr.RepositoryException if repository exception occurred 046 */ 047 public ParentRdfContext(final FedoraResource resource, 048 final IdentifierConverter<Resource, FedoraResource> idTranslator) 049 throws RepositoryException { 050 super(resource, idTranslator); 051 052 if (resource.getNode().getDepth() > 0) { 053 LOGGER.trace("Determined that this resource has a parent."); 054 // The parent node of a frozen node for a versionable resource is not a node we want to link to because it 055 // is in the jcr:system space 056 if (!resource().isFrozenResource() || !resource().getUnfrozenResource().hasType(VERSIONABLE)) { 057 concat(of(create(subject(), HAS_PARENT.asNode(), uriFor(resource().getContainer())))); 058 } 059 } 060 } 061}