diff --git a/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/solrUpdate/AggregateUpdateProcessor.java b/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/solrUpdate/AggregateUpdateProcessor.java index a51ef80b3d..744bf30887 100644 --- a/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/solrUpdate/AggregateUpdateProcessor.java +++ b/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/solrUpdate/AggregateUpdateProcessor.java @@ -17,15 +17,18 @@ import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; -import edu.unc.lib.boxc.model.fcrepo.ids.RepositoryPaths; import edu.unc.lib.boxc.operations.jms.indexing.IndexingActionType; import edu.unc.lib.boxc.operations.jms.indexing.IndexingMessageSender; +import edu.unc.lib.boxc.search.solr.config.SolrSettings; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.Processor; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrServerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.Collection; /** @@ -37,8 +40,14 @@ public class AggregateUpdateProcessor implements Processor { private static final Logger log = LoggerFactory.getLogger(AggregateUpdateProcessor.class); private IndexingMessageSender messageSender; private IndexingActionType actionType; + private SolrSettings solrSettings; + private SolrClient solrClient; private boolean forceCommit; + public void init() { + solrClient = solrSettings.getSolrClient(); + } + @Override public void process(Exchange exchange) throws Exception { final Message in = exchange.getIn(); @@ -48,7 +57,11 @@ public void process(Exchange exchange) throws Exception { } if (forceCommit) { // Force commit of any pending solr updates before sending indexing operations - messageSender.sendIndexingOperation(null, RepositoryPaths.getRootPid(), IndexingActionType.COMMIT); + try { + solrClient.commit(); + } catch (SolrServerException | IOException e) { + log.error("Failed to commit solr updates prior to indexing children of a collection"); + } } for (Object idObj : idCollection) { PID pid = PIDs.get(idObj.toString()); @@ -60,6 +73,14 @@ public void setIndexingMessageSender(IndexingMessageSender messageSender) { this.messageSender = messageSender; } + public void setSolrSettings(SolrSettings solrSettings) { + this.solrSettings = solrSettings; + } + + public void setSolrClient(SolrClient solrClient) { + this.solrClient = solrClient; + } + public void setActionType(IndexingActionType actionType) { this.actionType = actionType; } diff --git a/services-camel-app/src/main/webapp/WEB-INF/solr-indexing-context.xml b/services-camel-app/src/main/webapp/WEB-INF/solr-indexing-context.xml index 224bc999e0..414f978e6d 100644 --- a/services-camel-app/src/main/webapp/WEB-INF/solr-indexing-context.xml +++ b/services-camel-app/src/main/webapp/WEB-INF/solr-indexing-context.xml @@ -469,10 +469,12 @@ - + + diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateRouterTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateRouterTest.java index 00e34e1738..1b7d1d4c55 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateRouterTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateRouterTest.java @@ -30,6 +30,7 @@ import org.apache.camel.builder.NotifyBuilder; import org.apache.camel.test.spring.CamelSpringRunner; import org.apache.camel.test.spring.CamelTestContextBootstrapper; +import org.apache.solr.client.solrj.SolrClient; import org.jdom2.Document; import org.jdom2.Element; import org.junit.Before; @@ -94,6 +95,9 @@ public class SolrUpdateRouterTest { @Autowired private SolrUpdatePreprocessor solrUpdatePreprocessor; + @Autowired + private SolrClient solrClient; + private ArgumentCaptor exchangeCaptor; private PIDMinter pidMinter; @@ -262,6 +266,7 @@ public void multipleWorkFromFile() throws Exception { notify.matches(3l, TimeUnit.SECONDS); + verify(solrClient).commit(); verify(indexingMessageSender).sendIndexingOperation(null, targetPid1, IndexingActionType.UPDATE_WORK_FILES); verify(indexingMessageSender).sendIndexingOperation(null, targetPid2, IndexingActionType.UPDATE_WORK_FILES); } diff --git a/services-camel-app/src/test/resources/solr-update-context.xml b/services-camel-app/src/test/resources/solr-update-context.xml index 7b1a660b4f..e6e978746a 100644 --- a/services-camel-app/src/test/resources/solr-update-context.xml +++ b/services-camel-app/src/test/resources/solr-update-context.xml @@ -38,10 +38,15 @@ + + + + + diff --git a/services-camel-app/src/test/resources/solr-update-processor-it-context.xml b/services-camel-app/src/test/resources/solr-update-processor-it-context.xml index 83cb92846b..42ef3b3633 100644 --- a/services-camel-app/src/test/resources/solr-update-processor-it-context.xml +++ b/services-camel-app/src/test/resources/solr-update-processor-it-context.xml @@ -208,6 +208,7 @@ +