use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class ParGzipCsvInputMetaInjection method injectStepMetadataEntries.
@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> all) throws KettleException {
List<TextFileInputField> fields = new ArrayList<TextFileInputField>();
//
for (StepInjectionMetaEntry lookFields : all) {
Entry fieldsEntry = Entry.findEntry(lookFields.getKey());
if (fieldsEntry == null) {
continue;
}
String lookValue = (String) lookFields.getValue();
switch(fieldsEntry) {
case FIELDS:
for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
Entry fieldEntry = Entry.findEntry(lookField.getKey());
if (fieldEntry == Entry.FIELD) {
TextFileInputField field = new TextFileInputField();
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 FIELD_NAME:
field.setName(value);
break;
case FIELD_POSITION:
field.setPosition(Const.toInt(value, -1));
break;
case FIELD_LENGTH:
field.setLength(Const.toInt(value, -1));
break;
case FIELD_TYPE:
field.setType(ValueMetaFactory.getIdForValueMeta(value));
break;
case FIELD_IGNORE:
field.setIgnored("Y".equalsIgnoreCase(value));
break;
case FIELD_FORMAT:
field.setFormat(value);
break;
case FIELD_TRIM_TYPE:
field.setTrimType(ValueMetaString.getTrimTypeByCode(value));
break;
case FIELD_PRECISION:
field.setPrecision(Const.toInt(value, -1));
break;
case FIELD_DECIMAL:
field.setDecimalSymbol(value);
break;
case FIELD_GROUP:
field.setGroupSymbol(value);
break;
case FIELD_CURRENCY:
field.setCurrencySymbol(value);
break;
case FIELD_REPEAT:
field.setRepeated("Y".equalsIgnoreCase(value));
break;
case FIELD_NULL_STRING:
field.setNullString(value);
break;
case FIELD_IF_NULL:
field.setIfNullValue(value);
break;
default:
break;
}
}
}
fields.add(field);
}
}
break;
case FILENAME:
meta.setFilename(lookValue);
break;
case FILENAME_FIELD:
meta.setFilenameField(lookValue);
break;
case ROW_NUMBER_FIELD:
meta.setRowNumField(lookValue);
break;
case INCLUDING_FILENAMES:
meta.setIncludingFilename("Y".equalsIgnoreCase(lookValue));
break;
case DELIMITER:
meta.setDelimiter(lookValue);
break;
case ENCLOSURE:
meta.setEnclosure(lookValue);
break;
case HEADER_PRESENT:
meta.setHeaderPresent("Y".equalsIgnoreCase(lookValue));
break;
case BUFFER_SIZE:
meta.setBufferSize(lookValue);
break;
case LAZY_CONVERSION:
meta.setLazyConversionActive("Y".equalsIgnoreCase(lookValue));
break;
case ADD_FILES_TO_RESULT:
meta.setAddResultFile("Y".equalsIgnoreCase(lookValue));
break;
case RUN_IN_PARALLEL:
meta.setRunningInParallel("Y".equalsIgnoreCase(lookValue));
break;
case ENCODING:
meta.setEncoding(lookValue);
break;
default:
break;
}
}
//
if (fields.size() > 0) {
meta.setInputFields(fields.toArray(new TextFileInputField[fields.size()]));
}
}
use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class CsvInputMeta method injectStepMetadataEntries.
@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> metadata) {
for (StepInjectionMetaEntry entry : metadata) {
KettleAttributeInterface attr = findAttribute(entry.getKey());
//
if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
if (attr.getKey().equals("FILENAME")) {
filename = (String) entry.getValue();
} else if (attr.getKey().equals("FILENAME_FIELD")) {
filenameField = (String) entry.getValue();
} else if (attr.getKey().equals("ROW_NUM_FIELD")) {
rowNumField = (String) entry.getValue();
} else if (attr.getKey().equals("HEADER_PRESENT")) {
headerPresent = (Boolean) entry.getValue();
} else if (attr.getKey().equals("DELIMITER")) {
delimiter = (String) entry.getValue();
} else if (attr.getKey().equals("ENCLOSURE")) {
enclosure = (String) entry.getValue();
} else if (attr.getKey().equals("BUFFERSIZE")) {
bufferSize = (String) entry.getValue();
} else if (attr.getKey().equals("LAZY_CONVERSION")) {
lazyConversionActive = (Boolean) entry.getValue();
} else if (attr.getKey().equals("PARALLEL")) {
runningInParallel = (Boolean) entry.getValue();
} else if (attr.getKey().equals("NEWLINE_POSSIBLE")) {
newlinePossibleInFields = (Boolean) entry.getValue();
} else if (attr.getKey().equals("ADD_FILENAME_RESULT")) {
isaddresult = (Boolean) entry.getValue();
} else if (attr.getKey().equals("ENCODING")) {
encoding = (String) entry.getValue();
} else {
throw new RuntimeException("Unhandled metadata injection of attribute: " + attr.toString() + " - " + attr.getDescription());
}
} else {
if (attr.getKey().equals("FIELDS")) {
// This entry contains a list of lists...
// Each list contains a single CSV input field definition (one line in the dialog)
//
List<StepInjectionMetaEntry> inputFieldEntries = entry.getDetails();
inputFields = new TextFileInputField[inputFieldEntries.size()];
for (int row = 0; row < inputFieldEntries.size(); row++) {
StepInjectionMetaEntry inputFieldEntry = inputFieldEntries.get(row);
TextFileInputField inputField = new TextFileInputField();
List<StepInjectionMetaEntry> fieldAttributes = inputFieldEntry.getDetails();
for (int i = 0; i < fieldAttributes.size(); i++) {
StepInjectionMetaEntry fieldAttribute = fieldAttributes.get(i);
KettleAttributeInterface fieldAttr = findAttribute(fieldAttribute.getKey());
String attributeValue = (String) fieldAttribute.getValue();
if (fieldAttr.getKey().equals("FIELD_NAME")) {
inputField.setName(attributeValue);
} else if (fieldAttr.getKey().equals("FIELD_TYPE")) {
inputField.setType(ValueMetaFactory.getIdForValueMeta(attributeValue));
} else if (fieldAttr.getKey().equals("FIELD_FORMAT")) {
inputField.setFormat(attributeValue);
} else if (fieldAttr.getKey().equals("FIELD_LENGTH")) {
inputField.setLength(attributeValue == null ? -1 : Integer.parseInt(attributeValue));
} else if (fieldAttr.getKey().equals("FIELD_PRECISION")) {
inputField.setPrecision(attributeValue == null ? -1 : Integer.parseInt(attributeValue));
} else if (fieldAttr.getKey().equals("FIELD_CURRENCY")) {
inputField.setCurrencySymbol(attributeValue);
} else if (fieldAttr.getKey().equals("FIELD_DECIMAL")) {
inputField.setDecimalSymbol(attributeValue);
} else if (fieldAttr.getKey().equals("FIELD_GROUP")) {
inputField.setGroupSymbol(attributeValue);
} else if (fieldAttr.getKey().equals("FIELD_TRIM_TYPE")) {
inputField.setTrimType(ValueMetaString.getTrimTypeByCode(attributeValue));
} else {
throw new RuntimeException("Unhandled metadata injection of attribute: " + fieldAttr.toString() + " - " + fieldAttr.getDescription());
}
}
inputFields[row] = inputField;
}
}
}
}
}
use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class CsvInputMeta method saveRep.
@Override
public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step) throws KettleException {
try {
rep.saveStepAttribute(id_transformation, id_step, getRepCode("FILENAME"), filename);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("FILENAME_FIELD"), filenameField);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("ROW_NUM_FIELD"), rowNumField);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("INCLUDE_FILENAME"), includingFilename);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("DELIMITER"), delimiter);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("ENCLOSURE"), enclosure);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("BUFFERSIZE"), bufferSize);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("HEADER_PRESENT"), headerPresent);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("LAZY_CONVERSION"), lazyConversionActive);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("ADD_FILENAME_RESULT"), isaddresult);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("PARALLEL"), runningInParallel);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("NEWLINE_POSSIBLE"), newlinePossibleInFields);
rep.saveStepAttribute(id_transformation, id_step, getRepCode("ENCODING"), encoding);
for (int i = 0; i < inputFields.length; i++) {
TextFileInputField field = inputFields[i];
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_NAME"), field.getName());
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_TYPE"), ValueMetaFactory.getValueMetaName(field.getType()));
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_FORMAT"), field.getFormat());
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_CURRENCY"), field.getCurrencySymbol());
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_DECIMAL"), field.getDecimalSymbol());
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_GROUP"), field.getGroupSymbol());
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_LENGTH"), field.getLength());
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_PRECISION"), field.getPrecision());
rep.saveStepAttribute(id_transformation, id_step, i, getRepCode("FIELD_TRIM_TYPE"), ValueMetaString.getTrimTypeCode(field.getTrimType()));
}
} catch (Exception e) {
throw new KettleException("Unable to save step information to the repository for id_step=" + id_step, e);
}
}
use of org.pentaho.di.trans.steps.textfileinput.TextFileInputField in project pentaho-kettle by pentaho.
the class CsvInputMeta method readData.
private void readData(Node stepnode) throws KettleXMLException {
try {
filename = XMLHandler.getTagValue(stepnode, getXmlCode("FILENAME"));
filenameField = XMLHandler.getTagValue(stepnode, getXmlCode("FILENAME_FIELD"));
rowNumField = XMLHandler.getTagValue(stepnode, getXmlCode("ROW_NUM_FIELD"));
includingFilename = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, getXmlCode("INCLUDE_FILENAME")));
delimiter = XMLHandler.getTagValue(stepnode, getXmlCode("DELIMITER"));
enclosure = XMLHandler.getTagValue(stepnode, getXmlCode("ENCLOSURE"));
bufferSize = XMLHandler.getTagValue(stepnode, getXmlCode("BUFFERSIZE"));
headerPresent = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, getXmlCode("HEADER_PRESENT")));
lazyConversionActive = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, getXmlCode("LAZY_CONVERSION")));
isaddresult = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, getXmlCode("ADD_FILENAME_RESULT")));
runningInParallel = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, getXmlCode("PARALLEL")));
String nlp = XMLHandler.getTagValue(stepnode, getXmlCode("NEWLINE_POSSIBLE"));
if (Utils.isEmpty(nlp)) {
if (runningInParallel) {
newlinePossibleInFields = false;
} else {
newlinePossibleInFields = true;
}
} else {
newlinePossibleInFields = "Y".equalsIgnoreCase(nlp);
}
encoding = XMLHandler.getTagValue(stepnode, getXmlCode("ENCODING"));
Node fields = XMLHandler.getSubNode(stepnode, getXmlCode("FIELDS"));
int nrfields = XMLHandler.countNodes(fields, getXmlCode("FIELD"));
allocate(nrfields);
for (int i = 0; i < nrfields; i++) {
inputFields[i] = new TextFileInputField();
Node fnode = XMLHandler.getSubNodeByNr(fields, getXmlCode("FIELD"), i);
inputFields[i].setName(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_NAME")));
inputFields[i].setType(ValueMetaFactory.getIdForValueMeta(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_TYPE"))));
inputFields[i].setFormat(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_FORMAT")));
inputFields[i].setCurrencySymbol(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_CURRENCY")));
inputFields[i].setDecimalSymbol(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_DECIMAL")));
inputFields[i].setGroupSymbol(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_GROUP")));
inputFields[i].setLength(Const.toInt(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_LENGTH")), -1));
inputFields[i].setPrecision(Const.toInt(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_PRECISION")), -1));
inputFields[i].setTrimType(ValueMetaString.getTrimTypeByCode(XMLHandler.getTagValue(fnode, getXmlCode("FIELD_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 CsvInputMeta method setDefault.
@Override
public void setDefault() {
delimiter = ",";
enclosure = "\"";
headerPresent = true;
lazyConversionActive = true;
isaddresult = false;
bufferSize = "50000";
TextFileInputField field = new TextFileInputField();
field.setName("field");
field.setType(ValueMetaInterface.TYPE_STRING);
inputFields = new TextFileInputField[] { field };
}
Aggregations