Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Dec 7, 2013
1 parent 5a07599 commit 05ad676
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -8,7 +8,7 @@ FedoraRepository/
indexes/
ObjectStore/
*/.cache
fcrepo-jms-indexer-core/data/**
**/data
.cache
.DS_Store
*~
Expand Down
Expand Up @@ -24,7 +24,7 @@
* @author ajs6f
* @date Dec 4, 2013
*/
public class CannotTransformToNamedFieldsException extends Exception {
public class AbsentTransformPropertyException extends Exception {

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

Expand Down
Expand Up @@ -29,6 +29,8 @@


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

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

}
Expand Up @@ -48,6 +48,6 @@ public interface Indexer {
public IndexerType getIndexerType();

public static enum IndexerType {
NAMEDFIELDS, RDF, NOOP
NAMEDFIELDS, RDF, NO_CONTENT
}
}
Expand Up @@ -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);
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Expand Up @@ -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;
Expand All @@ -45,35 +46,33 @@ public class NamedFieldsRetriever extends CachingRetriever {

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 =
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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.