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 VGAMedia implements RunnableGroovy { def String templatePath = "/var/lib/hope-scripts/templates" def BlockingQueue resultsQueue, inputQueue; def String dataProvider = 'VGA' def String collectionID = 'media' def String repositoryId; def VGAMarcUtils utils = new VGAMarcUtils() @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.collectionID, this.collectionID) resultsQueue.put(marcCollection) def c = 1; while(!((input = this.inputQueue.take()).equals("END"))){ println "processing record" 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 NodeList marcRecords =xmlRoot.'**'.metadata.'*:collection'.'*:record' println "Found "+marcRecords.size()+" marc records" marcRecords.each{ def String marcRecord =utils.transformMarcRecord(it, libraryTemplate, this.dataProvider, this.collectionID, '', repoId, dateOfCollection, this.collectionID) if(marcRecord){ resultsQueue.put(marcRecord); c++; } } } libraryTemplate.reset() println c +" marc records enueued" this.resultsQueue.put("END") println "closedQueue" } def createCollection = { template, dateOfColl, repoId, set, collID -> template.reset() def OAIHeader oaiheader = new OAIHeader(dateOfCollection:dateOfColl, repositoryId:repoId, setSpec:set, identifier:collID, objIdentifier:repoId+"::"+collID) def String theAbstract = ''' The 20th century history is almost completely documented in pictorial sources of high quality and great variety that make the Photo Archives of the AZ represent a cultural heritage of international renown. It was therefore placed under preservation order by the Austrian Archivamt, the authority responsible for the protection of archival materials. From 1997 onwards, when the Photo Archives of the AZ were incorporated into the Labour History Society (VGA), more than 40.000 photographs have been catalogued, and the majority of them digitised in a comprehensive database. In contrast to commercial photo archives and image banks, indexing and description is primarily oriented towards the demands of education and research institutions. This means that additional information is collected regarding the historic events, the persons and sites depicted in the photographs. The Internet platform »Bildarchiv Austria«, established under the aegis of the Austrian National Library (Österreichische Nationalbibliothek), in cooperation with the archives of the Austrian Broadcasting Company (ORF), the Austrian Society of Contemporary History (Österreichische Gesellschaft für Zeitgeschichte) and Photo Archives of the AZ, offers a wide selection of pictorial sources to the general public. ''' def MarcRecord marcCollection = new MarcRecord(descriptionLevel:'collection', repositories:[dataProvider], europeanaType:'IMAGE',language:'deu', accessRights:'free access', useRights:'Restricted use', europeanaRights:'Rights Reserved - Free Access', leader:'', pid:'', aggregator:"HOPE - Heritage of the people's Europe", creationDate:new DateStm(date:'1972', stm:'1972'), accumulationDate:new DateStm(date:'2012', stm:'2012'), isbn_020:'', issn_022:'', localID:collID, providerName:dataProvider, providerLanguage:'deu', bookNo_091:'', extents:[], physDetails:[], dimensions:[],materialDesignations:[], accruals:[], toc:'', theabstracts:[ new LanguagedValue(language:'eng', value:theAbstract) ], genre:'', keywords:[], creatorPersons_100:['Michaela Meier'], creatorCorps_110:[dataProvider], contributorMeetings_711:[], personSubjects_600:[], corporateSubjects_610:[], temporalCoverages_648:['1900 - 2000'], topicSubjects_650:[], spatialCoverages_651:['Österreich'], personContributors:[], corporateContributors:[], creatorMeetings_111:[], titles_245:[ new MarcTitle(main:new MarcTranslatedTitle(original:'AZ-Fotoarchiv Collection')) ], owner:dataProvider, editionStms_250:[]) 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} }