Skip to content

Commit

Permalink
Minor cleanup to serializations
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Jan 28, 2013
1 parent f9e1f22 commit 7ceeeeb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
8 changes: 3 additions & 5 deletions src/main/java/org/fcrepo/modeshape/AbstractResource.java
Expand Up @@ -11,7 +11,6 @@
import javax.inject.Inject;
import javax.jcr.LoginException;
import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Workspace;
Expand Down Expand Up @@ -55,10 +54,9 @@ public void initialize() throws LoginException, NoSuchWorkspaceException,
protected Response deleteResource(final String path)
throws RepositoryException {
final Session session = ws.getSession();
final Node root = session.getRootNode();
if (root.hasNode(path)) {
if (session.hasPermission("/" + path, "remove")) {
root.getNode(path).remove();
if (session.nodeExists(path)) {
if (session.hasPermission(path, "remove")) {
session.getNode(path).remove();
session.save();
return Response.status(204).build();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fcrepo/modeshape/FedoraDatastreams.java
Expand Up @@ -207,6 +207,6 @@ public Response getDatastreamHistory(@PathParam("pid") final String pid,
@Path("/{dsid}")
public Response deleteDatastream(@PathParam("pid") String pid,
@PathParam("dsid") String dsid) throws RepositoryException {
return deleteResource(pid + "/" + dsid);
return deleteResource("/" + pid + "/" + dsid);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/fcrepo/modeshape/FedoraIdentifiers.java
Expand Up @@ -26,7 +26,7 @@ public Response getNextPid(
@QueryParam("numPids") @DefaultValue("1") Integer numPids)
throws RepositoryException, IOException, TemplateException {

ImmutableSet.Builder<String> b = new Builder<String>();
ImmutableSet.Builder<String> b = ImmutableSet.builder();
for (int i = 0; i < numPids; i++) {
b.add(pidMinter.mintPid());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/fcrepo/modeshape/FedoraObjects.java
Expand Up @@ -77,7 +77,7 @@ public Response getObjectInXML(@PathParam("pid") final String pid)
if (session.nodeExists("/" + pid)) {
final Node obj = session.getNode("/" + pid);
PropertyIterator i = obj.getProperties();
ImmutableMap.Builder<String, String> b = new ImmutableMap.Builder<String, String>();
ImmutableMap.Builder<String, String> b = ImmutableMap.builder();
while (i.hasNext()) {
Property p = i.nextProperty();
b.put(p.getName(), p.toString());
Expand All @@ -95,7 +95,7 @@ public Response getObjectInXML(@PathParam("pid") final String pid)
@Path("/{pid}")
public Response deleteObject(@PathParam("pid") final String pid)
throws RepositoryException {
return deleteResource(pid);
return deleteResource("/" + pid);
}

}
40 changes: 17 additions & 23 deletions src/main/java/org/fcrepo/modeshape/foxml/FedoraOXML.java
Expand Up @@ -3,37 +3,37 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;

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.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.fcrepo.modeshape.AbstractResource;
import org.modeshape.common.logging.Logger;
import org.modeshape.jcr.ConfigurationException;
import org.modeshape.jcr.api.JcrTools;

import com.google.common.collect.ImmutableMap;

@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")
@Consumes("text/xml")
public Response addFOXML(@PathParam("filename") final String filename,
InputStream foxml) throws RepositoryException, IOException {

Expand All @@ -45,11 +45,6 @@ public Response addFOXML(@PathParam("filename") final String filename,
final Node foxmlnode = jcrtools.uploadFile(session, foxmlpath,
foxml);
session.save();
/*
* fseq.execute( foxmlnode.getNode("jcr:content")
* .getProperty("jcr:data"), session.getRootNode()
* .addNode(filename,"nt:folder"), null);
*/
return Response.created(URI.create(foxmlnode.getPath())).build();
} else
return four01;
Expand All @@ -73,22 +68,21 @@ public Response getFOXML(@PathParam("filename") final String filename)

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

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

ImmutableMap.Builder<String, String> b = ImmutableMap.builder();
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");
}
b.put(n.getName(), n.getPath());
}

return Response.ok().entity(nodes.toString()).build();
return Response
.ok()
.entity(mapper.writerWithType(Map.class).writeValueAsString(
b.build())).build();

}
}

0 comments on commit 7ceeeeb

Please sign in to comment.