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.http.api.url; 019 020import static org.apache.jena.rdf.model.ModelFactory.createDefaultModel; 021import static org.apache.jena.rdf.model.ResourceFactory.createResource; 022import static org.fcrepo.kernel.api.RdfLexicon.HAS_FIXITY_SERVICE; 023import static org.fcrepo.kernel.api.RdfLexicon.HAS_TRANSACTION_SERVICE; 024import static org.fcrepo.kernel.api.RdfLexicon.REPOSITORY_ROOT; 025 026import org.apache.jena.rdf.model.Model; 027import org.apache.jena.rdf.model.Resource; 028 029import org.fcrepo.http.api.Transactions; 030import org.fcrepo.http.commons.api.rdf.UriAwareResourceModelFactory; 031import org.fcrepo.kernel.api.models.Binary; 032import org.fcrepo.kernel.api.models.FedoraResource; 033import org.fcrepo.kernel.api.models.NonRdfSourceDescription; 034 035import org.springframework.stereotype.Component; 036 037import javax.ws.rs.core.UriInfo; 038 039/** 040 * Inject our HTTP API methods into the object graphs 041 * 042 * @author awoods 043 */ 044@Component 045public class HttpApiResources implements UriAwareResourceModelFactory { 046 047 @Override 048 public Model createModelForResource(final FedoraResource resource, 049 final UriInfo uriInfo) { 050 051 final Model model = createDefaultModel(); 052 053 final Resource s = createResource(resource.getFedoraId().getFullId()); 054 055 if (resource.hasType(REPOSITORY_ROOT.getURI())) { 056 addRepositoryStatements(uriInfo, model, s); 057 } 058 059 if (resource instanceof NonRdfSourceDescription && !resource.isMemento()) { 060 addContentStatements((Binary)resource.getDescribedResource(), model); 061 } 062 return model; 063 } 064 065 private static void addContentStatements(final Binary resource, 066 final Model model) { 067 // fcr:fixity 068 final Resource subject = createResource(resource.getFedoraId().getFullId()); 069 model.add(subject, HAS_FIXITY_SERVICE, createResource(subject.getURI() + 070 "/fcr:fixity")); 071 } 072 073 074 private void addRepositoryStatements(final UriInfo uriInfo, final Model model, 075 final Resource s) { 076 // fcr:tx 077 model.add(s, HAS_TRANSACTION_SERVICE, createResource(uriInfo 078 .getBaseUriBuilder().path(Transactions.class) 079 .build().toASCIIString())); 080 } 081 082}