001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.http.api.url; 007 008import static org.apache.jena.rdf.model.ModelFactory.createDefaultModel; 009import static org.apache.jena.rdf.model.ResourceFactory.createResource; 010import static org.fcrepo.kernel.api.RdfLexicon.HAS_FIXITY_SERVICE; 011import static org.fcrepo.kernel.api.RdfLexicon.HAS_TRANSACTION_SERVICE; 012import static org.fcrepo.kernel.api.RdfLexicon.REPOSITORY_ROOT; 013 014import org.apache.jena.rdf.model.Model; 015import org.apache.jena.rdf.model.Resource; 016 017import org.fcrepo.http.api.Transactions; 018import org.fcrepo.http.commons.api.rdf.UriAwareResourceModelFactory; 019import org.fcrepo.kernel.api.models.Binary; 020import org.fcrepo.kernel.api.models.FedoraResource; 021import org.fcrepo.kernel.api.models.NonRdfSourceDescription; 022 023import org.springframework.stereotype.Component; 024 025import javax.ws.rs.core.UriInfo; 026 027/** 028 * Inject our HTTP API methods into the object graphs 029 * 030 * @author awoods 031 */ 032@Component 033public class HttpApiResources implements UriAwareResourceModelFactory { 034 035 @Override 036 public Model createModelForResource(final FedoraResource resource, 037 final UriInfo uriInfo) { 038 039 final Model model = createDefaultModel(); 040 041 final Resource s = createResource(resource.getFedoraId().getFullId()); 042 043 if (resource.hasType(REPOSITORY_ROOT.getURI())) { 044 addRepositoryStatements(uriInfo, model, s); 045 } 046 047 if (resource instanceof NonRdfSourceDescription && !resource.isMemento()) { 048 addContentStatements((Binary)resource.getDescribedResource(), model); 049 } 050 return model; 051 } 052 053 private static void addContentStatements(final Binary resource, 054 final Model model) { 055 // fcr:fixity 056 final Resource subject = createResource(resource.getFedoraId().getFullId()); 057 model.add(subject, HAS_FIXITY_SERVICE, createResource(subject.getURI() + 058 "/fcr:fixity")); 059 } 060 061 062 private void addRepositoryStatements(final UriInfo uriInfo, final Model model, 063 final Resource s) { 064 // fcr:tx 065 model.add(s, HAS_TRANSACTION_SERVICE, createResource(uriInfo 066 .getBaseUriBuilder().path(Transactions.class) 067 .build().toASCIIString())); 068 } 069 070}