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 class OSAParanoiaLibrary implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def BlockingQueue resultsQueue, inputQueue; def OSALibraryUtils utils = new OSALibraryUtils() def String euroType = 'VIDEO' def String dataProvider = "Open Society Archives at Central European University" def String datasetName = "OSAParanoia" def String dataProviderLanguage = 'hun' def String collectionPID = "http://hdl.handle.net/10891/osa:cc6f2fcb-8883-492d-b029-0e836272aee4" def String repositoryId; /** * Namespaces */ def dri = new groovy.xml.Namespace("http://www.driver-repository.eu/namespace/dri", 'dri') def foxml= new groovy.xml.Namespace("info:fedora/fedora-system:def/foxml#", 'foxml') def marc=new groovy.xml.Namespace("http://www.loc.gov/MARC21/slim", 'marc') def osa=new groovy.xml.Namespace("http://greenfield.osaarchivum.org/ns/item", 'osa') def rdf = new groovy.xml.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", 'rdf') @Override public void run() { def StringTemplateGroup group = new StringTemplateGroup("libraryGroup", templatePath, DefaultTemplateLexer.class); def StringTemplate libraryTemplate = group.getInstanceOf("libraryTemplate"); println "got template at path "+templatePath def parser = new XmlParser(false, true) println "got parser" def input; def OAIHeader collectionHeader = new OAIHeader(repositoryId:this.repositoryId, identifier:this.collectionPID, objIdentifier:this.repositoryId+'::'+this.collectionPID) def MarcRecord collectionRecord = generateCollectionRecord() libraryTemplate.setAttribute("oaiheader", collectionHeader) libraryTemplate.setAttribute("marc", collectionRecord) resultsQueue.put(libraryTemplate.toString()) libraryTemplate.reset() while(!((input = this.inputQueue.take()).equals("END"))){ //print "processing record " def Node xmlRoot = parser.parseText(input) def Node oaiHeaderNode = xmlRoot.'**'.header[0] def String dateOfColl = oaiHeaderNode.'dri:dateOfCollection'.text() def Node theRecordRoot =xmlRoot.'**'.'foxml:digitalObject'[0] def String res = utils.transformRecord(theRecordRoot, libraryTemplate, this.repositoryId, dateOfColl, this.dataProvider, this.dataProviderLanguage, this.collectionPID) if(res) //println res resultsQueue.put(res.replace("&", "&")) //println " result pushed" libraryTemplate.reset() } println "consumed input queue" this.resultsQueue.put("END") } def generateCollectionRecord = { def String theAbstract = ''' The Paranoia Archive contains 58 Hungarian educational films on ABC (atomic, biological, chemical) warfare released between 1964-1982, as part of a public awareness campaign about protection against weapons of mass destruction. The films were produced by the Ministry of Defence department Polgári Védelem Országos Parancsnokság (PVOP; Civil Defense Alliance), which commissioned the works primarily from the Mafilm Military and Sport Film Studios. Four of the films were directly adapted from Soviet originals with the addition of a Hungarian voice-over. The early films instructed viewers how to build a bomb shelter at home, what to do in case of a nuclear attack, or how to counteract the side-effects of radioactivity. From the 1970s on, the films presented public drills and evacuations by civil defense units, some of which mobilized tens of thousands of civilians. The films were screened on a regular basis in schools, workplaces, cultural centers, or movie theaters before the main feature which, over time, affected the film’s quality. In 1991, the civil defense storage facility in Győr was liquidated. The 16-mm black-and-white celluloid films were salvaged and came into the possession of independent filmmaker József Szolnoki, who arranged for their digitization at OSA, where the digital copies remain. ''' def MarcRecord marcCollection = new MarcRecord(descriptionLevel:'collection', localID:this.collectionPID, pid:this.collectionPID, landingPage:new LandingPage(localID:this.collectionPID, href:this.collectionPID), europeanaType:this.euroType,language:'English; Hungarian', accessRights:'Rights Reserved - Free Access', useRights:'', europeanaRights:'Rights Reserved - Free Access', leader:'', aggregator:"HOPE - Heritage of the people's Europe", creationDate:new DateStm(date:'1964-1982', stm:'1964-1982'), accumulationDate:new DateStm(date:'', stm:''), isbn_020:'', issn_022:'', providerName:this.dataProvider, providerLanguage:'English', bookNo_091:'', extents:[ new LanguagedValue(value:'57') ], physDetails:[], dimensions:[],materialDesignations:[ new LanguagedValue(language:'eng', value:'Educational films; Propaganda') ], accruals:[], toc:'', theabstracts:[ new LanguagedValue(language:'eng', value:theAbstract) ], genre:'', keywords:[], creatorPersons_100:[], creatorCorps_110:[], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1941-1982'], topicSubjects_650:[], spatialCoverages_651:['Hungary', 'Soviet Union'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'Paranoia Archive'), language:'eng') ], editionStms_250:[], repositories:[this.dataProvider], languages_041:['Hungarian']) return marcCollection; } @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 } }