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);
}
}
}
}
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;
}
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;
}
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);
}
}
}
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.
}
}
Aggregations