use of org.talend.sdk.component.runtime.manager.chain.ChainedMapper in project component-runtime by Talend.
the class DIBatchSimulationTest method doRun.
private void doRun(final ComponentManager manager, final Collection<Object> sourceData, final Collection<Object> processorData, final Map<String, Object> globalMap, final AutoChunkProcessor processorProcessor, final InputsHandler inputsHandlerProcessor, final OutputsHandler outputHandlerProcessor, final InputFactory inputsProcessor, final OutputFactory outputsProcessor, final Mapper tempMapperMapper) {
row1Struct row1 = new row1Struct();
tempMapperMapper.start();
final ChainedMapper mapperMapper;
try {
final List<Mapper> splitMappersMapper = tempMapperMapper.split(tempMapperMapper.assess());
mapperMapper = new ChainedMapper(tempMapperMapper, splitMappersMapper.iterator());
mapperMapper.start();
globalMap.put("mapperMapper", mapperMapper);
} finally {
try {
tempMapperMapper.stop();
} catch (final RuntimeException re) {
re.printStackTrace();
}
}
final Input inputMapper = mapperMapper.create();
inputMapper.start();
globalMap.put("inputMapper", inputMapper);
final Jsonb jsonbMapper = Jsonb.class.cast(manager.findPlugin(mapperMapper.plugin()).get().get(ComponentManager.AllServices.class).getServices().get(Jsonb.class));
Object dataMapper;
while ((dataMapper = inputMapper.next()) != null) {
final String jsonValueMapper = javax.json.JsonValue.class.isInstance(dataMapper) ? javax.json.JsonValue.class.cast(dataMapper).toString() : jsonbMapper.toJson(dataMapper);
row1 = jsonbMapper.fromJson(jsonValueMapper, row1.getClass());
sourceData.add(row1);
inputsHandlerProcessor.reset();
inputsHandlerProcessor.setInputValue("FLOW", row1);
outputHandlerProcessor.reset();
processorProcessor.onElement(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
final Object read = inputsProcessor.read(name);
processorData.add(read);
return read;
}, outputsProcessor);
}
}
use of org.talend.sdk.component.runtime.manager.chain.ChainedMapper in project component-runtime by Talend.
the class TaCoKitGuessSchema method guessInputComponentSchemaThroughResult.
private boolean guessInputComponentSchemaThroughResult() throws Exception {
final Mapper mapper = componentManager.findMapper(family, componentName, 1, configuration).orElseThrow(() -> new IllegalArgumentException("Can't find " + family + "#" + componentName));
if (JobStateAware.class.isInstance(mapper)) {
JobStateAware.class.cast(mapper).setState(new JobStateAware.State());
}
Input input = null;
try {
mapper.start();
final ChainedMapper chainedMapper = new ChainedMapper(mapper, mapper.split(mapper.assess()).iterator());
chainedMapper.start();
input = chainedMapper.create();
input.start();
Object rowObject = input.next();
if (rowObject == null) {
return false;
}
if (rowObject instanceof java.util.Map) {
return guessInputSchemaThroughResults(input, (java.util.Map) rowObject);
} else if (rowObject instanceof java.util.Collection) {
throw new Exception("Can't guess schema from a Collection");
} else {
return guessSchemaThroughResultClass(rowObject.getClass());
}
} finally {
if (input != null) {
try {
input.stop();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
try {
mapper.stop();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
Aggregations