...
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.
Code Block |
---|
RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
repositoriesMeta.readData();
RepositoryMeta repositoryMeta = findRepository( repositoryName );
PluginRegistry registry = PluginRegistry.getInstance()
Repository repository = registry.loadClass(
RepositoryPluginType.class,
repositoryMeta,
Repository.class
);
|
Once you have a handle on the repository, you can connect to it like this:
Code Block |
---|
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:
Code Block |
---|
RepositoryDirectoryInterface tree = repository.loadRepositoryDirectoryTree();
RepositoryDirectoryInterface fooBar = tree.findDirectory("/foo/bar");
|
Load a transformation
Code Block |
---|
/**
* 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:
Code Block |
---|
TransMeta transMeta = repository.loadTransformation("Example", fooBar, null, true, null);
|
Load a job
Code Block |
---|
/**
* 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:
Code Block |
---|
JobMeta jobMeta = repository.loadJob("Example", fooBar, null, null);
|