Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved getObjects() machinery from FedoraObjects to ObjectService
  • Loading branch information
ajs6f committed Feb 21, 2013
1 parent 09669b4 commit 914b035
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
23 changes: 21 additions & 2 deletions fcrepo-kernel/src/main/java/org/fcrepo/services/ObjectService.java
@@ -1,10 +1,16 @@

package org.fcrepo.services;

import static com.google.common.collect.ImmutableSet.builder;
import static org.fcrepo.services.PathService.getObjectJcrNodePath;

import java.util.Set;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
Expand All @@ -14,6 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class ObjectService {

private static final Logger logger = LoggerFactory
Expand All @@ -32,13 +40,24 @@ public class ObjectService {

public static Node createObjectNodeByName(final Session session,
final String name) throws RepositoryException {
return new FedoraObject(session, "/objects/" + name).getNode();
return new FedoraObject(session, getObjectJcrNodePath(name)).getNode();
}

public static Node getObjectNode(final String pid)
throws PathNotFoundException, RepositoryException {
logger.trace("Executing getObjectNode() with pid: " + pid);
return readOnlySession.getNode("/objects/" + pid);
return readOnlySession.getNode(getObjectJcrNodePath(pid));
}

public static Set<String> getObjectNames() throws RepositoryException {

Node objects = readOnlySession.getNode(getObjectJcrNodePath(""));
Builder<String> b = builder();
for (NodeIterator i = objects.getNodes(); i.hasNext();) {
b.add(i.nextNode().getName());
}
return b.build();

}

@PostConstruct
Expand Down
Expand Up @@ -9,6 +9,7 @@
import static org.fcrepo.api.legacy.FedoraDatastreams.getContentSize;
import static org.fcrepo.jaxb.responses.ObjectProfile.ObjectStates.A;
import static org.fcrepo.services.ObjectService.createObjectNode;
import static org.fcrepo.services.ObjectService.getObjectNames;
import static org.fcrepo.services.ObjectService.getObjectNode;
import static org.fcrepo.services.PathService.getObjectJcrNodePath;
import static org.fcrepo.utils.FedoraJcrTypes.DC_TITLE;
Expand Down Expand Up @@ -53,20 +54,8 @@ public class FedoraObjects extends AbstractResource {
*/
@GET
public Response getObjects() throws RepositoryException {
final Session session = repo.login();
try {
Node objects = session.getNode(getObjectJcrNodePath(""));
StringBuffer nodes = new StringBuffer();

for (NodeIterator i = objects.getNodes(); i.hasNext();) {
Node n = i.nextNode();
nodes.append("Name: " + n.getName() + ", Path:" + n.getPath() +
"\n");
}
return ok(nodes.toString()).build();
} finally {
session.logout();
}
return ok(getObjectNames().toString()).build();

}

Expand Down

0 comments on commit 914b035

Please sign in to comment.