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 FESLibraryNZ 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, 'nz' ,'http://library.fes.de/nz/','http://hdl.handle.net/11088/de-bo133:nz') 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 = ''' "Trotz ihres finalen Siechtums aber war die "Neue Zeit" als intellektuelles Forum der europäischen sozialistischen Intelligenz vor dem Ersten Weltkrieg ein singuläres Projekt, das keine vergleichbaren Vorgänger hatte und nicht entfernt einen solchen Nachfolger fand." Aus der Einleitung zur Online-Edition von Till Schelz-Brandenburg. ''' 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:'1883', stm:'1883-1923'), accumulationDate:new DateStm(date:'1923', stm:''), isbn_020:'', issn_022:'', providerName:providerName, providerLanguage:providerLanguage, bookNo_091:'', extents:[ new LanguagedValue(value:'9111') ], 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:['1883-1923'], topicSubjects_650:[ 'Socialists and social democrats' ], spatialCoverages_651:['DE'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'Die neue Zeit : Wochenschrift der deutschen Sozialdemokratie (1883 – 1923)')) ], 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 } }