Java Code Examples for org.pentaho.di.core.Result#getResultFilesList()

The following examples show how to use org.pentaho.di.core.Result#getResultFilesList() . 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: FilesFromResult.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  data = (FilesFromResultData) sdi;

  if ( super.init( smi, sdi ) ) {
    Result result = getTrans().getPreviousResult();

    if ( result != null ) {
      data.resultFilesList = result.getResultFilesList();
    } else {
      data.resultFilesList = null;
    }

    // Add init code here.
    return true;
  }
  return false;
}
 
Example 2
Source File: TransExecutor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void collectExecutionResultFiles( Result result ) throws KettleException {
  RowSet resultFilesRowSet = getData().getResultFilesRowSet();
  if ( meta.getResultFilesTargetStepMeta() != null && result.getResultFilesList() != null && resultFilesRowSet != null ) {
    for ( ResultFile resultFile : result.getResultFilesList() ) {
      Object[] targetRow = RowDataUtil.allocateRowData( getData().getResultFilesOutputRowMeta().size() );
      int idx = 0;
      targetRow[ idx++ ] = resultFile.getFile().getName().toString();

      // TODO: time, origin, ...

      putRowTo( getData().getResultFilesOutputRowMeta(), targetRow, resultFilesRowSet );
    }
  }
}
 
Example 3
Source File: JobEntryDeleteResultFilenames.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;
  result.setResult( false );

  if ( previousResult != null ) {
    try {
      int size = previousResult.getResultFiles().size();
      if ( log.isBasic() ) {
        logBasic( BaseMessages.getString( PKG, "JobEntryDeleteResultFilenames.log.FilesFound", "" + size ) );
      }
      if ( !specifywildcard ) {
        // Delete all files
        previousResult.getResultFiles().clear();
        if ( log.isDetailed() ) {
          logDetailed( BaseMessages.getString( PKG, "JobEntryDeleteResultFilenames.log.DeletedFiles", "" + size ) );
        }
      } else {

        List<ResultFile> resultFiles = result.getResultFilesList();
        if ( resultFiles != null && resultFiles.size() > 0 ) {
          for ( Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext() && !parentJob.isStopped(); ) {
            ResultFile resultFile = it.next();
            FileObject file = resultFile.getFile();
            if ( file != null && file.exists() ) {
              if ( CheckFileWildcard( file.getName().getBaseName(), environmentSubstitute( wildcard ), true )
                && !CheckFileWildcard(
                  file.getName().getBaseName(), environmentSubstitute( wildcardexclude ), false ) ) {
                // Remove file from result files list
                result.getResultFiles().remove( resultFile.getFile().toString() );

                if ( log.isDetailed() ) {
                  logDetailed( BaseMessages.getString(
                    PKG, "JobEntryDeleteResultFilenames.log.DeletedFile", file.toString() ) );
                }
              }

            }
          }
        }
      }
      result.setResult( true );
    } catch ( Exception e ) {
      logError( BaseMessages.getString( PKG, "JobEntryDeleteResultFilenames.Error", e.toString() ) );
    }
  }
  return result;
}
 
Example 4
Source File: JobEntryCopyMoveResultFilenames.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;
  result.setNrErrors( 1 );
  result.setResult( false );

  boolean deleteFile = getAction().equals( "delete" );

  //Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
  if ( parentJobMeta.getNamedClusterEmbedManager() != null ) {
    parentJobMeta.getNamedClusterEmbedManager()
      .passEmbeddedMetastoreKey( this, parentJobMeta.getEmbeddedMetastoreProviderKey() );
  }

  String realdestinationFolder = null;
  if ( !deleteFile ) {
    realdestinationFolder = environmentSubstitute( getDestinationFolder() );

    if ( !CreateDestinationFolder( realdestinationFolder ) ) {
      return result;
    }
  }
  if ( !Utils.isEmpty( wildcard ) ) {
    wildcardPattern = Pattern.compile( environmentSubstitute( wildcard ) );
  }
  if ( !Utils.isEmpty( wildcardexclude ) ) {
    wildcardExcludePattern = Pattern.compile( environmentSubstitute( wildcardexclude ) );
  }

  if ( previousResult != null ) {
    NrErrors = 0;
    limitFiles = Const.toInt( environmentSubstitute( getNrErrorsLessThan() ), 10 );
    NrErrors = 0;
    NrSuccess = 0;
    successConditionBroken = false;
    successConditionBrokenExit = false;

    FileObject file = null;

    try {
      int size = result.getResultFiles().size();
      if ( log.isBasic() ) {
        logBasic( BaseMessages.getString( PKG, "JobEntryCopyMoveResultFilenames.log.FilesFound", "" + size ) );
      }

      List<ResultFile> resultFiles = result.getResultFilesList();
      if ( resultFiles != null && resultFiles.size() > 0 ) {
        for ( Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext() && !parentJob.isStopped(); ) {
          if ( successConditionBroken ) {
            logError( BaseMessages.getString(
              PKG, "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors ) );
            throw new Exception( BaseMessages.getString(
              PKG, "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors ) );
          }

          ResultFile resultFile = it.next();
          file = resultFile.getFile();
          if ( file != null && file.exists() ) {
            if ( !specifywildcard
              || ( CheckFileWildcard( file.getName().getBaseName(), wildcardPattern, true )
                && !CheckFileWildcard( file.getName().getBaseName(), wildcardExcludePattern, false )
                && specifywildcard ) ) {
              // Copy or Move file
              if ( !processFile( file, realdestinationFolder, result, parentJob, deleteFile ) ) {
                // Update Errors
                updateErrors();
              }
            }

          } else {
            logError( BaseMessages.getString(
              PKG, "JobEntryCopyMoveResultFilenames.log.ErrorCanNotFindFile", file.toString() ) );
            // Update Errors
            updateErrors();
          }
        } // end for
      }
    } catch ( Exception e ) {
      logError( BaseMessages.getString( PKG, "JobEntryCopyMoveResultFilenames.Error", e.toString() ) );
    } finally {
      if ( file != null ) {
        try {
          file.close();
          file = null;
        } catch ( Exception ex ) { /* Ignore */
        }
      }
    }
  }
  // Success Condition
  result.setNrErrors( NrErrors );
  result.setNrLinesWritten( NrSuccess );
  if ( getSuccessStatus() ) {
    result.setResult( true );
  }

  return result;
}