diff --git a/src/scripts/repair_adisp_oai-pmh_ddis.ts b/src/scripts/repair_adisp_oai-pmh_ddis.ts index c8795f4ceda6f076493048b2f3da88fca13d942d..8d5ea9334490f3ce3f05be4a6548b293b729c7f7 100644 --- a/src/scripts/repair_adisp_oai-pmh_ddis.ts +++ b/src/scripts/repair_adisp_oai-pmh_ddis.ts @@ -125,19 +125,49 @@ async function main() { `, - ``, + ``, ) const xmlParsed = new DOMParser().parseFromString( xmlRepaired, "application/xml", ) - const title = xmlParsed - .getElementsByTagName("docDscr")[0] + + const IDNoTag = xmlParsed + .getElementsByTagName("stdyDscr")[0] ?.getElementsByTagName("citation")[0] ?.getElementsByTagName("titlStmt")[0] - ?.getElementsByTagName("titl")[0] - ?.firstChild?.nodeValue?.trim() + ?.getElementsByTagName("IDNo")[0] + + const IDNoTxt = IDNoTag!.textContent!.trim() + + IDNoTag!.setAttribute("agency", "DOI") + IDNoTag!.textContent = "doi:10.13144/"+IDNoTxt + + + const holdingsTag = xmlParsed + .getElementsByTagName("docDscr")[0] + ?.getElementsByTagName("citation")[0] + ?.getElementsByTagName("holdings")[0] + + if (holdingsTag != null) { + const stdyCitationTag = xmlParsed + .getElementsByTagName("stdyDscr")[0] + ?.getElementsByTagName("citation")[0] + + const newHoldingsTag = holdingsTag!.cloneNode() + stdyCitationTag?.appendChild(newHoldingsTag) + } else if (!options.silent) { + console.warn(`No tag found in ${filename}`) + } + + + const title = xmlParsed + .getElementsByTagName("docDscr")[0] + ?.getElementsByTagName("citation")[0] + ?.getElementsByTagName("titlStmt")[0] + ?.getElementsByTagName("titl")[0] + ?.textContent?.trim() const titleLastDate = title ? /\d{4}(?!.*\d{4})/.exec(title)?.[0] : null if (titleLastDate != null) { @@ -155,12 +185,13 @@ async function main() { prodDate.setAttribute("date", titleLastDate) prodDate.textContent = titleLastDate - const xmlSerializer = new XMLSerializer() - xmlRepaired = xmlSerializer.serializeToString(xmlParsed) } else if (!options.silent) { console.warn(`No date found in title of ${filename}: ${title}`) } + const xmlSerializer = new XMLSerializer() + xmlRepaired = xmlSerializer.serializeToString(xmlParsed) + if (xmlRepaired !== xml && !options.silent) { console.log(`Repaired ${filename}.`) }