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.impl.rdf.impl;
017
018import static com.hp.hpl.jena.graph.Triple.create;
019import static com.hp.hpl.jena.vocabulary.RDF.type;
020import static org.fcrepo.kernel.FedoraJcrTypes.FEDORA_CONTAINER;
021import static org.fcrepo.kernel.RdfLexicon.BASIC_CONTAINER;
022import static org.fcrepo.kernel.RdfLexicon.CONTAINER;
023import static org.fcrepo.kernel.RdfLexicon.RDF_SOURCE;
024import static org.slf4j.LoggerFactory.getLogger;
025
026import org.fcrepo.kernel.models.Container;
027import org.fcrepo.kernel.models.FedoraResource;
028import org.fcrepo.kernel.identifiers.IdentifierConverter;
029import org.slf4j.Logger;
030
031import com.hp.hpl.jena.graph.Triple;
032import com.hp.hpl.jena.rdf.model.Resource;
033
034/**
035 * @author cabeer
036 * @since 9/16/14
037 */
038public class LdpRdfContext extends NodeRdfContext {
039
040    private static final Logger LOGGER = getLogger(LdpRdfContext.class);
041
042    /**
043     * Default constructor.
044     *
045     * @param resource
046     * @param idTranslator
047     */
048    public LdpRdfContext(final FedoraResource resource,
049                         final IdentifierConverter<Resource, FedoraResource> idTranslator) {
050        super(resource, idTranslator);
051
052        concat(typeContext());
053
054        if (resource instanceof Container) {
055            concat(containerContext());
056
057            if (!resource.hasType(FEDORA_CONTAINER)) {
058                concat(defaultContainerContext());
059            }
060        }
061
062    }
063
064    private Triple typeContext() {
065        return create(subject(), type.asNode(), RDF_SOURCE.asNode());
066    }
067
068    private Triple containerContext() {
069        return create(subject(), type.asNode(), CONTAINER.asNode());
070    }
071
072    private Triple defaultContainerContext() {
073        return create(subject(), type.asNode(), BASIC_CONTAINER.asNode());
074    }
075}