Search in sources :

Example 26 with KettlePluginException

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

the class RowsFromResultMeta method getFields.

public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < this.fieldname.length; i++) {
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(fieldname[i], type[i], length[i], precision[i]);
            v.setOrigin(origin);
            r.addValueMeta(v);
        } catch (KettlePluginException e) {
            throw new KettleStepException(e);
        }
    }
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 27 with KettlePluginException

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

the class ScriptMeta method getFields.

public void getFields(RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < fieldname.length; i++) {
        if (!Utils.isEmpty(fieldname[i])) {
            String fieldName;
            int replaceIndex;
            int fieldType;
            if (replace[i]) {
                // 
                if (row.searchValueMeta(fieldname[i]) == null && Utils.isEmpty(rename[i])) {
                    throw new KettleStepException(BaseMessages.getString(PKG, "ScriptMeta.Exception.FieldToReplaceNotFound", fieldname[i]));
                }
                replaceIndex = row.indexOfValue(rename[i]);
                // Change the data type to match what's specified...
                // 
                fieldType = type[i];
                fieldName = rename[i];
            } else {
                replaceIndex = -1;
                fieldType = type[i];
                if (rename[i] != null && rename[i].length() != 0) {
                    fieldName = rename[i];
                } else {
                    fieldName = fieldname[i];
                }
            }
            try {
                ValueMetaInterface v = ValueMetaFactory.createValueMeta(fieldName, fieldType);
                v.setLength(length[i]);
                v.setPrecision(precision[i]);
                v.setOrigin(originStepname);
                if (replace[i] && replaceIndex >= 0) {
                    row.setValueMeta(replaceIndex, v);
                } else {
                    row.addValueMeta(v);
                }
            } catch (KettlePluginException e) {
            // Ignore errors
            }
        }
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 28 with KettlePluginException

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

the class CarteServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    cartePluginRegistry = new ConcurrentHashMap<String, CartePluginInterface>();
    detections = Collections.synchronizedList(new ArrayList<SlaveServerDetection>());
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    List<PluginInterface> plugins = pluginRegistry.getPlugins(CartePluginType.class);
    // Initial Registry scan
    for (PluginInterface plugin : plugins) {
        try {
            registerServlet(loadServlet(plugin));
        } catch (KettlePluginException e) {
            log.logError("Unable to instantiate plugin for use with CarteServlet " + plugin.getName());
        }
    }
    // Servlets configured in web.xml take precedence to those discovered during plugin scan
    @SuppressWarnings("unchecked") Enumeration<String> initParameterNames = config.getInitParameterNames();
    while (initParameterNames.hasMoreElements()) {
        final String paramName = initParameterNames.nextElement();
        final String className = config.getInitParameter(paramName);
        final Class<?> clazz;
        try {
            clazz = Class.forName(className);
            registerServlet((CartePluginInterface) clazz.newInstance());
        } catch (ClassNotFoundException e) {
            log.logError("Unable to find configured " + paramName + " of " + className, e);
        } catch (InstantiationException e) {
            log.logError("Unable to instantiate configured " + paramName + " of " + className, e);
        } catch (IllegalAccessException e) {
            log.logError("Unable to access configured " + paramName + " of " + className, e);
        } catch (ClassCastException e) {
            log.logError("Unable to cast configured " + paramName + " of " + className + " to " + CartePluginInterface.class, e);
        }
    }
    // Catch servlets as they become available
    pluginRegistry.addPluginListener(CartePluginType.class, new PluginTypeListener() {

        @Override
        public void pluginAdded(Object serviceObject) {
            try {
                registerServlet(loadServlet((PluginInterface) serviceObject));
            } catch (KettlePluginException e) {
                log.logError(MessageFormat.format("Unable to load plugin: {0}", serviceObject), e);
            }
        }

        @Override
        public void pluginRemoved(Object serviceObject) {
            try {
                String key = getServletKey(loadServlet((PluginInterface) serviceObject));
                cartePluginRegistry.remove(key);
            } catch (KettlePluginException e) {
                log.logError(MessageFormat.format("Unable to load plugin: {0}", serviceObject), e);
            }
        }

        @Override
        public void pluginChanged(Object serviceObject) {
            pluginAdded(serviceObject);
        }
    });
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ArrayList(java.util.ArrayList) PluginTypeListener(org.pentaho.di.core.plugins.PluginTypeListener) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry)

Example 29 with KettlePluginException

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

the class GroupByMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) {
    // re-assemble a new row of metadata
    // 
    RowMetaInterface fields = new RowMeta();
    if (!passAllRows) {
        // 
        for (int i = 0; i < groupField.length; i++) {
            ValueMetaInterface valueMeta = rowMeta.searchValueMeta(groupField[i]);
            if (valueMeta != null) {
                fields.addValueMeta(valueMeta);
            }
        }
    } else {
        // Add all the original fields from the incoming row meta
        // 
        fields.addRowMeta(rowMeta);
    }
    // 
    for (int i = 0; i < subjectField.length; i++) {
        ValueMetaInterface subj = rowMeta.searchValueMeta(subjectField[i]);
        if (subj != null || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
            String valueName = aggregateField[i];
            int valueType = ValueMetaInterface.TYPE_NONE;
            int length = -1;
            int precision = -1;
            switch(aggregateType[i]) {
                case TYPE_GROUP_SUM:
                case TYPE_GROUP_AVERAGE:
                case TYPE_GROUP_CUMULATIVE_SUM:
                case TYPE_GROUP_CUMULATIVE_AVERAGE:
                case TYPE_GROUP_FIRST:
                case TYPE_GROUP_LAST:
                case TYPE_GROUP_FIRST_INCL_NULL:
                case TYPE_GROUP_LAST_INCL_NULL:
                case TYPE_GROUP_MIN:
                case TYPE_GROUP_MAX:
                    valueType = subj.getType();
                    break;
                case TYPE_GROUP_COUNT_DISTINCT:
                case TYPE_GROUP_COUNT_ANY:
                case TYPE_GROUP_COUNT_ALL:
                    valueType = ValueMetaInterface.TYPE_INTEGER;
                    break;
                case TYPE_GROUP_CONCAT_COMMA:
                    valueType = ValueMetaInterface.TYPE_STRING;
                    break;
                case TYPE_GROUP_STANDARD_DEVIATION:
                case TYPE_GROUP_MEDIAN:
                case TYPE_GROUP_PERCENTILE:
                    valueType = ValueMetaInterface.TYPE_NUMBER;
                    break;
                case TYPE_GROUP_CONCAT_STRING:
                    valueType = ValueMetaInterface.TYPE_STRING;
                    break;
                default:
                    break;
            }
            // 
            if (aggregateType[i] == TYPE_GROUP_CUMULATIVE_AVERAGE && valueType == ValueMetaInterface.TYPE_INTEGER) {
                valueType = ValueMetaInterface.TYPE_NUMBER;
                precision = -1;
                length = -1;
            } else if (aggregateType[i] == TYPE_GROUP_COUNT_ALL || aggregateType[i] == TYPE_GROUP_COUNT_DISTINCT || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
                length = ValueMetaInterface.DEFAULT_INTEGER_LENGTH;
                precision = 0;
            } else if (aggregateType[i] == TYPE_GROUP_SUM && valueType != ValueMetaInterface.TYPE_INTEGER && valueType != ValueMetaInterface.TYPE_NUMBER && valueType != ValueMetaInterface.TYPE_BIGNUMBER) {
                // If it ain't numeric, we change it to Number
                // 
                valueType = ValueMetaInterface.TYPE_NUMBER;
                precision = -1;
                length = -1;
            }
            if (valueType != ValueMetaInterface.TYPE_NONE) {
                ValueMetaInterface v;
                try {
                    v = ValueMetaFactory.createValueMeta(valueName, valueType);
                } catch (KettlePluginException e) {
                    v = new ValueMetaNone(valueName);
                }
                v.setOrigin(origin);
                v.setLength(length, precision);
                if (subj != null) {
                    v.setConversionMask(subj.getConversionMask());
                }
                fields.addValueMeta(v);
            }
        }
    }
    if (passAllRows) {
        // If we pass all rows, we can add a line nr in the group...
        if (addingLineNrInGroup && !Utils.isEmpty(lineNrInGroupField)) {
            ValueMetaInterface lineNr = new ValueMetaInteger(lineNrInGroupField);
            lineNr.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
            lineNr.setOrigin(origin);
            fields.addValueMeta(lineNr);
        }
    }
    // Now that we have all the fields we want, we should clear the original row and replace the values...
    // 
    rowMeta.clear();
    rowMeta.addRowMeta(fields);
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 30 with KettlePluginException

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

the class JobExecutorMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    row.clear();
    if (nextStep != null && resultRowsTargetStepMeta != null && nextStep.equals(resultRowsTargetStepMeta)) {
        for (int i = 0; i < resultRowsField.length; i++) {
            ValueMetaInterface value;
            try {
                value = ValueMetaFactory.createValueMeta(resultRowsField[i], resultRowsType[i], resultRowsLength[i], resultRowsPrecision[i]);
            } catch (KettlePluginException e) {
                value = new ValueMetaNone(resultRowsField[i]);
                value.setLength(resultRowsLength[i], resultRowsPrecision[i]);
            }
            row.addValueMeta(value);
        }
    } else if (nextStep != null && resultFilesTargetStepMeta != null && nextStep.equals(resultFilesTargetStepMeta)) {
        if (!Utils.isEmpty(resultFilesFileNameField)) {
            ValueMetaInterface value = new ValueMetaString("filename", 255, 0);
            row.addValueMeta(value);
        }
    } else if (nextStep != null && executionResultTargetStepMeta != null && nextStep.equals(executionResultTargetStepMeta)) {
        if (!Utils.isEmpty(executionTimeField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionTimeField, 15, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionResultField)) {
            ValueMetaInterface value = new ValueMetaBoolean(executionResultField);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionNrErrorsField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionNrErrorsField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLinesReadField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionLinesReadField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLinesWrittenField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionLinesWrittenField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLinesInputField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionLinesInputField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLinesOutputField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionLinesOutputField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLinesRejectedField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionLinesRejectedField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLinesUpdatedField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionLinesUpdatedField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLinesDeletedField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionLinesDeletedField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionFilesRetrievedField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionFilesRetrievedField, 9, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionExitStatusField)) {
            ValueMetaInterface value = new ValueMetaInteger(executionExitStatusField, 3, 0);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLogTextField)) {
            ValueMetaInterface value = new ValueMetaString(executionLogTextField);
            value.setLargeTextField(true);
            row.addValueMeta(value);
        }
        if (!Utils.isEmpty(executionLogChannelIdField)) {
            ValueMetaInterface value = new ValueMetaString(executionLogChannelIdField, 50, 0);
            row.addValueMeta(value);
        }
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)47 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)23 FileObject (org.apache.commons.vfs2.FileObject)12 Node (org.w3c.dom.Node)11 RowMeta (org.pentaho.di.core.row.RowMeta)10 ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)10 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 KettleStepException (org.pentaho.di.core.exception.KettleStepException)9 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)9 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)9 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)7 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)6 Map (java.util.Map)4 KettleException (org.pentaho.di.core.exception.KettleException)4 PluginFolderInterface (org.pentaho.di.core.plugins.PluginFolderInterface)4 IOException (java.io.IOException)3 Annotation (java.lang.annotation.Annotation)3 URLClassLoader (java.net.URLClassLoader)3 HashMap (java.util.HashMap)3