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.* class IISHNDBooksLibrary implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def BlockingQueue resultsQueue, inputQueue; def String dataProvider = 'International Institute of Social History' def String collectionID = 'NonDigitalBooksAndBrochures' def String collectionPID = 'NonDigitalBooksAndBrochures' def String repositoryId; def IISHNDLibraryUtils utils = new IISHNDLibraryUtils() @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) resultsQueue.put(marcCollection) def c = 1; def inserted = 1 while(!((input = this.inputQueue.take()).equals("END"))){ if(c > 336449){ def Node xmlRoot = parser.parseText(input) def NodeList marcRecords =xmlRoot.'**'.metadata.'*:record' marcRecords.each{ def String marcRecord = utils.createMarcRecord(it, libraryTemplate, collectionDate, repositoryId, dataProvider, collectionID, collectionPID) if(marcRecord){ resultsQueue.put(marcRecord); inserted++ } Thread.sleep(100) } } c++ } libraryTemplate.reset() println inserted +" marc records enueued" this.resultsQueue.put("END") println "closedQueue" } def createCollection = { StringTemplate template, String dateOfColl -> template.reset() def OAIHeader oaiheader = new OAIHeader(dateOfCollection:dateOfColl, repositoryId:repositoryId, setSpec:'', identifier:collectionID, objIdentifier:repositoryId+"::"+collectionID, nonDigitalCollection:true) def String landingPageURL = 'http://search.socialhistory.org/Search/Results?lookfor=&type=AllFields&filter[]=format%3A%22Books+and+brochures%22' def String theAbstract = ''' The IISH Library holds about one million records. Next to scholarly journals and monographs in the field of social history, the original publications of the social movements, e.g. periodicals, posters and leaflets, are abundantly present. All these printed materials are available for research and can be retrieved through different types of searches in the IISH catalogue. The scope of the library collections extends considerably beyond the boundaries of social history. This is thanks to the inclusion of specialized libraries and subject-based collections of books, leaflets, pamphlets, and periodicals. ''' def MarcRecord marcCollection = new MarcRecord(descriptionLevel:'collection', localID:collectionID, pid:collectionPID, landingPage:new LandingPage(href:landingPageURL, localID:landingPageURL), repositories:[dataProvider], europeanaType:'TEXT',language:'eng', accessRights:'Rights Reserved - Free Access', useRights:'Rights Reserved - Free Access', europeanaRights:'http://www.europeana.eu/rights/rr-f/', leader:'', , aggregator:"HOPE - Heritage of the people's Europe", creationDate:new DateStm(date:'1500-2013', stm:'1500-2013'), accumulationDate:new DateStm(date:'1500-2013', stm:'1500-2013'), isbn_020:'', issn_022:'', providerName:dataProvider, providerLanguage:'eng', bookNo_091:'', extents:[ new LanguagedValue(value:'599972') ], physDetails:[], dimensions:[],materialDesignations:[ new LanguagedValue(language:'eng', value:'books and brochures') ], accruals:[], toc:'', theabstracts:[ new LanguagedValue(language:'eng', value:theAbstract) ], genre:'', keywords:[], creatorPersons_100:[], creatorCorps_110:[], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1500-2013'], topicSubjects_650:[], spatialCoverages_651:[], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'Books and Brochures on Social History from IISH Library, 1500-2013'), language:'eng') ], owner:dataProvider, editionStms_250:[], languages_041:[ 'eng', 'dut', 'fra', 'ger', 'spa', 'rus', 'ara', 'tur', 'ita', 'por' ]) 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 } }