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.LidoDescription import eu.dnetlib.hope.domains.visual.LidoPlace import eu.dnetlib.hope.domains.visual.LidoTitle import eu.dnetlib.hope.domains.visual.TypedSubjects class FESPhotosLIDO implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def FESLidoUtils utils = new FESLidoUtils() def BlockingQueue resultsQueue, inputQueue; 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') def String collectionID = 'Fotosammlung' String providerName = "Archiv der sozialen Demokratie (AdsD)" def generateCollectionRecord = { template, dateOfCollection, setSpec-> def String lPageURL = 'http://archiv2.fes.de/dok_start.fau?prj=fes&dm=Fotos' def String abstractSum='Neben zahlreichen Fotografien des SPD-Parteivorstandes enthält die Sammlung unter anderem Fotografien verschiedener Organisationen, Fotografen und Agenturen.' def OAIHeader collOaiheader = new OAIHeader(dateOfCollection:dateOfCollection, repositoryId:repositoryId, setSpec:setSpec, identifier:collectionID, objIdentifier:repositoryId+"::"+collectionID) def LIDOCollection coll = new LIDOCollection(collectionID:collectionID, langCode:'deu', titles:[ new LidoTitle(value:'photographs') ], abstractSummaries:[ new LidoDescription(type:'abstract', value:abstractSum) ], creationDates:['1840-2012'], accumulationDates:['1996-2012'], owners:[providerName], sizeItems:'4', itemType:'IMAGE', itemFormatStm:'', associatedPub:'', typedSubjects:[ new TypedSubjects(type:'association', dates:['1840-2012'], places:[ new LidoPlace(preferredName:'Germany'), new LidoPlace(preferredName:'Egypt'), new LidoPlace(preferredName:'Ethiopia'), new LidoPlace(preferredName:'Afghanistan'), new LidoPlace(preferredName:'Albania'), new LidoPlace(preferredName:'Algeria'), new LidoPlace(preferredName:'Australia'), new LidoPlace(preferredName:'Belgium'), new LidoPlace(preferredName:'Switzerland'), new LidoPlace(preferredName:'France'), new LidoPlace(preferredName:'Brazil'), new LidoPlace(preferredName:'Poland'), new LidoPlace(preferredName:'United States of America'), new LidoPlace(preferredName:'Romania'), new LidoPlace(preferredName:'Chile'), new LidoPlace(preferredName:'China'), new LidoPlace(preferredName:"Cote d'Ivoire"), new LidoPlace(preferredName:'Estonia'), new LidoPlace(preferredName:'Finland'), new LidoPlace(preferredName:'Ukraine'), new LidoPlace(preferredName:'United Kingdom'), new LidoPlace(preferredName:'India'), new LidoPlace(preferredName:'Indonesia'), new LidoPlace(preferredName:'Iraq'), new LidoPlace(preferredName:'Iran'), new LidoPlace(preferredName:'Ireland'), new LidoPlace(preferredName:'Israel'), new LidoPlace(preferredName:'Iceland'), new LidoPlace(preferredName:'Italy'), new LidoPlace(preferredName:'Japan'), new LidoPlace(preferredName:'Yemen'), new LidoPlace(preferredName:'Jordan'), new LidoPlace(preferredName:'Yugoslavia'), new LidoPlace(preferredName:'Cambodia'), new LidoPlace(preferredName:'Canada'), new LidoPlace(preferredName:'Croatia'), new LidoPlace(preferredName:'Latvia'), new LidoPlace(preferredName:'Libyan arab jamahiriya'), new LidoPlace(preferredName:'Lithuania'), new LidoPlace(preferredName:'Luxembourg'), new LidoPlace(preferredName:'Malaysia'), new LidoPlace(preferredName:'Morocco'), new LidoPlace(preferredName:'Mexico'), new LidoPlace(preferredName:'Mozambique'), new LidoPlace(preferredName:'Nepal'), new LidoPlace(preferredName:'Nicaragua'), new LidoPlace(preferredName:'Austria'), new LidoPlace(preferredName:'Pakistan'), new LidoPlace(preferredName:'Palestine'), new LidoPlace(preferredName:'Portugal'), new LidoPlace(preferredName:'Russian Federation'), new LidoPlace(preferredName:'Saudi Arabia'), new LidoPlace(preferredName:'England'), new LidoPlace(preferredName:'Sweden'), new LidoPlace(preferredName:'Senegal'), new LidoPlace(preferredName:'Serbia'), new LidoPlace(preferredName:'Spain'), new LidoPlace(preferredName:'Somalia'), new LidoPlace(preferredName:'Soviet Union'), new LidoPlace(preferredName:'South Africa'), new LidoPlace(preferredName:'Syria'), new LidoPlace(preferredName:'Thailand'), new LidoPlace(preferredName:'Turkey'), new LidoPlace(preferredName:'Tunisia'), new LidoPlace(preferredName:'Uganda'), new LidoPlace(preferredName:'Hungary'), new LidoPlace(preferredName:'Uruguay'), new LidoPlace(preferredName:'Zimbabwe'), new LidoPlace(preferredName:'Cyprus'), new LidoPlace(preferredName:'Yemen'), new LidoPlace(preferredName:'Angola'), new LidoPlace(preferredName:'Armenia'), new LidoPlace(preferredName:'Argentinia'), new LidoPlace(preferredName:'Azerbaijan'), new LidoPlace(preferredName:'Bahrain'), new LidoPlace(preferredName:'Bangladesh'), new LidoPlace(preferredName:'Lesotho'), new LidoPlace(preferredName:'Myanmar'), new LidoPlace(preferredName:'Bosnia and Herzegovina'), new LidoPlace(preferredName:'Bolivia'), new LidoPlace(preferredName:'Botsuana'), new LidoPlace(preferredName:'Bulgaria'), new LidoPlace(preferredName:'Czechoslovakia'), new LidoPlace(preferredName:'North Corea'), new LidoPlace(preferredName:'El Salvador'), new LidoPlace(preferredName:'Gabon'), new LidoPlace(preferredName:'Georgia'), new LidoPlace(preferredName:'Ghana'), new LidoPlace(preferredName:'Greece'), new LidoPlace(preferredName:'Guatemala'), new LidoPlace(preferredName:'Guinea'), new LidoPlace(preferredName:'Haiti'), new LidoPlace(preferredName:'Cameroon'), new LidoPlace(preferredName:'Kazakhstan'), new LidoPlace(preferredName:'Qatar'), new LidoPlace(preferredName:'Kenya'), new LidoPlace(preferredName:'Colombia'), new LidoPlace(preferredName:'Congo'), new LidoPlace(preferredName:'Croatia'), new LidoPlace(preferredName:'Cuba'), new LidoPlace(preferredName:'Laos'), new LidoPlace(preferredName:'Lesotho'), new LidoPlace(preferredName:'Bangladesh'), new LidoPlace(preferredName:'Lesotho'), new LidoPlace(preferredName:'Lebanon'), new LidoPlace(preferredName:'Liberia'), new LidoPlace(preferredName:'Madagascar'), new LidoPlace(preferredName:'Malawi'), new LidoPlace(preferredName:'Malta'), new LidoPlace(preferredName:'Macedonia'), new LidoPlace(preferredName:'Monaco'), new LidoPlace(preferredName:'Myanmar'), new LidoPlace(preferredName:'Namibia'), new LidoPlace(preferredName:'New Zealand'), new LidoPlace(preferredName:'Netherlands'), new LidoPlace(preferredName:'Niger'), new LidoPlace(preferredName:'Nigeria'), new LidoPlace(preferredName:'Norway'), new LidoPlace(preferredName:'Austria'), new LidoPlace(preferredName:'Oman'), new LidoPlace(preferredName:'Panama'), new LidoPlace(preferredName:'Peru'), new LidoPlace(preferredName:'Philippines'), new LidoPlace(preferredName:'Gabon'), new LidoPlace(preferredName:'Ruanda-Urundi'), new LidoPlace(preferredName:'Sambia'), new LidoPlace(preferredName:'Zimbabwe'), new LidoPlace(preferredName:'Singapore'), new LidoPlace(preferredName:'Slovenia'), new LidoPlace(preferredName:'Slovakia'), new LidoPlace(preferredName:'Tajikistan'), new LidoPlace(preferredName:'Tanzania'), new LidoPlace(preferredName:'Togo'), new LidoPlace(preferredName:'Trinidad'), new LidoPlace(preferredName:'Chad'), new LidoPlace(preferredName:'Czech Republic'), new LidoPlace(preferredName:'Venezuela'), new LidoPlace(preferredName:'Vietnam') ]) ], subjects:[''], repository:providerName, useRights:"Die Nutzung setzt eine Zustimmung des AdsD oder des jeweiligen Rechteinhabers voraus", accessRights:'Weitere Informationen finden Sie auf unseren Websites', collItemLanguages:[], europeanaType:'IMAGE', landingPage:new LandingPage(href:lPageURL, localID:this.collectionID)) def String collection = coll.getXML(template, collOaiheader, providerName, coll) return collection } @Override public void run() { def StringTemplateGroup group = new StringTemplateGroup("visualGroup", templatePath, DefaultTemplateLexer.class); def StringTemplate template = group.getInstanceOf("visualTemplate"); def parser = new XmlParser(false, true); def String input; def String collection = generateCollectionRecord(template,'', '') resultsQueue.put(collection); 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 setSpec = oaiHeaderNode.setSpec.text() //def Node fesRoot = xmlRoot.'**'.Fahnen[0]; def NodeList objects = xmlRoot.'**'.Objekt if(objects.size() > 1) println "Found "+objects.size()+" Objekts" objects.each { String lidoObject = utils.transformObjekt(it, template, dateOfCollection, repositoryId, setSpec, collectionID, true) //Hack for resolved XML entities... lidoObject = lidoObject.replace("&", "&") //add the Lido Element generated from the current (it) FaustObjekt resultsQueue.put(lidoObject); c++; // println lidoObject // println "***************" template.reset() } } println c +" lido objects enueued" this.resultsQueue.put("END") println "closedQueue" } @Override public void setResultsQueue(BlockingQueue queue) { this.resultsQueue = queue } @Override public void setInputQueue(BlockingQueue queue) { this.inputQueue = queue } /** * TODO: calling the method from the run() does not work. Kinda groovy strange stuff, I do not know why. */ @Override public void closeResultQueue() { this.resultsQueue.put("END") println "closedQueue" } @Override public void setRepositoryId(String repoId) {this.repositoryId = repoId} }