use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class TextFileInputDialog method getFixed.
private void getFixed() {
TextFileInputMeta info = new TextFileInputMeta();
getInfo(info);
Shell sh = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
try {
List<String> rows = getFirst(50, false);
fields = getFields(info, rows);
final TextFileImportWizardPage1 page1 = new TextFileImportWizardPage1("1", props, rows, fields);
page1.createControl(sh);
final TextFileImportWizardPage2 page2 = new TextFileImportWizardPage2("2", props, rows, fields);
page2.createControl(sh);
Wizard wizard = new Wizard() {
public boolean performFinish() {
wFields.clearAll(false);
for (TextFileInputFieldInterface field1 : fields) {
TextFileInputField field = (TextFileInputField) field1;
if (!field.isIgnored() && field.getLength() > 0) {
TableItem item = new TableItem(wFields.table, SWT.NONE);
item.setText(1, field.getName());
item.setText(2, "" + field.getTypeDesc());
item.setText(3, "" + field.getFormat());
item.setText(4, "" + field.getPosition());
item.setText(5, field.getLength() < 0 ? "" : "" + field.getLength());
item.setText(6, field.getPrecision() < 0 ? "" : "" + field.getPrecision());
item.setText(7, "" + field.getCurrencySymbol());
item.setText(8, "" + field.getDecimalSymbol());
item.setText(9, "" + field.getGroupSymbol());
item.setText(10, "" + field.getNullString());
item.setText(11, "" + field.getIfNullValue());
item.setText(12, "" + field.getTrimTypeDesc());
item.setText(13, field.isRepeated() ? BaseMessages.getString(PKG, "System.Combo.Yes") : BaseMessages.getString(PKG, "System.Combo.No"));
}
}
int size = wFields.table.getItemCount();
if (size == 0) {
new TableItem(wFields.table, SWT.NONE);
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
input.setChanged();
return true;
}
};
wizard.addPage(page1);
wizard.addPage(page2);
WizardDialog wd = new WizardDialog(shell, wizard);
WizardDialog.setDefaultImage(GUIResource.getInstance().getImageWizard());
wd.setMinimumPageSize(700, 375);
wd.updateSize();
wd.open();
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogMessage"), e);
}
}
use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class S3CsvInputDialog method getInfo.
private void getInfo(S3CsvInputMeta inputMeta) {
inputMeta.setAwsAccessKey(wAccessKey.getText());
inputMeta.setAwsSecretKey(wSecretKey.getText());
inputMeta.setBucket(wBucket.getText());
if (isReceivingInput) {
inputMeta.setFilenameField(wFilenameField.getText());
inputMeta.setIncludingFilename(wIncludeFilename.getSelection());
} else {
inputMeta.setFilename(wFilename.getText());
}
inputMeta.setDelimiter(wDelimiter.getText());
inputMeta.setEnclosure(wEnclosure.getText());
inputMeta.setMaxLineSize(wMaxLineSize.getText());
inputMeta.setLazyConversionActive(wLazyConversion.getSelection());
inputMeta.setHeaderPresent(wHeaderPresent.getSelection());
inputMeta.setRowNumField(wRowNumField.getText());
inputMeta.setRunningInParallel(wRunningInParallel.getSelection());
int nrNonEmptyFields = wFields.nrNonEmpty();
inputMeta.allocate(nrNonEmptyFields);
for (int i = 0; i < nrNonEmptyFields; i++) {
TableItem item = wFields.getNonEmpty(i);
inputMeta.getInputFields()[i] = new TextFileInputField();
int colnr = 1;
inputMeta.getInputFields()[i].setName(item.getText(colnr++));
inputMeta.getInputFields()[i].setType(ValueMeta.getType(item.getText(colnr++)));
inputMeta.getInputFields()[i].setFormat(item.getText(colnr++));
inputMeta.getInputFields()[i].setLength(Const.toInt(item.getText(colnr++), -1));
inputMeta.getInputFields()[i].setPrecision(Const.toInt(item.getText(colnr++), -1));
inputMeta.getInputFields()[i].setCurrencySymbol(item.getText(colnr++));
inputMeta.getInputFields()[i].setDecimalSymbol(item.getText(colnr++));
inputMeta.getInputFields()[i].setGroupSymbol(item.getText(colnr++));
inputMeta.getInputFields()[i].setTrimType(ValueMeta.getTrimTypeByDesc(item.getText(colnr++)));
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
inputMeta.setChanged();
}
use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class S3CsvInputMeta method readData.
private void readData(Node stepnode) throws KettleXMLException {
try {
awsAccessKey = Encr.decryptPasswordOptionallyEncrypted(XMLHandler.getTagValue(stepnode, "aws_access_key"));
awsSecretKey = Encr.decryptPasswordOptionallyEncrypted(XMLHandler.getTagValue(stepnode, "aws_secret_key"));
bucket = XMLHandler.getTagValue(stepnode, "bucket");
filename = XMLHandler.getTagValue(stepnode, "filename");
filenameField = XMLHandler.getTagValue(stepnode, "filename_field");
rowNumField = XMLHandler.getTagValue(stepnode, "rownum_field");
includingFilename = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "include_filename"));
delimiter = XMLHandler.getTagValue(stepnode, "separator");
enclosure = XMLHandler.getTagValue(stepnode, "enclosure");
maxLineSize = XMLHandler.getTagValue(stepnode, "max_line_size");
headerPresent = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "header"));
lazyConversionActive = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "lazy_conversion"));
runningInParallel = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "parallel"));
Node fields = XMLHandler.getSubNode(stepnode, "fields");
int nrfields = XMLHandler.countNodes(fields, "field");
allocate(nrfields);
for (int i = 0; i < nrfields; i++) {
inputFields[i] = new TextFileInputField();
Node fnode = XMLHandler.getSubNodeByNr(fields, "field", i);
inputFields[i].setName(XMLHandler.getTagValue(fnode, "name"));
inputFields[i].setType(ValueMetaFactory.getIdForValueMeta(XMLHandler.getTagValue(fnode, "type")));
inputFields[i].setFormat(XMLHandler.getTagValue(fnode, "format"));
inputFields[i].setCurrencySymbol(XMLHandler.getTagValue(fnode, "currency"));
inputFields[i].setDecimalSymbol(XMLHandler.getTagValue(fnode, "decimal"));
inputFields[i].setGroupSymbol(XMLHandler.getTagValue(fnode, "group"));
inputFields[i].setLength(Const.toInt(XMLHandler.getTagValue(fnode, "length"), -1));
inputFields[i].setPrecision(Const.toInt(XMLHandler.getTagValue(fnode, "precision"), -1));
inputFields[i].setTrimType(ValueMetaString.getTrimTypeByCode(XMLHandler.getTagValue(fnode, "trim_type")));
}
} catch (Exception e) {
throw new KettleXMLException("Unable to load step info from XML", e);
}
}
use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class S3CsvInputMeta method getFields.
@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
// Start with a clean slate, eats the input
rowMeta.clear();
for (int i = 0; i < inputFields.length; i++) {
TextFileInputField field = inputFields[i];
ValueMetaInterface valueMeta = new ValueMeta(field.getName(), field.getType());
valueMeta.setConversionMask(field.getFormat());
valueMeta.setLength(field.getLength());
valueMeta.setPrecision(field.getPrecision());
valueMeta.setConversionMask(field.getFormat());
valueMeta.setDecimalSymbol(field.getDecimalSymbol());
valueMeta.setGroupingSymbol(field.getGroupSymbol());
valueMeta.setCurrencySymbol(field.getCurrencySymbol());
valueMeta.setTrimType(field.getTrimType());
if (lazyConversionActive) {
valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
}
// In case we want to convert Strings...
// Using a copy of the valueMeta object means that the inner and outer representation format is the same.
// Preview will show the data the same way as we read it.
// This layout is then taken further down the road by the metadata through the transformation.
//
ValueMetaInterface storageMetadata = valueMeta.clone();
storageMetadata.setType(ValueMetaInterface.TYPE_STRING);
storageMetadata.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
// we don't really know the lengths of the strings read in advance.
storageMetadata.setLength(-1, -1);
valueMeta.setStorageMetadata(storageMetadata);
valueMeta.setOrigin(origin);
rowMeta.addValueMeta(valueMeta);
}
if (!Utils.isEmpty(filenameField) && includingFilename) {
ValueMetaInterface filenameMeta = new ValueMetaString(filenameField);
filenameMeta.setOrigin(origin);
if (lazyConversionActive) {
filenameMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
filenameMeta.setStorageMetadata(new ValueMetaString(filenameField));
}
rowMeta.addValueMeta(filenameMeta);
}
if (!Utils.isEmpty(rowNumField)) {
ValueMetaInterface rowNumMeta = new ValueMetaInteger(rowNumField);
rowNumMeta.setLength(10);
rowNumMeta.setOrigin(origin);
rowMeta.addValueMeta(rowNumMeta);
}
}
use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class S3CsvInputMeta_GetFields_Test method createSampleMeta.
private S3CsvInputMeta createSampleMeta() {
S3CsvInputMeta meta = new S3CsvInputMeta();
meta.allocate(2);
meta.getInputFields()[0] = new TextFileInputField("field1", 0, 1);
meta.getInputFields()[1] = new TextFileInputField("field2", 0, 2);
return meta;
}
Aggregations