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 FESLibraryGMH implements RunnableGroovy { def FESLibraryUtils utils = new FESLibraryUtils() 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 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, this.repositoryId, 'gmh' ,'http://library.fes.de/gmh/','http://hdl.handle.net/11088/de-bo133:gmh') resultsQueue.put(marcCollection) def c = 0; 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, this.repositoryId, collectionDate) resultsQueue.put(marcRecord); c++; } libraryTemplate.reset() println c +" marc records enueued" this.resultsQueue.put("END") println "closedQueue" } def createCollection = { template, dateOfColl, repoId, set, collID, collPID-> template.reset() def OAIHeader oaiheader = new OAIHeader(dateOfCollection:dateOfColl, repositoryId:repoId, setSpec:set, identifier:collPID, objIdentifier:repoId+"::"+collPID) def String theAbstract = '''Die "Gewerkschaftlichen Monatshefte", herausgegeben vom Bundesvorstand des DGB, waren von 1950 bis 2004 das theoretische Diskussionsorgan des DGB. Das Projekt "Online-Edition der Gewerkschaftlichen Monatshefte" wurde ermöglicht durch das Historische Forschungszentrum der Friedrich-Ebert-Stiftung und die Hans-Böckler-Stiftung in Kooperation mit dem DGB. ''' 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:'1950', stm:'1950-2004'), accumulationDate:new DateStm(date:'2004', stm:''), isbn_020:'', issn_022:'', providerName:providerName, providerLanguage:providerLanguage, bookNo_091:'', extents:[ new LanguagedValue(value:'4833') ], physDetails:[ new LanguagedValue(value:'application/pdf') ], 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:['1950-2004'], topicSubjects_650:[ 'workers movements' ], spatialCoverages_651:['DE'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'Die "Gewerkschaftlichen Monatshefte" (1950 - 2004)')) ], editionStms_250:[], landingPage:new LandingPage(href:collPID, localID:collPID), languages_041:['deu']) 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 } }