Search in sources :

Example 6 with KettlePluginException

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

the class KettleVariablesList method init.

public static void init() throws KettleException {
    InputStream inputStream = null;
    try {
        KettleVariablesList variablesList = getInstance();
        inputStream = variablesList.getClass().getResourceAsStream(Const.KETTLE_VARIABLES_FILE);
        if (inputStream == null) {
            inputStream = variablesList.getClass().getResourceAsStream("/" + Const.KETTLE_VARIABLES_FILE);
        }
        if (inputStream == null) {
            throw new KettlePluginException("Unable to find standard kettle variables definition file: " + Const.KETTLE_VARIABLES_FILE);
        }
        Document doc = XMLHandler.loadXMLFile(inputStream, null, false, false);
        Node varsNode = XMLHandler.getSubNode(doc, "kettle-variables");
        int nrVars = XMLHandler.countNodes(varsNode, "kettle-variable");
        for (int i = 0; i < nrVars; i++) {
            Node varNode = XMLHandler.getSubNodeByNr(varsNode, "kettle-variable", i);
            String description = XMLHandler.getTagValue(varNode, "description");
            String variable = XMLHandler.getTagValue(varNode, "variable");
            String defaultValue = XMLHandler.getTagValue(varNode, "default-value");
            variablesList.getDescriptionMap().put(variable, description);
            variablesList.getDefaultValueMap().put(variable, defaultValue);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to read file '" + Const.KETTLE_VARIABLES_FILE + "'", e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                // we do not able to close property file will log it
                logger.logDetailed("Unable to close file kettle variables definition file", e);
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Example 7 with KettlePluginException

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

the class AuthenticationPersistenceManager method getAuthenticationManager.

public static AuthenticationManager getAuthenticationManager() {
    AuthenticationManager manager = new AuthenticationManager();
    manager.registerAuthenticationProvider(new NoAuthenticationAuthenticationProvider());
    for (PluginInterface plugin : PluginRegistry.getInstance().getPlugins(AuthenticationConsumerPluginType.class)) {
        try {
            Object pluginMain = PluginRegistry.getInstance().loadClass(plugin);
            if (pluginMain instanceof AuthenticationConsumerType) {
                Class<? extends AuthenticationConsumer<?, ?>> consumerClass = ((AuthenticationConsumerType) pluginMain).getConsumerClass();
                manager.registerConsumerClass(consumerClass);
            } else {
                throw new KettlePluginException(BaseMessages.getString(PKG, "AuthenticationPersistenceManager.NotConsumerType", pluginMain, AuthenticationConsumerType.class));
            }
        } catch (KettlePluginException e) {
            log.logError(e.getMessage(), e);
        } catch (AuthenticationFactoryException e) {
            log.logError(e.getMessage(), e);
        }
    }
    return manager;
}
Also used : AuthenticationManager(org.pentaho.di.core.auth.core.AuthenticationManager) AuthenticationFactoryException(org.pentaho.di.core.auth.core.AuthenticationFactoryException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 8 with KettlePluginException

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

the class ExcelInputMeta method getEmptyFields.

public RowMetaInterface getEmptyFields() {
    RowMetaInterface row = new RowMeta();
    if (field != null) {
        for (int i = 0; i < field.length; i++) {
            ValueMetaInterface v;
            try {
                v = ValueMetaFactory.createValueMeta(field[i].getName(), field[i].getType());
            } catch (KettlePluginException e) {
                v = new ValueMetaNone(field[i].getName());
            }
            row.addValueMeta(v);
        }
    }
    return row;
}
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) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 9 with KettlePluginException

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

the class InjectorMeta method getFields.

public void getFields(RowMetaInterface inputRowMeta, String name, 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(this.fieldname[i], type[i], length[i], precision[i]);
            inputRowMeta.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 10 with KettlePluginException

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

the class MappingInputMeta method getFields.

public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // 
    if (inputRowMeta != null && !inputRowMeta.isEmpty()) {
        // First rename any fields...
        if (valueRenames != null) {
            for (MappingValueRename valueRename : valueRenames) {
                ValueMetaInterface valueMeta = inputRowMeta.searchValueMeta(valueRename.getSourceValueName());
                if (valueMeta == null) {
                    // ok, let's search once again, now using target name
                    valueMeta = inputRowMeta.searchValueMeta(valueRename.getTargetValueName());
                    if (valueMeta == null) {
                        throw new KettleStepException(BaseMessages.getString(PKG, "MappingInput.Exception.UnableToFindMappedValue", valueRename.getSourceValueName()));
                    }
                } else {
                    valueMeta.setName(valueRename.getTargetValueName());
                }
            }
        }
        if (selectingAndSortingUnspecifiedFields) {
            // Select the specified fields from the input, re-order everything and put the other fields at the back,
            // sorted...
            // 
            RowMetaInterface newRow = new RowMeta();
            for (int i = 0; i < fieldName.length; i++) {
                int index = inputRowMeta.indexOfValue(fieldName[i]);
                if (index < 0) {
                    throw new KettleStepException(BaseMessages.getString(PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
                }
                newRow.addValueMeta(inputRowMeta.getValueMeta(index));
            }
            // Now get the unspecified fields.
            // Sort the fields
            // Add them after the specified fields...
            // 
            List<String> extra = new ArrayList<String>();
            for (int i = 0; i < inputRowMeta.size(); i++) {
                String fieldName = inputRowMeta.getValueMeta(i).getName();
                if (newRow.indexOfValue(fieldName) < 0) {
                    extra.add(fieldName);
                }
            }
            Collections.sort(extra);
            for (String fieldName : extra) {
                ValueMetaInterface extraValue = inputRowMeta.searchValueMeta(fieldName);
                newRow.addValueMeta(extraValue);
            }
            // now merge the new row...
            // This is basically the input row meta data with the fields re-ordered.
            // 
            row.mergeRowMeta(newRow);
        } else {
            row.mergeRowMeta(inputRowMeta);
            // 
            if (!row.isEmpty()) {
                for (int i = 0; i < fieldName.length; i++) {
                    if (row.indexOfValue(fieldName[i]) < 0) {
                        throw new KettleStepException(BaseMessages.getString(PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
                    }
                }
            }
        }
    } else {
        if (row.isEmpty()) {
            // We'll have to work with the statically provided information
            for (int i = 0; i < fieldName.length; i++) {
                if (!Utils.isEmpty(fieldName[i])) {
                    int valueType = fieldType[i];
                    if (valueType == ValueMetaInterface.TYPE_NONE) {
                        valueType = ValueMetaInterface.TYPE_STRING;
                    }
                    ValueMetaInterface v;
                    try {
                        v = ValueMetaFactory.createValueMeta(fieldName[i], valueType);
                        v.setLength(fieldLength[i]);
                        v.setPrecision(fieldPrecision[i]);
                        v.setOrigin(origin);
                        row.addValueMeta(v);
                    } catch (KettlePluginException e) {
                        throw new KettleStepException(e);
                    }
                }
            }
        }
    // else: row is OK, keep it as it is.
    }
}
Also used : MappingValueRename(org.pentaho.di.trans.steps.mapping.MappingValueRename) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) 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