Search in sources :

Example 1 with TextFileField

use of org.pentaho.di.trans.steps.textfileoutput.TextFileField in project pentaho-kettle by pentaho.

the class ConcatFieldsDialog method getData.

/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData() {
    // New concat fields
    if (input.getTargetFieldName() != null) {
        wTargetFieldName.setText(input.getTargetFieldName());
    }
    wTargetFieldLength.setText("" + input.getTargetFieldLength());
    wRemoveSelectedFields.setSelection(input.isRemoveSelectedFields());
    // previous fields derived from TextFileOutputDialog
    wSeparator.setText(Const.NVL(input.getSeparator(), ""));
    wEnclosure.setText(Const.NVL(input.getEnclosure(), ""));
    if (input.getEncoding() != null) {
        wEncoding.setText(input.getEncoding());
    }
    if (input.getEndedLine() != null) {
        wEndedLine.setText(input.getEndedLine());
    }
    wSplitEvery.setText("" + input.getSplitEvery());
    wEnclForced.setSelection(input.isEnclosureForced());
    wDisableEnclosureFix.setSelection(input.isEnclosureFixDisabled());
    wHeader.setSelection(input.isHeaderEnabled());
    wFooter.setSelection(input.isFooterEnabled());
    wPad.setSelection(input.isPadded());
    wFastDump.setSelection(input.isFastDump());
    logDebug("getting fields info...");
    for (int i = 0; i < input.getOutputFields().length; i++) {
        TextFileField field = input.getOutputFields()[i];
        TableItem item = wFields.table.getItem(i);
        if (field.getName() != null) {
            item.setText(1, field.getName());
        }
        item.setText(2, field.getTypeDesc());
        if (field.getFormat() != null) {
            item.setText(3, field.getFormat());
        }
        if (field.getLength() >= 0) {
            item.setText(4, "" + field.getLength());
        }
        if (field.getPrecision() >= 0) {
            item.setText(5, "" + field.getPrecision());
        }
        if (field.getCurrencySymbol() != null) {
            item.setText(6, field.getCurrencySymbol());
        }
        if (field.getDecimalSymbol() != null) {
            item.setText(7, field.getDecimalSymbol());
        }
        if (field.getGroupingSymbol() != null) {
            item.setText(8, field.getGroupingSymbol());
        }
        String trim = field.getTrimTypeDesc();
        if (trim != null) {
            item.setText(9, trim);
        }
        if (field.getNullString() != null) {
            item.setText(10, field.getNullString());
        }
    }
    wFields.optWidth(true);
    setFlags();
    wStepname.selectAll();
    wStepname.setFocus();
}
Also used : TextFileField(org.pentaho.di.trans.steps.textfileoutput.TextFileField) TableItem(org.eclipse.swt.widgets.TableItem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point)

Example 2 with TextFileField

use of org.pentaho.di.trans.steps.textfileoutput.TextFileField in project pentaho-kettle by pentaho.

the class TextFileOutputDialog method saveInfoInMeta.

private void saveInfoInMeta(TextFileOutputMeta tfoi) {
    tfoi.setFileName(wFilename.getText());
    tfoi.setFileAsCommand(wFileIsCommand.getSelection());
    tfoi.setServletOutput(wServletOutput.getSelection());
    tfoi.setCreateParentFolder(wCreateParentFolder.getSelection());
    tfoi.setDoNotOpenNewFileInit(wDoNotOpenNewFileInit.getSelection());
    tfoi.setFileFormat(TextFileOutputMeta.formatMapperLineTerminator[wFormat.getSelectionIndex()]);
    tfoi.setFileCompression(wCompression.getText());
    tfoi.setEncoding(wEncoding.getText());
    tfoi.setSeparator(wSeparator.getText());
    tfoi.setEnclosure(wEnclosure.getText());
    tfoi.setExtension(wExtension.getText());
    tfoi.setSplitEvery(Const.toInt(wSplitEvery.getText(), 0));
    tfoi.setEndedLine(wEndedLine.getText());
    tfoi.setFileNameField(wFileNameField.getText());
    tfoi.setFileNameInField(wFileNameInField.getSelection());
    tfoi.setEnclosureForced(wEnclForced.getSelection());
    tfoi.setEnclosureFixDisabled(wDisableEnclosureFix.getSelection());
    tfoi.setHeaderEnabled(wHeader.getSelection());
    tfoi.setFooterEnabled(wFooter.getSelection());
    tfoi.setFileAppended(wAppend.getSelection());
    tfoi.setStepNrInFilename(wAddStepnr.getSelection());
    tfoi.setPartNrInFilename(wAddPartnr.getSelection());
    tfoi.setDateInFilename(wAddDate.getSelection());
    tfoi.setTimeInFilename(wAddTime.getSelection());
    tfoi.setDateTimeFormat(wDateTimeFormat.getText());
    tfoi.setSpecifyingFormat(wSpecifyFormat.getSelection());
    tfoi.setPadded(wPad.getSelection());
    tfoi.setAddToResultFiles(wAddToResult.getSelection());
    tfoi.setFastDump(wFastDump.getSelection());
    int i;
    // Table table = wFields.table;
    int nrfields = wFields.nrNonEmpty();
    tfoi.allocate(nrfields);
    for (i = 0; i < nrfields; i++) {
        TextFileField field = new TextFileField();
        TableItem item = wFields.getNonEmpty(i);
        field.setName(item.getText(1));
        field.setType(item.getText(2));
        field.setFormat(item.getText(3));
        field.setLength(Const.toInt(item.getText(4), -1));
        field.setPrecision(Const.toInt(item.getText(5), -1));
        field.setCurrencySymbol(item.getText(6));
        field.setDecimalSymbol(item.getText(7));
        field.setGroupingSymbol(item.getText(8));
        field.setTrimType(ValueMetaString.getTrimTypeByDesc(item.getText(9)));
        field.setNullString(item.getText(10));
        // CHECKSTYLE:Indentation:OFF
        tfoi.getOutputFields()[i] = field;
    }
}
Also used : TextFileField(org.pentaho.di.trans.steps.textfileoutput.TextFileField) TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point)

Example 3 with TextFileField

use of org.pentaho.di.trans.steps.textfileoutput.TextFileField in project pentaho-kettle by pentaho.

the class ConcatFieldsMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // remove selected fields from the stream when true
    if (removeSelectedFields) {
        if (getOutputFields().length > 0) {
            for (int i = 0; i < getOutputFields().length; i++) {
                TextFileField field = getOutputFields()[i];
                try {
                    row.removeValueMeta(field.getName());
                } catch (KettleValueException e) {
                // just ignore exceptions since missing fields are handled in the ConcatFields class
                }
            }
        } else {
            // no output fields selected, take them all, remove them all
            row.clear();
        }
    }
    // Check Target Field Name
    if (Utils.isEmpty(targetFieldName)) {
        throw new KettleStepException(BaseMessages.getString(PKG, "ConcatFieldsMeta.CheckResult.TargetFieldNameMissing"));
    }
    // add targetFieldName
    ValueMetaInterface vValue = new ValueMetaString(targetFieldName);
    vValue.setLength(targetFieldLength, 0);
    vValue.setOrigin(name);
    if (!Utils.isEmpty(getEncoding())) {
        vValue.setStringEncoding(getEncoding());
    }
    row.addValueMeta(vValue);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) TextFileField(org.pentaho.di.trans.steps.textfileoutput.TextFileField) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 4 with TextFileField

use of org.pentaho.di.trans.steps.textfileoutput.TextFileField in project pentaho-kettle by pentaho.

the class ConcatFieldsMetaInjection method injectStepMetadataEntries.

@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> all) throws KettleException {
    List<String> concatFields = new ArrayList<String>();
    List<String> concatTypes = new ArrayList<String>();
    List<String> concatLengths = new ArrayList<String>();
    List<String> concatFormats = new ArrayList<String>();
    List<String> concatPrecisions = new ArrayList<String>();
    List<String> concatCurrencies = new ArrayList<String>();
    List<String> concatDecimals = new ArrayList<String>();
    List<String> concatGroups = new ArrayList<String>();
    List<String> concatTrims = new ArrayList<String>();
    List<String> concatNulls = new ArrayList<String>();
    // 
    for (StepInjectionMetaEntry lookFields : all) {
        Entry fieldsEntry = Entry.findEntry(lookFields.getKey());
        if (fieldsEntry == null) {
            continue;
        }
        String lookValue = (String) lookFields.getValue();
        switch(fieldsEntry) {
            case CONCAT_FIELDS:
                for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
                    Entry fieldEntry = Entry.findEntry(lookField.getKey());
                    if (fieldEntry == Entry.CONCAT_FIELD) {
                        String concatFieldname = null;
                        String concatType = null;
                        String concatLength = null;
                        String concatFormat = null;
                        String concatPrecision = null;
                        String concatCurrency = null;
                        String concatDecimal = null;
                        String concatGroup = null;
                        String concatTrim = null;
                        String concatNull = null;
                        List<StepInjectionMetaEntry> entries = lookField.getDetails();
                        for (StepInjectionMetaEntry entry : entries) {
                            Entry metaEntry = Entry.findEntry(entry.getKey());
                            if (metaEntry != null) {
                                String value = (String) entry.getValue();
                                switch(metaEntry) {
                                    case CONCAT_FIELDNAME:
                                        concatFieldname = value;
                                        break;
                                    case CONCAT_TYPE:
                                        concatType = value;
                                        break;
                                    case CONCAT_LENGTH:
                                        concatLength = value;
                                        break;
                                    case CONCAT_FORMAT:
                                        concatFormat = value;
                                        break;
                                    case CONCAT_PRECISION:
                                        concatPrecision = value;
                                        break;
                                    case CONCAT_CURRENCY:
                                        concatCurrency = value;
                                        break;
                                    case CONCAT_DECIMAL:
                                        concatDecimal = value;
                                        break;
                                    case CONCAT_GROUP:
                                        concatGroup = value;
                                        break;
                                    case CONCAT_TRIM:
                                        concatTrim = value;
                                        break;
                                    case CONCAT_NULL:
                                        concatNull = value;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                        concatFields.add(concatFieldname);
                        concatTypes.add(concatType);
                        concatLengths.add(concatLength);
                        concatFormats.add(concatFormat);
                        concatPrecisions.add(concatPrecision);
                        concatCurrencies.add(concatCurrency);
                        concatDecimals.add(concatDecimal);
                        concatGroups.add(concatGroup);
                        concatTrims.add(concatTrim);
                        concatNulls.add(concatNull);
                    }
                }
                break;
            case TARGET_FIELDNAME:
                meta.setTargetFieldName(lookValue);
                break;
            case TARGET_LENGTH:
                meta.setTargetFieldLength(Const.toInt(lookValue, 0));
                break;
            case SEPARATOR:
                meta.setSeparator(lookValue);
                break;
            case ENCLOSURE:
                meta.setEnclosure(lookValue);
                break;
            case REMOVE_FIELDS:
                meta.setRemoveSelectedFields("Y".equalsIgnoreCase(lookValue));
                break;
            case FORCE_ENCLOSURE:
                meta.setEnclosureForced("Y".equalsIgnoreCase(lookValue));
                break;
            case DISABLE_ENCLOSURE_FIX:
                meta.setEnclosureFixDisabled("Y".equalsIgnoreCase(lookValue));
                break;
            case HEADER:
                meta.setHeaderEnabled("Y".equalsIgnoreCase(lookValue));
                break;
            case FOOTER:
                meta.setFooterEnabled("Y".equalsIgnoreCase(lookValue));
                break;
            case ENCODING:
                meta.setEncoding(lookValue);
                break;
            case RIGHT_PAD_FIELDS:
                meta.setPadded("Y".equalsIgnoreCase(lookValue));
                break;
            case FAST_DATA_DUMP:
                meta.setFastDump("Y".equalsIgnoreCase(lookValue));
                break;
            case SPLIT_EVERY:
                meta.setSplitEvery(Const.toInt(lookValue, 0));
                break;
            case ADD_ENDING_LINE:
                meta.setEndedLine(lookValue);
                break;
            default:
                break;
        }
    }
    // 
    if (concatFields.size() > 0) {
        TextFileField[] tff = new TextFileField[concatFields.size()];
        Iterator<String> iConcatFields = concatFields.iterator();
        Iterator<String> iConcatTypes = concatTypes.iterator();
        Iterator<String> iConcatLengths = concatLengths.iterator();
        Iterator<String> iConcatFormats = concatFormats.iterator();
        Iterator<String> iConcatPrecisions = concatPrecisions.iterator();
        Iterator<String> iConcatCurrencies = concatCurrencies.iterator();
        Iterator<String> iConcatDecimals = concatDecimals.iterator();
        Iterator<String> iConcatGroups = concatGroups.iterator();
        Iterator<String> iConcatTrims = concatTrims.iterator();
        Iterator<String> iConcatNulls = concatNulls.iterator();
        int i = 0;
        while (iConcatFields.hasNext()) {
            TextFileField field = new TextFileField();
            field.setName(iConcatFields.next());
            field.setType(ValueMetaFactory.getIdForValueMeta(iConcatTypes.next()));
            field.setFormat(iConcatFormats.next());
            field.setLength(Const.toInt(iConcatLengths.next(), -1));
            field.setPrecision(Const.toInt(iConcatPrecisions.next(), -1));
            field.setCurrencySymbol(iConcatCurrencies.next());
            field.setDecimalSymbol(iConcatDecimals.next());
            field.setGroupingSymbol(iConcatGroups.next());
            field.setNullString(iConcatNulls.next());
            field.setTrimType(ValueMetaBase.getTrimTypeByDesc(iConcatTrims.next()));
            tff[i] = field;
            i++;
        }
        meta.setOutputFields(tff);
    }
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) TextFileField(org.pentaho.di.trans.steps.textfileoutput.TextFileField) ArrayList(java.util.ArrayList) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 5 with TextFileField

use of org.pentaho.di.trans.steps.textfileoutput.TextFileField in project pentaho-metaverse by pentaho.

the class TextFileOutputStepAnalyzer method getOutputResourceFields.

@Override
public Set<String> getOutputResourceFields(TextFileOutputMeta meta) {
    Set<String> fields = new HashSet<>();
    TextFileField[] outputFields = meta.getOutputFields();
    for (int i = 0; i < outputFields.length; i++) {
        TextFileField outputField = outputFields[i];
        fields.add(outputField.getName());
    }
    return fields;
}
Also used : TextFileField(org.pentaho.di.trans.steps.textfileoutput.TextFileField) HashSet(java.util.HashSet)

Aggregations

TextFileField (org.pentaho.di.trans.steps.textfileoutput.TextFileField)8 Point (org.eclipse.swt.graphics.Point)4 TableItem (org.eclipse.swt.widgets.TableItem)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)1