Batch service

To import a batch of data, you create a Batch object using a service, then run a import loop to transform records and commit imported data.

service haplo:data-import-framework:batch

This service take three arguments:

let batch = O.service("haplo:data-import-framework:batch",
        control, files, errorCallback);
control A control file, as a JavaScript data structure (not serialised JSON).
files An Object with properties naming the files, and BinaryData objects as the values.
errorCallback A function called with two arguments, the error message and the current Record.

The service returns a Batch object, which is used to run the import loop.

Example

// Control file is a JavaScript data structure
let control = {
    "dataImportControlFileVersion": 0,
    "model": "haplo:person",
    // ...
};

// Map of name to BinaryData object, eg result of O.file()
let files = {
    "people": O.file(...)
};

// Callback function to output error messages
let errorCallback = function(message, record) {
    console.log(message);
};

// Create a Batch object
let batch = O.service("haplo:data-import-framework:batch",
        control, files, errorCallback);

// Run the import loop to import data
batch.eachRecord((record) => {
    let transformation = batch.transform(record);
    if(transformation.isComplete) {
        transformation.commit();
    }
});