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 static java.util.stream.Stream.of;
021import static org.apache.jena.graph.Triple.create;
022import static org.fcrepo.kernel.api.RdfLexicon.DESCRIBES;
023import static org.fcrepo.kernel.api.RdfLexicon.DESCRIBED_BY;
024
025import org.fcrepo.kernel.api.models.NonRdfSourceDescription;
026import org.fcrepo.kernel.api.models.FedoraBinary;
027import org.fcrepo.kernel.api.models.FedoraResource;
028import org.fcrepo.kernel.api.identifiers.IdentifierConverter;
029
030import org.apache.jena.graph.Node;
031import org.apache.jena.rdf.model.Resource;
032
033/**
034 * @author cabeer
035 * @author ajs6f
036 * @since 10/16/14
037 */
038public class ContentRdfContext extends NodeRdfContext {
039    /**
040     * Default constructor.
041     *
042     * @param resource the resource
043     * @param idTranslator the idTranslator
044     */
045    public ContentRdfContext(final FedoraResource resource,
046                             final IdentifierConverter<Resource, FedoraResource> idTranslator) {
047        super(resource, idTranslator);
048
049        // if there's an accessible jcr:content node, include information about it
050        if (resource instanceof NonRdfSourceDescription) {
051            final FedoraResource contentNode = resource().getDescribedResource();
052            final Node subject = uriFor(resource());
053            final Node contentSubject = uriFor(contentNode);
054            // add triples representing parent-to-content-child relationship
055            concat(of(create(subject, DESCRIBES.asNode(), contentSubject)));
056
057        } else if (resource instanceof FedoraBinary) {
058            final FedoraResource description = resource.getDescription();
059            concat(of(create(uriFor(resource), DESCRIBED_BY.asNode(), uriFor(description))));
060        }
061    }
062}