import java.util.concurrent.BlockingQueue import org.antlr.stringtemplate.StringTemplate import org.antlr.stringtemplate.StringTemplateGroup import org.antlr.stringtemplate.language.DefaultTemplateLexer import org.apache.commons.lang.StringEscapeUtils import eu.dnetlib.enabling.manager.msro.hope.groovy.RunnableGroovy import eu.dnetlib.hope.domains.common.Derivative 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.LidoResourceWrap import eu.dnetlib.hope.domains.visual.LidoTitle import eu.dnetlib.hope.domains.visual.TypedSubjects /** * DNetGroovy class for SSA F1015: Records come with no derivative2 and 3 (for now, becasue the SOR does not produce them yet). * @author alessia * */ class SozArchLIDO1015 implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def SozArchUtils utils = new SozArchUtils() def BlockingQueue resultsQueue, inputQueue; def String collectionID = 'F_1015' /** * Driver namespace for elements in the OAI header. */ def dri = new groovy.xml.Namespace("http://www.driver-repository.eu/namespace/dri", 'dri') def generateCollectionRecord = { template, repoId, setSpec, dateOfCollection -> def String lPageURL = "http://www.bild-video-ton.ch/archiv/images?Bilder.ssaBestand=F_1015 Gewerkschaft Bau und Industrie (GBI) - Syndicat industrie et bâtiment (SIB) - Sindacato dell'edilizia e dell'industria (SEI)" def String providerName = 'Schweizerisches Sozialarchiv' def String abstractSum="Vom Gesamtbestand der Tonaufnahmen der GBI wurde diejenigen Tonaufnahmen digitalisiert, für die es keine schriftliche Parallelüberlieferung gibt. Unter anderem sind die Trauerfeier von Ezio Cannonica erhalten oder die Aufnahmen einer Weiterbildung für italienischsprechende Gewerkschaftsfunkionäre." def OAIHeader collOaiheader = new OAIHeader(dateOfCollection:dateOfCollection, repositoryId:repoId, setSpec:setSpec, identifier:collectionID, objIdentifier:repoId+"::"+collectionID) def LIDOCollection coll1015 = new LIDOCollection(collectionID:collectionID, langCode:'ger', titles:[ new LidoTitle(value:"Gewerkschaft Bau und Industrie (GBI) - Syndicat industrie et bâtiment (SIB) - Sindacato dell'edilizia e dell'industria (SEI)") ], abstractSummaries:[ new LidoDescription(type:'abstract', value:abstractSum) ], collItemLanguages:['ger', 'gsw', 'ita'], creationDates:['1955P20Y'], accumulationDates:['2005'], owners:[providerName], sizeItems:'10', itemType:'SOUND', itemFormatStm:'', itemFormats:[ 'Tonbänder openreel', 'Vinyl-Schallplatten' ], associatedPub:'http://findmittel.ch/archive/archNeu/ArGBI.html', typedSubjects:[ new TypedSubjects(type:'association', dates:['1962-1978'], places:[ new LidoPlace(preferredName:'CH') ]) ], subjects:['Gewerkschaften'], repository:providerName, useRights:"Jede Art der Verwendung und der Reproduktion setzt eine Bewilligung und einen vereinbarten Zweck voraus. Jede weitere Nutzung bedarf der erneuten Zustimmung des Schweizerischen Sozialarchivs oder des jeweiligen Rechteinhabers.", accessRights:'Auf den Bestand oder auf Teile davon gewährt das Schweizerische Sozialarchiv öffentlichen, kostenlosen Zugang. Weitere Bestimmungen finden Sie auf unseren Websites.', europeanaType:'SOUND', landingPage:new LandingPage(href:lPageURL, localID:lPageURL)) def String collection1015 = coll1015.getXML(template, collOaiheader, providerName, coll1015) return collection1015 } @Override public void run() { def StringTemplateGroup group = new StringTemplateGroup("visualGroup", templatePath, DefaultTemplateLexer.class); def StringTemplate template = group.getInstanceOf("visualTemplate"); //iterates on the input xml to generate records contained by the collection created above def parser = new XmlParser(false, true); def String input; def c = 0; while(!((input = this.inputQueue.take()).equals("END"))){ template.reset() def Node xmlRoot = parser.parseText(input) def Node oaiHeaderNode = xmlRoot.'**'.header[0] //Common OAI Header elements def dateOfCollection = oaiHeaderNode.'dri:dateOfCollection'.text() def repoId = oaiHeaderNode.'dri:repositoryId'.text() def setSpec = oaiHeaderNode.setSpec.text() //create collection from constants values from the mapping if(c == 0){ def String collection1015 = generateCollectionRecord(template, repoId, setSpec, dateOfCollection) resultsQueue.put(collection1015); c++ } def Node sozRoot = xmlRoot.'**'.ImagicXML[0] def NodeList sozObjects = sozRoot.Update.Row println "Found "+sozObjects.size()+" rows" sozObjects.each { String lidoObject = utils.transformSozObjekt(it, template, dateOfCollection, repoId, setSpec, collectionID, generateDigitalResources) resultsQueue.put(lidoObject); c++ template.reset() } } println c +" lido objects enueued" this.resultsQueue.put("END") println "closedQueue" } /** * Generate digital resources, if needed. It returns an object of class LidoResourceWrap. * The returned object is never null, but all properties can be empty. */ def generateDigitalResources = {Node sozObjekt -> def String resourcePid = 'http://hdl.handle.net/'+sozObjekt.Field.find{it.'@Name'.equals('tk_pid')}.'@Value' def String europeanaType = sozObjekt.Field.find{it.'@Name'.equals('dcTY_typ')}?.'@Value' def String rights = sozObjekt.Field.find{it.'@Name'.equals('ssaRechte')}?.'@Value' def String trans = '' //set resourcePid to null, so we do not generate digital resources for closed objects if(rights.equals("kein Onlinezugriff auf Ressource!") || rights.equals("kein Online-Zugriff auf Ressource!")){ resourcePid = '' } if(europeanaType.equals('SOUND') || europeanaType.equals('VIDEO')) trans = StringEscapeUtils.escapeXml(utils.recodeLineBreaks(sozObjekt.Field.find{it.'@Name'.equals('dcBE_besch')}?.'@Value')) def ders = [ new Derivative(pid:resourcePid+'?locatt=view:level1', type:'derivative2'), //new Derivative(pid:resourcePid+'?locatt=view:level3', type:'derivative3') ] def LidoResourceWrap resWrap = new LidoResourceWrap(localID:resourcePid, pid:resourcePid, europeanaType:sozObjekt.Field.find{it.'@Name'.equals('dcTY_typ')}?.'@Value', languages:sozObjekt.Field.findAll{it.'@Name'.equals('dcLA_spra')}*.'@Value', creditLine:rights,transcription:trans, derivatives:ders) return resWrap; } @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" } /** * TODO: use this to set the repoId of the collection instead of the current trick * {@inheritDoc} * @see eu.dnetlib.enabling.manager.msro.hope.groovy.RunnableGroovy#setRepositoryId(java.lang.String) */ @Override public void setRepositoryId(String repoId) {} }