IMPORT_DATE = new Date().parse('yyyy-MM-dd', '2018-06-05')


boolean shouldSetFullLevel (record) {
    createdDate = new Date().parse('yyyy-MM-dd', record.created)

    if (createdDate.before(IMPORT_DATE))
        return true
    else if (record.technicalNote?.find { it['label']?.contains('Imported from')})
        return true
}

selectByCollection('bib') { data ->
    // guard against missing entity
    if (data.graph.size() < 2) {
        return
    }

    if (data.graph[1].containsKey('instanceOf')) {
        def (record, instance, work) = data.graph

        if (!record) return

        // If encodingLevel already exists, don't do anything
        if (record.encodingLevel) return

        if (shouldSetFullLevel(record)) {
            record.put('encodingLevel', 'marc:FullLevel')
            data.scheduleSave()
        } else {
            println("${data.graph[0][ID]} Record does not match conditions. Will not update.")
        }
    }
}

Add script to add encodingLevel: marc:FullLevel, where it is missing
Add script to add encodingLevel: marc:FullLevel, where it is missing

This global update of records is needed due to a incorrect
mapping, at the time of LibrisXL was released. All records that were
cataloged as marc:FullLevel, did not get any encodingLevel at all.

To correct this, the script adds encodingLvel: marc:FullLevel to all
records that:
* were created before LibrisXL was released
* are imported FullLevel records (specified in technicalNote)

NB. This script only takes care of FullLevel records.
Another script is needed to handle the remaining records with
missing encodingLevel.
