use of org.talend.core.utils.CsvArray in project tdi-studio-se by Talend.
the class ShadowProcess method runWithErrorOutputAsException.
/**
*
* DOC xye Comment method "runWithErrorOutputAsException".
*
* @param outputErrorAsException
* @return
* @throws ProcessorException
*/
public CsvArray runWithErrorOutputAsException(final boolean outputErrorAsException) throws ProcessorException {
IProcess talendProcess = buildProcess();
IProcessor processor = ProcessorUtilities.getProcessor(talendProcess, null);
processor.setProxyParameters(getProxyParameters());
File previousFile = outPath.toFile();
if (previousFile.exists()) {
previousFile.delete();
}
IContext context = talendProcess.getContextManager().getDefaultContext();
processor.setContext(context);
process = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
String error = ProcessStreamTrashReader.readErrorStream(process);
if (error != null) {
log.warn(error, new ProcessorException(error));
}
if (!outPath.toFile().exists()) {
if (outputErrorAsException && error != null) {
throw new ProcessorException(error);
} else {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("ShadowProcess.notGeneratedOutputException"));
}
}
try {
CsvArray array = new CsvArray();
array = array.createFrom(outPath.toFile(), currentProcessEncoding);
return array;
} catch (IOException ioe) {
throw new ProcessorException(ioe);
}
}
use of org.talend.core.utils.CsvArray in project tdi-studio-se by Talend.
the class JSONFileStep2Form method refreshPreview.
/**
* refreshPreview use ShadowProcess to refresh the preview.
*/
void refreshPreview() {
clearPreview();
// if no file, the process don't be executed
if (getConnection().getJSONFilePath() == null || !(new File(getConnection().getJSONFilePath()).exists()) && JSONUtil.tempJSONXsdPath == null) {
previewInformationLabel.setText(" " + "The file path must be specified");
return;
}
// if incomplete settings, , the process don't be executed
if (!checkFieldsValue()) {
previewInformationLabel.setText(" " + "The settings must be completed to show the preview");
return;
}
// set row limit
if (jsonXPathLoopDescriptor.getLimitBoucle() > 0 && jsonXPathLoopDescriptor.getLimitBoucle() < XmlArray.getRowLimit()) {
XmlArray.setRowLimit(jsonXPathLoopDescriptor.getLimitBoucle());
}
previewInformationLabel.setText(" " + "Preview in progress...");
String shadowProcessType = null;
if (EJsonReadbyMode.JSONPATH.getValue().equals(getConnection().getReadbyMode())) {
//$NON-NLS-1$
shadowProcessType = "FILE_JSON";
}
final String finalShadowProcessType = shadowProcessType;
AsynchronousPreviewHandler<CsvArray> previewHandler = null;
try {
previewHandler = ShadowProcessHelper.createPreviewHandler(finalShadowProcessType);
} catch (CoreException e) {
previewInError(e);
return;
}
StoppablePreviewLoader previewLoader = new StoppablePreviewLoader<CsvArray>(previewHandler, previewInformationLabel) {
/*
* (non-Javadoc)
*
* @see
* org.talend.repository.ui.wizards.metadata.connection.files.JSON.StoppablePreviewLoader#previewEnded(java
* .lang.Object)
*/
@Override
protected void previewEnded(CsvArray result) {
jsonFilePreview.refreshTablePreview(result, false, (getConnection().getSchema().get(0)).getSchemaTargets());
if (jsonFilePreview.isCsvRowsEmpty()) {
clearPreview();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
handleErrorOutput(outputComposite, tabFolder, outputTabItem);
}
});
log.error("No result for this settings");
previewButton.setEnabled(true);
}
}
@Override
public void previewInError(CoreException e) {
JSONFileStep2Form.this.previewInError(e);
}
@Override
protected String getShadowProcessType() {
if (finalShadowProcessType != null && !finalShadowProcessType.isEmpty()) {
return finalShadowProcessType;
} else {
return super.getShadowProcessType();
}
}
};
previewLoader.load(getProcessDescription(false));
}
use of org.talend.core.utils.CsvArray in project tdi-studio-se by Talend.
the class MultiSchemasUI method launch.
private void launch() {
try {
String filePath = this.multiSchemaManager.getOriginalValue(this.getConnection().getFilePath());
CsvArray csvArray = getMultiSchemaManager().getCsvArrayForMultiSchemaDelimited(filePath, multiSeparatorsText.getText(), encodingCombo.getText(), keyValuesText.getText(), multiSchemaManager.getSelectedColumnIndex());
processor.setCsvArray(csvArray);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
processor.execute2();
}
});
} catch (FileNotFoundException e) {
ExceptionHandler.process(e);
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.utils.CsvArray in project tdi-studio-se by Talend.
the class MultiSchemasUI method fetchCodes.
@SuppressWarnings("restriction")
private void fetchCodes() {
try {
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
dialog.run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Fetch...", IProgressMonitor.UNKNOWN);
monitor.setCanceled(false);
final CsvArray csvArray = processor.getCsvArray();
Display.getDefault().syncExec(new Runnable() {
public void run() {
SchemasKeyData schemasModel = null;
boolean checked = (csvArray != null && csvArray.getRows().size() > 0);
CSVArrayAndSeparator uniqueCsvArray = null;
if (useMultiSaparators.getSelection()) {
getMultiSchemaManager().setKeyValues(keyValuesText.getText());
}
if (multiSchemasFilePreview.getSelectColumnIndex() < 0 && multiSchemaManager.getSelectedColumnIndex() != 0) {
uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemaManager.getSelectedColumnIndex(), useMultiSaparators.getSelection());
schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemaManager.getSelectedColumnIndex());
} else {
uniqueCsvArray = getMultiSchemaManager().retrieveCsvArrayInUniqueModel(getProcessDescription(), checked, multiSchemasFilePreview.getSelectColumnIndex(), useMultiSaparators.getSelection());
schemasModel = getMultiSchemaManager().createSchemasTree(uniqueCsvArray, multiSchemasFilePreview.getSelectColumnIndex());
getMultiSchemaManager().setSelectedColumnIndex(multiSchemasFilePreview.getSelectColumnIndex());
schemaTreeViewer.setInput(schemasModel);
getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
clearSchemaDetail();
checkDialog();
}
}
});
monitor.done();
}
});
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.utils.CsvArray in project tdi-studio-se by Talend.
the class MultiSchemasManager method getCsvArrayForMultiSchemaDelimited.
public CsvArray getCsvArrayForMultiSchemaDelimited(String filePath, String separators, String encoding, String keyValues, int keyIndex) throws UnsupportedEncodingException, IOException {
File file = new File(TalendTextUtils.removeQuotes(filePath));
separators = TalendTextUtils.removeQuotes(separators);
CsvArray csvArray = new CsvArray();
if (file.exists()) {
BufferedReader reader = new BufferedReader(new FileReader(file));
String readLine = "";
String[] row = null;
int i = 0;
while ((readLine = reader.readLine()) != null && i < maximumRowsToPreview) {
boolean added = false;
int count = 0;
while (count < separators.length()) {
CSVReader csvReader = getCsvReader(new ByteArrayInputStream(readLine.getBytes()), separators.charAt(count), encoding);
List items = csvReader.parse(readLine);
// csvReader.readRecord();
if (items.size() > 0) {
// csvReader.getValues();
row = (String[]) items.get(0);
}
if (row.length > 1 && row.length > keyIndex) {
if (isInKeyValues(keyValues, row[keyIndex])) {
added = true;
csvArray.add(row);
// csvReader.close();
i++;
break;
}
}
// csvReader.close();
count++;
}
if (!added && row != null && row.length > keyIndex) {
if (isInKeyValues(keyValues, row[keyIndex])) {
csvArray.add(row);
i++;
}
}
}
}
return csvArray;
}
Aggregations