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 import eu.dnetlib.hope.domains.common.* import eu.dnetlib.hope.domains.library.* import eu.dnetlib.miscutils.datetime.DateUtils class FESLibraryMARX implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def BlockingQueue resultsQueue, inputQueue; def String repositoryId def String providerName = "Bibliothek der Friedrich-Ebert-Stiftung" def String providerLanguage = "deu" def oai_hope = new groovy.xml.Namespace("http://library.fes.de/xsd/hope/ http://library.fes.de/xsd/hope/hope.xsd", 'oai_hope') @Override public void run() { def FESLibraryUtils utils = new FESLibraryUtils(isDigital:false) def StringTemplateGroup group = new StringTemplateGroup("libraryGroup", templatePath, DefaultTemplateLexer.class); def StringTemplate libraryTemplate = group.getInstanceOf("libraryTemplate"); def parser = new XmlParser(false, true) def input def String collectionDate = DateUtils.now_ISO8601() def String marcCollection = createCollection(libraryTemplate, collectionDate, 'marx', 'http://library.fes.de/cgi-bin/populo/marx.pl','http://hdl.handle.net/11088/de-bo133:marx') resultsQueue.put(marcCollection) def c = 1; while(!((input = this.inputQueue.take()).equals("END"))){ // println "processing record" def Node xmlRoot = parser.parseText(input) def Node theRecord = xmlRoot.'**'.'metadata'.'oai_hope:record'[0] def String marcRecord = utils.transformRecord(theRecord, libraryTemplate, repositoryId, collectionDate) resultsQueue.put(marcRecord); c++; Thread.sleep(20) } libraryTemplate.reset() println c +" marc records enueued" this.resultsQueue.put("END") println "closedQueue" } def createCollection = { template, dateOfColl, set, collID, collPID-> template.reset() def OAIHeader oaiheader = new OAIHeader(dateOfCollection:dateOfColl, repositoryId:repositoryId, setSpec:set, identifier:collPID, objIdentifier:this.repositoryId+"::"+collPID, nonDigitalCollection:true) def String theAbstract = '''Dieser Katalog weist die Bestände der ehemaligen Bibliothek des Karl-Marx-Hauses nach. ''' def MarcRecord marcCollection = new MarcRecord(pid:collPID,localID:collID, descriptionLevel:'collection', europeanaType:'TEXT',language:'deu', accessRights:'General Public (Open Access)', useRights:'Copyright Bibliothek der Friedrich-Ebert-Stiftung', europeanaRights:'http://www.europeana.eu/rights/rr-f/', leader:'', aggregator:"HOPE - Heritage of the people's Europe", creationDate:new DateStm(date:'1988', stm:'1988-2009'), accumulationDate:new DateStm(date:'2009', stm:''), isbn_020:'', issn_022:'', providerName:providerName, providerLanguage:providerLanguage, bookNo_091:'', extents:[ new LanguagedValue(value:'48311') ], physDetails:[], dimensions:[],materialDesignations:[ new LanguagedValue(value:'Text') ], accruals:[], toc:'', theabstracts:[ new LanguagedValue(value:theAbstract, language:'deu') ], genre:'', keywords:[], creatorPersons_100:[], creatorCorps_110:[providerName], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1800-2009'], topicSubjects_650:[ 'social democracy', 'labour movement', 'Socialists and social democrats', 'Fascism and Nazism/Anti-fascists' ], spatialCoverages_651:['DE'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(language:'eng', translationLanguage:'deu', main:new MarcTranslatedTitle(original:'Library of the Karl Marx House', translation:'Bibliothek des Karl-Marx-Hauses')) ], editionStms_250:[], landingPage:new LandingPage(href:collPID, localID:collPID), languages_041:['deu'], owner:providerName, repositories:[providerName]) template.setAttribute("oaiheader", oaiheader) template.setAttribute("marc", marcCollection) return template.toString(); } @Override public void setResultsQueue(BlockingQueue queue) { this.resultsQueue = queue } @Override public void setInputQueue(BlockingQueue queue) { this.inputQueue = queue } @Override public void closeResultQueue() { this.resultsQueue.put("END") } @Override public void setRepositoryId(String repoId) { this.repositoryId = repoId } }