Open wwelling opened 6 months ago
The task requires us to intercept the message body within a specific Apache Camel route and replace all occurrences of the string ldp:contains
with ldp:ccontains
. The reasoning behind this solution is to work around the limitation of the XSLT transformation that cannot handle the ldp:contains
string correctly. By creating a custom processor, we can manipulate the message body before it reaches the Solr update route, ensuring that the transformed data is indexed correctly by Solr.
CustomProcessor
class in the org.fcrepo.camel.indexing.solr
package. This class will override the process
method from the Processor
interface to perform the string replacement.package org.fcrepo.camel.indexing.solr;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class CustomProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
String modifiedBody = body.replaceAll("ldp:contains", "ldp:ccontains");
exchange.getIn().setBody(modifiedBody);
}
}
SolrRouter.java
file, locate the route that starts with from("direct:update.solr")
and insert the custom processor before the .to("direct:send.to.solr")
step. The modification should be applied to both branches of the choice that handle the presence or absence of a transformation header.from("direct:update.solr").routeId("FcrepoSolrUpdater")
.log(LoggingLevel.INFO, logger, "Indexing Solr Object ${header.CamelFcrepoUri}")
.setHeader(INDEXING_URI).simple("${header.CamelFcrepoUri}")
.filter().simple("${header.CamelIndexingTransformation} != ${header.CamelIndexingUri}")
.choice()
.when(header(INDEXING_TRANSFORMATION).isNotNull())
.log(LoggingLevel.INFO, logger,
"Sending RDF for Transform with XSLT from ${header.CamelIndexingTransformation}")
.toD("xslt:${header.CamelIndexingTransformation}")
.process(new CustomProcessor()) // Insert custom processor here
.to("direct:send.to.solr")
.when(or(header(INDEXING_TRANSFORMATION).isNull(), header(INDEXING_TRANSFORMATION).isEqualTo("")))
.log(LoggingLevel.INFO, logger,"No Transform supplied")
.process(new CustomProcessor()) // Insert custom processor here
.to("direct:send.to.solr")
.otherwise()
.log(LoggingLevel.INFO, logger, "Skipping ${header.CamelFcrepoUri}");
Compile and Test:
After implementing the CustomProcessor
and updating the SolrRouter
, compile the project to ensure there are no compilation errors. Test the route to verify that the string replacement is working as intended.
Deploy the Changes: Once the solution is confirmed to work correctly, deploy the updated code to the production environment where the Fedora repository and Solr instance are running.
Click here to create a Pull Request with the proposed solution
Files used for this task:
What - description of what you me to do
Add custom camel route processor to replace all instances of string literal
ldp:contains
withldp:ccontains
. Updateorg.fcrepo.camel.indexing.solr.SolrRouter
"direct:update.solr"
camel route to process using new custom processor before sending todirect:send.to.solr
route.Why - explain why this is important
This is important to resolve an inability of the XSLT of RDF+XML with the XSL is not able to select
rdf:RDF/rdf:Description/ldp:contains/@rdf:resource
.