Skip to content

Commit b189fb1

Browse files
committed
feat: add --syllabus flag to collect.js, document
ref #115
1 parent 052b8bc commit b189fb1

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

collection-export/collect.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import rc from 'rc'
88
import xpath from 'xpath'
99
import { DOMParser as xmldom } from '@xmldom/xmldom'
1010

11-
import { toStrictMODS } from './strict-mods.js'
11+
import {toStrictMODS} from './strict-mods.js'
12+
import {convertSyllabusXMLtoMODS} from './syllabus.js'
1213

1314
const defaults = {
1415
// obviously need attachment & metadata info
@@ -17,6 +18,7 @@ const defaults = {
1718
info: 'attachment,basic,detail,metadata',
1819
limit: Infinity,
1920
mods: true,
21+
syllabus: false,
2022
}
2123
const options = rc('app', defaults)
2224
const UUIDRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/
@@ -29,6 +31,7 @@ if (options.help || options.h || (options._.length && options._[0].match(/^help$
2931
console.log(' --item <UUID> UUID of single item to export')
3032
console.log(' --name Use item name for export folders instead of UUID')
3133
console.log(' --no-mods Do not write strict MODS XML for each item')
34+
console.log(' --syllabus Convert courseInfo syllabus metadata to MODS')
3235
console.log(' --verbose Print debug info')
3336
console.log('\nYou can also specify any valid EQUELLA search parameters such as "--status DRAFT,ARCHIVE" or "--modifiedBefore 2020-01-01".\nSee https://vault.cca.edu/apidocs.do#operations-tag-Searching')
3437
process.exit(0)
@@ -188,8 +191,19 @@ function getAttachments(item, itemDir) {
188191
function writeXML(item, dir) {
189192
debug(`Writing XML metadata for item ${item.links.view}`)
190193
fs.writeFile(path.join(dir, 'metadata', 'metadata.xml'), item.metadata, handleErr)
194+
if (options.syllabus) {
195+
const syllabusMods = convertSyllabusXMLtoMODS(item.metadata) // returns Document not string
196+
if (!syllabusMods) {
197+
return console.error(`Error: unable to convert courseInfo syllabus metadata to MODS for item ${item.links.view}`)
198+
}
199+
// do not write other MODS if --syllabus is specified, since it's a strict MODS document
200+
return fs.writeFile(path.join(dir, 'metadata', 'metadata.mods.xml'), syllabusMods.toString(), handleErr)
201+
}
191202
if (options.mods) {
192203
const strictMods = toStrictMODS(item.metadata)
204+
if (!strictMods) {
205+
return console.error(`Error: unable to convert metadata to strict MODS for item ${item.links.view}`)
206+
}
193207
fs.writeFile(path.join(dir, 'metadata', 'metadata.mods.xml'), strictMods, handleErr)
194208
}
195209
}

collection-export/readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Options:
2323
--item <UUID> UUID of single item to export
2424
--name Use item name for export folders instead of UUID
2525
--no-mods Do not write strict MODS XML for each item
26+
--syllabus Convert courseInfo syllabus metadata to MODS
2627
--verbose Print debug info
2728

2829
You can also specify any valid EQUELLA search parameters such as "--status DRAFT,ARCHIVE" or "--modifiedBefore 2020-01-01".
@@ -36,6 +37,8 @@ node collect --collection $UUID --status DRAFT,ARCHIVE --modifiedBefore 2020-01-
3637
node collect --collection $UUID --name
3738
# sub-collection of Libraries, note --where needs fully-specified /xml/... path
3839
node collect --collection 6b755832-4070-73d2-77b3-3febcc1f5fad --where "/xml/mods/relatedItem/title = 'Robert Sommer Mudflats Collection'"
40+
# download syllabi & convert their metadata to MODS
41+
node collect --collection (eq coll --name "Syllabus Collection" | jq -r .uuid) --syllabus
3942
```
4043

4144
By default item folders are named after UUID and then version. The `--name` flag makes the folder's the item's title, but titles can be duplicative or absent. An integer is append to the folder name if it would collide with an existing folder.
@@ -100,11 +103,11 @@ node test-collection-samples.js data/mudflats.json 10
100103
101104
The `test-collection-samples.js` script tests random samples of XML metadata from exported EQUELLA JSON files against the strict-mods library to verify conversions work correctly. We can also download item XML to run the strict MODS conversion on our own.
102105
103-
## Syllabus Conversion
106+
## Syllabus Metadata Conversion
104107
105-
The syllabus.js file converts XML metadata from CCA's "courseInfo" schema to standards-compliant MODS. It can be used as a library or passed a single XML file on the command line; it will print the converted MODS to stdout.
108+
The syllabus.js file converts XML metadata from CCA's "courseInfo" schema to standards-compliant MODS. It can be used as a library or passed a single XML file on the command line; it will print the converted MODS to stdout. `npm run sylxmltest` runs the test suite.
106109
107-
TODO: add `--syllabus` flag to collect.js to convert syllabus XML to MODS.
110+
Running `node collect` with the `--syllabus` flag will automatically convert syllabus XML to MODS for any items in the collection that have a syllabus attachment.
108111
109112
### Converting & Validating MODS Files
110113

0 commit comments

Comments
 (0)