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