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 OSAEphemeraLibrary implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def BlockingQueue resultsQueue, inputQueue; def OSALibraryUtils utils = new OSALibraryUtils() def String euroType = 'IMAGE' def String dataProvider = "Open Society Archives at Central European University" def String datasetName = "OSAEphemera" def String dataProviderLanguage = 'hun' def String collectionPID = 'http://hdl.handle.net/10891/osa:554e8ec5-a131-4087-9b5d-4551cc82b291' 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 = ''' This collection consists of 372 digitized objects – stamps, envelopes, postmarks and postcards, calendars, photos, fliers, posters and fake banknotes – produced and distributed by the Polish underground movement in the 1980s and preserved by Radio Free Europe/Radio Liberty's (RFE/RL) Polish Underground Publications Unit. This unit was the first RFE/RL national section dedicated to the underground press, established in March 1984 and led by section chief Witold Pronobis and chief archivist Anna Pomian. Items in the collection were originally obtained by the Polish Underground Publications Unit through private donations and barter. Materials were often produced in more than one form, and used clearly recognizable and accessible images, often borrowing from political (Solidarity and other opposition groups), national and religious iconography. A significant portion of the collection is comprised of items produced within the underground postage system operated from 1981 onwards, and which was unique to Poland. The expansion of underground political activity and improvements to printing techniques took place in tandem. It is estimated that in 1986 alone, around 200 sets of stamps were produced in print runs of 5,000-10,000 each. Stamps often served as fundraising means for various initiatives, and became popular collectors' items not only for underground activists but also among the population at large. ''' 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', accessRights:'Ownership of and financial copyrights to the reports belong to RFE/RL, Inc. Reprinted with the permission of Radio Free Europe/Radio Liberty, 1201 Connecticut Ave., N.W., Washington, DC 20036, USA. Users of RFE/RL content cannot alter the meaning, name or integrity of the content. RFE/RL reserves the right to revoke permission for use of its content at any time. The sale of RFE/RL content is strictly prohibited.', useRights:'Rights Reserved - Free Access', europeanaRights:'Rights Reserved - Free Access', leader:'', aggregator:"HOPE - Heritage of the people's Europe", creationDate:new DateStm(date:'1981-1989', stm:'1981-1989'), accumulationDate:new DateStm(date:'', stm:''), isbn_020:'', issn_022:'', providerName:this.dataProvider, providerLanguage:'English', bookNo_091:'', extents:[ new LanguagedValue(value:'372') ], physDetails:[], dimensions:[],materialDesignations:[ new LanguagedValue(language:'eng', value:'Bank notes; Calendars; Drawings; Envelopes; Fliers; Greeting cards; Invitations; Photographs; Postage stamps; Postcards; Posters; Stickers; Stock certificates') ], accruals:[], toc:'', theabstracts:[ new LanguagedValue(language:'eng', value:theAbstract) ], genre:'', keywords:[], creatorPersons_100:[], creatorCorps_110:[ 'Radio Free Europe/Radio Liberty (RFE/RL) Research Institute' ], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1939-1989'], topicSubjects_650:[], spatialCoverages_651:['Poland'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'Polish Underground Ephemera'), language:'eng') ], editionStms_250:[], repositories:[this.dataProvider], languages_041:['Polish']) 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 } }