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.DateStm import eu.dnetlib.hope.domains.library.MarcRecord import eu.dnetlib.hope.domains.library.MarcTitle import eu.dnetlib.hope.domains.library.MarcTranslatedTitle import eu.dnetlib.miscutils.datetime.DateUtils class VGAArchiv implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def BlockingQueue resultsQueue, inputQueue; def String dataProvider = 'VGA' def String collectionID = 'archiv' def String repositoryId; def VGAMarcUtils utils = new VGAMarcUtils() @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, this.collectionID, this.collectionID) resultsQueue.put(marcCollection) def c = 1; while(!((input = this.inputQueue.take()).equals("END"))){ println "processing record" 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 NodeList marcRecords =xmlRoot.'**'.metadata.'*:collection'.'*:record' println "Found "+marcRecords.size()+" marc records" marcRecords.each{ def String marcRecord =utils.transformMarcRecord(it, libraryTemplate, this.dataProvider, this.collectionID, '', repoId, dateOfCollection, this.collectionID) if(marcRecord){ resultsQueue.put(marcRecord); c++; } } } libraryTemplate.reset() println c +" marc records enueued" this.resultsQueue.put("END") println "closedQueue" } def createCollection = { template, dateOfColl, repoId, set, collID -> template.reset() def OAIHeader oaiheader = new OAIHeader(dateOfCollection:dateOfColl, repositoryId:repoId, setSpec:set, identifier:collID, objIdentifier:repoId+"::"+collID) def String theAbstract = ''' The Arbeiter-Zeitung (Workers‘ News) was founded by Victor Adler in 1889 as the central political medium of the Austrian Social Democratic Workers Party, its editorial board being identical with the party executive well into the 20th century. Originally appearing every fortnight, it was edited from October 1889 onwards as a weekly and from 1895 as a daily paper until 12 February 1934, when it was banned by the Austrofascist government. A weekly edition was produced at the Brno exile in Czechoslovakia from 1934 to 1938. In 1945 the Arbeiter-Zeitung was relaunched as the official daily paper of the Austrian Socialists (SPÖ). In addition to the already extensive bulk of Social Democratic newspapers and periodicals, the Glühlichter presented the first humoristic-satirical weekly (“comic paper“). It considered itself an organ of radical democracy, was anti-monarchist and anti-clerical, severely castigating the populist anti-semitism of the nascent mass movement of the Christan Socialists – though not always refraining from attacks itself. In the basic orientation of the paper, the dominating influence is that of Franz Schuhmeier, Viennese Social Democratic member of parliament (Reichstag) and “tribune of the plebs“ for the Vienna district of Ottakring. ''' def MarcRecord marcCollection = new MarcRecord(descriptionLevel:'collection', repositories:[dataProvider], europeanaType:'IMAGE',language:'deu', accessRights:'free access', useRights:'Restricted use', europeanaRights:'Rights Reserved - Free Access', leader:'', pid:'', aggregator:"HOPE - Heritage of the people's Europe", creationDate:new DateStm(date:'1972', stm:'1972'), accumulationDate:new DateStm(date:'2012', stm:'2012'), isbn_020:'', issn_022:'', localID:collID, providerName:dataProvider, providerLanguage:'deu', bookNo_091:'', extents:[], physDetails:[], dimensions:[],materialDesignations:[], accruals:[], toc:'', theabstracts:[ new LanguagedValue(language:'eng', value:theAbstract) ], genre:'', keywords:[], creatorPersons_100:['Michaela Meier'], creatorCorps_110:[dataProvider], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1885 - 1932'], topicSubjects_650:[], spatialCoverages_651:['Österreich'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'Arbeiter-Zeitung, Sozialdemokratische Parteitage und Glühlichter')) ], owner:dataProvider, editionStms_250:[]) 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} }