import java.util.concurrent.BlockingQueue import org.antlr.stringtemplate.StringTemplate /** * DNetGroovy class for IISH sample metadata records. * @author alessia * */ class IISHLido{ def String euroType = 'IMAGE' def BlockingQueue resultsQueue, inputQueue; def boolean isDigital = true /** * Driver namespace for elements in the OAI header. */ def dri = new groovy.xml.Namespace("http://www.driver-repository.eu/namespace/dri", 'dri') def marc = new groovy.xml.Namespace("http://www.loc.gov/MARC21/slim", 'marc') public int enqueueResults(StringTemplate template, String collectionPID) { def IISHLidoUtils utils = new IISHLidoUtils(euroType:euroType) 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 repoId = oaiHeaderNode.'dri:repositoryId'.text() def String setSpec = oaiHeaderNode.setSpec.text() def NodeList iishRecords = xmlRoot.'**'.'marc:record'; //println "Found "+iishRecords.size()+" marc records" iishRecords.each { String lidoObject = utils.transformMarcRecord(it, template, dateOfCollection, repoId, setSpec, collectionPID, isDigital) //Hack for resolved XML entities... lidoObject = lidoObject.replace("&", "&") resultsQueue.put(lidoObject); c++; template.reset() //IISHDutchPolitical generates ConcurrentModificationException...we try to avoid that with the following sleep Thread.sleep(20) } } println c +" lido objects enueued" return c } }