Exporting Data from a Scenario
Conversely, we can also use the data integration service to read data from a given scenario, and process it with our own implementation of DataSourceConsumer. For example, if we want to save the content of the entities that constitute the solution part of a data model (let's say two entities SolutionEntity1 and SolutionEntity2) back to the same staging database, we can provide our own implementation of DataSourceConsumer that writes data to this database (let's call it StagingDBDataSourceConsumer), and use it with the data integration service like in the following example:
@Component
public class ExportSolutionTask implements Task {
private static final Logger LOGGER = LoggerFactory.getLogger(ExportSolutionTask.class);
@Autowire
DataIntegrationService dataIntegrationService;
@Override
public void execute(Parameter input, Parameter output, ExecutionContext context) {
try {
dataIntegrationService.readData(
new String(input.get("scenarioId")),
new StagingDBDataSourceConsumer(),
List.of("SolutionEntity1", "SolutionEntity2")
);
} catch (DataIntegrationException e) {
LOGGER.error("Error while importing data from staging database.", e);
}
}
}