Importing Data Into a Scenario

The data integration service can be used with any implementation of DataSource to write data to a given scenario. The data integration service will take care of consuming the datasource and save its data to the Data Service.

As an example, let's consider that we want to import data from a staging database, and that we have implemented our own data source to read data from it (let's call it StagingDBDataSource). Then here is an example of using this datasource with the data integration service in a worker task:

@Component
public class ImportTask implements Task {

    private static final Logger LOGGER = LoggerFactory.getLogger(ImportTask.class);

    @Autowire
    DataIntegrationService dataIntegrationService;

    @Override
    public void execute(Parameter input, Parameter output, ExecutionContext context) {

        try {
          dataIntegrationService.writeData(
            new String(input.get("scenarioId")),
            new StagingDBDataSource()
          );
        } catch (DataIntegrationException e) {
          LOGGER.error("Error while importing data from staging database.", e);
        }
    }
}