Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'rdf-generator'
* rdf-generator:
  explicit dependency on xerces in generator-rdf
  wire in rdf generator
  wire in rdf generator to the webapp by default.
  Rename fcrepo-dc module to fcrepo-generator-dc
  update the webapp with the new names for some of the classes
  rename dublin core stuff for consistency with the rdf generator
  add RDF generator stub, that pulls data from the jcr properties
  • Loading branch information
cbeer committed Mar 8, 2013
2 parents 157ac89 + 65218d4 commit c00ad05
Show file tree
Hide file tree
Showing 29 changed files with 499 additions and 40 deletions.
4 changes: 2 additions & 2 deletions fcrepo-dc/pom.xml → fcrepo-generator-dc/pom.xml
Expand Up @@ -6,7 +6,7 @@
<artifactId>fcrepo</artifactId>
<version>4.0-SNAPSHOT</version>
</parent>
<artifactId>fcrepo-dc</artifactId>
<artifactId>fcrepo-generator-dc</artifactId>
<name>fcrepo dc</name>

<packaging>bundle</packaging>
Expand All @@ -28,7 +28,7 @@
<!-- test gear -->
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-legacy-api</artifactId>
<artifactId>fcrepo-http-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
Expand Down
File renamed without changes.
Expand Up @@ -19,13 +19,13 @@
import javax.ws.rs.core.Response;

import org.fcrepo.AbstractResource;
import org.fcrepo.generator.dublincore.AbstractIndexer;
import org.fcrepo.generator.dublincore.DCGenerator;

@Path("/objects/{pid}/oai_dc")
public class DublinCore extends AbstractResource {
public class DublinCoreGenerator extends AbstractResource {

@Resource
List<AbstractIndexer> indexers;
List<DCGenerator> indexers;

@GET
@Produces(TEXT_XML)
Expand All @@ -34,7 +34,7 @@ public Response getObjectAsDublinCore(@PathParam("pid")

final Node obj = getObjectNode(pid);

for (AbstractIndexer indexer : indexers) {
for (DCGenerator indexer : indexers) {
InputStream inputStream = indexer.getStream(obj);

if (inputStream != null) {
Expand Down
Expand Up @@ -5,10 +5,7 @@

import javax.jcr.Node;

public abstract class AbstractIndexer {

public AbstractIndexer() {
}
public interface DCGenerator {

public abstract InputStream getStream(Node node);

Expand Down
Expand Up @@ -5,7 +5,7 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class IndexFromJcrProperties extends AbstractIndexer {
public class JcrPropertiesGenerator implements DCGenerator {

@Override
public InputStream getStream(Node node) {
Expand Down
Expand Up @@ -10,9 +10,9 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;

public class IndexFromWellKnownPath extends AbstractIndexer {
public class WellKnownDatastreamGenerator implements DCGenerator {

private String wellKnownPath;
private String wellKnownDsid;

@Override
public InputStream getStream(final Node node) {
Expand All @@ -28,8 +28,8 @@ public InputStream getStream(final Node node) {

private InputStream getContentInputStream(final Node node)
throws RepositoryException {
if (node.hasNode(this.wellKnownPath)) {
final Node dc = node.getNode(this.wellKnownPath);
if (node.hasNode(this.wellKnownDsid)) {
final Node dc = node.getNode(this.wellKnownDsid);

Binary binary =
dc.getNode(JCR_CONTENT).getProperty(JCR_DATA).getBinary();
Expand All @@ -40,7 +40,7 @@ private InputStream getContentInputStream(final Node node)
}
}

public void setWellKnownPath(String wellKnownPath) {
this.wellKnownPath = wellKnownPath;
public void setWellKnownDsid(String wellKnownDsid) {
this.wellKnownDsid = wellKnownDsid;
}
}
Expand Up @@ -5,7 +5,7 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class WorstCaseIndexer extends AbstractIndexer {
public class WorstCaseGenerator implements DCGenerator {

@Override
public InputStream getStream(Node node) {
Expand Down
Expand Up @@ -10,11 +10,11 @@

<context:annotation-config/>

<util:list value-type="org.fcrepo.generator.dublincore.AbstractIndexer">
<bean class="org.fcrepo.generator.dublincore.IndexFromWellKnownPath">
<property name="wellKnownPath" value="DC"/>
<util:list value-type="org.fcrepo.generator.dublincore.DCGenerator">
<bean class="org.fcrepo.generator.dublincore.WellKnownDatastreamGenerator">
<property name="wellKnownDsid" value="DC"/>
</bean>
<bean class="org.fcrepo.generator.dublincore.IndexFromJcrProperties"/>
<bean class="org.fcrepo.generator.dublincore.JcrPropertiesGenerator"/>
</util:list>

</beans>
Expand Up @@ -14,7 +14,7 @@
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration({"/spring-test/generator.xml", "/spring-test/repo.xml"})
public class DublinCoreTest extends AbstractResourceTest {
public class DublinCoreGeneratorTest extends AbstractResourceTest {

@Test
public void testJcrPropertiesBasedOaiDc() throws Exception {
Expand Down
Expand Up @@ -18,9 +18,9 @@

<jaxrs:server address="http://localhost:${test.port:8080}/rest">
<jaxrs:serviceBeans>
<bean class="org.fcrepo.generator.DublinCore"/>
<bean class="org.fcrepo.api.legacy.FedoraObjects"/>
<bean class="org.fcrepo.api.legacy.FedoraDatastreams"/>
<bean class="org.fcrepo.generator.DublinCoreGenerator"/>
<bean class="org.fcrepo.api.FedoraObjects"/>
<bean class="org.fcrepo.api.FedoraDatastreams"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.fcrepo.exceptionhandlers.PathNotFoundExceptionMapper"/>
Expand All @@ -31,11 +31,11 @@
</jaxrs:providers>
</jaxrs:server>

<util:list id="indexers" value-type="org.fcrepo.generator.dublincore.AbstractIndexer">
<bean class="org.fcrepo.generator.dublincore.IndexFromWellKnownPath">
<property name="wellKnownPath" value="DC"/>
<util:list id="indexers" value-type="org.fcrepo.generator.dublincore.DCGenerator">
<bean class="org.fcrepo.generator.dublincore.WellKnownDatastreamGenerator">
<property name="wellKnownDsid" value="DC"/>
</bean>
<bean class="org.fcrepo.generator.dublincore.IndexFromJcrProperties"/>
<bean class="org.fcrepo.generator.dublincore.JcrPropertiesGenerator"/>
</util:list>

<!-- Mints PIDs-->
Expand Down
90 changes: 90 additions & 0 deletions fcrepo-generator-rdf/pom.xml
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>fcrepo</artifactId>
<groupId>org.fcrepo</groupId>
<version>4.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>fcrepo-generator-rdf</artifactId>

<dependencies>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-kernel</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-commons</artifactId>
<version>${project.version}</version>
</dependency>

<!-- test gear -->
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>2.10.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>

<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.7.1</version>
</dependency>
<!-- This dependency is for compile-time: it keeps this module independent
of any given choice of JAX-RS implementation. It must be _after_ the test
gear. Otherwise it will get loaded during test phase, but because this is
just an API, the tests will not be able to execute. -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,60 @@
package org.fcrepo.generator;


import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.RDFWriter;
import org.fcrepo.generator.rdf.TripleGenerator;

import javax.annotation.Resource;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.io.ByteArrayOutputStream;
import java.util.List;

import static javax.ws.rs.core.MediaType.TEXT_XML;
import static javax.ws.rs.core.Response.ok;
import static org.fcrepo.services.ObjectService.getObjectNode;

@Path("/objects/{pid}/rdf")
public class RdfGenerator {

@Resource
List<TripleGenerator> indexers;

@GET
@Produces(TEXT_XML)
public Response getObjectAsRdfXml(@PathParam("pid")
final String pid) throws RepositoryException {

final Node obj = getObjectNode(pid);


final Model model = getObjectAsRdf(obj);

RDFWriter w = model.getWriter("RDF/XML");

ByteArrayOutputStream os = new ByteArrayOutputStream();
w.write(model, os, "RDF/XML");

return ok(os.toString()).build();
}

private Model getObjectAsRdf(final Node obj) throws RepositoryException {

final Model model = ModelFactory.createDefaultModel();

final com.hp.hpl.jena.rdf.model.Resource resource = model.createResource(obj.getIdentifier());
for (TripleGenerator indexer : indexers) {
indexer.updateResourceFromNode(resource, obj);
}

return model;
}

}
@@ -0,0 +1,43 @@
package org.fcrepo.generator.rdf;

import com.hp.hpl.jena.rdf.model.Resource;

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Value;

public class JcrPropertiesGenerator implements TripleGenerator {

@Override
public void updateResourceFromNode(final Resource resource, final Node node) throws RepositoryException {
final PropertyIterator properties = node.getProperties();

while(properties.hasNext()) {

final Property property = (Property) properties.next();

if(property.isMultiple()) {
for(final Value v : property.getValues()) {
addPropertyToResource(resource, property, v);
}
}
else {
addPropertyToResource(resource, property, property.getValue());
}
}
}

private void addPropertyToResource(final Resource resource, final Property property, final Value v) throws RepositoryException {
String n = property.getName();

final String[] parts = n.split(":", 2);

String namespace = property.getParent().getSession().getWorkspace().getNamespaceRegistry().getURI(parts[0]);

String local_part = parts[1];

resource.addProperty(resource.getModel().createProperty(namespace, local_part), v.getString());
}
}
@@ -0,0 +1,12 @@
package org.fcrepo.generator.rdf;

import com.hp.hpl.jena.rdf.model.Resource;

import javax.jcr.Node;
import javax.jcr.RepositoryException;

public interface TripleGenerator {

public void updateResourceFromNode(Resource resource, Node node) throws RepositoryException;

}

0 comments on commit c00ad05

Please sign in to comment.