use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class Xslt method processRow.
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
meta = (XsltMeta) smi;
data = (XsltData) sdi;
Object[] row = getRow();
if (row == null) {
// no more input to be expected...
setOutputDone();
return false;
}
if (first) {
first = false;
data.outputRowMeta = getInputRowMeta().clone();
meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
// Check if The result field is given
if (Utils.isEmpty(meta.getResultfieldname())) {
// Result Field is missing !
logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorResultFieldMissing"));
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorResultFieldMissing"));
}
// Check if The XML field is given
if (Utils.isEmpty(meta.getFieldname())) {
// Result Field is missing !
logError(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXMLFieldMissing"));
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXMLFieldMissing"));
}
// Try to get XML Field index
data.fieldposition = getInputRowMeta().indexOfValue(meta.getFieldname());
// Let's check the Field
if (data.fieldposition < 0) {
// The field is unreachable !
logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorFindingField") + "[" + meta.getFieldname() + "]");
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.CouldnotFindField", meta.getFieldname()));
}
// Check if the XSL Filename is contained in a column
if (meta.useXSLField()) {
if (Utils.isEmpty(meta.getXSLFileField())) {
// The field is missing
// Result field is missing !
logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFileFieldMissing"));
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLFileFieldMissing"));
}
// Try to get Field index
data.fielxslfiledposition = getInputRowMeta().indexOfValue(meta.getXSLFileField());
// Let's check the Field
if (data.fielxslfiledposition < 0) {
// The field is unreachable !
logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFileFieldFinding") + "[" + meta.getXSLFileField() + "]");
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLFileFieldFinding", meta.getXSLFileField()));
}
} else {
if (Utils.isEmpty(meta.getXslFilename())) {
logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFile"));
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLFile"));
}
// Check if XSL File exists!
data.xslfilename = environmentSubstitute(meta.getXslFilename());
FileObject file = null;
try {
file = KettleVFS.getFileObject(data.xslfilename);
if (!file.exists()) {
logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLFileNotExists", data.xslfilename));
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLFileNotExists", data.xslfilename));
}
if (file.getType() != FileType.FILE) {
logError(BaseMessages.getString(PKG, "Xslt.Log.ErrorXSLNotAFile", data.xslfilename));
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ErrorXSLNotAFile", data.xslfilename));
}
} catch (Exception e) {
throw new KettleStepException(e);
} finally {
try {
if (file != null) {
file.close();
}
} catch (Exception e) {
/* Ignore */
}
}
}
// Check output parameters
int nrOutputProps = meta.getOutputPropertyName() == null ? 0 : meta.getOutputPropertyName().length;
if (nrOutputProps > 0) {
data.outputProperties = new Properties();
for (int i = 0; i < nrOutputProps; i++) {
data.outputProperties.put(meta.getOutputPropertyName()[i], environmentSubstitute(meta.getOutputPropertyValue()[i]));
}
data.setOutputProperties = true;
}
// Check parameters
data.nrParams = meta.getParameterField() == null ? 0 : meta.getParameterField().length;
if (data.nrParams > 0) {
data.indexOfParams = new int[data.nrParams];
data.nameOfParams = new String[data.nrParams];
for (int i = 0; i < data.nrParams; i++) {
String name = environmentSubstitute(meta.getParameterName()[i]);
String field = environmentSubstitute(meta.getParameterField()[i]);
if (Utils.isEmpty(field)) {
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ParameterFieldMissing", name, i));
}
data.indexOfParams[i] = getInputRowMeta().indexOfValue(field);
if (data.indexOfParams[i] < 0) {
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ParameterFieldNotFound", name));
}
data.nameOfParams[i] = name;
}
data.useParameters = true;
}
data.factory = TransformerFactory.newInstance();
if (meta.getXSLFactory().equals("SAXON")) {
// Set the TransformerFactory to the SAXON implementation.
data.factory = new net.sf.saxon.TransformerFactoryImpl();
}
}
// end if first
// Get the field value
String xmlValue = getInputRowMeta().getString(row, data.fieldposition);
if (meta.useXSLField()) {
// Get the value
data.xslfilename = getInputRowMeta().getString(row, data.fielxslfiledposition);
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "Xslt.Log.XslfileNameFromFied", data.xslfilename, meta.getXSLFileField()));
}
}
try {
if (log.isDetailed()) {
if (meta.isXSLFieldIsAFile()) {
logDetailed(BaseMessages.getString(PKG, "Xslt.Log.Filexsl") + data.xslfilename);
} else {
logDetailed(BaseMessages.getString(PKG, "Xslt.Log.XslStream", data.xslfilename));
}
}
// Get the template from the cache
Transformer transformer = data.getTemplate(data.xslfilename, data.xslIsAfile);
// Do we need to set output properties?
if (data.setOutputProperties) {
transformer.setOutputProperties(data.outputProperties);
}
// Do we need to pass parameters?
if (data.useParameters) {
for (int i = 0; i < data.nrParams; i++) {
transformer.setParameter(data.nameOfParams[i], row[data.indexOfParams[i]]);
}
}
Source source = new StreamSource(new StringReader(xmlValue));
// Prepare output stream
StreamResult result = new StreamResult(new StringWriter());
// transform xml source
transformer.transform(source, result);
String xmlString = result.getWriter().toString();
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "Xslt.Log.FileResult"));
logDetailed(xmlString);
}
Object[] outputRowData = RowDataUtil.addValueData(row, getInputRowMeta().size(), xmlString);
if (log.isRowLevel()) {
logRowlevel(BaseMessages.getString(PKG, "Xslt.Log.ReadRow") + " " + getInputRowMeta().getString(row));
}
// add new values to the row.
// copy row to output rowset(s);
putRow(data.outputRowMeta, outputRowData);
} catch (Exception e) {
String errorMessage = e.getClass().toString() + ": " + e.getMessage();
if (getStepMeta().isDoingErrorHandling()) {
// Simply add this row to the error row
putError(getInputRowMeta(), row, 1, errorMessage, meta.getResultfieldname(), "XSLT01");
} else {
logError(BaseMessages.getString(PKG, "Xslt.ErrorProcesing" + " : " + errorMessage), e);
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.ErrorProcesing"), e);
}
}
return true;
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class S3CsvInputDialog method open.
@Override
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, inputMeta);
ModifyListener lsMod = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
inputMeta.setChanged();
}
};
changed = inputMeta.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
// $NON-NLS-1$
shell.setText(Messages.getString("S3CsvInputDialog.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Step name line
//
wlStepname = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlStepname.setText(Messages.getString("S3CsvInputDialog.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);
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);
Control lastControl = wStepname;
// Access key
Label wlAccessKey = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlAccessKey.setText(Messages.getString("S3CsvInputDialog.AccessKey.Label"));
props.setLook(wlAccessKey);
FormData fdlAccessKey = new FormData();
fdlAccessKey.top = new FormAttachment(lastControl, margin);
fdlAccessKey.left = new FormAttachment(0, 0);
fdlAccessKey.right = new FormAttachment(middle, -margin);
wlAccessKey.setLayoutData(fdlAccessKey);
wAccessKey = new PasswordTextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wAccessKey);
wAccessKey.addModifyListener(lsMod);
FormData fdAccessKey = new FormData();
fdAccessKey.top = new FormAttachment(lastControl, margin);
fdAccessKey.left = new FormAttachment(middle, 0);
fdAccessKey.right = new FormAttachment(100, 0);
wAccessKey.setLayoutData(fdAccessKey);
lastControl = wAccessKey;
// Secret key
Label wlSecretKey = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlSecretKey.setText(Messages.getString("S3CsvInputDialog.SecretKey.Label"));
props.setLook(wlSecretKey);
FormData fdlSecretKey = new FormData();
fdlSecretKey.top = new FormAttachment(lastControl, margin);
fdlSecretKey.left = new FormAttachment(0, 0);
fdlSecretKey.right = new FormAttachment(middle, -margin);
wlSecretKey.setLayoutData(fdlSecretKey);
wSecretKey = new PasswordTextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wSecretKey);
wSecretKey.addModifyListener(lsMod);
FormData fdSecretKey = new FormData();
fdSecretKey.top = new FormAttachment(lastControl, margin);
fdSecretKey.left = new FormAttachment(middle, 0);
fdSecretKey.right = new FormAttachment(100, 0);
wSecretKey.setLayoutData(fdSecretKey);
lastControl = wSecretKey;
// Bucket name
Label wlBucket = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlBucket.setText(Messages.getString("S3CsvInputDialog.Bucket.Label"));
props.setLook(wlBucket);
FormData fdlBucket = new FormData();
fdlBucket.top = new FormAttachment(lastControl, margin);
fdlBucket.left = new FormAttachment(0, 0);
fdlBucket.right = new FormAttachment(middle, -margin);
wlBucket.setLayoutData(fdlBucket);
wbBucket = new Button(shell, SWT.PUSH | SWT.CENTER);
props.setLook(wbBucket);
wbBucket.setText(Messages.getString("S3CsvInputDialog.Bucket.Button"));
FormData fdbBucket = new FormData();
fdbBucket.top = new FormAttachment(lastControl, margin);
fdbBucket.right = new FormAttachment(100, 0);
wbBucket.setLayoutData(fdbBucket);
wBucket = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wBucket);
wBucket.addModifyListener(lsMod);
FormData fdBucket = new FormData();
fdBucket.top = new FormAttachment(lastControl, margin);
fdBucket.left = new FormAttachment(middle, 0);
fdBucket.right = new FormAttachment(wbBucket, -margin);
wBucket.setLayoutData(fdBucket);
lastControl = wBucket;
// See if the step receives input. If so, we don't ask for the filename, but for the filename field.
//
isReceivingInput = transMeta.findNrPrevSteps(stepMeta) > 0;
if (isReceivingInput) {
RowMetaInterface previousFields;
try {
previousFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleStepException e) {
new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.ErrorDialog.UnableToGetInputFields.Title"), Messages.getString("S3CsvInputDialog.ErrorDialog.UnableToGetInputFields.Message"), e);
previousFields = new RowMeta();
}
// The filename field ...
//
Label wlFilename = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlFilename.setText(Messages.getString("S3CsvInputDialog.FilenameField.Label"));
props.setLook(wlFilename);
FormData fdlFilename = new FormData();
fdlFilename.top = new FormAttachment(lastControl, margin);
fdlFilename.left = new FormAttachment(0, 0);
fdlFilename.right = new FormAttachment(middle, -margin);
wlFilename.setLayoutData(fdlFilename);
wFilenameField = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wFilenameField.setItems(previousFields.getFieldNames());
props.setLook(wFilenameField);
wFilenameField.addModifyListener(lsMod);
FormData fdFilename = new FormData();
fdFilename.top = new FormAttachment(lastControl, margin);
fdFilename.left = new FormAttachment(middle, 0);
fdFilename.right = new FormAttachment(100, 0);
wFilenameField.setLayoutData(fdFilename);
lastControl = wFilenameField;
// Checkbox to include the filename in the output...
//
Label wlIncludeFilename = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlIncludeFilename.setText(Messages.getString("S3CsvInputDialog.IncludeFilenameField.Label"));
props.setLook(wlIncludeFilename);
FormData fdlIncludeFilename = new FormData();
fdlIncludeFilename.top = new FormAttachment(lastControl, margin);
fdlIncludeFilename.left = new FormAttachment(0, 0);
fdlIncludeFilename.right = new FormAttachment(middle, -margin);
wlIncludeFilename.setLayoutData(fdlIncludeFilename);
wIncludeFilename = new Button(shell, SWT.CHECK);
props.setLook(wIncludeFilename);
wFilenameField.addModifyListener(lsMod);
FormData fdIncludeFilename = new FormData();
fdIncludeFilename.top = new FormAttachment(lastControl, margin);
fdIncludeFilename.left = new FormAttachment(middle, 0);
fdIncludeFilename.right = new FormAttachment(100, 0);
wIncludeFilename.setLayoutData(fdIncludeFilename);
lastControl = wIncludeFilename;
} else {
// Filename...
//
// The filename browse button
//
wbbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
props.setLook(wbbFilename);
wbbFilename.setText(Messages.getString("System.Button.Browse"));
wbbFilename.setToolTipText(Messages.getString("System.Tooltip.BrowseForFileOrDirAndAdd"));
FormData fdbFilename = new FormData();
fdbFilename.top = new FormAttachment(lastControl, margin);
fdbFilename.right = new FormAttachment(100, 0);
wbbFilename.setLayoutData(fdbFilename);
// The field itself...
//
Label wlFilename = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlFilename.setText(Messages.getString("S3CsvInputDialog.Filename.Label"));
props.setLook(wlFilename);
FormData fdlFilename = new FormData();
fdlFilename.top = new FormAttachment(lastControl, margin);
fdlFilename.left = new FormAttachment(0, 0);
fdlFilename.right = new FormAttachment(middle, -margin);
wlFilename.setLayoutData(fdlFilename);
wFilename = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wFilename);
wFilename.addModifyListener(lsMod);
FormData fdFilename = new FormData();
fdFilename.top = new FormAttachment(lastControl, margin);
fdFilename.left = new FormAttachment(middle, 0);
fdFilename.right = new FormAttachment(wbbFilename, -margin);
wFilename.setLayoutData(fdFilename);
lastControl = wFilename;
}
// delimiter
Label wlDelimiter = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlDelimiter.setText(Messages.getString("S3CsvInputDialog.Delimiter.Label"));
props.setLook(wlDelimiter);
FormData fdlDelimiter = new FormData();
fdlDelimiter.top = new FormAttachment(lastControl, margin);
fdlDelimiter.left = new FormAttachment(0, 0);
fdlDelimiter.right = new FormAttachment(middle, -margin);
wlDelimiter.setLayoutData(fdlDelimiter);
wbDelimiter = new Button(shell, SWT.PUSH | SWT.CENTER);
props.setLook(wbDelimiter);
wbDelimiter.setText(Messages.getString("S3CsvInputDialog.Delimiter.Button"));
FormData fdbDelimiter = new FormData();
fdbDelimiter.top = new FormAttachment(lastControl, margin);
fdbDelimiter.right = new FormAttachment(100, 0);
wbDelimiter.setLayoutData(fdbDelimiter);
wDelimiter = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wDelimiter);
wDelimiter.addModifyListener(lsMod);
FormData fdDelimiter = new FormData();
fdDelimiter.top = new FormAttachment(lastControl, margin);
fdDelimiter.left = new FormAttachment(middle, 0);
fdDelimiter.right = new FormAttachment(wbDelimiter, -margin);
wDelimiter.setLayoutData(fdDelimiter);
lastControl = wDelimiter;
// enclosure
Label wlEnclosure = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlEnclosure.setText(Messages.getString("S3CsvInputDialog.Enclosure.Label"));
props.setLook(wlEnclosure);
FormData fdlEnclosure = new FormData();
fdlEnclosure.top = new FormAttachment(lastControl, margin);
fdlEnclosure.left = new FormAttachment(0, 0);
fdlEnclosure.right = new FormAttachment(middle, -margin);
wlEnclosure.setLayoutData(fdlEnclosure);
wEnclosure = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wEnclosure);
wEnclosure.addModifyListener(lsMod);
FormData fdEnclosure = new FormData();
fdEnclosure.top = new FormAttachment(lastControl, margin);
fdEnclosure.left = new FormAttachment(middle, 0);
fdEnclosure.right = new FormAttachment(100, 0);
wEnclosure.setLayoutData(fdEnclosure);
lastControl = wEnclosure;
// Max line size
//
Label wlMaxLineSize = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlMaxLineSize.setText(Messages.getString("S3CsvInputDialog.MaxLineSize.Label"));
props.setLook(wlMaxLineSize);
FormData fdlMaxLineSize = new FormData();
fdlMaxLineSize.top = new FormAttachment(lastControl, margin);
fdlMaxLineSize.left = new FormAttachment(0, 0);
fdlMaxLineSize.right = new FormAttachment(middle, -margin);
wlMaxLineSize.setLayoutData(fdlMaxLineSize);
wMaxLineSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wMaxLineSize);
wMaxLineSize.addModifyListener(lsMod);
FormData fdMaxLineSize = new FormData();
fdMaxLineSize.top = new FormAttachment(lastControl, margin);
fdMaxLineSize.left = new FormAttachment(middle, 0);
fdMaxLineSize.right = new FormAttachment(100, 0);
wMaxLineSize.setLayoutData(fdMaxLineSize);
lastControl = wMaxLineSize;
// performingLazyConversion?
//
Label wlLazyConversion = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlLazyConversion.setText(Messages.getString("S3CsvInputDialog.LazyConversion.Label"));
props.setLook(wlLazyConversion);
FormData fdlLazyConversion = new FormData();
fdlLazyConversion.top = new FormAttachment(lastControl, margin);
fdlLazyConversion.left = new FormAttachment(0, 0);
fdlLazyConversion.right = new FormAttachment(middle, -margin);
wlLazyConversion.setLayoutData(fdlLazyConversion);
wLazyConversion = new Button(shell, SWT.CHECK);
props.setLook(wLazyConversion);
FormData fdLazyConversion = new FormData();
fdLazyConversion.top = new FormAttachment(lastControl, margin);
fdLazyConversion.left = new FormAttachment(middle, 0);
fdLazyConversion.right = new FormAttachment(100, 0);
wLazyConversion.setLayoutData(fdLazyConversion);
lastControl = wLazyConversion;
// header row?
//
Label wlHeaderPresent = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlHeaderPresent.setText(Messages.getString("S3CsvInputDialog.HeaderPresent.Label"));
props.setLook(wlHeaderPresent);
FormData fdlHeaderPresent = new FormData();
fdlHeaderPresent.top = new FormAttachment(lastControl, margin);
fdlHeaderPresent.left = new FormAttachment(0, 0);
fdlHeaderPresent.right = new FormAttachment(middle, -margin);
wlHeaderPresent.setLayoutData(fdlHeaderPresent);
wHeaderPresent = new Button(shell, SWT.CHECK);
props.setLook(wHeaderPresent);
FormData fdHeaderPresent = new FormData();
fdHeaderPresent.top = new FormAttachment(lastControl, margin);
fdHeaderPresent.left = new FormAttachment(middle, 0);
fdHeaderPresent.right = new FormAttachment(100, 0);
wHeaderPresent.setLayoutData(fdHeaderPresent);
lastControl = wHeaderPresent;
// The field itself...
//
Label wlRowNumField = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlRowNumField.setText(Messages.getString("S3CsvInputDialog.RowNumField.Label"));
props.setLook(wlRowNumField);
FormData fdlRowNumField = new FormData();
fdlRowNumField.top = new FormAttachment(lastControl, margin);
fdlRowNumField.left = new FormAttachment(0, 0);
fdlRowNumField.right = new FormAttachment(middle, -margin);
wlRowNumField.setLayoutData(fdlRowNumField);
wRowNumField = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wRowNumField);
wRowNumField.addModifyListener(lsMod);
FormData fdRowNumField = new FormData();
fdRowNumField.top = new FormAttachment(lastControl, margin);
fdRowNumField.left = new FormAttachment(middle, 0);
fdRowNumField.right = new FormAttachment(100, 0);
wRowNumField.setLayoutData(fdRowNumField);
lastControl = wRowNumField;
// running in parallel?
//
Label wlRunningInParallel = new Label(shell, SWT.RIGHT);
// $NON-NLS-1$
wlRunningInParallel.setText(Messages.getString("S3CsvInputDialog.RunningInParallel.Label"));
props.setLook(wlRunningInParallel);
FormData fdlRunningInParallel = new FormData();
fdlRunningInParallel.top = new FormAttachment(lastControl, margin);
fdlRunningInParallel.left = new FormAttachment(0, 0);
fdlRunningInParallel.right = new FormAttachment(middle, -margin);
wlRunningInParallel.setLayoutData(fdlRunningInParallel);
wRunningInParallel = new Button(shell, SWT.CHECK);
props.setLook(wRunningInParallel);
FormData fdRunningInParallel = new FormData();
fdRunningInParallel.top = new FormAttachment(lastControl, margin);
fdRunningInParallel.left = new FormAttachment(middle, 0);
wRunningInParallel.setLayoutData(fdRunningInParallel);
lastControl = wRunningInParallel;
// Some buttons first, so that the dialog scales nicely...
//
wOK = new Button(shell, SWT.PUSH);
// $NON-NLS-1$
wOK.setText(Messages.getString("System.Button.OK"));
wCancel = new Button(shell, SWT.PUSH);
// $NON-NLS-1$
wCancel.setText(Messages.getString("System.Button.Cancel"));
wPreview = new Button(shell, SWT.PUSH);
// $NON-NLS-1$
wPreview.setText(Messages.getString("System.Button.Preview"));
wPreview.setEnabled(!isReceivingInput);
wGet = new Button(shell, SWT.PUSH);
// $NON-NLS-1$
wGet.setText(Messages.getString("System.Button.GetFields"));
wGet.setEnabled(!isReceivingInput);
setButtonPositions(new Button[] { wOK, wCancel, wPreview, wGet }, margin, null);
// Fields
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(Messages.getString("S3CsvInputDialog.NameColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.TypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMeta.getTypes(), true), new ColumnInfo(Messages.getString("S3CsvInputDialog.FormatColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, Const.getConversionFormats()), new ColumnInfo(Messages.getString("S3CsvInputDialog.LengthColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.PrecisionColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.CurrencyColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.DecimalColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.GroupColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(Messages.getString("S3CsvInputDialog.TrimTypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMeta.trimTypeDesc) };
colinf[2].setComboValuesSelectionListener(new ComboValuesSelectionListener() {
@Override
public String[] getComboValues(TableItem tableItem, int rowNr, int colNr) {
String[] comboValues = new String[] {};
int type = ValueMeta.getType(tableItem.getText(colNr - 1));
switch(type) {
case ValueMetaInterface.TYPE_DATE:
comboValues = Const.getDateFormats();
break;
case ValueMetaInterface.TYPE_INTEGER:
case ValueMetaInterface.TYPE_BIGNUMBER:
case ValueMetaInterface.TYPE_NUMBER:
comboValues = Const.getNumberFormats();
break;
default:
break;
}
return comboValues;
}
});
wFields = new TableView(transMeta, shell, SWT.FULL_SELECTION | SWT.MULTI, colinf, 1, lsMod, props);
FormData fdFields = new FormData();
fdFields.top = new FormAttachment(lastControl, margin * 2);
fdFields.bottom = new FormAttachment(wOK, -margin * 2);
fdFields.left = new FormAttachment(0, 0);
fdFields.right = new FormAttachment(100, 0);
wFields.setLayoutData(fdFields);
// Add listeners
lsCancel = new Listener() {
@Override
public void handleEvent(Event e) {
cancel();
}
};
lsOK = new Listener() {
@Override
public void handleEvent(Event e) {
ok();
}
};
lsPreview = new Listener() {
@Override
public void handleEvent(Event e) {
preview();
}
};
lsGet = new Listener() {
@Override
public void handleEvent(Event e) {
getCSV();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
wOK.addListener(SWT.Selection, lsOK);
wPreview.addListener(SWT.Selection, lsPreview);
wGet.addListener(SWT.Selection, lsGet);
lsDef = new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
if (wFilename != null) {
wFilename.addSelectionListener(lsDef);
}
if (wFilenameField != null) {
wFilenameField.addSelectionListener(lsDef);
}
wDelimiter.addSelectionListener(lsDef);
wEnclosure.addSelectionListener(lsDef);
wMaxLineSize.addSelectionListener(lsDef);
wRowNumField.addSelectionListener(lsDef);
// Allow the insertion of tabs as separator...
wbDelimiter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent se) {
Text t = wDelimiter.getTextWidget();
if (t != null) {
t.insert("\t");
}
}
});
wbBucket.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
//
try {
S3CsvInputMeta meta = new S3CsvInputMeta();
getInfo(meta);
S3ObjectsProvider s3ObjProvider = new S3ObjectsProvider(meta.getS3Service(transMeta));
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, s3ObjProvider.getBucketsNames(), Messages.getString("S3CsvInputDialog.Exception.SelectBucket.Title"), Messages.getString("S3CsvInputDialog.Exception.SelectBucket.Message"));
dialog.setMulti(false);
String bucketname = dialog.open();
if (bucketname != null) {
wBucket.setText(bucketname);
}
} catch (Exception e) {
new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.Exception.UnableToGetBuckets.Title"), Messages.getString("S3CsvInputDialog.Exception.UnableToGetBuckets.Message"), e);
}
}
});
if (wbbFilename != null) {
// Listen to the browse button next to the file name
wbbFilename.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
S3CsvInputMeta meta = new S3CsvInputMeta();
getInfo(meta);
S3ObjectsProvider s3ObjProvider = new S3ObjectsProvider(meta.getS3Service(transMeta));
String[] objectnames = s3ObjProvider.getS3ObjectsNames(meta.getBucket());
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, objectnames, Messages.getString("S3CsvInputDialog.Exception.SelectObject.Title"), Messages.getString("S3CsvInputDialog.Exception.SelectObject.Message"));
dialog.setMulti(false);
if (!Utils.isEmpty(wFilename.getText())) {
int index = Const.indexOfString(wFilename.getText(), objectnames);
if (index >= 0) {
dialog.setSelectedNrs(new int[] { index });
}
}
String objectname = dialog.open();
if (objectname != null) {
wFilename.setText(objectname);
}
} catch (Exception e) {
new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.Exception.UnableToGetFiles.Title"), Messages.getString("S3CsvInputDialog.Exception.UnableToGetFiles.Message"), e);
}
}
});
}
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
cancel();
}
});
// Set the shell size, based upon previous time...
setSize();
getData();
inputMeta.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 SalesforceInputMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
int i;
for (i = 0; i < inputFields.length; i++) {
SalesforceInputField field = inputFields[i];
int type = field.getType();
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setOrigin(name);
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setCurrencySymbol(field.getCurrencySymbol());
r.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeTargetURL && !Utils.isEmpty(targetURLField)) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(targetURLField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeModule && !Utils.isEmpty(moduleField)) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(moduleField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeSQL && !Utils.isEmpty(sqlField)) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(sqlField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeTimestamp && !Utils.isEmpty(timestampField)) {
ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(timestampField));
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber && !Utils.isEmpty(rowNumberField)) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeDeletionDate && !Utils.isEmpty(deletionDateField)) {
ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(deletionDateField));
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class SalesforceInsert method processRow.
@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
// get one row ... This does some basic initialization of the objects, including loading the info coming in
Object[] outputRowData = getRow();
if (outputRowData == null) {
if (data.iBufferPos > 0) {
flushBuffers();
}
setOutputDone();
return false;
}
// If we haven't looked at a row before then do some basic setup.
if (first) {
first = false;
data.sfBuffer = new SObject[meta.getBatchSizeInt()];
data.outputBuffer = new Object[meta.getBatchSizeInt()][];
// get total fields in the grid
data.nrfields = meta.getUpdateLookup().length;
// Check if field list is filled
if (data.nrfields == 0) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInsertDialog.FieldsMissing.DialogMessage"));
}
// Create the output row meta-data
data.inputRowMeta = getInputRowMeta().clone();
data.outputRowMeta = data.inputRowMeta.clone();
meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
// Build the mapping of input position to field name
data.fieldnrs = new int[meta.getUpdateStream().length];
for (int i = 0; i < meta.getUpdateStream().length; i++) {
data.fieldnrs[i] = getInputRowMeta().indexOfValue(meta.getUpdateStream()[i]);
if (data.fieldnrs[i] < 0) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceInsert.CanNotFindField", meta.getUpdateStream()[i]));
}
}
}
try {
writeToSalesForce(outputRowData);
} catch (Exception e) {
throw new KettleStepException(BaseMessages.getString(PKG, "SalesforceInsert.log.Exception", e));
}
return true;
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class SalesforceUpsert method processRow.
@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
// get one row ... This does some basic initialization of the objects, including loading the info coming in
Object[] outputRowData = getRow();
if (outputRowData == null) {
if (data.iBufferPos > 0) {
flushBuffers();
}
setOutputDone();
return false;
}
// If we haven't looked at a row before then do some basic setup.
if (first) {
first = false;
data.sfBuffer = new SObject[meta.getBatchSizeInt()];
data.outputBuffer = new Object[meta.getBatchSizeInt()][];
// get total fields in the grid
data.nrfields = meta.getUpdateLookup().length;
// Check if field list is filled
if (data.nrfields == 0) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpsertDialog.FieldsMissing.DialogMessage"));
}
// Create the output row meta-data
data.inputRowMeta = getInputRowMeta().clone();
data.outputRowMeta = data.inputRowMeta.clone();
meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
// Build the mapping of input position to field name
data.fieldnrs = new int[meta.getUpdateStream().length];
for (int i = 0; i < meta.getUpdateStream().length; i++) {
data.fieldnrs[i] = getInputRowMeta().indexOfValue(meta.getUpdateStream()[i]);
if (data.fieldnrs[i] < 0) {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpsert.FieldNotFound", meta.getUpdateStream()[i]));
}
}
}
try {
writeToSalesForce(outputRowData);
} catch (Exception e) {
throw new KettleStepException(BaseMessages.getString(PKG, "SalesforceUpsert.log.Exception"), e);
}
return true;
}
Aggregations