Search in sources :

Example 36 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class JobEntryExportRepositoryDialog method displaydirectoryList.

private void displaydirectoryList() {
    RepositoriesMeta repositoriesMeta = null;
    RepositoryMeta repositoryMeta = null;
    Repository repos = null;
    try {
        repositoriesMeta = new RepositoriesMeta();
        repositoriesMeta.readData();
        repositoryMeta = repositoriesMeta.findRepository(jobMeta.environmentSubstitute(wRepositoryname.getText()));
        if (repositoryMeta == null) {
            // Can not find repository
            displayMsg(BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotFindRep"), BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotFindRepMsg", wRepositoryname.getText()), true);
        }
        repos = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
        repos.init(repositoryMeta);
        try {
            repos.connect(jobMeta.environmentSubstitute(wUserName.getText()), jobMeta.environmentSubstitute(wPassword.getText()));
        } catch (Exception e) {
            displayMsg(BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotConnect"), BaseMessages.getString(PKG, "JobExportRepository.Error.CanNotConnectMsg", wRepositoryname.getText()), true);
        }
        if (repos.isConnected()) {
            try {
                FileDialogOperation fileDialogOperation = new FileDialogOperation(FileDialogOperation.SELECT_FOLDER, FileDialogOperation.ORIGIN_SPOON);
                fileDialogOperation.setTitle(BaseMessages.getString(PKG, "JobExportRepository.SelectDirectoryDialog.Title"));
                fileDialogOperation.setFilter(null);
                fileDialogOperation.setRepository(repos);
                if (!Utils.isEmpty(wFoldername.getText())) {
                    fileDialogOperation.setStartDir(wFoldername.getText());
                }
                ExtensionPointHandler.callExtensionPoint(null, KettleExtensionPoint.SpoonOpenSaveRepository.id, fileDialogOperation);
                if (fileDialogOperation.getRepositoryObject() != null) {
                    String path = ((RepositoryObject) fileDialogOperation.getRepositoryObject()).getRepositoryDirectory().getPath();
                    wFoldername.setText(path);
                }
            } catch (KettleException e) {
            // Do Nothing
            }
        }
    } catch (Exception e) {
        displayMsg(BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobExportRepository.ErrorGettingFolderds.DialogMessage") + Const.CR + ":" + e.getMessage(), true);
    } finally {
        if (repos != null) {
            repos.disconnect();
            repos = null;
        }
        if (repositoryMeta != null) {
            repositoryMeta = null;
        }
        repositoriesMeta.clear();
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) JobEntryExportRepository(org.pentaho.di.job.entries.exportrepository.JobEntryExportRepository) Repository(org.pentaho.di.repository.Repository) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) KettleException(org.pentaho.di.core.exception.KettleException) FileDialogOperation(org.pentaho.di.ui.core.FileDialogOperation)

Example 37 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class RepositoryConnectControllerTest method testEditConnectedRepository.

@Test
public void testEditConnectedRepository() throws Exception {
    RepositoryMeta before = new TestRepositoryMeta(ID, "name1", PLUGIN_DESCRIPTION, "same");
    RepositoryMeta edited = new TestRepositoryMeta(ID, "name2", PLUGIN_DESCRIPTION, "same");
    when(pluginRegistry.loadClass(RepositoryPluginType.class, ID, Repository.class)).thenReturn(repository);
    when(pluginRegistry.loadClass(RepositoryPluginType.class, ID, RepositoryMeta.class)).thenReturn(edited);
    when(repositoriesMeta.nrRepositories()).thenReturn(1);
    when(repositoriesMeta.getRepository(0)).thenReturn(before);
    controller.setConnectedRepository(before.clone());
    controller.setCurrentRepository(before);
    when(repositoriesMeta.findRepository(anyString())).thenReturn(edited);
    controller.updateRepository(ID, new HashMap<>());
    assertEquals(edited, controller.getConnectedRepository());
}
Also used : BaseRepositoryMeta(org.pentaho.di.repository.BaseRepositoryMeta) KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Test(org.junit.Test)

Example 38 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class RepositoryConnectController method reconnectToRepository.

public void reconnectToRepository(String repositoryName, String username, String password) throws KettleException {
    final RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryName);
    if (repositoryMeta != null) {
        currentRepository = repositoryMeta;
        reconnectToRepository(username, password);
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta)

Example 39 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class RepositorySpoonStartExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    if (!(object instanceof CommandLineOption[])) {
        return;
    }
    CommandLineOption[] options = (CommandLineOption[]) object;
    StringBuilder optionRepname = getCommandLineOption(options, "rep").getArgument();
    StringBuilder optionFilename = getCommandLineOption(options, "file").getArgument();
    StringBuilder optionUsername = getCommandLineOption(options, "user").getArgument();
    StringBuilder optionPassword = getCommandLineOption(options, "pass").getArgument();
    if (!Utils.isEmpty(optionRepname) && Utils.isEmpty(optionFilename)) {
        RepositoryMeta repositoryMeta = repositoryConnectController.getRepositoryMetaByName(optionRepname.toString());
        if (repositoryMeta != null && !Utils.isEmpty(optionUsername) && !Utils.isEmpty(optionPassword)) {
            repositoryConnectController.connectToRepository(repositoryMeta, optionUsername.toString(), optionPassword.toString());
        } else if (repositoryMeta != null) {
            repositoryConnectController.connectToRepository(repositoryMeta, null, null);
        }
        if (!repositoryConnectController.isConnected()) {
            String msg = BaseMessages.getString(PKG, "Repository.NoConnected.Message");
            // "No repositories defined on this system."
            log.logError(msg);
            MessageBox mb = new MessageBox(getSpoon().getShell(), SWT.OK | SWT.ICON_ERROR);
            mb.setMessage(BaseMessages.getString(PKG, "Repository.NoConnected.Message", optionRepname.toString()));
            mb.setText(BaseMessages.getString(PKG, "Repository.NoConnected.Message.Title"));
            mb.open();
        }
    } else if (Utils.isEmpty(optionFilename)) {
        RepositoryMeta repositoryMeta = repositoryConnectController.getDefaultRepositoryMeta();
        if (repositoryMeta != null) {
            if (repositoryMeta.getId().equals("KettleFileRepository")) {
                repositoryConnectController.connectToRepository(repositoryMeta);
            } else {
                new RepositoryDialog(getSpoon().getShell(), repositoryConnectController).openLogin(repositoryMeta);
            }
        }
    }
}
Also used : CommandLineOption(org.pentaho.di.pan.CommandLineOption) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) RepositoryDialog(org.pentaho.di.ui.repo.dialog.RepositoryDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 40 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class RequestLoginToRepositoryExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    ILoginCallback loginCallback = defaultLoginCallback;
    if ((object instanceof ILoginCallback)) {
        loginCallback = (ILoginCallback) object;
    }
    RepositoryMeta repositoryMeta = findRepositoryToConnect();
    if (repositoryMeta != null) {
        if (isKettleFileRepository(repositoryMeta)) {
            repositoryConnectController.connectToRepository(repositoryMeta);
            loginCallback.onSuccess(repositoryConnectController.getConnectedRepositoryInstance());
        } else {
            loginToRepository(repositoryMeta, loginCallback);
        }
    } else {
        String errorMessage = BaseMessages.getString(PKG, "Repository.NoDefinedRepositoryToConnect");
        KettleException exception = new KettleException(errorMessage);
        loginCallback.onError(exception);
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) ILoginCallback(org.pentaho.di.ui.repository.ILoginCallback)

Aggregations

RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)44 KettleException (org.pentaho.di.core.exception.KettleException)27 Repository (org.pentaho.di.repository.Repository)16 RepositoriesMeta (org.pentaho.di.repository.RepositoriesMeta)14 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)10 Test (org.junit.Test)4 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)4 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Map (java.util.Map)3 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)3 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)3 RepositoryDialog (org.pentaho.di.ui.repo.dialog.RepositoryDialog)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringBufferInputStream (java.io.StringBufferInputStream)2 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2