Batch interface
Batch
objects control a batch import process.
Construction
Call the haplo:data-import-framework:batch
service.
Usage
Construct a Batch
object, call any methods to set up the process, then run the data import loop:
batch.eachRecord((record) => { let transformation = batch.transform(record); if(transformation.isComplete) { transformation.commit(); } });
Interface
function eachRecord(iterator)
Calls the iterator
function with each Record in the input data files.
function transform(record, recordIdentifier)
Transform the input record
, returning a Transformation
object which can be used to commit the imported data.
recordIdentifier
is an optional string which identifies the current record in error messages. If not specified, a suitable identifier is generated automatically.
prepareTransformation()
may be useful when more control over the transformation is needed.
function option(name, value)
Set an option:
"report-all-errors" |
If true , then all errors will be reported. Otherwise no more errors will be reported over a reasonable number. |
function observe(event, callback)
When the named event
occurs, call the callback
function.
"object:save" |
Called when a StoreObject is saved with arguments callback(transformation, destinationName, object, isNewObject) |
function prepareTransformation(record, recordIdentifier)
Like transform()
, but just returns a Transformation
without doing any work. After any additional setup, call transform()
on the Transformation
object.
property errorCount
The current number of errors which have been encountered so far in this batch process. Most useful after the process has completed.