Java Code Examples for org.pentaho.di.core.exception.KettleException#toString()

The following examples show how to use org.pentaho.di.core.exception.KettleException#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LDIFInput.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {

    Object[] r = null;

    boolean sendToErrorRow = false;
    String errorMessage = null;

    try {
      // Grab one row
      Object[] outputRowData = getOneRow();
      if ( outputRowData == null ) {
        setOutputDone(); // signal end to receiver(s)
        return false; // end of data or error.
      }

      putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s);

      if ( meta.getRowLimit() > 0 && data.rownr > meta.getRowLimit() ) { // limit has been reached: stop now.
        setOutputDone();
        return false;
      }
    } catch ( KettleException e ) {
      if ( getStepMeta().isDoingErrorHandling() ) {
        sendToErrorRow = true;
        errorMessage = e.toString();
      } else {
        logError( BaseMessages.getString( PKG, "LDIFInput.ErrorInStepRunning", e.getMessage() ) );
        setErrors( 1 );
        stopAll();
        setOutputDone(); // signal end to receiver(s)
        return false;
      }
      if ( sendToErrorRow ) {
        // Simply add this row to the error row
        putError( getInputRowMeta(), r, 1, errorMessage, null, "LDIFInput001" );
      }
    }
    return true;
  }
 
Example 2
Source File: AccessInput.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {

    Object[] r = null;

    boolean sendToErrorRow = false;
    String errorMessage = null;

    try {
      // Grab one row
      Object[] outputRowData = getOneRow();
      if ( outputRowData == null ) {
        setOutputDone(); // signal end to receiver(s)
        return false; // end of data or error.
      }

      putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s);

      if ( meta.getRowLimit() > 0 && data.rownr > meta.getRowLimit() ) { // limit has been reached: stop now.
        setOutputDone();
        return false;
      }
    } catch ( KettleException e ) {
      if ( getStepMeta().isDoingErrorHandling() ) {
        sendToErrorRow = true;
        errorMessage = e.toString();
      } else {
        logError( BaseMessages.getString( PKG, "AccessInput.ErrorInStepRunning", e.getMessage() ) );
        setErrors( 1 );
        stopAll();
        setOutputDone(); // signal end to receiver(s)
        return false;
      }
      if ( sendToErrorRow ) {
        // Simply add this row to the error row
        putError( getInputRowMeta(), r, 1, errorMessage, null, "AccessInput001" );
      }
    }
    return true;
  }
 
Example 3
Source File: DatabaseJoin.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (DatabaseJoinMeta) smi;
  data = (DatabaseJoinData) sdi;

  boolean sendToErrorRow = false;
  String errorMessage = null;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...
    setOutputDone();
    return false;
  }

  try {
    lookupValues( getInputRowMeta(), r ); // add new values to the row in rowset[0].

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isBasic() ) {
        logBasic( BaseMessages.getString( PKG, "DatabaseJoin.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {

      logError( BaseMessages.getString( PKG, "DatabaseJoin.Log.ErrorInStepRunning" ) + e.getMessage(), e );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "DBJOIN001" );
    }
  }

  return true;
}
 
Example 4
Source File: Delete.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (DeleteMeta) smi;
  data = (DeleteData) sdi;

  boolean sendToErrorRow = false;
  String errorMessage = null;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...

    setOutputDone();
    return false;
  }

  if ( first ) {
    first = false;

    // What's the output Row format?
    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.schemaTable =
      meta.getDatabaseMeta().getQuotedSchemaTableCombination(
        environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) );

    // lookup the values!
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "Delete.Log.CheckingRow" ) + getInputRowMeta().getString( r ) );
    }

    data.keynrs = new int[meta.getKeyStream().length];
    data.keynrs2 = new int[meta.getKeyStream().length];
    for ( int i = 0; i < meta.getKeyStream().length; i++ ) {
      data.keynrs[i] = getInputRowMeta().indexOfValue( meta.getKeyStream()[i] );
      if ( data.keynrs[i] < 0 && // couldn't find field!
        !"IS NULL".equalsIgnoreCase( meta.getKeyCondition()[i] ) && // No field needed!
        !"IS NOT NULL".equalsIgnoreCase( meta.getKeyCondition()[i] ) // No field needed!
      ) {
        throw new KettleStepException( BaseMessages.getString( PKG, "Delete.Exception.FieldRequired", meta
          .getKeyStream()[i] ) );
      }
      data.keynrs2[i] = meta.getKeyStream2().length == 0 ? -1
        : getInputRowMeta().indexOfValue( meta.getKeyStream2()[i] );
      if ( data.keynrs2[i] < 0 && // couldn't find field!
        "BETWEEN".equalsIgnoreCase( meta.getKeyCondition()[i] ) // 2 fields needed!
      ) {
        throw new KettleStepException( BaseMessages.getString( PKG, "Delete.Exception.FieldRequired", meta
          .getKeyStream2()[i] ) );
      }

      if ( log.isDebug() ) {
        logDebug( BaseMessages.getString( PKG, "Delete.Log.FieldInfo", meta.getKeyStream()[i] ) + data.keynrs[i] );
      }
    }

    prepareDelete( getInputRowMeta() );
  }

  try {
    deleteValues( getInputRowMeta(), r ); // add new values to the row in rowset[0].
    putRow( data.outputRowMeta, r ); // output the same rows of data, but with a copy of the metadata

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isBasic() ) {
        logBasic( BaseMessages.getString( PKG, "Delete.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {

      logError( BaseMessages.getString( PKG, "Delete.Log.ErrorInStep" ) + e.getMessage() );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }

    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "DEL001" );
    }
  }

  return true;
}
 
Example 5
Source File: NumberRange.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Column number where the input value is stored
 */

public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  Object[] row = getRow();
  if ( row == null ) {
    setOutputDone();
    return false;
  }

  if ( first ) {
    first = false;

    numberRange = new NumberRangeSet( meta.getRules(), meta.getFallBackValue() );
    data.outputRowMeta = getInputRowMeta().clone();
    // Prepare output fields
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    // Find column numbers
    data.inputColumnNr = data.outputRowMeta.indexOfValue( meta.getInputField() );

    // Check if a field was not available
    if ( data.inputColumnNr < 0 ) {
      logError( "Field for input could not be found: " + meta.getInputField() );
      return false;
    }
  }
  try {
    // get field value
    Double value = getInputRowMeta().getNumber( row, data.inputColumnNr );

    // return range
    String ranges = numberRange.evaluate( value );
    // add value to output
    row = RowDataUtil.addRowData( row, getInputRowMeta().size(), new Object[] { ranges } );
    putRow( data.outputRowMeta, row );
    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "NumberRange.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "NumberRange.Log.ErrorInStepRunning" ) + e.getMessage() );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), row, 1, errorMessage, null, "NumberRange001" );
    }
  }

  return true;
}
 
Example 6
Source File: HTTP.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (HTTPMeta) smi;
  data = (HTTPData) sdi;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...
    setOutputDone();
    return false;
  }

  if ( first ) {
    data.outputRowMeta = getInputRowMeta().clone();
    data.inputRowMeta = getInputRowMeta();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    if ( meta.isUrlInField() ) {
      if ( Utils.isEmpty( meta.getUrlField() ) ) {
        logError( BaseMessages.getString( PKG, "HTTP.Log.NoField" ) );
        throw new KettleException( BaseMessages.getString( PKG, "HTTP.Log.NoField" ) );
      }

      // cache the position of the field
      if ( data.indexOfUrlField < 0 ) {
        String realUrlfieldName = environmentSubstitute( meta.getUrlField() );
        data.indexOfUrlField = getInputRowMeta().indexOfValue( realUrlfieldName );
        if ( data.indexOfUrlField < 0 ) {
          // The field is unreachable !
          logError( BaseMessages.getString( PKG, "HTTP.Log.ErrorFindingField", realUrlfieldName ) );
          throw new KettleException( BaseMessages.getString( PKG, "HTTP.Exception.ErrorFindingField",
            realUrlfieldName ) );
        }
      }
    } else {
      data.realUrl = environmentSubstitute( meta.getUrl() );
    }

    // check for headers
    int nrHeaders = meta.getHeaderField().length;
    if ( nrHeaders > 0 ) {
      data.useHeaderParameters = true;
    }

    data.header_parameters_nrs = new int[ nrHeaders ];
    data.headerParameters = new NameValuePair[ nrHeaders ];

    // get the headers
    for ( int i = 0; i < nrHeaders; i++ ) {
      int fieldIndex = data.inputRowMeta.indexOfValue( meta.getHeaderField()[ i ] );
      if ( fieldIndex < 0 ) {
        logError( BaseMessages.getString( PKG,
          "HTTP.Exception.ErrorFindingField" ) + meta.getHeaderField()[ i ] + "]" );
        throw new KettleStepException( BaseMessages.getString( PKG, "HTTP.Exception.ErrorFindingField", meta
          .getHeaderField()[ i ] ) );
      }

      data.header_parameters_nrs[ i ] = fieldIndex;
      data.headerParameters[ i ] =
        new BasicNameValuePair( environmentSubstitute( meta.getHeaderParameter()[ i ] ),
          data.outputRowMeta.getString( r,
            data.header_parameters_nrs[ i ] ) );
    }

  } // end if first

  try {
    Object[] outputRowData = execHttp( getInputRowMeta(), r ); // add new values to the row
    putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s);

    if ( checkFeedback( getLinesRead() ) ) {
      if ( isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "HTTP.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "HTTP.ErrorInStepRunning" ) + e.getMessage() );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "HTTP001" );
    }
  }

  return true;
}
 
Example 7
Source File: SetValueField.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (SetValueFieldMeta) smi;
  data = (SetValueFieldData) sdi;

  // Get one row from one of the rowsets...
  Object[] r = getRow();

  if ( r == null ) { // no more input to be expected...

    setOutputDone();
    return false;
  }

  if ( first ) {
    first = false;
    // What's the format of the output row?
    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.indexOfField = new int[meta.getFieldName().length];
    data.indexOfReplaceByValue = new int[meta.getFieldName().length];
    for ( int i = 0; i < meta.getFieldName().length; i++ ) {
      // Check if this field was specified only one time
      for ( int j = 0; j < meta.getFieldName().length; j++ ) {
        if ( meta.getFieldName()[j].equals( meta.getFieldName()[i] ) ) {
          if ( j != i ) {
            throw new KettleException( BaseMessages.getString(
              PKG, "SetValueField.Log.FieldSpecifiedMoreThatOne", meta.getFieldName()[i], "" + i, "" + j ) );
          }
        }
      }

      data.indexOfField[i] = data.outputRowMeta.indexOfValue( environmentSubstitute( meta.getFieldName()[i] ) );
      if ( data.indexOfField[i] < 0 ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "SetValueField.Log.CouldNotFindFieldInRow", meta.getFieldName()[i] ) );
      }
      String sourceField = environmentSubstitute(
        meta.getReplaceByFieldValue() != null && meta.getReplaceByFieldValue().length > 0
          ? meta.getReplaceByFieldValue()[i] : null
      );
      if ( Utils.isEmpty( sourceField ) ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "SetValueField.Log.ReplaceByValueFieldMissing", "" + i ) );
      }
      data.indexOfReplaceByValue[i] = data.outputRowMeta.indexOfValue( sourceField );
      if ( data.indexOfReplaceByValue[i] < 0 ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "SetValueField.Log.CouldNotFindFieldInRow", sourceField ) );
      }
      // Compare fields type
      ValueMetaInterface SourceValue = getInputRowMeta().getValueMeta( data.indexOfField[i] );
      ValueMetaInterface ReplaceByValue = getInputRowMeta().getValueMeta( data.indexOfReplaceByValue[i] );

      if ( SourceValue.getType() != ReplaceByValue.getType() ) {
        String err =
          BaseMessages.getString( PKG, "SetValueField.Log.FieldsTypeDifferent", SourceValue.getName()
            + " (" + SourceValue.getTypeDesc() + ")", ReplaceByValue.getName()
            + " (" + ReplaceByValue.getTypeDesc() + ")" );
        throw new KettleStepException( err );
      }
    }
  }
  try {
    for ( int i = 0; i < data.indexOfField.length; i++ ) {
      r[data.indexOfField[i]] = r[data.indexOfReplaceByValue[i]];
    }
    putRow( data.outputRowMeta, r ); // copy row to output rowset(s);
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "SetValueField.Log.ErrorInStep", e.getMessage() ) );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( data.outputRowMeta, r, 1, errorMessage, null, "SetValueField001" );
    }
  }
  return true;
}
 
Example 8
Source File: ReplaceString.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (ReplaceStringMeta) smi;
  data = (ReplaceStringData) sdi;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...

    setOutputDone();
    return false;
  }

  if ( first ) {
    first = false;

    // What's the format of the output row?
    data.outputRowMeta = getInputRowMeta().clone();
    data.inputFieldsNr = data.outputRowMeta.size();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.numFields = meta.getFieldInStream().length;
    data.inStreamNrs = new int[data.numFields];
    data.outStreamNrs = new String[data.numFields];
    data.patterns = new Pattern[data.numFields];
    data.replaceByString = new String[data.numFields];
    data.setEmptyString = new boolean[data.numFields];
    data.replaceFieldIndex = new int[data.numFields];

    for ( int i = 0; i < data.numFields; i++ ) {
      data.inStreamNrs[i] = getInputRowMeta().indexOfValue( meta.getFieldInStream()[i] );
      if ( data.inStreamNrs[i] < 0 ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "ReplaceString.Exception.FieldRequired", meta.getFieldInStream()[i] ) );
      }

      // check field type
      if ( getInputRowMeta().getValueMeta( data.inStreamNrs[i] ).getType() != ValueMetaInterface.TYPE_STRING ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "ReplaceString.Exception.FieldTypeNotString", meta.getFieldInStream()[i] ) );
      }

      data.outStreamNrs[i] = environmentSubstitute( meta.getFieldOutStream()[i] );
      data.patterns[ i ] = buildPattern( !meta.getUseRegEx()[ i ], meta.getCaseSensitive()[ i ],
        meta.getWholeWord()[ i ], environmentSubstitute( meta.getReplaceString()[ i ] ), meta.isUnicode()[ i ] );

      String field = meta.getFieldReplaceByString()[i];
      if ( !Utils.isEmpty( field ) ) {
        data.replaceFieldIndex[i] = getInputRowMeta().indexOfValue( field );
        if ( data.replaceFieldIndex[i] < 0 ) {
          throw new KettleStepException( BaseMessages.getString(
            PKG, "ReplaceString.Exception.FieldRequired", field ) );
        }
      } else {
        data.replaceFieldIndex[i] = -1;
        data.replaceByString[i] = environmentSubstitute( meta.getReplaceByString()[i] );
      }
      data.setEmptyString[i] = meta.isSetEmptyString()[i];

    }
  } // end if first

  try {
    Object[] output = getOneRow( getInputRowMeta(), r );
    putRow( data.outputRowMeta, output );

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "ReplaceString.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "ReplaceString.Log.ErrorInStep", e.getMessage() ) );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "ReplaceString001" );
    }
  }
  return true;
}
 
Example 9
Source File: DBProc.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (DBProcMeta) smi;
  data = (DBProcData) sdi;

  boolean sendToErrorRow = false;
  String errorMessage = null;

  // A procedure/function could also have no input at all
  // However, we would still need to know how many times it gets executed.
  // In short: the procedure gets executed once for every input row.
  //
  Object[] r;

  if ( data.readsRows ) {
    r = getRow(); // Get row from input rowset & set row busy!
    if ( r == null ) { // no more input to be expected...

      setOutputDone();
      return false;
    }
    data.inputRowMeta = getInputRowMeta();
  } else {
    r = new Object[] {}; // empty row
    incrementLinesRead();
    data.inputRowMeta = new RowMeta(); // empty row metadata too
    data.readsRows = true; // make it drop out of the loop at the next entrance to this method
  }

  try {
    Object[] outputRowData = runProc( data.inputRowMeta, r ); // add new values to the row in rowset[0].
    putRow( data.outputMeta, outputRowData ); // copy row to output rowset(s);

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isBasic() ) {
        logBasic( BaseMessages.getString( PKG, "DBProc.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
      // CHE: Read the chained SQL exceptions and add them
      // to the errorMessage
      SQLException nextSQLExOnChain = null;
      if ( ( e.getCause() != null ) && ( e.getCause() instanceof SQLException ) ) {
        nextSQLExOnChain = ( (SQLException) e.getCause() ).getNextException();
        while ( nextSQLExOnChain != null ) {
          errorMessage = errorMessage + nextSQLExOnChain.getMessage() + Const.CR;
          nextSQLExOnChain = nextSQLExOnChain.getNextException();
        }
      }
    } else {

      logError( BaseMessages.getString( PKG, "DBProc.ErrorInStepRunning" ) + e.getMessage() );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }

    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "DBP001" );
    }
  }

  return true;
}
 
Example 10
Source File: PropertyInput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  if ( first && !meta.isFileField() ) {
    data.files = meta.getFiles( this );
    if ( data.files == null || data.files.nrOfFiles() == 0 ) {
      throw new KettleException( BaseMessages.getString( PKG, "PropertyInput.Log.NoFiles" ) );
    }

    handleMissingFiles();

    // Create the output row meta-data
    data.outputRowMeta = new RowMeta();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); // get the metadata
                                                                                                  // populated

    // Create convert meta-data objects that will contain Date & Number formatters
    //
    data.convertRowMeta = data.outputRowMeta.cloneToType( ValueMetaInterface.TYPE_STRING );
  }
  Object[] r = null;

  boolean sendToErrorRow = false;
  String errorMessage = null;

  try {
    // Grab one row
    Object[] outputRowData = getOneRow();
    if ( outputRowData == null ) {
      setOutputDone(); // signal end to receiver(s)
      return false; // end of data or error.
    }

    putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s);

    if ( meta.getRowLimit() > 0 && data.rownr > meta.getRowLimit() ) { // limit has been reached: stop now.
      setOutputDone();
      return false;
    }
  } catch ( KettleException e ) {
    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "PropertyInput.ErrorInStepRunning", e.getMessage() ) );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "PropertyInput001" );
    }
  }
  return true;
}
 
Example 11
Source File: StringCut.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (StringCutMeta) smi;
  data = (StringCutData) sdi;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...

    setOutputDone();
    return false;
  }

  if ( first ) {
    first = false;
    // What's the format of the output row?
    data.outputRowMeta = getInputRowMeta().clone();
    data.inputFieldsNr = data.outputRowMeta.size();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.inStreamNrs = new int[meta.getFieldInStream().length];
    for ( int i = 0; i < meta.getFieldInStream().length; i++ ) {
      data.inStreamNrs[i] = getInputRowMeta().indexOfValue( meta.getFieldInStream()[i] );
      if ( data.inStreamNrs[i] < 0 ) {
        throw new KettleStepException( BaseMessages.getString( PKG, "StringCut.Exception.FieldRequired", meta
          .getFieldInStream()[i] ) );
      }

      // check field type
      if ( getInputRowMeta().getValueMeta( data.inStreamNrs[i] ).getType() != ValueMetaInterface.TYPE_STRING ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "StringCut.Exception.FieldTypeNotString", meta.getFieldInStream()[i] ) );
      }
    }

    data.outStreamNrs = new String[meta.getFieldInStream().length];
    for ( int i = 0; i < meta.getFieldInStream().length; i++ ) {
      data.outStreamNrs[i] = environmentSubstitute( meta.getFieldOutStream()[i] );
    }

    data.cutFrom = new int[meta.getFieldInStream().length];
    data.cutTo = new int[meta.getFieldInStream().length];
    for ( int i = 0; i < meta.getFieldInStream().length; i++ ) {
      if ( Utils.isEmpty( environmentSubstitute( meta.getCutFrom()[i] ) ) ) {
        data.cutFrom[i] = 0;
      } else {
        data.cutFrom[i] = Const.toInt( environmentSubstitute( meta.getCutFrom()[i] ), 0 );
      }

      if ( Utils.isEmpty( environmentSubstitute( meta.getCutTo()[i] ) ) ) {
        data.cutTo[i] = 0;
      } else {
        data.cutTo[i] = Const.toInt( environmentSubstitute( meta.getCutTo()[i] ), 0 );
      }

    } // end for
  } // end if first

  try {
    Object[] output = getOneRow( getInputRowMeta(), r );
    putRow( data.outputRowMeta, output );

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "StringCut.Log.LineNumber" ) + getLinesRead() );
      }

    }
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "StringCut.Log.ErrorInStep", e.getMessage() ) );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "StringCut001" );
    }
  }
  return true;
}
 
Example 12
Source File: FuzzyMatch.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (FuzzyMatchMeta) smi;
  data = (FuzzyMatchData) sdi;

  if ( data.readLookupValues ) {
    data.readLookupValues = false;

    // Read values from lookup step (look)
    if ( !readLookupValues() ) {
      logError( BaseMessages.getString( PKG, "FuzzyMatch.Log.UnableToReadDataFromLookupStream" ) );
      setErrors( 1 );
      stopAll();
      return false;
    }
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "FuzzyMatch.Log.ReadValuesInMemory", data.look.size() ) );
    }
  }

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) {
    // no more input to be expected...
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "FuzzyMatch.Log.StoppedProcessingWithEmpty", getLinesRead() ) );
    }
    setOutputDone();
    return false;
  }

  try {

    // Do the actual lookup in the hastable.
    Object[] outputRow = lookupValues( getInputRowMeta(), r );
    if ( outputRow == null ) {
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    putRow( data.outputRowMeta, outputRow ); // copy row to output rowset(s);

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isBasic() ) {
        logBasic( BaseMessages.getString( PKG, "FuzzyMatch.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "FuzzyMatch.Log.ErrorInStepRunning" ) + e.getMessage() );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, meta.getMainStreamField(), "FuzzyMatch001" );
    }

  }

  return true;
}
 
Example 13
Source File: DynamicSQLRow.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (DynamicSQLRowMeta) smi;
  data = (DynamicSQLRowData) sdi;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...
    setOutputDone();
    return false;
  }
  if ( first ) {
    if ( Utils.isEmpty( meta.getSQLFieldName() ) ) {
      throw new KettleException( BaseMessages.getString( PKG, "DynamicSQLRow.Exception.SQLFieldNameEmpty" ) );
    }

    if ( Utils.isEmpty( meta.getSql() ) ) {
      throw new KettleException( BaseMessages.getString( PKG, "DynamicSQLRow.Exception.SQLEmpty" ) );
    }

    // cache the position of the field
    if ( data.indexOfSQLField < 0 ) {
      data.indexOfSQLField = getInputRowMeta().indexOfValue( meta.getSQLFieldName() );
      if ( data.indexOfSQLField < 0 ) {
        // The field is unreachable !
        throw new KettleException( BaseMessages.getString( PKG, "DynamicSQLRow.Exception.FieldNotFound", meta
          .getSQLFieldName() ) );
      }
    }
  }
  try {
    lookupValues( getInputRowMeta(), r );

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "DynamicSQLRow.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;

    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "DynamicSQLRow.Log.ErrorInStepRunning" ) + e.getMessage() );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "DynamicSQLRow001" );
    }
  }

  return true;
}
 
Example 14
Source File: TableExists.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (TableExistsMeta) smi;
  data = (TableExistsData) sdi;

  boolean sendToErrorRow = false;
  String errorMessage = null;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...

    setOutputDone();
    return false;
  }

  boolean tablexists = false;
  try {
    if ( first ) {
      first = false;
      data.outputRowMeta = getInputRowMeta().clone();
      meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

      // Check is tablename field is provided
      if ( Utils.isEmpty( meta.getDynamicTablenameField() ) ) {
        logError( BaseMessages.getString( PKG, "TableExists.Error.TablenameFieldMissing" ) );
        throw new KettleException( BaseMessages.getString( PKG, "TableExists.Error.TablenameFieldMissing" ) );
      }

      // cache the position of the field
      if ( data.indexOfTablename < 0 ) {
        data.indexOfTablename = getInputRowMeta().indexOfValue( meta.getDynamicTablenameField() );
        if ( data.indexOfTablename < 0 ) {
          // The field is unreachable !
          logError( BaseMessages.getString( PKG, "TableExists.Exception.CouldnotFindField" )
            + "[" + meta.getDynamicTablenameField() + "]" );
          throw new KettleException( BaseMessages.getString(
            PKG, "TableExists.Exception.CouldnotFindField", meta.getDynamicTablenameField() ) );
        }
      }
    } // End If first

    // get tablename
    String tablename = getInputRowMeta().getString( r, data.indexOfTablename );

    // Check if table exists on the specified connection
    tablexists = data.db.checkTableExists( data.realSchemaname, tablename );

    Object[] outputRowData = RowDataUtil.addValueData( r, getInputRowMeta().size(), tablexists );

    // add new values to the row.
    putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s);

    if ( log.isRowLevel() ) {
      logRowlevel( BaseMessages.getString( PKG, "TableExists.LineNumber", getLinesRead()
        + " : " + getInputRowMeta().getString( r ) ) );
    }
  } catch ( KettleException e ) {
    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "TableExists.ErrorInStepRunning" + " : " + e.getMessage() ) );
      throw new KettleStepException( BaseMessages.getString( PKG, "TableExists.Log.ErrorInStep" ), e );
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, meta.getResultFieldName(), "TableExistsO01" );
    }
  }

  return true;
}
 
Example 15
Source File: GetPreviousRowField.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (GetPreviousRowFieldMeta) smi;
  data = (GetPreviousRowFieldData) sdi;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...

    setOutputDone();
    return false;
  }

  if ( first ) {
    data.inputRowMeta = getInputRowMeta();
    data.NrPrevFields = data.inputRowMeta.size();
    data.outputRowMeta = data.inputRowMeta.clone();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.inStreamNrs = new int[meta.getFieldInStream().length];
    for ( int i = 0; i < meta.getFieldInStream().length; i++ ) {
      data.inStreamNrs[i] = data.inputRowMeta.indexOfValue( meta.getFieldInStream()[i] );
      if ( data.inStreamNrs[i] < 0 ) { // couldn't find field!

        throw new KettleException( BaseMessages.getString(
          PKG, "GetPreviousRowField.Exception.FieldRequired", meta.getFieldInStream()[i] ) );
      }
    }

    data.outStreamNrs = new String[meta.getFieldInStream().length];
    for ( int i = 0; i < meta.getFieldInStream().length; i++ ) {
      data.outStreamNrs[i] = meta.getFieldOutStream()[i];
      if ( Utils.isEmpty( data.outStreamNrs[i] ) ) {
        throw new KettleStepException( BaseMessages.getString(
          PKG, "GetPreviousRowField.Exception.OutputFieldEmpty", "" + i ) );
      }
    }
  } // end if first

  try {
    Object[] outputRow = getOutputRowData( r );

    putRow( data.outputRowMeta, outputRow ); // copy row to output rowset(s);

    if ( checkFeedback( getLinesRead() ) ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "GetPreviousRowField.Log.LineNumber" ) + getLinesRead() );
      }
    }
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;
    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "GetPreviousRowField.Log.ErrorInStep", e.getMessage() ) );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, null, "GetPreviousRowField001" );
    }
  }
  return true;
}
 
Example 16
Source File: SalesforceInput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  if ( first ) {
    first = false;

    // Create the output row meta-data
    data.outputRowMeta = new RowMeta();

    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    // For String to <type> conversions, we allocate a conversion meta data row as well...
    //
    data.convertRowMeta = data.outputRowMeta.cloneToType( ValueMetaInterface.TYPE_STRING );

    // Let's query Salesforce
    data.connection.query( meta.isSpecifyQuery() );

    data.limitReached = true;
    data.recordcount = data.connection.getQueryResultSize();
    if ( data.recordcount > 0 ) {
      data.limitReached = false;
      data.nrRecords = data.connection.getRecordsCount();
    }
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "SalesforceInput.Log.RecordCount" ) + " : " + data.recordcount );
    }

  }

  Object[] outputRowData = null;

  try {
    // get one row ...
    outputRowData = getOneRow();

    if ( outputRowData == null ) {
      setOutputDone();
      return false;
    }

    putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s);

    if ( checkFeedback( getLinesInput() ) ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "SalesforceInput.log.LineRow", "" + getLinesInput() ) );
      }
    }

    data.rownr++;
    data.recordIndex++;

    return true;
  } catch ( KettleException e ) {
    boolean sendToErrorRow = false;
    String errorMessage = null;
    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "SalesforceInput.log.Exception", e.getMessage() ) );
      logError( Const.getStackTracker( e ) );
      setErrors( 1 );
      stopAll();
      setOutputDone(); // signal end to receiver(s)
      return false;
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), outputRowData, 1, errorMessage, null, "SalesforceInput001" );
    }
  }
  return true;
}