Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
cbeer committed May 10, 2013
1 parent 2931930 commit 359f69a
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 45 deletions.
27 changes: 18 additions & 9 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraChildren.java
Expand Up @@ -51,23 +51,32 @@ public class FedoraChildren extends AbstractResource {
@Produces({TEXT_XML, APPLICATION_JSON, TEXT_HTML})
public Response getObjects(
@PathParam("path") final List<PathSegment> pathList,
@QueryParam("mixin") @DefaultValue("") String mixin
@QueryParam("mixin") @DefaultValue("") final String limitByMixinValue
) throws RepositoryException, IOException {


final Session session = getAuthenticatedSession();

final String mixin;
try {
final String path = toPath(pathList);
logger.info("getting children of {}", path);
if ("".equals(mixin)) {
mixin = null;
}
else if (FedoraJcrTypes.FEDORA_OBJECT.equals(mixin)) {
mixin = "nt:folder";
} else if (FedoraJcrTypes.FEDORA_DATASTREAM.equals(mixin)) {
mixin = "nt:file";
}

switch (limitByMixinValue) {
case "":
mixin = null;
break;
case FedoraJcrTypes.FEDORA_OBJECT:
mixin = "nt:folder";
break;
case FedoraJcrTypes.FEDORA_DATASTREAM:
mixin = "nt:file";
break;
default:
mixin = limitByMixinValue;
break;
}

return ok(nodeService.getObjectNames(session, path, mixin).toString()).build();
} finally {
session.logout();
Expand Down
Expand Up @@ -345,10 +345,9 @@ public Response createObject(
final MediaType contentType =
requestContentType != null ? requestContentType
: APPLICATION_OCTET_STREAM_TYPE;
final Node result =

datastreamService.createDatastreamNode(session, path, contentType
.toString(), requestBodyStream, checksumType, checksum);
Datastream ds = new Datastream(result);
}
session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
Expand Down
Expand Up @@ -106,12 +106,11 @@ public DescribeRepository describe() throws RepositoryException {
* Gets the cluster configurations
* @return
*/
public Map<String, String> getClusterConfig() {
private Map<String, String> getClusterConfig() {
//get infinispan binarystore and cachemanager to set cluster configuration information
GetClusterConfiguration getClusterConfig =
new GetClusterConfiguration();
Map<String, String> result = getClusterConfig.apply(repo);
return result;
return getClusterConfig.apply(repo);
}

@GET
Expand Down
Expand Up @@ -41,9 +41,6 @@
@Path("/rest/{path: .*}/fcr:versions")
public class FedoraVersions extends AbstractResource {

private static final Logger logger = LoggerFactory
.getLogger(FedoraVersions.class);

@Autowired
FedoraNodes objectsResource;

Expand Down
2 changes: 0 additions & 2 deletions fcrepo-kernel/src/main/java/org/fcrepo/FedoraObject.java
Expand Up @@ -15,8 +15,6 @@
import org.modeshape.jcr.api.JcrConstants;
import org.slf4j.Logger;

import com.codahale.metrics.Timer;

/**
* An abstraction that represents a Fedora Object backed by
* a JCR node.
Expand Down
@@ -1,6 +1,7 @@

package org.fcrepo.services;

import static com.codahale.metrics.MetricRegistry.name;
import static com.google.common.base.Throwables.propagate;
import static javax.jcr.query.Query.JCR_SQL2;

Expand All @@ -19,6 +20,7 @@
import javax.jcr.query.QueryResult;
import javax.jcr.query.RowIterator;

import com.codahale.metrics.Timer;
import org.fcrepo.metrics.RegistryService;
import org.fcrepo.utils.FedoraJcrTypes;
import org.modeshape.jcr.api.JcrTools;
Expand All @@ -35,6 +37,9 @@ public class RepositoryService extends JcrTools implements FedoraJcrTypes {

public static final MetricRegistry metrics = RegistryService.getMetrics();

private final Timer objectSizeCalculationTimer = metrics.timer(name(RepositoryService.class, "objectSizeCalculation"));


@Inject
protected Repository repo;

Expand Down Expand Up @@ -66,28 +71,35 @@ public boolean isFile(Session session, String path) throws RepositoryException {
* @return a double of the size of the fedora:datastream binary content
* @throws RepositoryException
*/
public long getAllObjectsDatastreamSize() throws RepositoryException {
private long getAllObjectsDatastreamSize() throws RepositoryException {

final Timer.Context context = objectSizeCalculationTimer.time();
logger.info("Calculating repository size from index");

final Session session = repo.login();
long sum = 0;
final QueryManager queryManager =
session.getWorkspace().getQueryManager();
try {
final Session session = repo.login();
long sum = 0;
final QueryManager queryManager =
session.getWorkspace().getQueryManager();

final String querystring =
"\n" + "SELECT [" + CONTENT_SIZE + "] FROM [" + FEDORA_BINARY +
"]";
final String querystring =
"\n" + "SELECT [" + CONTENT_SIZE + "] FROM [" + FEDORA_BINARY +
"]";

final QueryResult queryResults =
queryManager.createQuery(querystring, JCR_SQL2).execute();
final QueryResult queryResults =
queryManager.createQuery(querystring, JCR_SQL2).execute();

for (final RowIterator rows = queryResults.getRows(); rows.hasNext();) {
final Value value = rows.nextRow().getValue(CONTENT_SIZE);
sum += value.getLong();
}
for (final RowIterator rows = queryResults.getRows(); rows.hasNext();) {
final Value value = rows.nextRow().getValue(CONTENT_SIZE);
sum += value.getLong();
}

session.logout();
session.logout();

return sum;
return sum;
} finally {
context.stop();
}
}

public Long getRepositorySize() {
Expand Down
Expand Up @@ -7,9 +7,15 @@
import javax.jcr.NodeIterator;

import org.fcrepo.Datastream;
import org.modeshape.jcr.api.JcrConstants;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

public class DatastreamIterator implements Iterator<Datastream> {

private static final Logger logger = getLogger(DatastreamIterator.class);

private final NodeIterator nodes;

private Node nextNode;
Expand Down Expand Up @@ -41,8 +47,11 @@ private void lookAhead() {
while (nextNode == null && nodes.hasNext()) {
try {
Node n = nodes.nextNode();
if (n.isNodeType("nt:file")) nextNode = n;
else System.out.println("rejected node of type " + n.getPrimaryNodeType());
if (n.isNodeType(JcrConstants.NT_FILE)) {
nextNode = n;
} else {
logger.debug("skipping node of type {}", n.getPrimaryNodeType());
}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Expand Up @@ -20,7 +20,7 @@

import static org.slf4j.LoggerFactory.getLogger;

public class JcrRdfTools {
public abstract class JcrRdfTools {

private static final Logger logger = getLogger(JcrRdfTools.class);

Expand Down
Expand Up @@ -177,7 +177,7 @@ public String getExternalIdentifier() {
":" + ispnExternalId;
} else if ( store instanceof FileSystemBinaryStore) {
final FileSystemBinaryStore fsStore = (FileSystemBinaryStore)store;
return getExternalId() + "/" + store.getClass().getName() + ":" + ((FileSystemBinaryStore) store).getDirectory().toPath();
return getExternalId() + "/" + store.getClass().getName() + ":" + fsStore.getDirectory().toPath();
} else {
return getExternalId() + "/" + store.toString();
}
Expand Down
Expand Up @@ -14,7 +14,7 @@
import static org.fcrepo.utils.FedoraTypesUtils.getDefinitionForPropertyName;
import static org.slf4j.LoggerFactory.getLogger;

public class NodePropertiesTools {
public abstract class NodePropertiesTools {

private static final Logger logger = getLogger(NodePropertiesTools.class);

Expand Down
Expand Up @@ -31,7 +31,7 @@ public class ObjectServiceIT extends AbstractIT {
public void testGetAllObjectsDatastreamSize() throws Exception {
Session session = repository.login();

final double originalSize = objectService.getAllObjectsDatastreamSize();
final double originalSize = objectService.getRepositorySize();

datastreamService.createDatastreamNode(session,
"testObjectServiceNode", "application/octet-stream",
Expand All @@ -41,7 +41,7 @@ public void testGetAllObjectsDatastreamSize() throws Exception {

session = repository.login();

final double afterSize = objectService.getAllObjectsDatastreamSize();
final double afterSize = objectService.getRepositorySize();

assertEquals(4.0, afterSize - originalSize);

Expand Down
Expand Up @@ -89,7 +89,11 @@ public void initialize() throws LoginException, NoSuchWorkspaceException,

public static void runHooks(final Node resource, final FedoraEvent event)
throws RepositoryException {
if (resource == null) logger.warn("resource node is null; event path is {}", event.getPath());
if (resource == null) {
logger.warn("resource node is null; event path is {}", event.getPath());
return;
}

final NodeIterator webhooksIterator =
resource.getSession().getRootNode().getNodes(WEBHOOK_SEARCH);

Expand All @@ -106,14 +110,14 @@ public static void runHooks(final Node resource, final FedoraEvent event)
eventSerialization.writeTo(writer);
method.setEntity(new StringEntity(writer.toString()));
} catch (final IOException e) {
e.printStackTrace();
logger.warn("Got exception generating webhook body: {}", e);
}

try {
logger.debug("Firing callback for" + hook.getName());
client.execute(method);
} catch (final IOException e) {
e.printStackTrace();
logger.warn("Got exception running webhook callback for {}: {}", hook.getName(), e);
}

}
Expand Down

0 comments on commit 359f69a

Please sign in to comment.