import org.antlr.stringtemplate.StringTemplate import eu.dnetlib.hope.domains.common.* import eu.dnetlib.hope.domains.library.* class FESLibraryUtils { def boolean isDigital = true def escapeXml = {String s -> if(s) return s.replaceAll("&", "&").replaceAll(">", ">").replaceAll("<", "<") else return '' } def String transformRecord(Node theRecord, StringTemplate template, String repoId, String dateOfColl){ template.reset() //identifiers def String objPID = theRecord.'oai_hope:resourceIdentifier'.'dc:identifier'.text() def String objLID = theRecord.'oai_hope:resourceIdentifier'.'oai_hope:localIdentifier'.text() def String repoObjId = (repoId+"::"+objPID) //oai header def OAIHeader oaiheader = new OAIHeader(dateOfCollection:dateOfColl, repositoryId:repoId, identifier:objPID, objIdentifier:repoObjId, nonDigitalCollection:!isDigital) def String issn = theRecord.'oai_hope:resourceIdentifier'.'oai_hope:ISSN'?.text() def String isbn = theRecord.'oai_hope:resourceIdentifier'.'oai_hope:ISBN'?.text() def String bookNo = objLID def LandingPage landingpage = new LandingPage(localID:theRecord.'oai_hope:landingPage'?.'europeana:isShownAt'?.text(), href: theRecord.'oai_hope:landingPage'?.'dc:identifier'?.text()) //String proper, parallel, responsibility, materialDesignation //MarcTranslatedTitle main, subtitle def MarcTitle marcTitle = new MarcTitle(proper:escapeXml(theRecord.'oai_hope:titleProper'?.'dc:title'?.text()), parallel:escapeXml(theRecord.'oai_hope:parallelTitle'?.'dc:title'?.text()), responsibility:theRecord.'oai_hope:statementOfResponsibility'?.'oai_hope:titleStatement'?.text(), materialDesignation:theRecord.'oai_hope:generalMaterialDesignation'?.'oai_hope:materialDesigantion'?.text(), main:new MarcTranslatedTitle(original:escapeXml(theRecord.'oai_hope:titleProper'?.'oai_hope:generalTitle'?.text()), translation:escapeXml(theRecord.'oai_hope:parallelTitle'?.'oai_hope:translatedTitle'?.text())), subtitle:new MarcTranslatedTitle(original:escapeXml(theRecord.'oai_hope:otherTitleInformation'?.'dc:title'?.text()), translation:escapeXml(theRecord.'oai_hope:otherTitleInformation'?.'oai_hope:translatedSubtitle'?.text())) ) def publicationNode = theRecord.'oai_hope:publication' def productionNode = theRecord.'oai_hope:production' def MarcPublication marcPublication= new MarcPublication(placeOfPublication:publicationNode?.'dc:subject'?.text(), publisher: publicationNode?.'dc:publisher'?.text(), dateOfPublication:publicationNode?.'dc:date'?.text(), frequency:theRecord.'oai_hope:physicalDescription'?.'oai_hope:publicationFrequency'?.text(), dateOfPrinting:productionNode?.'dc:date'?.text(), placeOfPrinting:productionNode?.'dc:subject'?.text(), productor:productionNode?.'oai_hope:producer'?.text() ) def String descrLevel = theRecord.'oai_hope:levelOfDescription'?.'oai_hope:descriptionLevel'?.text() def String edmType = theRecord.'oai_hope:administrativeMetadata'?.'europeana:type'?.text() def String edmRights = theRecord.'oai_hope:administrativeMetadata'?.'europeana:rights'?.text() def MarcRecord marcRecord = new MarcRecord(leader:'NA',pid:objPID, aggregator:theRecord.'oai_hope:provider'?.'europeana:provider'?.text(), descriptionLevel:descrLevel, localID:objPID, issn_022:issn, isbn_020:isbn, landingPage:landingpage, providerName:theRecord.'oai_hope:provider'.'europeana:dataProvider'.text(), providerLanguage:theRecord.'oai_hope:provider'.'dc:language'.text(), bookNo_091:bookNo, extents:theRecord.'oai_hope:physicalDescription'.'oai_hope:extent'*.text().collect{return new LanguagedValue(value:it)}, physDetails:theRecord.'oai_hope:physicalDescription'.'oai_hope:physicalDetails'*.text().collect{return new LanguagedValue(value:it)}, dimensions:theRecord.'oai_hope:physicalDescription'.'dcterms:extent'*.text().collect{return new LanguagedValue(value:it)}, materialDesignations:theRecord.'oai_hope:physicalDescription'.'oai_hope:contentTypeTerm'*.text().collect{return new LanguagedValue(value:it)}, toc:theRecord.'oai_hope:subject'?.'dcterms:tableOfContents'?.text(), theabstracts:theRecord.'oai_hope:subject'*.'oai_hope:abstract'*.text().collect{return new LanguagedValue(value:it)}, genre:theRecord.'oai_hope:subject'?.'oai_hope:subjectGenre'?.text(), keywords:theRecord.'oai_hope:subject'?.'dc:subject'*.text().collect{return new LanguagedValue(value:it)}, topicSubjects_650:theRecord.'oai_hope:subject'?.'oai_hope:subjectTopic'*.text(), creatorPersons_100:theRecord.'oai_hope:person'?.'dc:creator'*.text(), creatorCorps_110:theRecord.'oai_hope:corporate'?.'dc:creator'*.text(), personContributors:theRecord.'oai_hope:person'?.'dc:contributor'*.text(), corporateContributors:theRecord.'oai_hope:corporate'?.'dc:contributor'*.text(), creatorMeetings_111:theRecord.'oai_hope:meeting'.collect{new MarcMeeting(name:it?.'oai_hope:meetingName'?.text(), location:it?.'dc:subject'?.text(), date:it?.'dc:date'?.text())}, contributorMeetings_711:theRecord.'oai_hope:meeting'?.'oai_hope:meetingNameAdded'*.text(), personSubjects_600:theRecord.'oai_hope:subject'?.'oai_hope:subjectPerson'*.text(), corporateSubjects_610:theRecord.'oai_hope:subject'?.'oai_hope:subjectCorporate'*.text(), temporalCoverages_648:theRecord.'oai_hope:subject'?.'dcterms:temporal'*.text(), spatialCoverages_651:theRecord.'oai_hope:subject'?.'dcterms:spatial'*.text(), //theRecord.'oai_hope:meeting'?.'oai_hope:meetingName'*.text()[new MarcMeeting(name:, location:, date:) ] titles_245:[marcTitle], editionStms_250:[ new MarcEditionStm(main:theRecord.'oai_hope:edition'?.'oai_hope:editionStatement'?.text(), parallel:theRecord.'oai_hope:edition'?.'oai_hope:parallelEditionStatement'?.text(), responsibility:theRecord.'oai_hope:edition'?.'oai_hope:statementOfResponsibility'?.text()) ], publication:marcPublication, europeanaType:edmType, europeanaRights:edmRights, languages_041:[ theRecord.'oai_hope:administrativeMetadata'?.'dc:language'?.text() ]) def Node nextRecord = theRecord.'oai_hope:sequence'[0] def Node parentRecord = theRecord.'oai_hope:parentRecord'[0] marcRecord.setParentRecord(new MarcRelative(localID:escapeXml(parentRecord?.'oai_hope:localIdentifier'?.text()), pid:escapeXml(parentRecord?.'dc:identifier'?.text()))) marcRecord.setNextRecord(new MarcRelative(localID:escapeXml(nextRecord?.'oai_hope:localIdentifier'?.text()), pid:escapeXml(nextRecord?.'dc:identifier'?.text()))) if(isDigital){ def String resourcePID = theRecord.'oai_hope:digitalRepresentation'?.'dc:identifier'?.text() def derivative2Node = theRecord.'oai_hope:derivate2'[0] def derivative3Node = theRecord.'oai_hope:derivate3'[0] def transNode = theRecord.'oai_hope:transcription'[0] if(resourcePID){ def nextRes = derivative2Node.'oai_hope:nextIdentifier'?.text() def List derivativeList def String der2Pid = derivative2Node.'dc:identifier'.text() def String der2URL = derivative2Node.'europeana:isShownBy'.text() def String der2Id = derivative2Node.'oai_hope:localIdentifier'.text() def String der3Pid = derivative3Node.'dc:identifier'.text() def String der3URL = derivative3Node.'europeana:object'.text() def String der3Id = derivative3Node.'oai_hope:localIdentifier'.text() def String transPid = transNode?.'dc:identifier'?.text() def String transURL = transNode?.'oai_hope:url'?.text() def String transId = transNode?.'oai_hope:localIdentifier'?.text() def Derivative der2 = new Derivative(pid:der2Pid, href:der2URL, localID:der2Id, type:'derivative2') def Derivative der3 = new Derivative(pid:der3Pid, href:der3URL, localID:der3Id, type:'derivative3') def Derivative trans = new Derivative(pid:transPid, href:transURL, localID:transId, type:'transcription') def MarcResource resource = new MarcResource(pid:resourcePID, id:resourcePID, nextResource: new MarcRelative(localID:nextRes, pid:nextRes), type:edmType, rights:edmRights, languages:theRecord.'oai_hope:administrativeMetadata'?.'dc:language'*.text(), derivatives:[der2, der3, trans], transcriptions_591:theRecord.'oai_hope:transcription'?.'europeana:unstored'*.text()) template.setAttribute("resources", [resource]) } else { template.setAttribute("resources", []) println "No resource PID --> no digital resource associated to "+objPID } } template.setAttribute("oaiheader", oaiheader) template.setAttribute("marc", marcRecord) return template.toString(); } }