import java.util.concurrent.BlockingQueue import org.antlr.stringtemplate.StringTemplate import org.antlr.stringtemplate.StringTemplateGroup import org.antlr.stringtemplate.language.DefaultTemplateLexer import eu.dnetlib.enabling.manager.msro.hope.groovy.RunnableGroovy class FESPhotosND implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def FESLidoUtils utils = new FESLidoUtils() def BlockingQueue resultsQueue, inputQueue; def String repositoryId = ""; /** * Driver namespace for elements in the OAI header. */ def dri = new groovy.xml.Namespace("http://www.driver-repository.eu/namespace/dri", 'dri') def String collectionID = 'Fotosammlung' def String providerName = "Archiv der sozialen Demokratie (AdsD)" @Override public void run() { def StringTemplateGroup group = new StringTemplateGroup("visualGroup", templatePath, DefaultTemplateLexer.class); def StringTemplate template = group.getInstanceOf("visualTemplate"); def parser = new XmlParser(false, true); def String input; def c = 0; while(!((input = this.inputQueue.take()).equals("END"))){ def Node xmlRoot = parser.parseText(input) def Node oaiHeaderNode = xmlRoot.'**'.header[0] //Common OAI Header elements def String dateOfCollection = oaiHeaderNode.'dri:dateOfCollection'.text() def String setSpec = oaiHeaderNode.setSpec.text() //def Node fesRoot = xmlRoot.'**'.Fahnen[0]; def NodeList objects = xmlRoot.'**'.Objekt if(objects.size() > 1) println "Found "+objects.size()+" Objekts" objects.each { String lidoObject = utils.transformObjekt(it, template, dateOfCollection, repositoryId, setSpec, collectionID, false) //Hack for resolved XML entities... lidoObject = lidoObject.replace("&", "&") //add the Lido Element generated from the current (it) FaustObjekt resultsQueue.put(lidoObject); c++; // println lidoObject // println "***************" template.reset() //need to sleep for a while (10 are not enough) because otherwise //I got a ConcurrentModificationEception on the push result set on the side of the aggregator (as installed on node1.p.hope) //Please consider that we might not need this in the future at Amsterdam -- the aggregator will be faster! Thread.sleep(30) } } println c +" lido objects enueued" this.resultsQueue.put("END") println "closedQueue" } @Override public void setResultsQueue(BlockingQueue queue) { this.resultsQueue = queue } @Override public void setInputQueue(BlockingQueue queue) { this.inputQueue = queue } /** * TODO: calling the method from the run() does not work. Kinda groovy strange stuff, I do not know why. */ @Override public void closeResultQueue() { this.resultsQueue.put("END") println "closedQueue" } @Override public void setRepositoryId(String repoId) {this.repositoryId = repoId} }