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