use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class HL7InputDialog method open.
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
props.setLook(shell);
setShellImage(shell, input);
ModifyListener lsMod = new ModifyListener() {
public void modifyText(ModifyEvent e) {
input.setChanged();
}
};
changed = input.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "HL7InputDialog.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Stepname line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "HL7InputDialog.Stepname.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
fdlStepname.right = new FormAttachment(middle, -margin);
fdlStepname.top = new FormAttachment(0, margin);
wlStepname.setLayoutData(fdlStepname);
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wStepname.setText(stepname);
props.setLook(wStepname);
wStepname.addModifyListener(lsMod);
fdStepname = new FormData();
fdStepname.left = new FormAttachment(middle, 0);
fdStepname.top = new FormAttachment(0, margin);
fdStepname.right = new FormAttachment(100, 0);
wStepname.setLayoutData(fdStepname);
// MessageField line
Label wlMessageField = new Label(shell, SWT.RIGHT);
wlMessageField.setText(BaseMessages.getString(PKG, "HL7InputDialog.MessageField.Label"));
props.setLook(wlMessageField);
FormData fdlMessageField = new FormData();
fdlMessageField.left = new FormAttachment(0, 0);
fdlMessageField.right = new FormAttachment(middle, -margin);
fdlMessageField.top = new FormAttachment(wStepname, margin);
wlMessageField.setLayoutData(fdlMessageField);
wMessageField = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wMessageField.setText(stepname);
props.setLook(wMessageField);
wMessageField.addModifyListener(lsMod);
FormData fdMessageField = new FormData();
fdMessageField.left = new FormAttachment(middle, 0);
fdMessageField.top = new FormAttachment(wStepname, margin);
fdMessageField.right = new FormAttachment(100, 0);
wMessageField.setLayoutData(fdMessageField);
try {
RowMetaInterface fields = transMeta.getPrevStepFields(stepMeta);
String[] names = fields.getFieldNames();
Arrays.sort(names);
wMessageField.setItems(names);
} catch (KettleStepException e) {
log.logError("Unable to get list of input fields... ", e);
}
// Some buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wCancel }, margin, wMessageField);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
wOK.addListener(SWT.Selection, lsOK);
lsDef = new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
// Set the shell size, based upon previous time...
setSize();
getData();
input.setChanged(changed);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class JsonInputMeta method getFields.
@Override
public void getFields(RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (inFields && removeSourceField && !Utils.isEmpty(valueField)) {
int index = rowMeta.indexOfValue(valueField);
if (index != -1) {
rowMeta.removeValueMeta(index);
}
}
for (JsonInputField field : getInputFields()) {
try {
rowMeta.addValueMeta(field.toValueMeta(name, space));
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
rowMeta.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
rowMeta.addValueMeta(v);
}
// Add additional fields
additionalOutputFields.normalize();
additionalOutputFields.getFields(rowMeta, name, info, space, repository, metaStore);
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class OpenERPObjectDeleteDialog method getSteamFieldsNames.
private String[] getSteamFieldsNames(boolean showError) {
String[] fields = null;
// Set stream fields
RowMetaInterface row;
try {
row = transMeta.getPrevStepFields(stepMeta);
fields = new String[row.size()];
for (int i = 0; i < row.size(); i++) {
fields[i] = row.getValueMeta(i).getName();
}
} catch (KettleStepException e) {
if (showError) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "OpenERPObjectOutputDialog.UnableToFindStreamFieldsTitle"), BaseMessages.getString(PKG, "OpenERPObjectOutputDialog.UnableToFindStreamFieldsMessage"), e);
}
return null;
}
return fields;
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class JsonInputTest method testErrorRedirect.
@Test
public void testErrorRedirect() throws Exception {
JsonInputField field = new JsonInputField("value");
field.setPath("$.value");
field.setType(ValueMetaInterface.TYPE_STRING);
String input1 = "{{";
String input2 = "{ \"value\": \"ok\" }";
JsonInputMeta meta = createSimpleMeta("json", field);
meta.setRemoveSourceField(true);
when(helper.stepMeta.isDoingErrorHandling()).thenReturn(true);
JsonInput jsonInput = createJsonInput("json", meta, new Object[] { input1 }, new Object[] { input2 });
StepErrorMeta errMeta = new StepErrorMeta(jsonInput, helper.stepMeta);
errMeta.setEnabled(true);
errMeta.setErrorFieldsValuename("err field");
when(helper.stepMeta.getStepErrorMeta()).thenReturn(errMeta);
final List<Object[]> errorLines = new ArrayList<>();
jsonInput.addRowListener(new RowComparatorListener(new Object[] { "ok" }) {
@Override
public void errorRowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
errorLines.add(row);
}
});
processRows(jsonInput, 3);
Assert.assertEquals("fwd error", 1, errorLines.size());
Assert.assertEquals("input in err line", input1, errorLines.get(0)[0]);
Assert.assertEquals("rows written", 1, jsonInput.getLinesWritten());
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class LucidDBBulkLoaderMeta method getSQLStatements.
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
// default: nothing to do!
SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
if (databaseMeta != null) {
if (prev != null && prev.size() > 0) {
// Copy the row
RowMetaInterface tableFields = new RowMeta();
// Now change the field names
for (int i = 0; i < fieldTable.length; i++) {
ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
if (v != null) {
ValueMetaInterface tableField = v.clone();
tableField.setName(fieldTable[i]);
tableFields.addValueMeta(tableField);
} else {
throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
}
}
if (!Utils.isEmpty(tableName)) {
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
try {
db.connect();
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
if (Utils.isEmpty(sql)) {
retval.setSQL(null);
} else {
retval.setSQL(sql);
}
} catch (KettleException e) {
retval.setError(BaseMessages.getString(PKG, "LucidDBBulkLoaderMeta.GetSQL.ErrorOccurred") + e.getMessage());
}
} else {
retval.setError(BaseMessages.getString(PKG, "LucidDBBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "LucidDBBulkLoaderMeta.GetSQL.NotReceivingAnyFields"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "LucidDBBulkLoaderMeta.GetSQL.NoConnectionDefined"));
}
return retval;
}
Aggregations