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

Commit

Permalink
Supporting new header field for baseURL and new identifier format (al…
Browse files Browse the repository at this point in the history
…ways node path, not property path). Indexing parent object of datastreams that are indexed
  • Loading branch information
escowles committed Jun 3, 2014
1 parent 7d73eb3 commit 4198deb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
Expand Up @@ -49,6 +49,7 @@
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.fcrepo.kernel.RdfLexicon.HAS_CHILD;
import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.fcrepo.kernel.RdfLexicon.RESTAPI_NAMESPACE;
import static org.slf4j.LoggerFactory.getLogger;

/**
Expand Down Expand Up @@ -78,6 +79,16 @@ public class IndexerGroup implements MessageListener {
static final String IDENTIFIER_HEADER_NAME = REPOSITORY_NAMESPACE
+ "identifier";

/**
* Properties message header
*/
static final String PROPERTIES_HEADER_NAME = REPOSITORY_NAMESPACE + "properties";

/**
* BaseURL message header
*/
static final String BASE_URL_HEADER_NAME = REPOSITORY_NAMESPACE + "baseURL";

/**
* Event type message header
*/
Expand Down Expand Up @@ -112,6 +123,11 @@ public class IndexerGroup implements MessageListener {
public static final Resource INDEXABLE_MIXIN =
createResource(INDEXER_NAMESPACE + "indexable");

/**
* Indicates that a resource is a datastream.
**/
static final Resource DATASTREAM_TYPE = createResource(RESTAPI_NAMESPACE + "datastream");

private static final Reader EMPTY_CONTENT = null;

/**
Expand Down Expand Up @@ -187,23 +203,18 @@ public void onMessage(final Message message) {
propagate(e);
}
try {
final String pid;
// get pid and eventType from message
// get id and eventType from message
final String eventType =
message.getStringProperty(EVENT_TYPE_HEADER_NAME);
if (eventType.contains("PROPERTY") && !eventType.contains("NODE_ADDED")) {
// it seems the URL is for the property, not the node on which
// the property is set...
final String id = message.getStringProperty(IDENTIFIER_HEADER_NAME);
pid = id.substring(0, id.lastIndexOf('/'));
} else {
pid = message.getStringProperty(IDENTIFIER_HEADER_NAME);
}
final String id = message.getStringProperty(IDENTIFIER_HEADER_NAME);
final String baseURL = message.getStringProperty(BASE_URL_HEADER_NAME);

LOGGER.debug("Discovered pid: {} in message.", pid);
LOGGER.debug("Discovered id: {} in message.", id);
LOGGER.debug("Discovered event type: {} in message.", eventType);
LOGGER.debug("Discovered baseURL: {} in message.", baseURL);
LOGGER.debug("Discovered properties: {} in message.", message.getStringProperty(PROPERTIES_HEADER_NAME));

index( getRepositoryURL() + pid, eventType );
index( baseURL + id, eventType );
} catch (final JMSException e) {
LOGGER.error("Error processing JMS event!", e);
}
Expand Down Expand Up @@ -232,6 +243,13 @@ private void index( final String uri, final String eventType ) {
"Resource: {} retrieved without indexable type.",
uri);
}

// if this is a datastream, also index the parent object
if (rdf.contains(createResource(uri), type, DATASTREAM_TYPE) && uri.indexOf("/fedora:system/") == -1 ) {
final String parent = uri.substring(0, uri.lastIndexOf("/"));
LOGGER.info("Datastream found, also indexing parent {}", parent);
index( parent, "NODE_UPDATED");
}
}

for (final Indexer<Object> indexer : indexers) {
Expand Down
Expand Up @@ -118,7 +118,7 @@ public void testInvalidMessage() {

@Test
public void testNonIndexableObjectUpdateMessage() throws Exception {
final String id = "/test";
final String id = "/test1";
indexerGroup.onMessage(createUnindexableMessage(REPOSITORY_NAMESPACE
+ EventType.valueOf(NODE_ADDED).toString(), id));
verify(indexer, never()).update(anyString(), any());
Expand All @@ -127,7 +127,7 @@ public void testNonIndexableObjectUpdateMessage() throws Exception {
@Test
public void testNamedFieldsIndexableObjectUpdateMessage() throws Exception {
when(indexer.getIndexerType()).thenReturn(Indexer.IndexerType.NAMEDFIELDS);
final String id = "/test";
final String id = "/test2";
indexerGroup.onMessage(createIndexableMessage(REPOSITORY_NAMESPACE
+ EventType.valueOf(NODE_ADDED).toString(), id));
verify(indexer, atLeastOnce()).update(anyString(), any());
Expand All @@ -136,7 +136,7 @@ public void testNamedFieldsIndexableObjectUpdateMessage() throws Exception {
@Test
public void testRDFIndexablePropertyUpdateMessage() throws Exception {
when(indexer.getIndexerType()).thenReturn(Indexer.IndexerType.RDF);
final String id = "/test/dc:title";
final String id = "/test3";
indexerGroup.onMessage(createIndexablePropertyMessage(REPOSITORY_NAMESPACE
+ EventType.valueOf(PROPERTY_CHANGED).toString(), id));
verify(indexer, atLeastOnce()).update(anyString(), any());
Expand Down Expand Up @@ -188,8 +188,9 @@ private Message createMockMessage(final boolean jmsExceptionOnGetMessage,
}
if (identifier != null) {
when(m.getStringProperty(IndexerGroup.IDENTIFIER_HEADER_NAME)).thenReturn(identifier);
mockContent(property ? parentId(identifier) : identifier, indexable, indexerName);
mockContent(identifier, indexable, indexerName);
}
when(m.getStringProperty(IndexerGroup.BASE_URL_HEADER_NAME)).thenReturn("http://example.org:80");
return m;
}

Expand All @@ -207,10 +208,6 @@ private void mockContent(final String identifier,
when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(r);
}

private String parentId(final String identifier) {
return identifier.substring(0, identifier.lastIndexOf('/'));
}

private String getIndexableTriples(final String id, final boolean indexable, final String indexerName) {
return "\n" +
"<" + repoUrl + id + "> a <http://fedora.info/definitions/v4/rest-api#resource> , " +
Expand Down
Expand Up @@ -15,7 +15,7 @@

<!-- translates events from the internal bus to JMS -->
<bean class="org.fcrepo.jms.headers.DefaultMessageFactory">
<constructor-arg value="http://localhost:8080/rest"/>
<constructor-arg value="http://localhost:${test.port:8080}"/>
</bean>

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
Expand Down

0 comments on commit 4198deb

Please sign in to comment.