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 AMSAB6191 implements RunnableGroovy { def AMSABModsUtils utils = new AMSABModsUtils() def String templatePath = "/var/lib/hope-scripts/templates" def BlockingQueue resultsQueue, inputQueue; def String repositoryId; def String collectionPID = "5446FB43-BDCF-4E84-BC99-B57B099D01AA" //def mods = new groovy.xml.Namespace("http://www.loc.gov/mods/v3", 'mods') @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.collectionPID) 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() //name or "*:name" matches an element named "name" irrespective of the namespace it's in (i.e. this is the default mode of operation) //however the option without the *: seems to not work def NodeList modsObjects =xmlRoot.'**'.'*:mods' //println "Found "+modsObjects.size()+" mods entries" modsObjects.each{ def String marcRecord = utils.transformModsRecord(it, libraryTemplate, dateOfCollection, repoId, setSpec, collectionPID) //Hack for resolved XML entities... if(marcRecord){ marcRecord = marcRecord.replace("", "<Va>") resultsQueue.put(marcRecord); c++; } } } libraryTemplate.reset() println c +" marc records enueued" this.resultsQueue.put("END") println "closedQueue" } def createCollection = { template, dateOfColl, repoId, collPID-> template.reset() def OAIHeader oaiheader = new OAIHeader(dateOfCollection:dateOfColl, repositoryId:repoId, setSpec:'', identifier:collPID, objIdentifier:repoId+"::"+collPID) def String theAbstract = '''Combat: hebdomadaire wallon d'action socialiste''' def MarcRecord marcCollection = new MarcRecord(descriptionLevel:'collection', europeanaType:'TEXT',language:'Dutch', accessRights:'Europeana Rights Reserved Free Access', useRights:'Europeana Rights Reserved Free Access', europeanaRights:'http://www.europeana.eu/rights/rr-f/', leader:'', pid:collPID, aggregator:"HOPE - Heritage of the people's Europe", creationDate:new DateStm(date:'1961-1991', stm:'1961-1991'), accumulationDate:new DateStm(date:'2007', stm:'2007'), isbn_020:'', issn_022:'', localID:collPID, providerName:'Amsab-Institute of Social History', providerLanguage:'Dutch', bookNo_091:'', extents:[ new LanguagedValue(value:'1480') ], physDetails:[], dimensions:[],materialDesignations:[ new LanguagedValue(value:'TEXT') ], accruals:[], toc:'', theabstracts:[ new LanguagedValue(language:'eng', value:theAbstract) ], genre:'', keywords:[], creatorPersons_100:[], creatorCorps_110:[ 'Amsab-Institute of Social History' ], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1961-1991'], topicSubjects_650:[], spatialCoverages_651:['Belgium'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'Trade Union Periodicals: 1961-1991')) ], editionStms_250:[], repositories:[ 'Amsab-Institute of Social History' ], languages_041:['French']) 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} }