|
| 1 | +module.exports = { |
| 2 | + async up(db, client) { |
| 3 | + await db |
| 4 | + .collection("PublishedData") |
| 5 | + .find({}) |
| 6 | + .forEach(async (publishedData) => { |
| 7 | + const pid = publishedData._id; |
| 8 | + const metadata = { |
| 9 | + affiliation: publishedData.affiliation, |
| 10 | + downloadLink: publishedData.downloadLink, |
| 11 | + scicatUser: publishedData.scicatUser, |
| 12 | + thumbnail: publishedData.thumbnail, |
| 13 | + url: publishedData.url, |
| 14 | + creators: publishedData.creator.map((creator) => ({ |
| 15 | + name: creator.trim(), |
| 16 | + affiliation: [{ name: publishedData.affiliation?.trim() || "" }], |
| 17 | + })), |
| 18 | + publisher: { |
| 19 | + name: publishedData.publisher.trim(), |
| 20 | + }, |
| 21 | + publicationYear: publishedData.publicationYear, |
| 22 | + dataDescription: publishedData.dataDescription, |
| 23 | + resourceType: publishedData.resourceType, |
| 24 | + contributors: |
| 25 | + publishedData.authors?.map((author) => ({ |
| 26 | + name: author.trim(), |
| 27 | + })) || [], |
| 28 | + relatedIdentifiers: |
| 29 | + publishedData.relatedPublications?.map((relatedPublication) => ({ |
| 30 | + relatedIdentifier: relatedPublication, |
| 31 | + })) || [], |
| 32 | + }; |
| 33 | + const datasetPids = publishedData.pidArray; |
| 34 | + const status = |
| 35 | + publishedData.status === "registered" ? "registered" : "private"; |
| 36 | + |
| 37 | + console.log(`Updating PublishedData (Id: ${pid})`); |
| 38 | + await db.collection("PublishedData").updateOne( |
| 39 | + { _id: pid }, |
| 40 | + { |
| 41 | + $set: { |
| 42 | + pid, |
| 43 | + metadata, |
| 44 | + datasetPids, |
| 45 | + status, |
| 46 | + }, |
| 47 | + $unset: { |
| 48 | + affiliation: true, |
| 49 | + downloadLink: true, |
| 50 | + scicatUser: true, |
| 51 | + authors: true, |
| 52 | + pidArray: true, |
| 53 | + creator: true, |
| 54 | + publisher: true, |
| 55 | + publicationYear: true, |
| 56 | + dataDescription: true, |
| 57 | + relatedPublications: true, |
| 58 | + resourceType: true, |
| 59 | + thumbnail: true, |
| 60 | + url: true, |
| 61 | + }, |
| 62 | + }, |
| 63 | + ); |
| 64 | + }); |
| 65 | + }, |
| 66 | + async down(db, client) { |
| 67 | + await db |
| 68 | + .collection("PublishedData") |
| 69 | + .find({}) |
| 70 | + .forEach(async (publishedData) => { |
| 71 | + console.log(`Updating PublishedData (Id: ${publishedData._id})`); |
| 72 | + await db.collection("PublishedData").updateOne( |
| 73 | + { _id: publishedData._id }, |
| 74 | + { |
| 75 | + $set: { |
| 76 | + affiliation: publishedData.metadata.affiliation, |
| 77 | + downloadLink: publishedData.metadata.downloadLink, |
| 78 | + scicatUser: publishedData.metadata.scicatUser, |
| 79 | + thumbnail: publishedData.metadata.thumbnail, |
| 80 | + url: publishedData.metadata.url, |
| 81 | + creator: publishedData.metadata.creators.map( |
| 82 | + (creator) => creator.name, |
| 83 | + ), |
| 84 | + publisher: publishedData.metadata.publisher.name, |
| 85 | + publicationYear: publishedData.metadata.publicationYear, |
| 86 | + dataDescription: publishedData.metadata.dataDescription, |
| 87 | + resourceType: publishedData.metadata.resourceType, |
| 88 | + authors: publishedData.metadata.contributors?.map( |
| 89 | + (contributor) => contributor.name, |
| 90 | + ), |
| 91 | + relatedPublications: |
| 92 | + publishedData.metadata.relatedIdentifiers?.map( |
| 93 | + (relatedIdentifier) => relatedIdentifier.relatedIdentifier, |
| 94 | + ), |
| 95 | + pidArray: publishedData.datasetPids, |
| 96 | + status: |
| 97 | + publishedData.status === "registered" |
| 98 | + ? "registered" |
| 99 | + : "pending_registration", |
| 100 | + }, |
| 101 | + $unset: { metadata: true, datasetPids: true, pid: true }, |
| 102 | + }, |
| 103 | + ); |
| 104 | + }); |
| 105 | + }, |
| 106 | +}; |
0 commit comments