Java Code Examples for org.pentaho.di.repository.Repository#init()

The following examples show how to use org.pentaho.di.repository.Repository#init() . 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: ExecuteJobServlet.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
Repository openRepository( String repositoryName, String user, String pass ) throws KettleException {

  if ( Utils.isEmpty( repositoryName ) ) {
    return null;
  }

  RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
  repositoriesMeta.readData();
  RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );
  if ( repositoryMeta == null ) {
    String message = BaseMessages.getString( PKG, "ExecuteJobServlet.Error.UnableToFindRepository", repositoryName );
    throw new KettleRepositoryNotFoundException( message );
  }
  PluginRegistry registry = PluginRegistry.getInstance();
  Repository repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class );
  repository.init( repositoryMeta );
  repository.connect( user, pass );
  return repository;
}
 
Example 2
Source File: ExecuteTransServlet.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private Repository openRepository( String repositoryName, String user, String pass ) throws KettleException {

    if ( Utils.isEmpty( repositoryName ) ) {
      return null;
    }

    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    repositoriesMeta.readData();
    RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );
    if ( repositoryMeta == null ) {
      throw new KettleException( "Unable to find repository: " + repositoryName );
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    Repository repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class );
    repository.init( repositoryMeta );
    repository.connect( user, pass );
    return repository;
  }
 
Example 3
Source File: JobExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ) throws KettleException {
  RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );
  if ( repositoryMeta == null ) {
    log.logBasic( "I couldn't find the repository with name '" + repositoryName + "'" );
    return null;
  }

  Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta,
      Repository.class );
  rep.init( repositoryMeta );

  try {
    rep.connect( username, password );
    log.logBasic( "Connected to " + repositoryName + " as " + username );
    setRepository( rep );
    return rep;
  } catch ( Exception e ) {
    log.logBasic( "Unable to connect to the repository with name '" + repositoryName + "'" );
    return null;
  }
}
 
Example 4
Source File: TransExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ) throws KettleException {
  RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );
  if ( repositoryMeta == null ) {
    log.logBasic( "I couldn't find the repository with name '" + repositoryName + "'" );
    return null;
  }
  Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class );
  if ( rep == null ) {
    log.logBasic( "Unable to load repository plugin for '" + repositoryName + "'" );
    return null;
  }
  rep.init( repositoryMeta );

  try {
    rep.connect( username, password );
    setRepository( rep );
    return rep;
  } catch ( Exception e ) {
    log.logBasic( "Unable to connect to the repository with name '" + repositoryName + "'" );
    return null;
  }
}
 
Example 5
Source File: RepositoryConnectController.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public RepositoryMeta createRepository( String id, Map<String, Object> items ) {
  RepositoryMeta repositoryMeta;
  try {
    repositoryMeta = pluginRegistry.loadClass( RepositoryPluginType.class, id, RepositoryMeta.class );
    repositoryMeta.populate( items, repositoriesMeta );

    if ( repositoryMeta.getName() != null ) {
      Repository repository =
        pluginRegistry.loadClass( RepositoryPluginType.class, repositoryMeta.getId(), Repository.class );
      repository.init( repositoryMeta );
      repositoriesMeta.addRepository( repositoryMeta );
      repositoriesMeta.writeData();
      currentRepository = repositoryMeta;
      if ( !testRepository( repository ) ) {
        return null;
      }
      ( (AbstractRepository) repository ).create();
    }
  } catch ( KettleException ke ) {
    log.logError( "Unable to load repository type", ke );
    return null;
  }
  return repositoryMeta;
}
 
Example 6
Source File: RepositoryConnectController.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void connectToRepository( RepositoryMeta repositoryMeta, String username, String password ) throws KettleException {
  final Repository repository = loadRepositoryObject( repositoryMeta.getId() );
  repository.init( repositoryMeta );
  repositoryConnect( repository, username, password );
  if ( username != null ) {
    getPropsUI().setLastRepositoryLogin( username );
  }
  Spoon spoon = spoonSupplier.get();
  Runnable execute = () -> {
    if ( spoon.getRepository() != null ) {
      spoon.closeRepository();
    } else {
      spoon.closeAllJobsAndTransformations( true );
    }
    spoon.setRepository( repository );
    setConnectedRepository( repositoryMeta );
    fireListeners();
    spoon.updateTreeForActiveAbstractMetas();
  };
  if ( spoon.getShell() != null ) {
    spoon.getShell().getDisplay().asyncExec( execute );
  } else {
    execute.run();
  }
}
 
Example 7
Source File: AbstractKettleTransformationProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Repository connectToRepository() throws KettleException {
  if ( repositoryName == null ) {
    throw new NullPointerException();
  }

  final RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
  try {
    repositoriesMeta.readData();
  } catch ( final KettleException ke ) {
    // we're a bit low to bubble a dialog to the user here..
    // when ramaiz fixes readData() to stop throwing exceptions
    // even when successful we can remove this and use
    // the more favorable repositoriesMeta.getException() or something
    // like it (I'm guessing on the method name)
  }

  // Find the specified repository.
  final RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );

  if ( repositoryMeta == null ) {
    // repository object is not necessary for filesystem transformations
    return null;
  }

  final Repository repository =
    PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta.getId(), Repository.class );
  repository.init( repositoryMeta );
  repository.connect( username, password );
  return repository;
}
 
Example 8
Source File: AbstractBaseCommandExecutor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public Repository establishRepositoryConnection( RepositoryMeta repositoryMeta, final String username, final String password,
                                                   final RepositoryOperation... operations ) throws KettleException {

  Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class );
  rep.init( repositoryMeta );
  rep.getLog().setLogLevel( getLog().getLogLevel() );
  rep.connect( username != null ? username : null, password != null ? password : null );

  if ( operations != null ) {
    // throws KettleSecurityException if username does does have permission for given operations
    rep.getSecurityProvider().validateAction( operations );
  }

  return rep;
}
 
Example 9
Source File: RepositoryConnectController.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean updateRepository( String id, Map<String, Object> items ) {
  RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( (String) items.get( ORIGINAL_NAME ) );
  boolean isConnected = repositoryMeta == connectedRepository;
  repositoryMeta.populate( items, repositoriesMeta );
  save();
  if ( isConnected ) {
    Spoon spoon = spoonSupplier.get();
    Runnable execute = () -> {
      spoon.setRepositoryName( repositoryMeta.getName() );
      fireListeners();
    };
    if ( spoon.getShell() != null ) {
      spoon.getShell().getDisplay().asyncExec( execute );
    } else {
      execute.run();
    }
  }
  try {
    Repository repository =
      pluginRegistry.loadClass( RepositoryPluginType.class, repositoryMeta.getId(), Repository.class );
    repository.init( repositoryMeta );
    if ( !testRepository( repository ) ) {
      return false;
    }
  } catch ( KettleException e ) {
    return false;
  }
  currentRepository = repositoryMeta;
  return true;
}