Open wwelling opened 2 months ago
The task involves creating a custom processor to modify the message body within a Camel route. The processor will search for instances of the string ldp:contains
and replace them with ldp:ccontains
. This is necessary because the XSLT transformation is unable to select the desired elements due to the presence of ldp:contains
. By replacing it with ldp:ccontains
, the XSLT should be able to perform the selection as intended.
Create the Custom Processor:
CustomProcessor
in the package org.fcrepo.camel.indexing.solr
.org.apache.camel.Processor
interface in this class.process
method to replace ldp:contains
with ldp:ccontains
in the message body.Modify the SolrRouter:
SolrRouter.java
file, locate the route that starts with from("direct:update.solr")
..process(new CustomProcessor())
step before the .to("direct:send.to.solr")
step.Here's the code for the CustomProcessor.java
:
package org.fcrepo.camel.indexing.solr;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Message;
public class CustomProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
String body = in.getBody(String.class);
String modifiedBody = body.replaceAll("ldp:contains", "ldp:ccontains");
in.setBody(modifiedBody);
}
}
And the modified section of the SolrRouter.java
file:
...
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()) // Custom processor added 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()) // Custom processor added here as well
.to("direct:send.to.solr")
.otherwise()
.log(LoggingLevel.INFO, logger, "Skipping ${header.CamelFcrepoUri}");
...
Make sure to import the CustomProcessor
class at the top of the SolrRouter.java
file:
import org.fcrepo.camel.indexing.solr.CustomProcessor;
After implementing these changes, the Camel route will replace ldp:contains
with ldp:ccontains
before sending the message to Solr, which should allow the XSLT to function correctly.
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
.