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 /** * DNetGroovy class for TA. * @author alessia * */ class TADefaultLIDO implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def TALidoUtils utils = new TALidoUtils() def BlockingQueue resultsQueue, inputQueue; def String repositoryId; def String collectionID = "TA1" /** * Driver namespace for elements in the OAI header. */ def dri = new groovy.xml.Namespace("http://www.driver-repository.eu/namespace/dri", 'dri') def lido = new groovy.xml.Namespace("http://www.lido-schema.org", 'lido') def oai = new groovy.xml.Namespace("http://www.openarchives.org/OAI/2.0/", 'oai') def generateCollectionRecord = { template, repoId, setSpec, dateOfCollection -> def String lPageURL = "" def String providerName = "Työväen Arkisto" def String abstractSum=" Photographs and posters of the Finnish Labour movement's activities in Finland" def OAIHeader collOaiheader = new OAIHeader(dateOfCollection:dateOfCollection, repositoryId:repoId, setSpec:setSpec, identifier:collectionID, objIdentifier:repoId+'::'+collectionID) def LIDOCollection coll = new LIDOCollection(collectionID:collectionID, langCode:'fin', titles:[ new LidoTitle(value:"Valokuvat ja julisteet") ], abstractSummaries:[ new LidoDescription(type:'abstract', value:abstractSum) ], collItemLanguages:['fin'], creationDates:['1880-2010'], accumulationDates:['1909-2010'], owners:[providerName], sizeItems:'28768', itemType:'IMAGE', itemFormatStm:'', itemFormats:[], associatedPub:'', subjects:['Labour movement'], repository:"Työväen Arkisto / Akseli -konsortio", typedSubjects:[ new TypedSubjects(type:'association', dates:['1880-2010'], places:[ new LidoPlace(preferredName:'Finland') ]) ], useRights:'Public Domain',accessRights:'No restrictions', europeanaRights:'http://www.europeana.eu/rights/rr-f/', europeanaType:'IMAGE', landingPage:new LandingPage(href:lPageURL, localID:lPageURL)) 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; String collectionRecord = this.generateCollectionRecord(template, repositoryId, '', '') resultsQueue.put(collectionRecord); def c = 0; while(!((input = this.inputQueue.take()).equals("END"))){ template.reset() def Node xmlRoot = parser.parseText(input) //println xmlRoot.name() //xmlRoot.children().each{println it.name()} def Node oaiHeaderNode = xmlRoot.'**'[oai.header][0] if(oaiHeaderNode == null){ oaiHeaderNode = xmlRoot.'**'.header[0] if(oaiHeaderNode == null) println "e' null anche senza ns per "+xmlRoot.'**'.identifier.text() //println xmlRoot.'**'.identifier //println xmlRoot.name() //xmlRoot.children().each{println it.name()} } else{ println "got header with ns for record "+xmlRoot.'**'.identifier.text() } //Common OAI Header elements def dateOfCollection = oaiHeaderNode.'dri:dateOfCollection'.text() def repoId = oaiHeaderNode.'dri:repositoryId'.text() def setSpec = oaiHeaderNode.setSpec.text() def Node lidoNode = xmlRoot.'**'.'lido:lido'[0] String lidoObject = utils.transformSozObjekt(lidoNode, template, dateOfCollection, repoId, setSpec, collectionID) resultsQueue.put(lidoObject); c++ 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" } /** * {@inheritDoc} * @see eu.dnetlib.enabling.manager.msro.hope.groovy.RunnableGroovy#setRepositoryId(java.lang.String) */ @Override public void setRepositoryId(String repoId) { this.repositoryId = repoId; } }