Search in sources :

Example 1 with KettleAttributeInterface

use of org.pentaho.di.core.KettleAttributeInterface in project pentaho-kettle by pentaho.

the class MonetDBBulkLoaderMeta method injectStepMetadataEntries.

public void injectStepMetadataEntries(List<StepInjectionMetaEntry> metadata) {
    for (StepInjectionMetaEntry entry : metadata) {
        KettleAttributeInterface attr = findAttribute(entry.getKey());
        // 
        if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
            if (entry.getKey().equals("SCHEMA")) {
                schemaName = (String) entry.getValue();
            } else if (entry.getKey().equals("TABLE")) {
                tableName = (String) entry.getValue();
            } else if (entry.getKey().equals("LOGFILE")) {
                logFile = (String) entry.getValue();
            } else if (entry.getKey().equals("FIELD_SEPARATOR")) {
                fieldSeparator = (String) entry.getValue();
            } else if (entry.getKey().equals("FIELD_ENCLOSURE")) {
                fieldEnclosure = (String) entry.getValue();
            } else if (entry.getKey().equals("NULL_REPRESENTATION")) {
                setNULLrepresentation((String) entry.getValue());
            } else if (entry.getKey().equals("ENCODING")) {
                encoding = (String) entry.getValue();
            } else if (entry.getKey().equals("BUFFER_SIZE")) {
                bufferSize = (String) entry.getValue();
            } else if (entry.getKey().equals("TRUNCATE")) {
                truncate = (Boolean) entry.getValue();
            } else if (entry.getKey().equals("FULLY_QUOTE_SQL")) {
                fullyQuoteSQL = (Boolean) entry.getValue();
            } else {
                throw new RuntimeException("Unhandled metadata injection of attribute: " + attr.toString() + " - " + attr.getDescription());
            }
        } else {
            // 
            if (attr.getKey().equals("MAPPINGS")) {
                List<StepInjectionMetaEntry> selectMappings = entry.getDetails();
                fieldTable = new String[selectMappings.size()];
                fieldStream = new String[selectMappings.size()];
                fieldFormatOk = new boolean[selectMappings.size()];
                for (int row = 0; row < selectMappings.size(); row++) {
                    StepInjectionMetaEntry selectField = selectMappings.get(row);
                    List<StepInjectionMetaEntry> fieldAttributes = selectField.getDetails();
                    // CHECKSTYLE:Indentation:OFF
                    for (int i = 0; i < fieldAttributes.size(); i++) {
                        StepInjectionMetaEntry fieldAttribute = fieldAttributes.get(i);
                        KettleAttributeInterface fieldAttr = findAttribute(fieldAttribute.getKey());
                        Object attributeValue = fieldAttribute.getValue();
                        if (attributeValue == null) {
                            continue;
                        }
                        if (fieldAttr.getKey().equals("STREAMNAME")) {
                            getFieldStream()[row] = (String) attributeValue;
                        } else if (fieldAttr.getKey().equals("FIELDNAME")) {
                            getFieldTable()[row] = (String) attributeValue;
                        } else if (fieldAttr.getKey().equals("FIELD_FORMAT_OK")) {
                            getFieldFormatOk()[row] = (Boolean) attributeValue;
                        } else {
                            throw new RuntimeException("Unhandled metadata injection of attribute: " + fieldAttr.toString() + " - " + fieldAttr.getDescription());
                        }
                    }
                }
            }
            if (!Utils.isEmpty(getFieldStream())) {
                for (int i = 0; i < getFieldStream().length; i++) {
                    logDetailed("row " + Integer.toString(i) + ": stream=" + getFieldStream()[i] + " : table=" + getFieldTable()[i]);
                }
            }
        }
    }
}
Also used : KettleAttributeInterface(org.pentaho.di.core.KettleAttributeInterface) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 2 with KettleAttributeInterface

use of org.pentaho.di.core.KettleAttributeInterface in project pentaho-kettle by pentaho.

the class PGBulkLoaderMeta method injectStepMetadataEntries.

public void injectStepMetadataEntries(List<StepInjectionMetaEntry> metadata) {
    for (StepInjectionMetaEntry entry : metadata) {
        KettleAttributeInterface attr = findAttribute(entry.getKey());
        // 
        if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
            if (entry.getKey().equals("SCHEMA")) {
                schemaName = (String) entry.getValue();
            } else if (entry.getKey().equals("TABLE")) {
                tableName = (String) entry.getValue();
            } else if (entry.getKey().equals("LOADACTION")) {
                loadAction = (String) entry.getValue();
            } else if (entry.getKey().equals("DBNAMEOVERRIDE")) {
                dbNameOverride = (String) entry.getValue();
            } else if (entry.getKey().equals("ENCLOSURE")) {
                enclosure = (String) entry.getValue();
            } else if (entry.getKey().equals("DELIMITER")) {
                delimiter = (String) entry.getValue();
            } else if (entry.getKey().equals("STOPONERROR")) {
                stopOnError = (Boolean) entry.getValue();
            } else {
                throw new RuntimeException("Unhandled metadata injection of attribute: " + attr.toString() + " - " + attr.getDescription());
            }
        } else {
            // 
            if (attr.getKey().equals("MAPPINGS")) {
                List<StepInjectionMetaEntry> selectMappings = entry.getDetails();
                fieldTable = new String[selectMappings.size()];
                fieldStream = new String[selectMappings.size()];
                dateMask = new String[selectMappings.size()];
                for (int row = 0; row < selectMappings.size(); row++) {
                    StepInjectionMetaEntry selectField = selectMappings.get(row);
                    List<StepInjectionMetaEntry> fieldAttributes = selectField.getDetails();
                    // CHECKSTYLE:Indentation:OFF
                    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("STREAMNAME")) {
                            getFieldStream()[row] = attributeValue;
                        } else if (fieldAttr.getKey().equals("FIELDNAME")) {
                            getFieldTable()[row] = attributeValue;
                        } else if (fieldAttr.getKey().equals("DATEMASK")) {
                            getDateMask()[row] = attributeValue;
                        } else {
                            throw new RuntimeException("Unhandled metadata injection of attribute: " + fieldAttr.toString() + " - " + fieldAttr.getDescription());
                        }
                    }
                }
            }
            if (!Utils.isEmpty(getFieldStream())) {
                for (int i = 0; i < getFieldStream().length; i++) {
                    logDetailed("row " + Integer.toString(i) + ": stream=" + getFieldStream()[i] + " : table=" + getFieldTable()[i]);
                }
            }
        }
    }
}
Also used : KettleAttributeInterface(org.pentaho.di.core.KettleAttributeInterface) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 3 with KettleAttributeInterface

use of org.pentaho.di.core.KettleAttributeInterface in project pentaho-kettle by pentaho.

the class BaseStepMeta method loadStepAttributes.

/**
 * Load step attributes.
 *
 * @throws KettleException the kettle exception
 */
protected void loadStepAttributes() throws KettleException {
    try (InputStream inputStream = getClass().getResourceAsStream(STEP_ATTRIBUTES_FILE)) {
        if (inputStream != null) {
            Document document = XMLHandler.loadXMLFile(inputStream);
            Node attrsNode = XMLHandler.getSubNode(document, "attributes");
            List<Node> nodes = XMLHandler.getNodes(attrsNode, "attribute");
            attributes = new ArrayList<KettleAttributeInterface>();
            for (Node node : nodes) {
                String key = XMLHandler.getTagAttribute(node, "id");
                String xmlCode = XMLHandler.getTagValue(node, "xmlcode");
                String repCode = XMLHandler.getTagValue(node, "repcode");
                String description = XMLHandler.getTagValue(node, "description");
                String tooltip = XMLHandler.getTagValue(node, "tooltip");
                int valueType = ValueMetaFactory.getIdForValueMeta(XMLHandler.getTagValue(node, "valuetype"));
                String parentId = XMLHandler.getTagValue(node, "parentid");
                KettleAttribute attribute = new KettleAttribute(key, xmlCode, repCode, description, tooltip, valueType, findParent(attributes, parentId));
                attributes.add(attribute);
            }
        }
    } catch (Exception e) {
        throw new KettleException("Unable to load file " + STEP_ATTRIBUTES_FILE, e);
    }
}
Also used : KettleAttributeInterface(org.pentaho.di.core.KettleAttributeInterface) KettleException(org.pentaho.di.core.exception.KettleException) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) KettleAttribute(org.pentaho.di.core.KettleAttribute) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 4 with KettleAttributeInterface

use of org.pentaho.di.core.KettleAttributeInterface in project pentaho-kettle by pentaho.

the class BaseStepMeta method getStepInjectionMetadataEntries.

/**
 * Describe the metadata attributes that can be injected into this step metadata object.
 */
public List<StepInjectionMetaEntry> getStepInjectionMetadataEntries(Class<?> PKG) {
    List<StepInjectionMetaEntry> entries = new ArrayList<StepInjectionMetaEntry>();
    for (KettleAttributeInterface attr : attributes) {
        if (attr.getParent() == null) {
            entries.add(createEntry(attr, PKG));
        } else {
            StepInjectionMetaEntry entry = createEntry(attr, PKG);
            StepInjectionMetaEntry parentEntry = findParentEntry(entries, attr.getParent().getKey());
            if (parentEntry == null) {
                throw new RuntimeException("An error was detected in the step attributes' definition: the parent was not found for attribute " + attr);
            }
            parentEntry.getDetails().add(entry);
        }
    }
    return entries;
}
Also used : KettleAttributeInterface(org.pentaho.di.core.KettleAttributeInterface) ArrayList(java.util.ArrayList)

Example 5 with KettleAttributeInterface

use of org.pentaho.di.core.KettleAttributeInterface 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("FORMAT")) {
                fileFormat = (String) 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;
                }
            }
        }
    }
}
Also used : KettleAttributeInterface(org.pentaho.di.core.KettleAttributeInterface) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Aggregations

KettleAttributeInterface (org.pentaho.di.core.KettleAttributeInterface)5 StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)3 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 KettleAttribute (org.pentaho.di.core.KettleAttribute)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 TextFileInputField (org.pentaho.di.trans.steps.textfileinput.TextFileInputField)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1