Search in sources :

Example 16 with RepositoriesMeta

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

the class JobEntryConnectedToRepositoryDialog method getListRepositories.

/**
 * Get a list of repositories defined in this system, allow the user to select from it.
 */
private void getListRepositories() {
    RepositoriesMeta reps_info = null;
    try {
        reps_info = new RepositoriesMeta();
        try {
            reps_info.readData();
            int nrRepositories = reps_info.nrRepositories();
            if (nrRepositories == 0) {
                displayMsg(BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.Error.NoRep.DialogMessage"), true);
            } else {
                String[] available = new String[nrRepositories];
                for (int i = 0; i < nrRepositories; i++) {
                    RepositoryMeta ri = reps_info.getRepository(i);
                    available[i] = ri.getName();
                }
                String[] source = new String[1];
                source[0] = wRepName.getText();
                int[] idxSource = Const.indexsOfStrings(source, available);
                EnterSelectionDialog dialog = new EnterSelectionDialog(shell, available, BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.SelectRepository.Title"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.SelectRepository.Message"));
                dialog.setMulti(false);
                dialog.setAvoidQuickSearch();
                dialog.setSelectedNrs(idxSource);
                if (dialog.open() != null) {
                    int[] idx = dialog.getSelectionIndeces();
                    wRepName.setText(available[idx[0]]);
                }
            }
        } catch (Exception e) {
            displayMsg(BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.Error.NoRepsDefined"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.Error.NoRepsDefinedMsg"), true);
        }
    } catch (Exception e) {
        displayMsg(BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.ErrorGettingRepositories.DialogMessage") + Const.CR + ":" + e.getMessage(), true);
    } finally {
        reps_info.clear();
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog)

Example 17 with RepositoriesMeta

use of org.pentaho.di.repository.RepositoriesMeta 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 18 with RepositoriesMeta

use of org.pentaho.di.repository.RepositoriesMeta in project pentaho-platform by pentaho.

the class MetaStoreExportUtil method connectToRepository.

public static Repository connectToRepository(String repositoryName) throws KettleException {
    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    boolean singleDiServerInstance = // $NON-NLS-1$ //$NON-NLS-2$
    "true".equals(PentahoSystem.getSystemSetting(SINGLE_DI_SERVER_INSTANCE, "true"));
    try {
        if (singleDiServerInstance) {
            // only load a default enterprise repository. If this option is set, then you cannot load
            // transformations or jobs from anywhere but the local server.
            String repositoriesXml = // $NON-NLS-1$
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><repositories>" + // $NON-NLS-1$
            "<repository><id>PentahoEnterpriseRepository</id>" + "<name>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</name>" + "<description>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</description>" + "<repository_location_url>" + PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() + // $NON-NLS-1$ //$NON-NLS-2$
            "</repository_location_url>" + // $NON-NLS-1$
            "<version_comment_mandatory>N</version_comment_mandatory>" + // $NON-NLS-1$
            "</repository>" + // $NON-NLS-1$
            "</repositories>";
            ByteArrayInputStream sbis = new ByteArrayInputStream(repositoriesXml.getBytes("UTF8"));
            repositoriesMeta.readDataFromInputStream(sbis);
        } else {
            // TODO: add support for specified repositories.xml files...
            // Read from the default $HOME/.kettle/repositories.xml file.
            repositoriesMeta.readData();
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        throw new KettleException("Meta repository not populated", e);
    }
    // Find the specified repository.
    RepositoryMeta repositoryMeta = null;
    try {
        if (singleDiServerInstance) {
            repositoryMeta = repositoriesMeta.findRepository(SINGLE_DI_SERVER_INSTANCE);
        } else {
            repositoryMeta = repositoriesMeta.findRepository(repositoryName);
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        throw new KettleException("Repository not found", e);
    }
    if (repositoryMeta == null) {
        // $NON-NLS-1$
        throw new KettleException("RepositoryMeta is null");
    }
    Repository repository = null;
    try {
        repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
        repository.init(repositoryMeta);
    } catch (Exception e) {
        // $NON-NLS-1$
        throw new KettleException("Could not get repository instance", e);
    }
    // Two scenarios here: internal to server or external to server. If internal, you are already authenticated. If
    // external, you must provide a username and additionally specify that the IP address of the machine running this
    // code is trusted.
    repository.connect(PentahoSessionHolder.getSession().getName(), "password");
    return repository;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) KettleException(org.pentaho.di.core.exception.KettleException)

Example 19 with RepositoriesMeta

use of org.pentaho.di.repository.RepositoriesMeta in project pentaho-platform by pentaho.

the class KettleComponent method connectToRepository.

private Repository connectToRepository() {
    boolean useRepository = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    PentahoSystem.getSystemSetting("kettle/settings.xml", "repository.type", "files").equals("rdbms");
    if (!useRepository) {
        return null;
    }
    try {
        if (ComponentBase.debug) {
            // $NON-NLS-1$
            debug(Messages.getInstance().getString("Kettle.DEBUG_META_REPOSITORY"));
        }
        RepositoriesMeta repositoriesMeta = null;
        try {
            repositoriesMeta = new RepositoriesMeta();
        } catch (Exception e) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Kettle.ERROR_0007_BAD_META_REPOSITORY"), e);
            return null;
        }
        if (ComponentBase.debug) {
            // $NON-NLS-1$
            debug(Messages.getInstance().getString("Kettle.DEBUG_POPULATING_META"));
        }
        try {
            // TODO: add support for specified repositories.xml files...
            // Read from the default
            repositoriesMeta.readData();
        // $HOME/.kettle/repositories.xml
        // file.
        } catch (Exception e) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Kettle.ERROR_0018_META_REPOSITORY_NOT_POPULATED"), e);
            return null;
        }
        if (// $NON-NLS-1$
        (repositoriesXMLFile != null) && !"".equals(repositoriesXMLFile)) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Kettle.ERROR_0017_XML_REPOSITORY_NOT_SUPPORTED"));
            debug(getKettleLog(true));
            return null;
        }
        if (ComponentBase.debug) {
            // $NON-NLS-1$
            debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_REPOSITORY"));
        }
        // Find the specified repository.
        RepositoryMeta repositoryMeta = null;
        try {
            repositoryMeta = repositoriesMeta.findRepository(repositoryName);
        } catch (Exception e) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", repositoryName), e);
            return null;
        }
        if (repositoryMeta == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", repositoryName));
            debug(getKettleLog(true));
            return null;
        }
        if (ComponentBase.debug) {
            // $NON-NLS-1$
            debug(Messages.getInstance().getString("Kettle.DEBUG_GETTING_REPOSITORY"));
        }
        Repository repository = null;
        try {
            repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
            repository.init(repositoryMeta);
        } catch (Exception e) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("Kettle.ERROR_0016_COULD_NOT_GET_REPOSITORY_INSTANCE"), e);
            return null;
        }
        // OK, now try the username and password
        if (ComponentBase.debug) {
            // $NON-NLS-1$
            debug(Messages.getInstance().getString("Kettle.DEBUG_CONNECTING"));
        }
        repository.connect(username, password);
        // OK, the repository is open and ready to use.
        if (ComponentBase.debug) {
            // $NON-NLS-1$
            debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_DIRECTORY"));
        }
        return repository;
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e);
    }
    return null;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) 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) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

RepositoriesMeta (org.pentaho.di.repository.RepositoriesMeta)19 KettleException (org.pentaho.di.core.exception.KettleException)17 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)14 Repository (org.pentaho.di.repository.Repository)12 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)8 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)2