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();
}
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]);
}
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]);
}
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;
}
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;
}
Aggregations