Java Code Examples for org.pentaho.di.core.RowMetaAndData#getString()

The following examples show how to use org.pentaho.di.core.RowMetaAndData#getString() . 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: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
/**
 * List all unit tests which are defined
 * And allow the user to select one to delete
 */
public void deleteUnitTest() {
  try {

    RowMetaAndData selection = selectUnitTestFromAllTests();
    if ( selection != null ) {
      String unitTestName = selection.getString( 0, null );

      if ( StringUtils.isNotEmpty( unitTestName ) ) {
        deleteUnitTest( unitTestName );
      }
    }
  } catch ( Exception e ) {
    new ErrorDialog( Spoon.getInstance().getShell(), "Error", "Error deleting unit test", e );
  }
}
 
Example 2
Source File: SortRowsIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void checkStringSortCorrect( List<RowMetaAndData> list, boolean caseSensitive, boolean asc ) throws KettleValueException {
  List<String> actual = new ArrayList<String>();
  List<String> expected = new ArrayList<String>();

  String caseSen = caseSensitive ? "case sensitive" : "case unsensitive";

  for ( RowMetaAndData row : list ) {
    String value = row.getString( STR, null );
    if ( !caseSensitive ) {
      expected.add( value.toLowerCase() );
      actual.add( value.toLowerCase() );
    } else {
      expected.add( value );
      actual.add( value );
    }
  }
  if ( asc ) {
    Collections.sort( expected );
  } else {
    // avoid create custorm comparator
    Collections.sort( expected );
    Collections.reverse( expected );
  }

  Assert.assertEquals( "Data is sorted: " + caseSen, expected, actual );
}
 
Example 3
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public synchronized boolean getStepAttributeBoolean( ObjectId id_step, int nr, String code, boolean def )
  throws KettleException {
  RowMetaAndData r = null;
  if ( stepAttributesBuffer != null ) {
    r = searchStepAttributeInBuffer( id_step, code, nr );
  } else {
    r = getStepAttributeRow( id_step, nr, code );
  }

  if ( r == null ) {
    return def;
  }
  String v = r.getString( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_STR, null );
  if ( v == null || Utils.isEmpty( v ) ) {
    return def;
  }
  return ValueMetaString.convertStringToBoolean( v ).booleanValue();
}
 
Example 4
Source File: JobEntryCheckFilesLocked.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void processFromPreviousArgument( List<RowMetaAndData> rows ) throws KettleValueException {
  RowMetaAndData resultRow;
  // Copy the input row to the (command line) arguments
  for ( int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++ ) {
    resultRow = rows.get( iteration );

    // Get values from previous result
    String fileFolderPrevious = resultRow.getString( 0, "" );
    String fileMasksPrevious = resultRow.getString( 1, "" );

    // ok we can process this file/folder
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString(
        PKG, "JobEntryCheckFilesLocked.ProcessingRow", fileFolderPrevious, fileMasksPrevious ) );
    }

    processFile( fileFolderPrevious, fileMasksPrevious );
  }
}
 
Example 5
Source File: KettleDatabaseRepositoryTransDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String[] getTransformationsWithIDList( List<Object[]> list, RowMetaInterface rowMeta ) throws KettleException {
  String[] transList = new String[list.size()];
  for ( int i = 0; i < list.size(); i++ ) {
    long id_transformation =
      rowMeta.getInteger(
        list.get( i ), quote( KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_TRANSFORMATION ), -1L );
    if ( id_transformation > 0 ) {
      RowMetaAndData transRow = getTransformation( new LongObjectId( id_transformation ) );
      if ( transRow != null ) {
        String transName =
          transRow.getString( KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME, "<name not found>" );
        long id_directory =
          transRow.getInteger( KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY, -1L );
        RepositoryDirectoryInterface dir =
          repository.loadRepositoryDirectoryTree().findDirectory( new LongObjectId( id_directory ) );

        transList[i] = dir.getPathObjectCombination( transName );
      }
    }
  }

  return transList;
}
 
Example 6
Source File: KettleDatabaseRepositoryTransDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String[] getTransformationsWithIDList( ObjectId[] ids ) throws KettleException {
  String[] transList = new String[ids.length];
  for ( int i = 0; i < ids.length; i++ ) {
    ObjectId id_transformation = ids[i];
    if ( id_transformation != null ) {
      RowMetaAndData transRow = getTransformation( id_transformation );
      if ( transRow != null ) {
        String transName =
          transRow.getString( KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME, "<name not found>" );
        long id_directory =
          transRow.getInteger( KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY, -1L );
        RepositoryDirectoryInterface dir =
          repository.loadRepositoryDirectoryTree().findDirectory( new LongObjectId( id_directory ) );

        transList[i] = dir.getPathObjectCombination( transName );
      }
    }
  }

  return transList;
}
 
Example 7
Source File: KettleDatabaseRepositoryJobDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String[] getJobsWithIDList( List<Object[]> list, RowMetaInterface rowMeta ) throws KettleException {
  String[] jobList = new String[list.size()];
  for ( int i = 0; i < list.size(); i++ ) {
    long id_job = rowMeta.getInteger( list.get( i ), quote( KettleDatabaseRepository.FIELD_JOB_ID_JOB ), -1L );
    if ( id_job > 0 ) {
      RowMetaAndData jobRow = getJob( new LongObjectId( id_job ) );
      if ( jobRow != null ) {
        String jobName = jobRow.getString( KettleDatabaseRepository.FIELD_JOB_NAME, "<name not found>" );
        long id_directory = jobRow.getInteger( KettleDatabaseRepository.FIELD_JOB_ID_DIRECTORY, -1L );
        RepositoryDirectoryInterface dir =
          repository.loadRepositoryDirectoryTree().findDirectory( new LongObjectId( id_directory ) ); // always
                                                                                                      // reload the
                                                                                                      // directory
                                                                                                      // tree!

        jobList[i] = dir.getPathObjectCombination( jobName );
      }
    }
  }

  return jobList;
}
 
Example 8
Source File: KettleDatabaseRepositoryJobDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String[] getJobsWithIDList( ObjectId[] ids ) throws KettleException {
  String[] jobsList = new String[ids.length];
  for ( int i = 0; i < ids.length; i++ ) {
    ObjectId id_job = ids[i];
    if ( id_job != null ) {
      RowMetaAndData transRow = getJob( id_job );
      if ( transRow != null ) {
        String jobName = transRow.getString( KettleDatabaseRepository.FIELD_JOB_NAME, "<name not found>" );
        long id_directory = transRow.getInteger( KettleDatabaseRepository.FIELD_JOB_ID_DIRECTORY, -1L );
        RepositoryDirectoryInterface dir =
          repository.loadRepositoryDirectoryTree().findDirectory( new LongObjectId( id_directory ) );

        jobsList[i] = dir.getPathObjectCombination( jobName );
      }
    }
  }

  return jobsList;
}
 
Example 9
Source File: KettleDatabaseRepositoryMetaStore.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> getNamespaces() throws MetaStoreException {

  try {
    List<String> namespaces = new ArrayList<String>();
    Collection<RowMetaAndData> namespaceRows = delegate.getNamespaces();
    for ( RowMetaAndData namespaceRow : namespaceRows ) {
      String namespace = namespaceRow.getString( KettleDatabaseRepository.FIELD_NAMESPACE_NAME, null );
      if ( !Utils.isEmpty( namespace ) ) {
        namespaces.add( namespace );
      }
    }
    return namespaces;

  } catch ( Exception e ) {
    throw new MetaStoreException( e );
  }
}
 
Example 10
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
public void openUnitTestTransformation() {
  try {
    Spoon spoon = Spoon.getInstance();
    FactoriesHierarchy hierarchy = getHierarchy();
    RowMetaAndData selection = selectUnitTestFromAllTests();
    if ( selection != null ) {
      String filename = selection.getString( 2, null );
      if ( StringUtils.isNotEmpty( filename ) ) {
        // Load the unit test...
        //
        String unitTestName = selection.getString( 0, null );
        TransUnitTest targetTest = hierarchy.getTestFactory().loadElement( unitTestName );

        if ( targetTest != null ) {

          String completeFilename = targetTest.calculateCompleteFilename( Variables.getADefaultVariableSpace() );
          spoon.openFile( completeFilename, false );

          TransMeta transMeta = spoon.getActiveTransformation();
          if ( transMeta != null ) {
            switchUnitTest( targetTest, transMeta );
          }
        }
      } else {
        throw new KettleException( "No filename found: repositories not supported yet for this feature" );
      }
    }
  } catch ( Exception e ) {
    new ErrorDialog( Spoon.getInstance().getShell(), "Error", "Error opening unit test transformation", e );
  }
}
 
Example 11
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized String getJobAttributeString( ObjectId id_job, int nr, String code ) throws KettleException {
  RowMetaAndData r = null;
  r = getJobAttributeRow( id_job, nr, code );
  if ( r == null ) {
    return null;
  }
  return r.getString( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_STR, null );
}
 
Example 12
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public synchronized String getTransAttributeString( ObjectId id_transformation, int nr, String code )
  throws KettleException {
  RowMetaAndData r = null;
  r = getTransAttributeRow( id_transformation, nr, code );
  if ( r == null ) {
    return null;
  }
  return r.getString( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_STR, null );
}
 
Example 13
Source File: KettleDatabaseRepositoryMetaStoreDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public KDBRMetaStoreElement parseElement( IMetaStoreElementType elementType, RowMetaAndData elementRow ) throws KettleException {

    Long elementId = elementRow.getInteger( KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT );
    String name = elementRow.getString( KettleDatabaseRepository.FIELD_ELEMENT_NAME, null );

    KDBRMetaStoreElement element = new KDBRMetaStoreElement( this, elementType, Long.toString( elementId ), null );
    element.setName( name );

    // Now load the attributes...
    //
    addAttributes( element, new LongObjectId( elementId ), new LongObjectId( 0 ) );

    return element;
  }
 
Example 14
Source File: MetaInject.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * package-local visibility for testing purposes
 */
static void setEntryValue( StepInjectionMetaEntry entry, RowMetaAndData row, SourceStepField source )
  throws KettleValueException {
  // A standard attribute, a single row of data...
  //
  Object value = null;
  switch ( entry.getValueType() ) {
    case ValueMetaInterface.TYPE_STRING:
      value = row.getString( source.getField(), null );
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      value = row.getBoolean( source.getField(), false );
      break;
    case ValueMetaInterface.TYPE_INTEGER:
      value = row.getInteger( source.getField(), 0L );
      break;
    case ValueMetaInterface.TYPE_NUMBER:
      value = row.getNumber( source.getField(), 0.0D );
      break;
    case ValueMetaInterface.TYPE_DATE:
      value = row.getDate( source.getField(), null );
      break;
    case ValueMetaInterface.TYPE_BIGNUMBER:
      value = row.getBigNumber( source.getField(), null );
      break;
    default:
      break;
  }
  entry.setValue( value );
}
 
Example 15
Source File: KettleDatabaseRepositoryValueDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ValueMetaAndData loadValueMetaAndData( ObjectId id_value ) throws KettleException {
  ValueMetaAndData valueMetaAndData = new ValueMetaAndData();
  try {
    RowMetaAndData r = getValue( id_value );
    if ( r != null ) {
      String name = r.getString( KettleDatabaseRepository.FIELD_VALUE_NAME, null );
      int valtype = ValueMetaFactory.getIdForValueMeta(
        r.getString( KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE, null ) );
      boolean isNull = r.getBoolean( KettleDatabaseRepository.FIELD_VALUE_IS_NULL, false );
      ValueMetaInterface v = ValueMetaFactory.createValueMeta( name, valtype );
      valueMetaAndData.setValueMeta( v );

      if ( isNull ) {
        valueMetaAndData.setValueData( null );
      } else {
        ValueMetaInterface stringValueMeta = new ValueMetaString( name );
        ValueMetaInterface valueMeta = valueMetaAndData.getValueMeta();
        stringValueMeta.setConversionMetadata( valueMeta );

        valueMeta.setDecimalSymbol( ValueMetaAndData.VALUE_REPOSITORY_DECIMAL_SYMBOL );
        valueMeta.setGroupingSymbol( ValueMetaAndData.VALUE_REPOSITORY_GROUPING_SYMBOL );

        switch ( valueMeta.getType() ) {
          case ValueMetaInterface.TYPE_NUMBER:
            valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_NUMBER_CONVERSION_MASK );
            break;
          case ValueMetaInterface.TYPE_INTEGER:
            valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_INTEGER_CONVERSION_MASK );
            break;
          default:
            break;
        }

        String string = r.getString( "VALUE_STR", null );
        valueMetaAndData.setValueData( stringValueMeta.convertDataUsingConversionMetaData( string ) );

        // OK, now comes the dirty part...
        // We want the defaults back on there...
        //
        valueMeta = ValueMetaFactory.createValueMeta( name, valueMeta.getType() );
      }
    }

    return valueMetaAndData;
  } catch ( KettleException dbe ) {
    throw new KettleException( "Unable to load Value from repository with id_value=" + id_value, dbe );
  }
}
 
Example 16
Source File: JobEntryAddResultFilenames.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result result, int nr ) throws KettleException {
  List<RowMetaAndData> rows = result.getRows();
  RowMetaAndData resultRow = null;

  int nrErrFiles = 0;
  result.setResult( true );

  if ( deleteallbefore ) {
    // clear result filenames
    int size = result.getResultFiles().size();
    if ( log.isBasic() ) {
      logBasic( BaseMessages.getString( PKG, "JobEntryAddResultFilenames.log.FilesFound", "" + size ) );
    }

    result.getResultFiles().clear();
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryAddResultFilenames.log.DeletedFiles", "" + size ) );
    }
  }

  if ( argFromPrevious ) {
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryAddResultFilenames.FoundPreviousRows", String
        .valueOf( ( rows != null ? rows.size() : 0 ) ) ) );
    }
  }

  if ( argFromPrevious && rows != null ) { // Copy the input row to the (command line) arguments
    for ( int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++ ) {
      resultRow = rows.get( iteration );

      // Get values from previous result
      String filefolder_previous = resultRow.getString( 0, null );
      String fmasks_previous = resultRow.getString( 1, null );

      // ok we can process this file/folder
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString(
          PKG, "JobEntryAddResultFilenames.ProcessingRow", filefolder_previous, fmasks_previous ) );
      }

      if ( !processFile( filefolder_previous, fmasks_previous, parentJob, result ) ) {
        nrErrFiles++;
      }

    }
  } else if ( arguments != null ) {

    for ( int i = 0; i < arguments.length && !parentJob.isStopped(); i++ ) {

      // ok we can process this file/folder
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString(
          PKG, "JobEntryAddResultFilenames.ProcessingArg", arguments[i], filemasks[i] ) );
      }
      if ( !processFile( arguments[i], filemasks[i], parentJob, result ) ) {
        nrErrFiles++;
      }
    }
  }

  if ( nrErrFiles > 0 ) {
    result.setResult( false );
    result.setNrErrors( nrErrFiles );
  }

  return result;
}
 
Example 17
Source File: JobEntryMSAccessBulkLoad.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result previousResult, int nr ) {
  Result result = previousResult;

  List<RowMetaAndData> rows = result.getRows();
  RowMetaAndData resultRow = null;
  result.setResult( false );

  NrErrors = 0;
  NrSuccess = 0;
  NrFilesToProcess = 0;
  continueProcessing = true;
  limitFiles = Const.toInt( environmentSubstitute( getLimit() ), 10 );

  // Get source and destination files, also wildcard
  String[] vsourceFilefolder = source_filefolder;
  String[] vsourceWildcard = source_wildcard;
  String[] vsourceDelimiter = delimiter;
  String[] targetDb = target_Db;
  String[] targetTable = target_table;

  try {

    if ( is_args_from_previous ) {
      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString(
          PKG, "JobEntryMSAccessBulkLoad.Log.ArgFromPrevious.Found", ( rows != null ? rows.size() : 0 ) + "" ) );
      }
    }
    if ( is_args_from_previous && rows != null ) {
      for ( int iteration = 0; iteration < rows.size()
        && !parentJob.isStopped()
        && continueProcessing; iteration++ ) {
        resultRow = rows.get( iteration );

        // Get source and destination file names, also wildcard
        String vSourceFileFolder_previous = resultRow.getString( 0, null );
        String vSourceWildcard_previous = resultRow.getString( 1, null );
        String vDelimiter_previous = resultRow.getString( 2, null );
        String vTargetDb_previous = resultRow.getString( 3, null );
        String vTargetTable_previous = resultRow.getString( 4, null );

        processOneRow(
          vSourceFileFolder_previous, vSourceWildcard_previous, vDelimiter_previous, vTargetDb_previous,
          vTargetTable_previous, parentJob, result );

      }
    } else if ( vsourceFilefolder != null && targetDb != null && targetTable != null ) {
      for ( int i = 0; i < vsourceFilefolder.length && !parentJob.isStopped() && continueProcessing; i++ ) {
        // get real values
        String realSourceFileFolder = environmentSubstitute( vsourceFilefolder[i] );
        String realSourceWildcard = environmentSubstitute( vsourceWildcard[i] );
        String realSourceDelimiter = environmentSubstitute( vsourceDelimiter[i] );
        String realTargetDb = environmentSubstitute( targetDb[i] );
        String realTargetTable = environmentSubstitute( targetTable[i] );

        processOneRow(
          realSourceFileFolder, realSourceWildcard, realSourceDelimiter, realTargetDb, realTargetTable,
          parentJob, result );
      }
    }
  } catch ( Exception e ) {
    incrErrors();
    logError( BaseMessages.getString( PKG, "JobEntryMSAccessBulkLoad.UnexpectedError", e.getMessage() ) );
  }

  // Success Condition
  result.setNrErrors( NrErrors );
  result.setNrLinesInput( NrFilesToProcess );
  result.setNrLinesWritten( NrSuccess );
  if ( getSuccessStatus() ) {
    result.setResult( true );
  }

  displayResults();
  return result;
}
 
Example 18
Source File: JobEntryTruncateTables.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result previousResult, int nr ) {
  Result result = previousResult;
  List<RowMetaAndData> rows = result.getRows();
  RowMetaAndData resultRow = null;

  result.setResult( true );
  nrErrors = 0;
  continueProcess = true;
  nrSuccess = 0;

  if ( argFromPrevious ) {
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryTruncateTables.FoundPreviousRows", String
        .valueOf( ( rows != null ? rows.size() : 0 ) ) ) );
    }
    if ( rows.size() == 0 ) {
      return result;
    }
  }
  if ( connection != null ) {
    Database db = new Database( this, connection );
    db.shareVariablesWith( this );
    try {
      db.connect( parentJob.getTransactionId(), null );
      if ( argFromPrevious && rows != null ) { // Copy the input row to the (command line) arguments

        for ( int iteration = 0; iteration < rows.size() && !parentJob.isStopped() && continueProcess; iteration++ ) {
          resultRow = rows.get( iteration );

          // Get values from previous result
          String tablename_previous = resultRow.getString( 0, null );
          String schemaname_previous = resultRow.getString( 1, null );

          if ( !Utils.isEmpty( tablename_previous ) ) {
            if ( log.isDetailed() ) {
              logDetailed( BaseMessages.getString(
                PKG, "JobEntryTruncateTables.ProcessingRow", tablename_previous, schemaname_previous ) );
            }

            // let's truncate table
            if ( truncateTables( tablename_previous, schemaname_previous, db ) ) {
              updateSuccess();
            } else {
              updateErrors();
            }
          } else {
            logError( BaseMessages.getString( PKG, "JobEntryTruncateTables.RowEmpty" ) );
          }
        }

      } else if ( arguments != null ) {
        for ( int i = 0; i < arguments.length && !parentJob.isStopped() && continueProcess; i++ ) {
          String realTablename = environmentSubstitute( arguments[i] );
          String realSchemaname = environmentSubstitute( schemaname[i] );
          if ( !Utils.isEmpty( realTablename ) ) {
            if ( log.isDetailed() ) {
              logDetailed( BaseMessages.getString(
                PKG, "JobEntryTruncateTables.ProcessingArg", arguments[i], schemaname[i] ) );
            }

            // let's truncate table
            if ( truncateTables( realTablename, realSchemaname, db ) ) {
              updateSuccess();
            } else {
              updateErrors();
            }
          } else {
            logError( BaseMessages.getString(
              PKG, "JobEntryTruncateTables.ArgEmpty", arguments[i], schemaname[i] ) );
          }
        }
      }
    } catch ( Exception dbe ) {
      result.setNrErrors( 1 );
      logError( BaseMessages.getString( PKG, "JobEntryTruncateTables.Error.RunningEntry", dbe.getMessage() ) );
    } finally {
      if ( db != null ) {
        db.disconnect();
      }
    }
  } else {
    result.setNrErrors( 1 );
    logError( BaseMessages.getString( PKG, "JobEntryTruncateTables.NoDbConnection" ) );
  }

  result.setNrErrors( nrErrors );
  result.setNrLinesDeleted( nrSuccess );
  result.setResult( nrErrors == 0 );
  return result;
}
 
Example 19
Source File: KettleFileTableModel.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static String getLastExecutionResult( LogChannelInterface log, LoggingObjectInterface parentObject,
  ReportSubjectLocation filename ) throws KettleException {

  LogTableInterface logTable = null;
  if ( filename.isTransformation() ) {
    TransMeta transMeta = TransformationInformation.getInstance().getTransMeta( filename );
    logTable = transMeta.getTransLogTable();
  } else {
    JobMeta jobMeta = JobInformation.getInstance().getJobMeta( filename );
    logTable = jobMeta.getJobLogTable();
  }
  if ( logTable != null && logTable.isDefined() ) {
    DatabaseMeta dbMeta = logTable.getDatabaseMeta();
    Database database = new Database( parentObject, dbMeta );
    try {
      database.connect();
      String sql = "SELECT ";
      sql += dbMeta.quoteField( logTable.getStatusField().getFieldName() ) + ", ";
      sql += dbMeta.quoteField( logTable.getLogDateField().getFieldName() ) + ", ";
      sql += dbMeta.quoteField( logTable.getErrorsField().getFieldName() ) + "";
      sql += " FROM ";
      sql += dbMeta.getQuotedSchemaTableCombination( logTable.getSchemaName(), logTable.getTableName() );
      sql += " ORDER BY " + dbMeta.quoteField( logTable.getLogDateField().getFieldName() ) + " DESC";

      RowMetaAndData oneRow = database.getOneRow( sql );
      String status = oneRow.getString( 0, "?" );
      Date date = oneRow.getDate( 1, null );
      Long nrErrors = oneRow.getInteger( 2 );

      String evaluation;
      if ( status.equalsIgnoreCase( LogStatus.END.getStatus() ) ) {
        evaluation = "Ended";
      } else if ( status.equalsIgnoreCase( LogStatus.START.getStatus() ) ) {
        evaluation = "Started";
      } else if ( status.equalsIgnoreCase( LogStatus.STOP.getStatus() ) ) {
        evaluation = "Stopped";
      } else if ( status.equalsIgnoreCase( LogStatus.RUNNING.getStatus() ) ) {
        evaluation = "Running";
      } else if ( status.equalsIgnoreCase( LogStatus.PAUSED.getStatus() ) ) {
        evaluation = "Paused";
      } else if ( status.equalsIgnoreCase( LogStatus.ERROR.getStatus() ) ) {
        evaluation = "Failed";
      } else {
        evaluation = "Unknown";
      }
      if ( nrErrors > 0 ) {
        evaluation += " with errors";
      } else {
        evaluation += " with success";
      }

      return evaluation + " at " + XMLHandler.date2string( date );

    } catch ( Exception e ) {
      log.logBasic( "Unable to get logging information from log table" + logTable );
    } finally {
      database.disconnect();
    }
  }
  return null;
}
 
Example 20
Source File: JobEntryXMLWellFormed.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result previousResult, int nr ) throws KettleException {
  Result result = previousResult;
  result.setNrErrors( 1 );
  result.setResult( false );

  List<RowMetaAndData> rows = result.getRows();
  RowMetaAndData resultRow = null;

  NrErrors = 0;
  NrWellFormed = 0;
  NrBadFormed = 0;
  limitFiles = Const.toInt( environmentSubstitute( getNrErrorsLessThan() ), 10 );
  successConditionBroken = false;
  successConditionBrokenExit = false;

  // Get source and destination files, also wildcard
  String[] vsourcefilefolder = source_filefolder;
  String[] vwildcard = wildcard;

  if ( arg_from_previous ) {
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobXMLWellFormed.Log.ArgFromPrevious.Found", ( rows != null ? rows
          .size() : 0 )
          + "" ) );
    }

  }
  if ( arg_from_previous && rows != null ) {
    // Copy the input row to the (command line) arguments
    for ( int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++ ) {
      if ( successConditionBroken ) {
        if ( !successConditionBrokenExit ) {
          logError( BaseMessages.getString( PKG, "JobXMLWellFormed.Error.SuccessConditionbroken", "" + NrAllErrors ) );
          successConditionBrokenExit = true;
        }
        result.setEntryNr( NrAllErrors );
        result.setNrLinesRejected( NrBadFormed );
        result.setNrLinesWritten( NrWellFormed );
        return result;
      }

      resultRow = rows.get( iteration );

      // Get source and destination file names, also wildcard
      String vsourcefilefolder_previous = resultRow.getString( 0, null );
      String vwildcard_previous = resultRow.getString( 1, null );

      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "JobXMLWellFormed.Log.ProcessingRow", vsourcefilefolder_previous,
            vwildcard_previous ) );
      }

      processFileFolder( vsourcefilefolder_previous, vwildcard_previous, parentJob, result );
    }
  } else if ( vsourcefilefolder != null ) {
    for ( int i = 0; i < vsourcefilefolder.length && !parentJob.isStopped(); i++ ) {
      if ( successConditionBroken ) {
        if ( !successConditionBrokenExit ) {
          logError( BaseMessages.getString( PKG, "JobXMLWellFormed.Error.SuccessConditionbroken", "" + NrAllErrors ) );
          successConditionBrokenExit = true;
        }
        result.setEntryNr( NrAllErrors );
        result.setNrLinesRejected( NrBadFormed );
        result.setNrLinesWritten( NrWellFormed );
        return result;
      }

      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "JobXMLWellFormed.Log.ProcessingRow", vsourcefilefolder[i],
            vwildcard[i] ) );
      }

      processFileFolder( vsourcefilefolder[i], vwildcard[i], parentJob, result );

    }
  }

  // Success Condition
  result.setNrErrors( NrAllErrors );
  result.setNrLinesRejected( NrBadFormed );
  result.setNrLinesWritten( NrWellFormed );
  if ( getSuccessStatus() ) {
    result.setNrErrors( 0 );
    result.setResult( true );
  }

  displayResults();

  return result;
}