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; 019 020import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 021import org.fcrepo.kernel.api.models.FedoraResource; 022import org.fcrepo.kernel.api.models.NonRdfSource; 023import org.slf4j.Logger; 024 025import javax.jcr.RepositoryException; 026 027import static com.hp.hpl.jena.graph.NodeFactory.createURI; 028import static com.hp.hpl.jena.graph.Triple.create; 029import static com.hp.hpl.jena.vocabulary.RDF.type; 030 031import static org.fcrepo.kernel.api.RdfLexicon.MIX_NAMESPACE; 032import static org.slf4j.LoggerFactory.getLogger; 033 034/** 035 * @author cabeer 036 * @author ajs6f 037 * @since 10/1/14 038 */ 039public class TypeRdfContext extends NodeRdfContext { 040 private static final Logger LOGGER = getLogger(TypeRdfContext.class); 041 042 /** 043 * Default constructor. 044 * 045 * @param resource the resource 046 * @param idTranslator the id translator 047 * @throws RepositoryException if repository exception occurred 048 */ 049 public TypeRdfContext(final FedoraResource resource, 050 final IdentifierConverter<Resource, FedoraResource> idTranslator) 051 throws RepositoryException { 052 super(resource, idTranslator); 053 054 //include rdf:type for primaryType, mixins, and their supertypes 055 concat(resource().getTypes().stream() 056 .map(uri -> create(subject(), type.asNode(), createURI(uri.toString()))) 057 .iterator()); 058 if (resource() instanceof NonRdfSource) { 059 // gather versionability info from the parent 060 if (resource().getNode().getParent().isNodeType("mix:versionable")) { 061 concat(create(subject(), type.asNode(), createURI(MIX_NAMESPACE + "versionable"))); 062 } 063 } 064 } 065}