Skip to content

Commit

Permalink
Just cant get this dang sequencer to engage
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jan 20, 2013
1 parent e48993c commit 2e189f0
Show file tree
Hide file tree
Showing 7 changed files with 430 additions and 12 deletions.
Expand Up @@ -34,8 +34,8 @@ public abstract class AbstractResource {

static final ObjectMapper mapper = new ObjectMapper();

static final Response four01 = Response.status(404).entity("401").build();
static final Response four04 = Response.status(404).entity("404").build();
protected static final Response four01 = Response.status(404).entity("401").build();
protected static final Response four04 = Response.status(404).entity("404").build();

private final Logger logger = Logger.getLogger(AbstractResource.class);

Expand Down
Expand Up @@ -19,10 +19,13 @@
import org.codehaus.jackson.map.JsonMappingException;
import org.modeshape.common.logging.Logger;
import org.modeshape.jcr.ConfigurationException;
import org.modeshape.jcr.JcrRepository;
import org.modeshape.jcr.RepositoryConfiguration.Component;
import org.modeshape.jcr.api.nodetype.NodeTypeManager;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;

import freemarker.template.TemplateException;

/**
Expand All @@ -41,14 +44,14 @@ public FedoraRepository() throws ConfigurationException,
super();
}


@GET
@Path("/describe/modeshape")
public Response describeModeshape() throws JsonGenerationException,
JsonMappingException, IOException, RepositoryException {

// start with repo configuration properties
final Repository repo = ws.getSession().getRepository();
final JcrRepository repo = (JcrRepository) ws.getSession()
.getRepository();
logger.debug("Repository name: "
+ repo.getDescriptor(Repository.REP_NAME_DESC));
final Builder<String, Object> repoproperties = ImmutableMap.builder();
Expand All @@ -75,19 +78,30 @@ public Response describeModeshape() throws JsonGenerationException,
nodetypes.put(nt.getName(), nt.toString());
}
repoproperties.put("node.types", nodetypes.build());


// add in sequencers
final Builder<String, String> sequencers = ImmutableMap.builder();
for (Component seq : repo.getConfiguration().getSequencing()
.getSequencers()) {
sequencers.put(seq.getName(), seq.toString());
}
repoproperties.put("sequencers", sequencers.build());

return Response
.ok()
.entity(mapper.writerWithType(Map.class).writeValueAsString(
repoproperties.build())).build();
}
}

@GET
@Path("/describe")
public Response describe() throws RepositoryException,
IOException, TemplateException {
ImmutableMap.Builder<String, Object> b = ImmutableMap.builder();
return Response.ok().entity(renderTemplate("describeRepository.ftl",ImmutableMap.of("asdf", (Object)"asdf"))).build();
public Response describe() throws RepositoryException, IOException,
TemplateException {
ImmutableMap.Builder<String, Object> b = ImmutableMap.builder();
return Response
.ok()
.entity(renderTemplate("describeRepository.ftl",
ImmutableMap.of("asdf", (Object) "asdf"))).build();
}

@GET
Expand Down
@@ -0,0 +1,47 @@
package org.fcrepo.ffmodeshapeprototype.foxml;

import java.io.IOException;

import javax.jcr.NamespaceRegistry;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;

import org.modeshape.jcr.api.nodetype.NodeTypeManager;
import org.modeshape.jcr.api.sequencer.Sequencer;

public class FOXMLSequencer extends Sequencer {

private FOXMLParser parser;

public String description;

@Override
public boolean execute(Property inputProperty, Node outputNode,
Context context) throws Exception {

getLogger().debug(
"Now sequencing FOXML from: " + inputProperty.getPath());
try {
parser.parse(inputProperty.getBinary().getStream(), outputNode);
return true;
} catch (Exception e) {
getLogger().error(e, "Failed to sequence {}",
inputProperty.getPath());
return false;
}

}

@Override
public void initialize(NamespaceRegistry registry,
NodeTypeManager nodeTypeManager) throws RepositoryException,
IOException {
// registerDefaultMimeTypes("text/xml");
getLogger().debug(
"Initializing " + getClass().getCanonicalName() + "["
+ getName() + "]");
parser = new FOXMLParser();
}

}
@@ -0,0 +1,87 @@
package org.fcrepo.ffmodeshapeprototype.foxml;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import org.fcrepo.ffmodeshapeprototype.AbstractResource;
import org.modeshape.common.logging.Logger;
import org.modeshape.jcr.ConfigurationException;
import org.modeshape.jcr.api.JcrTools;

@Path("/foxml")
public class FedoraOXML extends AbstractResource {

private final JcrTools jcrtools = new JcrTools();

private final Logger logger = Logger.getLogger(FedoraOXML.class);

public FedoraOXML() throws ConfigurationException, RepositoryException,
IOException {
super();
}

@PUT
@Path("/{filename}")
@Consumes("text/xml")
public Response addFOXML(@PathParam("filename") final String filename,
InputStream foxml) throws RepositoryException, IOException {
logger.debug("Operating in workspace: " + ws.getName());
final Session session = ws.getSession();
if (session.hasPermission("/foxml", "add_node")) {
final Node foxmlnode = jcrtools.uploadFile(session, "/foxml/"
+ filename, foxml);
session.save();
return Response.created(URI.create(foxmlnode.getPath())).build();
} else
return four01;
}

@GET
@Path("/{filename}")
public Response getFOXML(@PathParam("filename") final String filename)
throws RepositoryException {

final Node foxmlfolder = ws.getSession().getNode("/foxml");

if (foxmlfolder.hasNode(filename)) {
final Node foxmlfile = foxmlfolder.getNode(filename);
return Response.ok(
foxmlfile.getNode("jcr:content").getProperty("jcr:data")
.getBinary().getStream(), "text/xml").build();
} else
return four04;
}

@GET
@Path("/")
public Response getFOXMLs() throws RepositoryException {
Session session = ws.getSession();
Node foxml = session.getNode("/foxml");
StringBuffer nodes = new StringBuffer();

for (NodeIterator i = foxml.getNodes(); i.hasNext();) {
Node n = i.nextNode();
nodes.append("Name: " + n.getName() + ", Path:" + n.getPath()
+ "\n");
for (NodeIterator j = n.getNodes(); j.hasNext();) {
Node n2 = j.nextNode();
nodes.append("\t Path:" + n2.getPath() + "\n");
}
}

return Response.ok().entity(nodes.toString()).build();

}
}
13 changes: 12 additions & 1 deletion src/main/resources/my_repository.json
Expand Up @@ -15,5 +15,16 @@
{ "classname" : "servlet" }
]
},
"node-types" : ["fedora-node-types.cnd"]
"sequencing" : {
"removeDerivedContentWithOriginal" : true,
"threadPool" : "modeshape-workers",
"sequencers" : {
"FOXML Sequencer" : {
"description" : "FOXML Files loaded under 'fedora:/foxml' and extracted into 'fedora:/'",
"classname" : "org.fcrepo.ffmodeshapeprototype.foxml.FOXMLSequencer",
"pathExpressions" : ["/foxml/(*)/jcr:content[@jcr:data] => fedora:/$1"]
}
}
},
"node-types" : ["fedora-node-types.cnd"]
}
@@ -0,0 +1,29 @@
package org.fcrepo.ffmodeshapeprototype.foxml

import javax.jcr._
import java.io.InputStream
import xml.XML

class FOXMLParser {

def parse(input: InputStream, objNode: Node) {

val foxmlObj = XML.load(input) \ "digitalObject"

objNode.setPrimaryType("fedora:object")

val objProperties = foxmlObj \ "objectProperties" \ "property"
val ownerProperty = objProperties filter (p => ((p.\("@NAME")) text) == "info:fedora/fedora-system:def/model#ownerId")
val ownerId = (ownerProperty \ "@VALUE") text

objNode.setProperty("fedora:ownerId", ownerId)

for (datastream <- foxmlObj \\ "datastream") {
var dsNode = objNode.addNode(datastream \ "@ID" text, "fedora:datastream")
dsNode.setProperty("fedora:contentType",
(datastream \ "datastreamVersion").head \ "@MIMETYPE" text)
}

}

}

0 comments on commit 2e189f0

Please sign in to comment.