Commit
…or a resource (to add e.g. HATEOS responsess)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.fcrepo.url; | ||
|
||
import com.google.common.collect.ImmutableBiMap; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.Resource; | ||
import org.fcrepo.FedoraResource; | ||
import org.fcrepo.api.FedoraExport; | ||
import org.fcrepo.api.FedoraFieldSearch; | ||
import org.fcrepo.api.FedoraFixity; | ||
import org.fcrepo.api.FedoraNodes; | ||
import org.fcrepo.api.FedoraSitemap; | ||
import org.fcrepo.api.FedoraTransactions; | ||
import org.fcrepo.api.FedoraVersions; | ||
import org.fcrepo.api.rdf.HttpComponentAppender; | ||
import org.fcrepo.api.repository.FedoraRepositoryNamespaces; | ||
import org.fcrepo.rdf.GraphSubjects; | ||
import org.fcrepo.serialization.FedoraObjectSerializer; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
import java.util.Map; | ||
|
||
@Component | ||
public class HttpApiResources implements HttpComponentAppender { | ||
|
||
@javax.annotation.Resource | ||
protected Map<String, FedoraObjectSerializer> serializers; | ||
|
||
@Override | ||
public void addResponseInformationToDataset(FedoraResource resource, Model model, UriInfo uriInfo, GraphSubjects graphSubjects) throws RepositoryException { | ||
|
||
final Resource s = graphSubjects.getGraphSubject(resource.getNode()); | ||
|
||
if (resource.getNode().getPrimaryNodeType().isNodeType("mode:root")) { | ||
model.add(s, model.createProperty("http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#link-type-search"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraFieldSearch.class).build().toASCIIString())); | ||
model.add(s, model.createProperty("http://microformats.org/wiki/rel-sitemap"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraSitemap.class).build().toASCIIString())); | ||
model.add(s, model.createProperty("info:fedora/hasTransactionProvider"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraTransactions.class).build().toASCIIString())); | ||
model.add(s, model.createProperty("info:fedora/hasNamespaces"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraRepositoryNamespaces.class).build().toASCIIString())); | ||
|
||
} else { | ||
|
||
for (String key : serializers.keySet()) { | ||
final Map<String, String> pathMap = ImmutableBiMap.of("path", resource.getPath().substring(1), "format", key); | ||
model.add(s, model.createProperty("info:fedora/exportsAs"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraExport.class).buildFromMap(pathMap).toASCIIString())); | ||
} | ||
|
||
final Map<String, String> pathMap = ImmutableBiMap.of("path", resource.getPath().substring(1)); | ||
model.add(s, model.createProperty("info:fedora/hasVersions"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraVersions.class).buildFromMap(pathMap).toASCIIString())); | ||
|
||
} | ||
|
||
if (resource.hasContent()) { | ||
final Map<String, String> pathMap = ImmutableBiMap.of("path", resource.getPath().substring(1)); | ||
model.add(s, model.createProperty("info:fedora/runFixityCheck"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraFixity.class).buildFromMap(pathMap).toASCIIString())); | ||
} | ||
|
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.fcrepo.api.rdf; | ||
|
||
import com.hp.hpl.jena.rdf.model.Model; | ||
import org.fcrepo.FedoraResource; | ||
import org.fcrepo.rdf.GraphSubjects; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
public interface HttpComponentAppender { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
awoods
|
||
void addResponseInformationToDataset(final FedoraResource resource, final Model model, final UriInfo uriInfo, GraphSubjects graphSubjects) throws RepositoryException; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.fcrepo.api.rdf; | ||
|
||
import com.hp.hpl.jena.query.Dataset; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.ModelFactory; | ||
import org.fcrepo.FedoraResource; | ||
import org.fcrepo.rdf.GraphSubjects; | ||
import org.slf4j.Logger; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.core.UriInfo; | ||
import java.util.Collection; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
@Component | ||
public class HttpComponentInjector implements ApplicationContextAware { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cbeer
Author
Contributor
|
||
private static final Logger LOGGER = getLogger(HttpComponentInjector.class); | ||
private ApplicationContext applicationContext; | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.applicationContext = applicationContext; | ||
} | ||
|
||
public void addResponseInformationToDataset(FedoraResource resource, Dataset dataset, UriInfo uriInfo, GraphSubjects graphSubjects) throws RepositoryException { | ||
|
||
final Model model = ModelFactory.createDefaultModel(); | ||
LOGGER.debug("Adding additional HTTP context triples to dataset"); | ||
for (HttpComponentAppender httpComponentAppender : getAppenders()) { | ||
LOGGER.debug("Adding response information using {}", httpComponentAppender.getClass().toString()); | ||
|
||
httpComponentAppender.addResponseInformationToDataset(resource, model, uriInfo, graphSubjects); | ||
} | ||
|
||
dataset.addNamedModel("info:fedora/http-uris", model); | ||
} | ||
|
||
private Collection<HttpComponentAppender> getAppenders() { | ||
return applicationContext.getBeansOfType(HttpComponentAppender.class).values(); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.fcrepo.api.rdf; | ||
|
||
import com.google.common.collect.ImmutableBiMap; | ||
import com.hp.hpl.jena.query.Dataset; | ||
import com.hp.hpl.jena.query.DatasetFactory; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.ModelFactory; | ||
import org.fcrepo.FedoraResource; | ||
import org.fcrepo.rdf.GraphSubjects; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
import java.util.Map; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class HttpComponentInjectorTest { | ||
|
||
private HttpComponentInjector testObj; | ||
private Dataset dataset; | ||
private UriInfo mockUriInfo; | ||
private GraphSubjects mockSubjects; | ||
private ApplicationContext mockContext; | ||
|
||
@Before | ||
public void setUp() { | ||
mockContext = mock(ApplicationContext.class); | ||
testObj = new HttpComponentInjector(); | ||
testObj.setApplicationContext(mockContext); | ||
|
||
dataset = DatasetFactory.create(ModelFactory.createDefaultModel()); | ||
mockUriInfo = mock(UriInfo.class); | ||
mockSubjects = mock(GraphSubjects.class); | ||
|
||
|
||
} | ||
|
||
@Test | ||
public void shouldAddTriplesFromRegisteredBeans() throws RepositoryException { | ||
final FedoraResource mockResource = mock(FedoraResource.class); | ||
|
||
HttpComponentAppender mockBean1 = mock(HttpComponentAppender.class); | ||
HttpComponentAppender mockBean2 = mock(HttpComponentAppender.class); | ||
Map<String, HttpComponentAppender> mockBeans = ImmutableBiMap.of("doesnt", mockBean1, "matter", mockBean2); | ||
when(mockContext.getBeansOfType(HttpComponentAppender.class)).thenReturn(mockBeans); | ||
testObj.addResponseInformationToDataset(mockResource, dataset, mockUriInfo, mockSubjects); | ||
verify(mockBean1).addResponseInformationToDataset(eq(mockResource), any(Model.class), eq(mockUriInfo), eq(mockSubjects)); | ||
verify(mockBean2).addResponseInformationToDataset(eq(mockResource), any(Model.class), eq(mockUriInfo), eq(mockSubjects)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.fcrepo.syndication; | ||
|
||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.Resource; | ||
import org.fcrepo.FedoraResource; | ||
import org.fcrepo.api.rdf.HttpComponentAppender; | ||
import org.fcrepo.rdf.GraphSubjects; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
public class RssResources implements HttpComponentAppender { | ||
@Override | ||
public void addResponseInformationToDataset(FedoraResource resource, Model model, UriInfo uriInfo, GraphSubjects graphSubjects) throws RepositoryException { | ||
|
||
final Resource s = graphSubjects.getGraphSubject(resource.getNode()); | ||
|
||
if (resource.getNode().getPrimaryNodeType().isNodeType("mode:root")) { | ||
model.add(s, model.createProperty("http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-feed"), model.createResource(uriInfo.getBaseUriBuilder().path(RSSPublisher.class).build().toASCIIString())); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.fcrepo.webhooks; | ||
|
||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.Resource; | ||
import org.fcrepo.FedoraResource; | ||
import org.fcrepo.api.rdf.HttpComponentAppender; | ||
import org.fcrepo.rdf.GraphSubjects; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
public class WebhooksResources implements HttpComponentAppender { | ||
@Override | ||
public void addResponseInformationToDataset(FedoraResource resource, Model model, UriInfo uriInfo, GraphSubjects graphSubjects) throws RepositoryException { | ||
|
||
final Resource s = graphSubjects.getGraphSubject(resource.getNode()); | ||
|
||
if (resource.getNode().getPrimaryNodeType().isNodeType("mode:root")) { | ||
model.add(s, model.createProperty("http://microformats.org/wiki/rel-subscription"), model.createResource(uriInfo.getBaseUriBuilder().path(FedoraWebhooks.class).build().toASCIIString())); | ||
} | ||
} | ||
} |
Suggestions for better names?