Working with a PDI repository

Working with a PDI repository

Below you will see a few examples on how to load jobs and transformations from a Pentaho Data Integration repository.

Connecting to a repository

Repository types are plugins since version 4 of PDI.  Therefor we need to ask the Plugin Registry for the appropriate repository interface.

RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
repositoriesMeta.readData();
RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );
PluginRegistry registry = PluginRegistry.getInstance();
Repository repository = registry.loadClass(
       RepositoryPluginType.class,
       repositoryMeta,
       Repository.class
  );
repository.init(repositoryMeta);

Once you have a handle on the repository, you can connect to it like this:

repository.connect(username, password);

Using the repository

The repository interface contains a lot of interesting methods that you can use ranging from security related interfaces to methods to load and save objects.  Below are a few examples.

Find a directory

If you want to find a certain directory, here is a way to do it:

RepositoryDirectoryInterface tree = repository.loadRepositoryDirectoryTree();
RepositoryDirectoryInterface fooBar = tree.findDirectory("/foo/bar");

Load a transformation

/**
   * Load a transformation with a name from a folder in the repository
   *
   *  @param transname the name of the transformation to load
   *  @param The folder to load it from
   *  @param monitor the progress monitor to use (UI feedback)
   *  @param setInternalVariables set to true if you want to automatically set the internal variables of the loaded transformation. (true is the default with very few exceptions!)
   *  @param revision the revision to load.  Specify null to load the last version.
   */
  public TransMeta loadTransformation(
    String transname,
    RepositoryDirectoryInterface repdir,
    ProgressMonitorListener monitor,
    boolean setInternalVariables,
    String revision
  ) throws KettleException;

for example:

TransMeta transMeta = repository.loadTransformation("Example", fooBar, null, true, null);

Load a job

  /**
   * Load a job from the repository
   * @param jobname the name
   * @param repdir the directory
   * @param monitor the progress monitor or null
   * @param revision the revision to load.  Specify null to load the last version.
   */
  public JobMeta loadJob(
    String jobname,
    RepositoryDirectoryInterface repdir,
    ProgressMonitorListener monitor,
    String revision
  ) throws KettleException;

for example:

JobMeta jobMeta = repository.loadJob("Example", fooBar, null, null);