imports/vx/server/daemon/recordimporter.js
/**
     * Given a "chunk" of rows, validate and insert data into MongoDB.  Iterate over all
     * of the rows in the chunk and build an array of records suitable for Meteor batch insert.
     *
     * @param {object} uploadStats Upload stats object.
     * @param {object} rowArray Chunk of rows.
     * @param {array} messages Array of messages mutated in place.
     * @param {string} taskName Task name from worker.
     * @param {string} headerArray Anchor to headerArray.
     * @return {object} Result object.
     */
Given a "chunk" of rows, validate and insert data into MongoDB.  Iterate over all
of the rows in the chunk and build an array of records suitable for Meteor batch insert.

@param {object} uploadStats Upload stats object.
@param {object} rowArray Chunk of rows.
@param {array} messages Array of messages mutated in place.
@param {string} taskName Task name from worker.
@param {string} headerArray Anchor to headerArray.
@return {object} Result object.
Given a " chunk " of rows validate and insert data into MongoDB . Iterate over all of the rows in the chunk and build an array of records suitable for Meteor batch insert . @param { object } uploadStats Upload stats object . @param { object } rowArray Chunk of rows . @param { array } messages Array of messages mutated in place . @param { string } taskName Task name from worker . @param { string } headerArray Anchor to headerArray . @return { object } Result object .
importFileChunk(uploadStats, rowArray, messages, taskName, headerArray) {
        try {
            OLog.debug(`recordimporter.js importFileChunk domainId=${uploadStats.domain} ` +
                `uploadType=${uploadStats.uploadType} userId=${uploadStats.userId} *prepare* ${taskName} ` +
                `records=${rowArray.length}`)
            const insertArray = []
            const uploadTypeObject = Util.getCodeObject("uploadType", uploadStats.uploadType)
            if (uploadTypeObject.validateHeaders && headerArray.length === 0) {
                Array.prototype.push.apply(headerArray, rowArray[0].row)
                const valid = VXApp.validatePaths(ImportSchemas[uploadStats.uploadType], headerArray,
                    messages, "common.header_path_specification")
                if (!valid) {
                    OLog.debug("recordimporter.js prepareGeneric *abort* header has invalid path one or more invalid paths")
                    return { success: true }
                }
                const commandColumnIndex = VXApp.validateCommandColumn(headerArray, messages, "common.header_path_specification")
                if (commandColumnIndex < 0) {
                    return { success: true }
                }
            }
            const commandColumnIndex = VXApp.validateCommandColumn(headerArray, messages, "common.header_path_specification")
            _.each(rowArray, rowObject => {
                if (rowObject.index === 0) {
                    OLog.debug(`recordimporter.js importFileChunk domainId=${uploadStats.domain} ` +
                        `uploadType=${uploadStats.uploadType} userId=${uploadStats.userId} ` +
                        `*header* headerArray=${headerArray}`)
                    return
                }
                try {
                    const func = get(global, uploadTypeObject.prepareFunctionName)
                    func(uploadStats, uploadTypeObject, headerArray, commandColumnIndex, rowObject.row,
                        rowObject.index, rowObject.rowIndex, messages, insertArray)
                }
                catch (error) {
                    OLog.error("recordimporter.js importFileChunk unexpected error " +
                        `uploadType=${uploadStats.uploadType} error=${error}`)
                }
            })
            if (insertArray.length === 0) {
                return { success: true }
            }
            OLog.debug(`recordimporter.js importFileChunk domainId=${uploadStats.domain} ` +
                `uploadType=${uploadStats.uploadType} userId=${uploadStats.userId} taskName=${taskName} ` +
                `*persisting* records=${insertArray.length}`)
            const coll = Util.getCollection(uploadTypeObject.collection)
            switch (uploadTypeObject.insertMode) {
            case "UPSERT":
                RecordImporter.performSimpleUpsert(coll, uploadStats, taskName, insertArray)
                break
            case "BATCH":
                RecordImporter.performBatchInsert(coll, uploadStats, taskName, insertArray)
                break
            }
            return { success: true }
        }
        catch (error) {
            OLog.error(`recordimporter.js importFileChunk unexpected error=${error}`)
            return { success: false, icon: "BUG", key: "common.alert_unexpected_error",
                variables: { error: error.toString() } }
        }
    }
importFileChunk ( uploadStats , rowArray , messages , taskName , headerArray ) { try { OLog . debug ( ` ${ uploadStats . domain } ` + ` ${ uploadStats . uploadType } ${ uploadStats . userId } ${ taskName } ` + ` ${ rowArray . length } ` ) const insertArray = [ ] const uploadTypeObject = Util . getCodeObject ( "uploadType" , uploadStats . uploadType ) if ( uploadTypeObject . validateHeaders && headerArray . length === 0 ) { Array . prototype . push . apply ( headerArray , rowArray [ 0 ] . row ) const valid = VXApp . validatePaths ( ImportSchemas [ uploadStats . uploadType ] , headerArray , messages , "common.header_path_specification" ) if ( ! valid ) { OLog . debug ( "recordimporter.js prepareGeneric *abort* header has invalid path one or more invalid paths" ) return { success : true } } const commandColumnIndex = VXApp . validateCommandColumn ( headerArray , messages , "common.header_path_specification" ) if ( commandColumnIndex < 0 ) { return { success : true } } } const commandColumnIndex = VXApp . validateCommandColumn ( headerArray , messages , "common.header_path_specification" ) _ . each ( rowArray , rowObject => { if ( rowObject . index === 0 ) { OLog . debug ( ` ${ uploadStats . domain } ` + ` ${ uploadStats . uploadType } ${ uploadStats . userId } ` + ` ${ headerArray } ` ) return } try { const func = get ( global , uploadTypeObject . prepareFunctionName ) func ( uploadStats , uploadTypeObject , headerArray , commandColumnIndex , rowObject . row , rowObject . index , rowObject . rowIndex , messages , insertArray ) } catch ( error ) { OLog . error ( "recordimporter.js importFileChunk unexpected error " + ` ${ uploadStats . uploadType } ${ error } ` ) } } ) if ( insertArray . length === 0 ) { return { success : true } } OLog . debug ( ` ${ uploadStats . domain } ` + ` ${ uploadStats . uploadType } ${ uploadStats . userId } ${ taskName } ` + ` ${ insertArray . length } ` ) const coll = Util . getCollection ( uploadTypeObject . collection ) switch ( uploadTypeObject . insertMode ) { case "UPSERT" : RecordImporter . performSimpleUpsert ( coll , uploadStats , taskName , insertArray ) break case "BATCH" : RecordImporter . performBatchInsert ( coll , uploadStats , taskName , insertArray ) break } return { success : true } } catch ( error ) { OLog . error ( ` ${ error } ` ) return { success : false , icon : "BUG" , key : "common.alert_unexpected_error" , variables : { error : error . toString ( ) } } } }
Given a "chunk" of rows, validate and insert data into MongoDB.
Given a " chunk " of rows validate and insert data into MongoDB .