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 IISHReviewLibrary 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 = 'http://socialhistory.org/en/irsh' def String repositoryId; def IISHMarcUtils utils = new IISHMarcUtils() @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) resultsQueue.put(marcCollection) def c = 1; while(!((input = this.inputQueue.take()).equals("END"))){ 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 String setSpec = oaiHeaderNode.setSpec.text() def String oaiIdentifier = oaiHeaderNode.identifier.text() if(oaiIdentifier != 'oai:socialhistoryservices.org:10622/S0020859002000755'){ def NodeList marcRecords =xmlRoot.'**'.'*:record' marcRecords.each{ def String marcRecord = utils.transformMarcRecord(it, libraryTemplate, this.dataProvider, this.collectionID, this.collectionID, repoId, dateOfCollection, setSpec, "http://www.europeana.eu/rights/rr-f/") if(marcRecord){ resultsQueue.put(marcRecord); c++; } } } else println "Found record to skip becasue of missing titles/descriptions: "+oaiIdentifier } 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 = '''Collection of articles, bookreviews, bibliographies and annual supplements from volumes of the International Review for Social History (IRSH) (1936-1940) and its successor, the International Review of Social History (IRSH) (1956-2011), with abstracts in English, French, German and Spanish. This journal is widely regarded as one of the pioneering journals in its field. It is internationally renowned for the quality, depth and originality of its articles, and provides an essential resource for scholars and researchers across the discipline of social history." ''' def MarcRecord marcCollection = new MarcRecord(descriptionLevel:'collection', localID:collID, pid:collID, landingPage: new LandingPage(href:collID, localID:collID), 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:'1936-2011', stm:'1936-2011'), accumulationDate:new DateStm(date:'1936-2011', stm:'1936-2011'), isbn_020:'', issn_022:'', providerName:dataProvider, providerLanguage:'eng', bookNo_091:'', extents:[ new LanguagedValue(value:'1881') ], physDetails:[], dimensions:[],materialDesignations:[], accruals:[], toc:'', theabstracts:[ new LanguagedValue(language:'eng', value:theAbstract) ], genre:'', keywords:[], creatorPersons_100:[], creatorCorps_110:[], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1936-2011'], topicSubjects_650:['social history'], spatialCoverages_651:['international'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'International Review for Social History (IRSH)')) ], owner:dataProvider, editionStms_250:[], languages_041:[ 'eng', 'fra', 'deu', 'spa', 'rus' ]) 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} }