Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Minor refactoring

  • Loading branch information...
ajs6f committed Dec 7, 2013
1 parent 5a07599 commit 05ad676d0ddfbb57ff84819eb7b602942e7cba6e
@@ -8,7 +8,7 @@ FedoraRepository/
indexes/
ObjectStore/
*/.cache
fcrepo-jms-indexer-core/data/**
**/data
.cache
.DS_Store
*~
@@ -24,7 +24,7 @@
* @author ajs6f
* @date Dec 4, 2013
*/
public class CannotTransformToNamedFieldsException extends Exception {
public class AbsentTransformPropertyException extends Exception {

/**
*
@@ -34,7 +34,7 @@
/**
* @param msg
*/
public CannotTransformToNamedFieldsException(final String msg) {
public AbsentTransformPropertyException(final String msg) {
super(msg);
}

@@ -29,6 +29,8 @@


/**
* {@link IndexableContentRetriever} that caches its results.
*
* @author ajs6f
* @date Dec 7, 2013
*/
@@ -43,7 +45,7 @@
*/
@Override
public InputStream call() throws ClientProtocolException, IOException,
CannotTransformToNamedFieldsException, HttpException {
AbsentTransformPropertyException, HttpException {
if (cached) {
return new ByteArrayInputStream(cache);
}
@@ -56,7 +58,7 @@ public InputStream call() throws ClientProtocolException, IOException,
}

protected abstract HttpResponse retrieveHttpResponse()
throws CannotTransformToNamedFieldsException,
throws AbsentTransformPropertyException,
ClientProtocolException, IOException, HttpException;

}
@@ -48,6 +48,6 @@
public IndexerType getIndexerType();

public static enum IndexerType {
NAMEDFIELDS, RDF, NOOP
NAMEDFIELDS, RDF, NO_CONTENT
}
}
@@ -148,10 +148,11 @@ public void onMessage(final Message message) {
final Boolean removal = REMOVAL_EVENT_TYPE.equals(eventType);
LOGGER.debug("It is {} that this is a removal operation.", removal);

final NamedFieldsRetriever nfr =
new NamedFieldsRetriever(getRepositoryURL() + pid, httpClient);
final RdfRetriever rdfr =
new RdfRetriever(getRepositoryURL() + pid, httpClient);
final NamedFieldsRetriever nfr =
new NamedFieldsRetriever(getRepositoryURL() + pid, httpClient,
rdfr);

for (final Indexer indexer : indexers) {
LOGGER.debug("Operating for indexer: {}", indexer);
@@ -168,7 +169,7 @@ public void onMessage(final Message message) {
"Could not retrieve content for update!",
e);
hasContent = false;
} catch (final CannotTransformToNamedFieldsException e) {
} catch (final AbsentTransformPropertyException e) {
hasContent = false;
}
case RDF:
@@ -180,7 +181,7 @@ public void onMessage(final Message message) {
"Could not retrieve content for update!",
e);
hasContent = false;
} catch (final CannotTransformToNamedFieldsException e1) {
} catch (final AbsentTransformPropertyException e1) {
hasContent = false;
}
default:
@@ -22,11 +22,12 @@
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;

import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.jena.riot.RiotNotFoundException;
import org.slf4j.Logger;

import com.hp.hpl.jena.rdf.model.Model;
@@ -45,35 +46,33 @@

private final HttpClient httpClient;

private final RdfRetriever rdfr;

private static final Logger LOGGER = getLogger(NamedFieldsRetriever.class);

/**
* @param uri
* @param client
*/
public NamedFieldsRetriever(final String uri, final HttpClient client) {
public NamedFieldsRetriever(final String uri, final HttpClient client,
final RdfRetriever rdfr) {
this.uri = uri;
this.httpClient = client;
this.rdfr = rdfr;
}

@Override
public HttpResponse retrieveHttpResponse() throws CannotTransformToNamedFieldsException,
ClientProtocolException, IOException {
public HttpResponse retrieveHttpResponse() throws AbsentTransformPropertyException,
ClientProtocolException, IOException, HttpException {
LOGGER.debug("Retrieving RDF representation from: {}", uri);
String transformKey;
try {
final Model rdf = createDefaultModel().read(uri);
if (!rdf.contains(createResource(uri), INDEXING_TRANSFORM_PREDICATE)) {
throw new CannotTransformToNamedFieldsException(uri);
}
final RDFNode indexingTransform =
rdf.listObjectsOfProperty(createResource(uri),
INDEXING_TRANSFORM_PREDICATE).next();
transformKey = indexingTransform.asLiteral().getString();
} catch (final RiotNotFoundException e) {
LOGGER.error("Couldn't retrieve representation of resource to determine its indexability!");
throw new CannotTransformToNamedFieldsException(uri);
final Model rdf = createDefaultModel().read(rdfr.call(), null);
if (!rdf.contains(createResource(uri), INDEXING_TRANSFORM_PREDICATE)) {
throw new AbsentTransformPropertyException(uri);
}
final RDFNode indexingTransform =
rdf.listObjectsOfProperty(createResource(uri),
INDEXING_TRANSFORM_PREDICATE).next();
final String transformKey = indexingTransform.asLiteral().getString();

LOGGER.debug("Discovered transform key: {}", transformKey);
final HttpGet transformedResourceRequest =
@@ -16,7 +16,7 @@

package org.fcrepo.indexer;

import static org.fcrepo.indexer.Indexer.IndexerType.NOOP;
import static org.fcrepo.indexer.Indexer.IndexerType.NO_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
@@ -116,6 +116,6 @@ public boolean receivedRemove(final String pid) {

@Override
public IndexerType getIndexerType() {
return NOOP;
return NO_CONTENT;
}
}

0 comments on commit 05ad676

Please sign in to comment.
You can’t perform that action at this time.