Search in sources :

Example 21 with RepositoryMeta

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

the class RepositoriesController method createBindings.

private void createBindings() {
    loginDialog = (XulDialog) document.getElementById("repository-login-dialog");
    repositoryEditButton = (XulButton) document.getElementById("repository-edit");
    repositoryRemoveButton = (XulButton) document.getElementById("repository-remove");
    username = (XulTextbox) document.getElementById("user-name");
    userPassword = (XulTextbox) document.getElementById("user-password");
    availableRepositories = (XulListbox) document.getElementById("available-repository-list");
    showAtStartup = (XulCheckbox) document.getElementById("show-login-dialog-at-startup");
    okButton = (XulButton) document.getElementById("repository-login-dialog_accept");
    cancelButton = (XulButton) document.getElementById("repository-login-dialog_cancel");
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    bf.createBinding(loginModel, "username", username, "value");
    bf.createBinding(loginModel, "password", userPassword, "value");
    bf.createBinding(loginModel, "availableRepositories", availableRepositories, "elements");
    bf.createBinding(loginModel, "selectedRepository", availableRepositories, "selectedItem");
    bf.createBinding(loginModel, "showDialogAtStartup", showAtStartup, "checked");
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(loginModel, "valid", okButton, "!disabled");
    BindingConvertor<RepositoryMeta, Boolean> buttonConverter = new BindingConvertor<RepositoryMeta, Boolean>() {

        @Override
        public Boolean sourceToTarget(RepositoryMeta value) {
            return (value == null);
        }

        @Override
        public RepositoryMeta targetToSource(Boolean value) {
            return null;
        }
    };
    BindingConvertor<RepositoryMeta, Boolean> userpassConverter = new BindingConvertor<RepositoryMeta, Boolean>() {

        @Override
        public Boolean sourceToTarget(RepositoryMeta value) {
            return (value == null) || !value.getRepositoryCapabilities().supportsUsers();
        }

        @Override
        public RepositoryMeta targetToSource(Boolean value) {
            return null;
        }
    };
    bf.createBinding(loginModel, "selectedRepository", username, "disabled", userpassConverter);
    bf.createBinding(loginModel, "selectedRepository", userPassword, "disabled", userpassConverter);
    bf.createBinding(loginModel, "selectedRepository", repositoryEditButton, "disabled", buttonConverter);
    bf.createBinding(loginModel, "selectedRepository", repositoryRemoveButton, "disabled", buttonConverter);
    final Shell loginShell = (Shell) loginDialog.getRootObject();
    helper = new RepositoriesHelper(loginModel, document, loginShell);
    helper.setPreferredRepositoryName(preferredRepositoryName);
    helper.getMetaData();
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Shell(org.eclipse.swt.widgets.Shell) RepositoriesHelper(org.pentaho.di.ui.repository.RepositoriesHelper) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor)

Example 22 with RepositoryMeta

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

the class TransExecutionConfigurationTest method testConnectRepository.

@Test
public void testConnectRepository() throws KettleException {
    TransExecutionConfiguration transExecConf = new TransExecutionConfiguration();
    final RepositoriesMeta repositoriesMeta = mock(RepositoriesMeta.class);
    final RepositoryMeta repositoryMeta = mock(RepositoryMeta.class);
    final Repository repository = mock(Repository.class);
    final String mockRepo = "mockRepo";
    final boolean[] connectionSuccess = { false };
    Repository initialRepo = mock(Repository.class);
    transExecConf.setRepository(initialRepo);
    KettleLogStore.init();
    // Create mock repository plugin
    MockRepositoryPlugin mockRepositoryPlugin = mock(MockRepositoryPlugin.class);
    when(mockRepositoryPlugin.getIds()).thenReturn(new String[] { "mockRepo" });
    when(mockRepositoryPlugin.matches("mockRepo")).thenReturn(true);
    when(mockRepositoryPlugin.getName()).thenReturn("mock-repository");
    when(mockRepositoryPlugin.getClassMap()).thenAnswer(new Answer<Map<Class<?>, String>>() {

        @Override
        public Map<Class<?>, String> answer(InvocationOnMock invocation) throws Throwable {
            Map<Class<?>, String> dbMap = new HashMap<Class<?>, String>();
            dbMap.put(Repository.class, repositoryMeta.getClass().getName());
            return dbMap;
        }
    });
    List<PluginInterface> registeredPlugins = PluginRegistry.getInstance().getPlugins(RepositoryPluginType.class);
    for (PluginInterface registeredPlugin : registeredPlugins) {
        PluginRegistry.getInstance().removePlugin(RepositoryPluginType.class, registeredPlugin);
    }
    PluginRegistry.getInstance().registerPlugin(RepositoryPluginType.class, mockRepositoryPlugin);
    // Define valid connection criteria
    when(repositoriesMeta.findRepository(anyString())).thenAnswer(new Answer<RepositoryMeta>() {

        @Override
        public RepositoryMeta answer(InvocationOnMock invocation) throws Throwable {
            return mockRepo.equals(invocation.getArguments()[0]) ? repositoryMeta : null;
        }
    });
    when(mockRepositoryPlugin.loadClass(Repository.class)).thenReturn(repository);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if ("username".equals(invocation.getArguments()[0]) && "password".equals(invocation.getArguments()[1])) {
                connectionSuccess[0] = true;
            } else {
                connectionSuccess[0] = false;
                throw new KettleException("Mock Repository connection failed");
            }
            return null;
        }
    }).when(repository).connect(anyString(), anyString());
    // Ignore repository not found in RepositoriesMeta
    transExecConf.connectRepository(repositoriesMeta, "notFound", "username", "password");
    assertEquals("Repository Changed", initialRepo, transExecConf.getRepository());
    // Ignore failed attempt to connect
    transExecConf.connectRepository(repositoriesMeta, mockRepo, "username", "");
    assertEquals("Repository Changed", initialRepo, transExecConf.getRepository());
    // Save repository if connection passes
    transExecConf.connectRepository(repositoriesMeta, mockRepo, "username", "password");
    assertEquals("Repository didn't change", repository, transExecConf.getRepository());
    assertTrue("Repository not connected", connectionSuccess[0]);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ClassLoadingPluginInterface(org.pentaho.di.core.plugins.ClassLoadingPluginInterface) Mockito.anyString(org.mockito.Mockito.anyString) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 23 with RepositoryMeta

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

the class JobExecutionConfigurationTest method testConnectRepository.

@Test
public void testConnectRepository() throws KettleException {
    JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration();
    final RepositoriesMeta repositoriesMeta = mock(RepositoriesMeta.class);
    final RepositoryMeta repositoryMeta = mock(RepositoryMeta.class);
    final Repository repository = mock(Repository.class);
    final String mockRepo = "mockRepo";
    final boolean[] connectionSuccess = { false };
    Repository initialRepo = mock(Repository.class);
    jobExecutionConfiguration.setRepository(initialRepo);
    KettleLogStore.init();
    // Create mock repository plugin
    MockRepositoryPlugin mockRepositoryPlugin = mock(MockRepositoryPlugin.class);
    when(mockRepositoryPlugin.getIds()).thenReturn(new String[] { "mockRepo" });
    when(mockRepositoryPlugin.matches("mockRepo")).thenReturn(true);
    when(mockRepositoryPlugin.getName()).thenReturn("mock-repository");
    when(mockRepositoryPlugin.getClassMap()).thenAnswer(new Answer<Map<Class<?>, String>>() {

        @Override
        public Map<Class<?>, String> answer(InvocationOnMock invocation) throws Throwable {
            Map<Class<?>, String> dbMap = new HashMap<Class<?>, String>();
            dbMap.put(Repository.class, repositoryMeta.getClass().getName());
            return dbMap;
        }
    });
    PluginRegistry.getInstance().registerPlugin(RepositoryPluginType.class, mockRepositoryPlugin);
    // Define valid connection criteria
    when(repositoriesMeta.findRepository(anyString())).thenAnswer(new Answer<RepositoryMeta>() {

        @Override
        public RepositoryMeta answer(InvocationOnMock invocation) throws Throwable {
            return mockRepo.equals(invocation.getArguments()[0]) ? repositoryMeta : null;
        }
    });
    when(mockRepositoryPlugin.loadClass(Repository.class)).thenReturn(repository);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if ("username".equals(invocation.getArguments()[0]) && "password".equals(invocation.getArguments()[1])) {
                connectionSuccess[0] = true;
            } else {
                connectionSuccess[0] = false;
                throw new KettleException("Mock Repository connection failed");
            }
            return null;
        }
    }).when(repository).connect(anyString(), anyString());
    // Ignore repository not found in RepositoriesMeta
    jobExecutionConfiguration.connectRepository(repositoriesMeta, "notFound", "username", "password");
    assertEquals("Repository Changed", initialRepo, jobExecutionConfiguration.getRepository());
    // Ignore failed attempt to connect
    jobExecutionConfiguration.connectRepository(repositoriesMeta, mockRepo, "username", "");
    assertEquals("Repository Changed", initialRepo, jobExecutionConfiguration.getRepository());
    // Save repository if connection passes
    jobExecutionConfiguration.connectRepository(repositoriesMeta, mockRepo, "username", "password");
    assertEquals("Repository didn't change", repository, jobExecutionConfiguration.getRepository());
    assertTrue("Repository not connected", connectionSuccess[0]);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 24 with RepositoryMeta

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

the class ExecuteJobServlet method openRepository.

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;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta)

Example 25 with RepositoryMeta

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

the class DIServerConfig method getRepositoryMeta.

private RepositoryMeta getRepositoryMeta() throws KettleException, ParserConfigurationException {
    if (repositoryMeta == null) {
        // Load Repository Meta
        RepositoryMeta repositoryMeta = pluginRegistry.loadClass(RepositoryPluginType.class, PUR_REPOSITORY_PLUGIN_ID, RepositoryMeta.class);
        DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = docBuilder.newDocument();
        Element repnode = document.createElement(RepositoryMeta.XML_TAG);
        Element id = document.createElement("id");
        id.setTextContent(PUR_REPOSITORY_PLUGIN_ID);
        repnode.appendChild(id);
        Element name = document.createElement("name");
        name.setTextContent(SINGLE_DI_SERVER_INSTANCE);
        repnode.appendChild(name);
        Element description = document.createElement("description");
        description.setTextContent(SINGLE_DI_SERVER_INSTANCE);
        repnode.appendChild(description);
        Element location = document.createElement("repository_location_url");
        location.setTextContent(PentahoSystem.getApplicationContext().getFullyQualifiedServerURL());
        repnode.appendChild(location);
        repositoryMeta.loadXML(repnode, Collections.<DatabaseMeta>emptyList());
        this.repositoryMeta = repositoryMeta;
    }
    return repositoryMeta;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

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