131 lines
5.7 KiB
Java
131 lines
5.7 KiB
Java
package eu.dnetlib.validatorapi.routes;
|
|
|
|
import eu.dnetlib.validator2.validation.guideline.openaire.AbstractOpenAireProfile;
|
|
import eu.dnetlib.validatorapi.entities.ValidationJob;
|
|
import eu.dnetlib.validatorapi.processors.XmlProcessor;
|
|
import eu.dnetlib.validatorapi.repositories.ValidationIssueRepository;
|
|
import eu.dnetlib.validatorapi.repositories.ValidationResultRepository;
|
|
import org.apache.camel.Exchange;
|
|
import org.apache.camel.Processor;
|
|
import org.apache.camel.builder.RouteBuilder;
|
|
|
|
public class OaiPmhRoute extends RouteBuilder {
|
|
|
|
private String oaiEndpoint;
|
|
|
|
private AbstractOpenAireProfile profile;
|
|
private long maxNumberOfRecords = 0;
|
|
private ValidationJob validationJob;
|
|
private final ValidationIssueRepository validationIssueRepository;
|
|
private final ValidationResultRepository validationResultRepository;
|
|
|
|
public OaiPmhRoute(String oaiEndpoint, AbstractOpenAireProfile profile, ValidationJob validationJob,
|
|
long maxNumberOfRecords, final ValidationIssueRepository validationIssueRepository,
|
|
final ValidationResultRepository validationResultRepository) {
|
|
this.oaiEndpoint = oaiEndpoint;
|
|
this.validationJob = validationJob;
|
|
this.profile = profile;
|
|
this.maxNumberOfRecords = maxNumberOfRecords;
|
|
this.validationIssueRepository = validationIssueRepository;
|
|
this.validationResultRepository = validationResultRepository;
|
|
}
|
|
|
|
@Override
|
|
public void configure() throws Exception {
|
|
|
|
|
|
from(oaiEndpoint)
|
|
.setProperty("totalRecords", constant(0))
|
|
.loopDoWhile().simple("${exchangeProperty.totalRecords} < 10")
|
|
.split(xpath("//*[local-name()='record']"))
|
|
.log("${exchangeProperty.totalRecords}")
|
|
// .log("\n\n\n----------------\n\n\n\n\n\n${body}\n\n\n----------------\n\n\n\n\n\n")
|
|
.process(new XmlProcessor(profile, validationJob, validationIssueRepository, validationResultRepository))
|
|
.end().to("direct:end");
|
|
|
|
/* from("oaipmh://http://repositorium.sdum.uminho.pt/oai/request?verb=ListRecords&metadataPrefix=oai_dc")
|
|
.setProperty("totalRecords", constant(0))
|
|
.loopDoWhile().simple("${exchangeProperty.totalRecords} < 10")
|
|
.split(xpath("//*[local-name()='record']"))
|
|
//.log("\n\n\n----------------\n\n\n\n\n\n${body}\n\n\n----------------\n\n\n\n\n\n")
|
|
.process(new XmlProcessor(profile, validationJob))
|
|
.end().to("direct:end");*/
|
|
|
|
|
|
|
|
/*** kai auto from(oaiEndpoint) // trigger the route every minute
|
|
.split(xpath("//*[local-name()='record']"))
|
|
.setProperty("totalRecords", constant(0))
|
|
.loopDoWhile().simple("${exchangeProperty.totalRecords} < 50")
|
|
.process(new XmlProcessor(profile, validationJob))
|
|
.end()
|
|
.to("direct:end");
|
|
**/
|
|
//from(oaiEndpoint).process(new XmlProcessor(profile,validationJob));
|
|
|
|
// from("direct:oaiRequest").process(new DummyXMLProcessor());
|
|
|
|
|
|
|
|
|
|
/*** AUTO PAIZEI !!!!!! ***/
|
|
/* from(oaiEndpoint).
|
|
split(xpath("//*[local-name()='record']")).process(new XmlProcessor(profile, validationJob));
|
|
*/
|
|
|
|
/*** KAI AUTO !!!!!! ***/
|
|
/*
|
|
from("timer://myTimer?fixedRate=true&period=60000") // trigger the route every minute
|
|
.setProperty("totalRecords", constant(0))
|
|
.loopDoWhile().simple("${exchangeProperty.totalRecords} < 50")
|
|
.to("direct:oaiRequest")
|
|
.process(new RecordCountProcessor())
|
|
.end()
|
|
.to("direct:end");
|
|
|
|
from("direct:oaiRequest").
|
|
process(exchange -> {
|
|
int counter = exchange.getProperty("totalRecords", 0, Integer.class);
|
|
System.out.println("Processing iteration: " + exchange.getProperty("totalRecords", 0, Integer.class));
|
|
counter++;
|
|
System.out.println("counter ++" + counter);
|
|
exchange.setProperty("processedRecords", counter);
|
|
System.out.println("Processing iteration: " + exchange.getProperty("totalRecords", 0, Integer.class));
|
|
|
|
});
|
|
*/
|
|
|
|
/** KAI AUTO ***/
|
|
/*
|
|
from("timer://myTimer?fixedRate=true&period=60000") // trigger the route every minute
|
|
.setProperty("totalRecords", constant(0))
|
|
.loopDoWhile().simple("${exchangeProperty.totalRecords} < 50")
|
|
.to("direct:oaiRequest")
|
|
.process(new RecordCountProcessor())
|
|
.end()
|
|
.to("direct:end");
|
|
|
|
from("direct:oaiRequest").
|
|
process(exchange -> {
|
|
int counter = exchange.getProperty("totalRecords", 0, Integer.class);
|
|
System.out.println("Processing iteration: " + exchange.getProperty("totalRecords", 0, Integer.class));
|
|
counter++;
|
|
System.out.println("counter ++" + counter);
|
|
exchange.setProperty("processedRecords", counter);
|
|
System.out.println("Processing iteration: " + exchange.getProperty("totalRecords", 0, Integer.class));
|
|
|
|
});
|
|
*/
|
|
}
|
|
|
|
|
|
class RecordCountProcessor implements Processor {
|
|
@Override
|
|
public void process(Exchange exchange) throws Exception {
|
|
System.out.println("RecordCountProcessor");
|
|
|
|
int processedRecords = exchange.getProperty("processedRecords", 0, Integer.class);
|
|
exchange.setProperty("totalRecords", processedRecords);
|
|
|
|
}
|
|
}} |