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.LandingPage import eu.dnetlib.hope.domains.common.OAIHeader import eu.dnetlib.hope.domains.visual.LIDOCollection import eu.dnetlib.hope.domains.visual.LidoActor import eu.dnetlib.hope.domains.visual.LidoDescription import eu.dnetlib.hope.domains.visual.LidoPlace import eu.dnetlib.hope.domains.visual.LidoTitle import eu.dnetlib.hope.domains.visual.TypedSubjects class AlbertLido implements RunnableGroovy { def BlockingQueue resultsQueue, inputQueue def PersMuseumLidoUtils utils = new PersMuseumLidoUtils() def String templatePath = "/var/lib/hope-scripts/templates" def String cpCompleteName = "Persmuseum" def String collectionPID = 'http://hdl.handle.net/10622/1922D088-0D58-4E3C-976A-AAD252224BB5' def String repositoryId /** * Driver namespace for elements in the OAI header. */ def dri = new groovy.xml.Namespace("http://www.driver-repository.eu/namespace/dri", 'dri') @Override public void run() { try{ def StringTemplateGroup group = new StringTemplateGroup("visualGroup", templatePath, DefaultTemplateLexer.class); def StringTemplate template = group.getInstanceOf("visualTemplate"); def coll = generateCollectionRecord(template) def OAIHeader oaiHeader = new OAIHeader(dateOfCollection:'', repositoryId:this.repositoryId, identifier:this.collectionPID, objIdentifier:this.repositoryId+'::'+this.collectionPID) def String collXML = coll.getXML(template, oaiHeader, cpCompleteName, coll) this.resultsQueue.put(collXML) template.reset() this.enqueueResults(template) this.resultsQueue.put("END") println "closedQueue" }catch(Exception e){ this.resultsQueue.put("FAIL") println "closedQueue after exception in groovy execution"+e throw new RuntimeException(e) } } def generateCollectionRecord = { template -> def String lPageURL = collectionPID def String abstractSum=''' Albert Hahn (1877-1918) is probably the most influential political cartoonist in Dutch history. His work for social-democrat magazines and newspapers reached a large audience, gave humorous or biting comments on the daily news, always from the point of view of the social-democrat workers' movement. His cartoons of struggling workmen, high-hatted capitalists and hypocritical politicians became icons. Besides cartoonist, Hahn was also a prolific and highly regarded poster designer, and wrote several influential articles on the position of art and artists in society. This collection contains thousands of Hahn's original drawings and designs, kept by himself and donated to the Persmuseum by his heirs. Together, they form a chronicle of Dutch social and political history in the early 20th century, and illustrate the rise of the social-democrat movement and issues as suffrage, child labour, the right to education. Hahn's drawings from 1914 onwards focus more on war and its consequences, giving an increasingly pessimistic view. ''' def LIDOCollection coll = new LIDOCollection(collectionID:collectionPID, collectionPID:collectionPID, langCode:'nld', collItemLanguages:['nld'], titles:[ new LidoTitle(value:'Collectie Albert Hahn'), ], abstractSummaries:[ new LidoDescription(langCode:'eng', value:abstractSum, type:'abstract') ], creationDates:['1900-1918'], accumulationDates:['1900-1918'], creators:[ new LidoActor(preferredName:'Albert Hahn') ], owners:[this.cpCompleteName], sizeItems:'3037', itemType:'IMAGE', itemFormatStm:'Drawings, designs, prints, posters, photographs', associatedPub:' Marien van der Heijden, Albert Hahn (Amsterdam 2003)', subjects:[ 'A.09 Socialists and social democrats; C.01 Capitalism/Anti-capitalists; C.10 Workers movements' ], typedSubjects:[ new TypedSubjects(type:'association', dates:['1900-1918'], places:[ new LidoPlace(preferredName:'NL') ]) ],repository:'International Institute of Social History', useRights:"Rights reserved - Free access", accessRights:'Rights reserved - Free access', europeanaType:'IMAGE', europeanaRights:'Rights reserved - Free access', landingPage:new LandingPage(href:lPageURL, localID:lPageURL)) return coll } public void enqueueResults(StringTemplate template) { def parser = new XmlParser(false, true); def String input; def c = 0; 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 NodeList iishRecords = xmlRoot.'**'.'marc:record'; //println "Found "+iishRecords.size()+" marc records" iishRecords.each { String lidoObject = utils.transformMarcRecord(it, template, dateOfCollection, repoId, setSpec, collectionPID) //Hack for resolved XML entities... lidoObject = lidoObject.replace("&", "&") //add the Lido Element generated from the current (it) FaustObjekt resultsQueue.put(lidoObject); c++; template.reset() } } println c +" lido objects enueued" } @Override public void setRepositoryId(String repoId) { repositoryId = repoId; } @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") println "closedQueue" } }