Java Code Examples for org.pentaho.di.core.vfs.KettleVFS

The following examples show how to use org.pentaho.di.core.vfs.KettleVFS. These examples are extracted from open source projects. 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 Project: pentaho-kettle   Source File: VFSFileProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param files
 * @return
 */
public List<VFSFile> delete( List<VFSFile> files ) {
  List<VFSFile> deletedFiles = new ArrayList<>();
  for ( VFSFile file : files ) {
    try {
      FileObject fileObject = KettleVFS
        .getFileObject( file.getPath(), new Variables(), VFSHelper.getOpts( file.getPath(), file.getConnection() ) );
      if ( fileObject.delete() ) {
        deletedFiles.add( file );
      }
    } catch ( KettleFileException | FileSystemException kfe ) {
      // Ignore don't add
    }
  }
  return deletedFiles;
}
 
Example 2
Source Project: pentaho-kettle   Source File: PartitionerPluginType.java    License: Apache License 2.0 6 votes vote down vote up
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "partitioner-plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError(
            "Error found while reading partitioning plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 3
Source Project: pentaho-kettle   Source File: JobMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Load the job from the XML file specified.
 *
 * @param fname The filename to load as a job
 * @param rep   The repository to bind againt, null if there is no repository available.
 * @throws KettleXMLException
 */
public JobMeta( VariableSpace parentSpace, String fname, Repository rep, IMetaStore metaStore,
    OverwritePrompter prompter ) throws KettleXMLException {
  this.initializeVariablesFrom( parentSpace );
  this.metaStore = metaStore;
  try {
    // OK, try to load using the VFS stuff...
    Document doc = XMLHandler.loadXMLFile( KettleVFS.getFileObject( fname, this ) );
    if ( doc != null ) {
      // The jobnode
      Node jobnode = XMLHandler.getSubNode( doc, XML_TAG );

      loadXML( jobnode, fname, rep, metaStore, false, prompter );
    } else {
      throw new KettleXMLException(
          BaseMessages.getString( PKG, "JobMeta.Exception.ErrorReadingFromXMLFile" ) + fname );
    }
  } catch ( Exception e ) {
    throw new KettleXMLException(
        BaseMessages.getString( PKG, "JobMeta.Exception.UnableToLoadJobFromXMLFile" ) + fname + "]", e );
  }
}
 
Example 4
Source Project: pentaho-kettle   Source File: TextFileInputMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
 * what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file.
 * For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like
 * that.
 *
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
@Override
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
  ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    // In case the name of the file comes from previous steps, forget about this!
    //
    if ( !acceptingFilenames ) {

      // Replace the filename ONLY (folder or filename)
      //
      for ( int i = 0; i < fileName.length; i++ ) {
        FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName[i] ), space );
        fileName[i] = resourceNamingInterface.nameResource( fileObject, space, Utils.isEmpty( fileMask[i] ) );
      }
    }
    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
Example 5
Source Project: pentaho-kettle   Source File: FileLoggingEventListener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Log only lines belonging to the specified log channel ID or one of it's children (grandchildren) to the specified
 * file.
 *
 * @param logChannelId
 * @param filename
 * @param append
 * @throws KettleException
 */
public FileLoggingEventListener( String logChannelId, String filename, boolean append ) throws KettleException {
  this.logChannelId = logChannelId;
  this.filename = filename;
  this.layout = new KettleLogLayout( true );
  this.exception = null;

  file = KettleVFS.getFileObject( filename );
  outputStream = null;
  try {
    outputStream = KettleVFS.getOutputStream( file, append );
  } catch ( Exception e ) {
    throw new KettleException(
      "Unable to create a logging event listener to write to file '" + filename + "'", e );
  }
}
 
Example 6
Source Project: pentaho-kettle   Source File: VFSFileProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param inputStream
 * @param destDir
 * @param path
 * @param overwrite
 * @return
 * @throws FileException
 */
@Override public VFSFile writeFile( InputStream inputStream, VFSFile destDir,
                                    String path, boolean overwrite )
  throws FileException {
  FileObject fileObject = null;
  try {
    fileObject = KettleVFS
      .getFileObject( path, new Variables(), VFSHelper.getOpts( destDir.getPath(), destDir.getConnection() ) );
  } catch ( KettleException ke ) {
    throw new FileException();
  }
  if ( fileObject != null ) {
    try ( OutputStream outputStream = fileObject.getContent().getOutputStream(); ) {
      IOUtils.copy( inputStream, outputStream );
      outputStream.flush();
      return VFSFile.create( destDir.getPath(), fileObject, destDir.getConnection(), destDir.getDomain() );
    } catch ( IOException e ) {
      return null;
    }
  }
  return null;
}
 
Example 7
Source Project: pentaho-kettle   Source File: ValueMetaPluginType.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void registerXmlPlugins() throws KettlePluginException {
  for ( PluginFolderInterface folder : pluginFolders ) {

    if ( folder.isPluginXmlFolder() ) {
      List<FileObject> pluginXmlFiles = findPluginXmlFiles( folder.getFolder() );
      for ( FileObject file : pluginXmlFiles ) {

        try {
          Document document = XMLHandler.loadXMLFile( file );
          Node pluginNode = XMLHandler.getSubNode( document, "plugin" );
          if ( pluginNode != null ) {
            registerPluginFromXmlResource( pluginNode, KettleVFS.getFilename( file.getParent() ), this
              .getClass(), false, file.getParent().getURL() );
          }
        } catch ( Exception e ) {
          // We want to report this plugin.xml error, perhaps an XML typo or something like that...
          //
          log.logError( "Error found while reading step plugin.xml file: " + file.getName().toString(), e );
        }
      }
    }
  }
}
 
Example 8
Source Project: pentaho-hadoop-shims   Source File: PluginPropertiesUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Loads a properties file from the plugin directory for the plugin interface provided
 *
 * @param plugin
 * @return
 * @throws KettleFileException
 * @throws IOException
 */
protected Properties loadProperties( PluginInterface plugin, String relativeName ) throws KettleFileException,
  IOException {
  if ( plugin == null ) {
    throw new NullPointerException();
  }
  FileObject propFile =
    KettleVFS.getFileObject( plugin.getPluginDirectory().getPath() + Const.FILE_SEPARATOR + relativeName );
  if ( !propFile.exists() ) {
    throw new FileNotFoundException( propFile.toString() );
  }
  try {
    return new PropertiesConfigurationProperties( propFile );
  } catch ( ConfigurationException e ) {
    throw new IOException( e );
  }
}
 
Example 9
Source Project: pentaho-kettle   Source File: SwtSvgImageUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Internal image loading from Kettle's VFS.
 */
private static SwtUniversalImage loadFromSimpleVFS( Display display, String location ) {
  try {
    InputStream s = KettleVFS.getInputStream( location );
    if ( s == null ) {
      return null;
    }
    try {
      return loadImage( display, s, location );
    } finally {
      IOUtils.closeQuietly( s );
    }
  } catch ( KettleFileException e ) {
    // do nothing. try to load next
  }
  return null;
}
 
Example 10
@Test
public void deleteDirectory() throws Exception {
  FileObject test = KettleVFS.getFileObject( "bin/test/deleteDirectoryTest" );
  test.createFolder();

  DistributedCacheUtilImpl ch = new DistributedCacheUtilImpl();
  ch.deleteDirectory( test );
  try {
    assertFalse( test.exists() );
  } finally {
    // Delete the directory with java.io.File if it wasn't removed
    File f = new File( "bin/test/deleteDirectoryTest" );
    if ( f.exists() && !f.delete() ) {
      throw new IOException( "unable to delete test directory: " + f.getAbsolutePath() );
    }
  }
}
 
Example 11
Source Project: pentaho-hadoop-shims   Source File: LegacyShimLocator.java    License: Apache License 2.0 6 votes vote down vote up
public static String getLegacyDefaultShimDir( String shimFolder ) throws IOException {
  PluginInterface pluginInterface =
    PluginRegistry.getInstance().findPluginWithId( LifecyclePluginType.class, HADOOP_SPOON_PLUGIN );
  Properties legacyProperties;

  try {
    legacyProperties = loadProperties( pluginInterface, BIG_DATA_PLUGIN_PROPERTIES );
    String legacyShimsFolder = legacyProperties.getProperty( HADOOP_CONFIGURATIONS_PATH );
    FileObject shimDirectoryObject =
      KettleVFS.getFileObject( pluginInterface.getPluginDirectory().getPath() + Const.FILE_SEPARATOR
        + legacyShimsFolder + Const.FILE_SEPARATOR + shimFolder );
    return shimDirectoryObject.getURL().getPath();
  } catch ( KettleFileException | NullPointerException e ) {
    throw new IOException( e );
  }
}
 
Example 12
Source Project: pentaho-kettle   Source File: JobEntryMSAccessBulkLoad.java    License: Apache License 2.0 6 votes vote down vote up
private void addFileToResultFilenames( String fileaddentry, Result result, Job parentJob ) {
  try {
    ResultFile resultFile =
      new ResultFile( ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject( fileaddentry, this ), parentJob
        .getJobname(), toString() );
    result.getResultFiles().put( resultFile.getFile().toString(), resultFile );

    if ( log.isDebug() ) {
      logDebug( " ------ " );
      logDebug( BaseMessages.getString(
        PKG, "JobEntryMSAccessBulkLoad.Log.FileAddedToResultFilesName", fileaddentry ) );
    }
  } catch ( Exception e ) {
    log.logError(
      BaseMessages.getString( PKG, "JobEntryMSAccessBulkLoad.Error.AddingToFilenameResult" ), fileaddentry
        + "" + e.getMessage() );
  }
}
 
Example 13
Source Project: pentaho-kettle   Source File: JobEntryFTPSGetIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void downloadFile_WhenDestinationIsSetViaVariable() throws Exception {
  final String myVar = "my-var";
  final String expectedDownloadedFilePath = ramDir + "/" + FtpsServer.SAMPLE_FILE;

  JobEntryFTPSGet job = createCommonJob();
  job.setVariable( myVar, ramDir );
  job.setTargetDirectory( String.format( "${%s}", myVar ) );

  FileObject downloaded = KettleVFS.getFileObject( expectedDownloadedFilePath );
  assertFalse( downloaded.exists() );
  try {
    job.execute( new Result(), 1 );
    downloaded = KettleVFS.getFileObject( expectedDownloadedFilePath );
    assertTrue( downloaded.exists() );
  } finally {
    downloaded.delete();
  }
}
 
Example 14
Source Project: pentaho-kettle   Source File: JobEntryTalendJobExec.java    License: Apache License 2.0 6 votes vote down vote up
private URL[] prepareJarFiles( FileObject zipFile ) throws Exception {

    // zip:file:///tmp/foo.zip
    FileInputList fileList = FileInputList.createFileList( this, new String[] { "zip:" + zipFile.toString(), },
      new String[] { ".*\\.jar$", }, // Include mask: only jar files
      new String[] { ".*classpath\\.jar$", }, // Exclude mask: only jar files
      new String[] { "Y", }, // File required
      new boolean[] { true, } ); // Search sub-directories

    List<URL> files = new ArrayList<URL>();

    // Copy the jar files in the temp folder...
    //
    for ( FileObject file : fileList.getFiles() ) {
      FileObject jarfilecopy =
        KettleVFS.createTempFile(
          file.getName().getBaseName(), ".jar", environmentSubstitute( "${java.io.tmpdir}" ) );
      jarfilecopy.copyFrom( file, new AllFileSelector() );
      files.add( jarfilecopy.getURL() );
    }

    return files.toArray( new URL[files.size()] );
  }
 
Example 15
Source Project: pentaho-kettle   Source File: TextFileInputTest.java    License: Apache License 2.0 6 votes vote down vote up
private static String createVirtualFile( String filename, String... rows ) throws Exception {
  String virtualFile = TestUtils.createRamFile( filename );

  StringBuilder content = new StringBuilder();
  if ( rows != null ) {
    for ( String row : rows ) {
      content.append( row );
    }
  }
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  bos.write( content.toString().getBytes() );

  try ( OutputStream os = KettleVFS.getFileObject( virtualFile ).getContent().getOutputStream() ) {
    IOUtils.copy( new ByteArrayInputStream( bos.toByteArray() ), os );
  }

  return virtualFile;
}
 
Example 16
Source Project: pentaho-kettle   Source File: SQLFileOutputMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
 * what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file.
 * For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like
 * that.
 *
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
  ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    //
    // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.data
    // To : /home/matt/test/files/foo/bar.data
    //
    FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName ), space );

    // If the file doesn't exist, forget about this effort too!
    //
    if ( fileObject.exists() ) {
      // Convert to an absolute path...
      //
      fileName = resourceNamingInterface.nameResource( fileObject, space, true );

      return fileName;
    }
    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
Example 17
Source Project: pentaho-kettle   Source File: RegisterPackageServlet.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Copy contents of <code>inputStream</code> to <code>directory</code>. Expecting zip file.
 * @param inputStream zip file input stream.
 * @param directory local destination directory.
 * @return copied file path.
 * @throws KettleException
 */
protected String copyRequestToDirectory( InputStream inputStream, String directory ) throws KettleException {
  String copiedFilePath;
  try {
    FileObject foDirectory = KettleVFS.getFileObject( directory );
    if ( !foDirectory.exists() ) {
      foDirectory.createFolder();
    }
    FileObject tempZipFile = KettleVFS.createTempFile( "export", ".zip", directory );
    OutputStream outputStream = KettleVFS.getOutputStream( tempZipFile, false );
    copyAndClose( inputStream, outputStream );
    copiedFilePath = tempZipFile.getName().getPath();
  } catch ( IOException ioe ) {
    throw new KettleException( BaseMessages.getString( PKG, "RegisterPackageServlet.Exception.CopyRequest",  directory ), ioe );
  }

  return copiedFilePath;
}
 
Example 18
Source Project: pentaho-kettle   Source File: CsvInputDialog.java    License: Apache License 2.0 6 votes vote down vote up
/**'
 * Returns the {@link InputStream} corresponding to the csv file, or null if the file cannot be read.
 * @return the {@link InputStream} corresponding to the csv file, or null if the file cannot be read
 */
private InputStream getInputStream( final CsvInputMeta meta ) {
  InputStream inputStream = null;
  try {
    final String filename = transMeta.environmentSubstitute( meta.getFilename() );

    final FileObject fileObject = KettleVFS.getFileObject( filename );
    if ( !( fileObject instanceof LocalFile ) ) {
      // We can only use NIO on local files at the moment, so that's what we
      // limit ourselves to.
      //
      throw new KettleException( BaseMessages.getString( PKG, "CsvInput.Log.OnlyLocalFilesAreSupported" ) );
    }

    inputStream = KettleVFS.getInputStream( fileObject );
  } catch ( final Exception e ) {
    logError( BaseMessages.getString( PKG, "CsvInputDialog.ErrorGettingFileDesc.DialogMessage" ), e );
  }
  return inputStream;
}
 
Example 19
Source Project: pentaho-kettle   Source File: MailConnection.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Export message content to a filename.
 *
 * @param filename
 *          the target filename
 * @param foldername
 *          the parent folder of filename
 * @throws KettleException
 */

public void saveMessageContentToFile( String filename, String foldername ) throws KettleException {
  OutputStream os = null;
  try {
    os = KettleVFS.getOutputStream( foldername + ( foldername.endsWith( "/" ) ? "" : "/" ) + filename, false );
    getMessage().writeTo( os );
    updateSavedMessagesCounter();
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.SavingMessageContent", ""
      + this.message.getMessageNumber(), filename, foldername ), e );
  } finally {
    if ( os != null ) {
      IOUtils.closeQuietly( os );
    }
  }
}
 
Example 20
Source Project: pentaho-kettle   Source File: MailConnection.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static String findValidTarget( String folderName, final String fileName ) throws KettleException {
  if ( fileName == null || folderName == null ) {
    throw new IllegalArgumentException( "Cannot have null arguments to findValidTarget" );
  }
  String fileNameRoot = FilenameUtils.getBaseName( fileName ), ext = "." + FilenameUtils.getExtension( fileName );
  if ( ( ext.length() == 1 ) ) { // only a "."
    ext = "";
  }
  String rtn = "", base = FilenameUtils.concat( folderName, fileNameRoot );
  int baseSz = base.length();
  StringBuilder build = new StringBuilder( baseSz ).append( base );
  int i = -1;
  do {
    i++;
    build.setLength( baseSz ); // bring string back to size
    build.append( i > 0 ? Integer.toString( i ) : "" ).append( ext );
    rtn = build.toString();
  } while ( KettleVFS.fileExists( rtn ) );

  return rtn;
}
 
Example 21
Source Project: pentaho-kettle   Source File: FixedInputMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
  ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    //
    // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.txt
    // To : /home/matt/test/files/foo/bar.txt
    //
    FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( filename ), space );

    // If the file doesn't exist, forget about this effort too!
    //
    if ( fileObject.exists() ) {
      // Convert to an absolute path...
      //
      filename = resourceNamingInterface.nameResource( fileObject, space, true );

      return filename;
    }
    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
Example 22
Source Project: pentaho-kettle   Source File: LoadFileInputMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
    ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    //
    if ( !fileinfield ) {
      for ( int i = 0; i < fileName.length; i++ ) {
        FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName[i] ), space );
        fileName[i] = resourceNamingInterface.nameResource( fileObject, space, Utils.isEmpty( fileMask[i] ) );
      }
    }
    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
Example 23
Source Project: pentaho-kettle   Source File: VFSFileProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param file
 * @param toPath
 * @param overwrite
 * @return
 * @throws FileException
 */
@Override
public VFSFile copy( VFSFile file, String toPath, boolean overwrite ) throws FileException {
  try {
    FileObject fileObject = KettleVFS
      .getFileObject( file.getPath(), new Variables(), VFSHelper.getOpts( file.getPath(), file.getConnection() ) );
    FileObject copyObject =
      KettleVFS.getFileObject( toPath, new Variables(), VFSHelper.getOpts( file.getPath(), file.getConnection() ) );
    copyObject.copyFrom( fileObject, Selectors.SELECT_SELF );
    if ( file instanceof VFSDirectory ) {
      return VFSDirectory
        .create( copyObject.getParent().getPublicURIString(), fileObject, file.getConnection(), file.getDomain() );
    } else {
      return VFSFile
        .create( copyObject.getParent().getPublicURIString(), fileObject, file.getConnection(), file.getDomain() );
    }
  } catch ( KettleFileException | FileSystemException e ) {
    throw new FileException();
  }
}
 
Example 24
Source Project: pentaho-kettle   Source File: XMLOutputMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
 * what this does is turn the name of the base path into an absolute path.
 * 
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 * 
 * @return the filename of the exported resource
 */
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
    ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore )
  throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    //
    if ( !Utils.isEmpty( fileName ) ) {
      FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName ), space );
      fileName = resourceNamingInterface.nameResource( fileObject, space, true );
    }

    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
Example 25
Source Project: pentaho-kettle   Source File: JobEntryPGPEncryptFiles.java    License: Apache License 2.0 6 votes vote down vote up
private void addFileToResultFilenames( String fileaddentry, Result result, Job parentJob ) {
  try {
    ResultFile resultFile =
      new ResultFile( ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject( fileaddentry ), parentJob
        .getJobname(), toString() );
    result.getResultFiles().put( resultFile.getFile().toString(), resultFile );

    if ( isDebug() ) {
      logDebug( " ------ " );
      logDebug( BaseMessages.getString( PKG, "JobPGPEncryptFiles.Log.FileAddedToResultFilesName", fileaddentry ) );
    }

  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "JobPGPEncryptFiles.Error.AddingToFilenameResult" ), fileaddentry
      + "" + e.getMessage() );
  }
}
 
Example 26
Source Project: pentaho-kettle   Source File: JobEntrySSH2PUT.java    License: Apache License 2.0 6 votes vote down vote up
private List<FileObject> getFiles( String localfolder ) throws KettleFileException {
  try {
    List<FileObject> myFileList = new ArrayList<FileObject>();

    // Get all the files in the local directory...

    FileObject localFiles = KettleVFS.getFileObject( localfolder, this );
    FileObject[] children = localFiles.getChildren();
    if ( children != null ) {
      for ( int i = 0; i < children.length; i++ ) {
        // Get filename of file or directory
        if ( children[i].getType().equals( FileType.FILE ) ) {
          myFileList.add( children[i] );

        }
      } // end for
    }

    return myFileList;
  } catch ( IOException e ) {
    throw new KettleFileException( e );
  }

}
 
Example 27
Source Project: pentaho-kettle   Source File: JobEntrySSH2GET.java    License: Apache License 2.0 5 votes vote down vote up
private boolean CreateFolder( String filefolder ) {
  FileObject folder = null;
  try {
    folder = KettleVFS.getFileObject( filefolder, this );

    if ( !folder.exists() ) {
      if ( createtargetfolder ) {
        folder.createFolder();
        if ( log.isDetailed() ) {
          logDetailed( BaseMessages.getString( PKG, "JobSSH2GET.Log.FolderCreated", folder.toString() ) );
        }
      } else {
        return false;
      }

    }
    return true;
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "JobSSH2GET.Log.CanNotCreateFolder", folder.toString() ), e );

  } finally {
    if ( folder != null ) {
      try {
        folder.close();
      } catch ( Exception ex ) { /* Ignore */
      }
    }
  }
  return false;
}
 
Example 28
private void snapshotMetaStore( String metaStoreSnapshotDir ) throws MetaStoreException {
  IMetaStore snapshot = new XmlMetaStore( metaStoreSnapshotDir );
  try {
    FileSystemConfigBuilder nc = KettleVFS.getInstance().getFileSystemManager().getFileSystemConfigBuilder( "hc" );
    Method snapshotMethod = nc.getClass().getMethod( "snapshotNamedClusterToMetaStore", IMetaStore.class );
    snapshotMethod.invoke( nc, snapshot );

    stageConfigurationFiles( metaStoreSnapshotDir );
  } catch ( FileSystemException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e ) {
    log.logError( "Error in snapshotNamedClusterToMetaStore.", e );
  }
}
 
Example 29
public FileObject extractToTemp( FileObject archive ) throws IOException, KettleFileException {
  if ( archive == null ) {
    throw new NullPointerException( "archive is required" );
  }
  // Ask KettleVFS for a temporary file name without extension and use that as our temporary folder to extract into
  FileObject dest = KettleVFS.createTempFile( "", "", System.getProperty( "java.io.tmpdir" ) );
  return extract( archive, dest );
}
 
Example 30
Source Project: pentaho-kettle   Source File: CubeInputMeta.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
@Override public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
                                         ResourceNamingInterface resourceNamingInterface, Repository repository,
                                         IMetaStore metaStore ) throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    //
    // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.data
    // To : /home/matt/test/files/foo/bar.data
    //
    FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( filename ), space );

    // If the file doesn't exist, forget about this effort too!
    //
    if ( fileObject.exists() ) {
      // Convert to an absolute path...
      //
      filename = resourceNamingInterface.nameResource( fileObject, space, true );

      return filename;
    }
    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}