imports/vx/server/daemon/recordimporter.js
/**
     * Transform a generic row from the CSV into an object in the
     * insertArray suitable for calling batch insert.
     *
     * @param {object} uploadStats Upload stats object.
     * @param {object} uploadTypeObject Upload type object from codes.
     * @param {array} headerArray Array of column headers (top row).
     * @param {number} commandColumnIndex Index of command column.
     * @param {array} row Row being processed.
     * @param {number} index Absolute index (in collection) of record to be created.
     * @param {number} rowIndex Index of row in spreadsheet (first data records is 1).
     * @param {array} messages Array of validation messages (mutated in place).
     * @param {array} insertArray Array of records to be inserted (mutated in place).
     */
Transform a generic row from the CSV into an object in the
insertArray suitable for calling batch insert.

@param {object} uploadStats Upload stats object.
@param {object} uploadTypeObject Upload type object from codes.
@param {array} headerArray Array of column headers (top row).
@param {number} commandColumnIndex Index of command column.
@param {array} row Row being processed.
@param {number} index Absolute index (in collection) of record to be created.
@param {number} rowIndex Index of row in spreadsheet (first data records is 1).
@param {array} messages Array of validation messages (mutated in place).
@param {array} insertArray Array of records to be inserted (mutated in place).
Transform a generic row from the CSV into an object in the insertArray suitable for calling batch insert . @param { object } uploadStats Upload stats object . @param { object } uploadTypeObject Upload type object from codes . @param { array } headerArray Array of column headers ( top row ) . @param { number } commandColumnIndex Index of command column . @param { array } row Row being processed . @param { number } index Absolute index ( in collection ) of record to be created . @param { number } rowIndex Index of row in spreadsheet ( first data records is 1 ) . @param { array } messages Array of validation messages ( mutated in place ) . @param { array } insertArray Array of records to be inserted ( mutated in place ) .
prepareGeneric(uploadStats, uploadTypeObject, headerArray, commandColumnIndex,
        row, index, rowIndex, messages, insertArray) {
        const fieldIdKey = "common.field_id_path_specification"
        const importSchema = ImportSchemas[uploadStats.uploadType]
        const keypathIndex = headerArray.indexOf(uploadTypeObject.keypath)
        const command = row[commandColumnIndex]
        const valid = VXApp.validateCommand(command, index, messages, fieldIdKey, { rowIndex: rowIndex,  path: "command" })
        if (!valid) {
            OLog.debug(`recordimporter.js prepareGeneric *bypassing* index=${index} invalid command=${command}`)
            return
        }
        const value = FX.trim.strip(row[keypathIndex])
        const results = {}
        results.selector = {}
        results.selector.domain = uploadStats.domain
        results.selector[uploadTypeObject.keypath] = value
        if (command === "create") {
            results.record = {}
            results.record.dateCreated = new Date()
            results.record.userCreated = uploadStats.userId
            results.record.domain = uploadStats.domain
            RecordImporter.processRow(uploadStats, importSchema, headerArray, row, index, rowIndex,
                messages, fieldIdKey, results, insertArray)
            return
        }
        if (command === "update") {
            const coll = Util.getCollection(uploadTypeObject.collection)
            results.record = coll.findOne(results.selector)
            if (!results.record) {
                VXApp.validateRecordNotFound(index, messages, "common.field_id_path_specification",
                    { rowIndex: rowIndex,  path: uploadTypeObject.keypath }, value)
                return
            }
            RecordImporter.processRow(uploadStats, importSchema, headerArray, row, index, rowIndex,
                messages, fieldIdKey, results, insertArray)
            return
        }
        if (command === "retire") {
            const coll = Util.getCollection(uploadTypeObject.collection)
            results.record = coll.findOne(results.selector)
            if (!results.record) {
                VXApp.validateRecordNotFound(index, messages, "common.field_id_path_specification",
                    { rowIndex: rowIndex,  path: uploadTypeObject.keypath })
                return
            }
            const modifier = {}
            modifier.$set = {}
            modifier.$set.dateRetired = new Date()
            modifier.$set.userRetired = uploadStats.userId
            coll.direct.update(results.record._id, modifier)
            OLog.debug(`recordimporter.js prepareGeneric index=${index} ` +
                `collection=${uploadTypeObject.collection} recordId=${results.record._id} *retired*`)
            return
        }
    }
prepareGeneric ( uploadStats , uploadTypeObject , headerArray , commandColumnIndex , row , index , rowIndex , messages , insertArray ) { const fieldIdKey = "common.field_id_path_specification" const importSchema = ImportSchemas [ uploadStats . uploadType ] const keypathIndex = headerArray . indexOf ( uploadTypeObject . keypath ) const command = row [ commandColumnIndex ] const valid = VXApp . validateCommand ( command , index , messages , fieldIdKey , { rowIndex : rowIndex , path : "command" } ) if ( ! valid ) { OLog . debug ( ` ${ index } ${ command } ` ) return } const value = FX . trim . strip ( row [ keypathIndex ] ) const results = { } results . selector = { } results . selector . domain = uploadStats . domain results . selector [ uploadTypeObject . keypath ] = value if ( command === "create" ) { results . record = { } results . record . dateCreated = new Date ( ) results . record . userCreated = uploadStats . userId results . record . domain = uploadStats . domain RecordImporter . processRow ( uploadStats , importSchema , headerArray , row , index , rowIndex , messages , fieldIdKey , results , insertArray ) return } if ( command === "update" ) { const coll = Util . getCollection ( uploadTypeObject . collection ) results . record = coll . findOne ( results . selector ) if ( ! results . record ) { VXApp . validateRecordNotFound ( index , messages , "common.field_id_path_specification" , { rowIndex : rowIndex , path : uploadTypeObject . keypath } , value ) return } RecordImporter . processRow ( uploadStats , importSchema , headerArray , row , index , rowIndex , messages , fieldIdKey , results , insertArray ) return } if ( command === "retire" ) { const coll = Util . getCollection ( uploadTypeObject . collection ) results . record = coll . findOne ( results . selector ) if ( ! results . record ) { VXApp . validateRecordNotFound ( index , messages , "common.field_id_path_specification" , { rowIndex : rowIndex , path : uploadTypeObject . keypath } ) return } const modifier = { } modifier . $set = { } modifier . $set . dateRetired = new Date ( ) modifier . $set . userRetired = uploadStats . userId coll . direct . update ( results . record . _id , modifier ) OLog . debug ( ` ${ index } ` + ` ${ uploadTypeObject . collection } ${ results . record . _id } ` ) return } }
Transform a generic row from the CSV into an object in the
 insertArray suitable for calling batch insert.
Transform a generic row from the CSV into an object in the insertArray suitable for calling batch insert .
// For command create we start off with a completely empty record except for audit/overhead fields: // For command update we first read the existing record using the value in the keypath column. // The record is used as the foundation for the update. // For command retire we'll retire the record right here: