use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class DatabaseConnectionConverter method convertToObject.
public IDatabaseConnection convertToObject(String xml) {
Document document = XMLParser.parse(xml);
Element element = document.getDocumentElement();
IDatabaseConnection databaseConnection = new DatabaseConnection();
databaseConnection.setDatabaseName(getNodeValueByTagName(element, DATABASE_NAME));
databaseConnection.setHostname(getNodeValueByTagName(element, HOSTNAME));
databaseConnection.setIndexTablespace(getNodeValueByTagName(element, INDEX_TABLESPACE));
databaseConnection.setDataTablespace(getNodeValueByTagName(element, DATA_TABLESPACE));
databaseConnection.setName(getNodeValueByTagName(element, NAME));
databaseConnection.setUsername(getNodeValueByTagName(element, USERNAME));
databaseConnection.setPassword(getNodeValueByTagName(element, PASSWORD));
databaseConnection.setDatabasePort(getNodeValueByTagName(element, DATABASE_PORT));
databaseConnection.setAccessType(DatabaseAccessType.getAccessTypeByName(getNodeValueByTagName(element, ACCESS_TYPE)));
databaseConnection.setDatabaseType((DatabaseType) databaseTypeHelper.getDatabaseTypeByShortName(getNodeValueByTagName(element, DATABASE_TYPE)));
databaseConnection.setPassword(getNodeValueByTagName(element, PASSWORD));
databaseConnection.setInformixServername(getNodeValueByTagName(element, SERVER_NAME));
for (Node node : getNodesByTagName(element, ATTRIBUTES)) {
databaseConnection.getAttributes().put(node.getNodeName(), node.getNodeValue());
}
return databaseConnection;
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testAdd.
@Test
public void testAdd() throws Exception {
doNothing().when(jdbcDatasourceResource).validateAccess();
DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
doReturn(true).when(jdbcDatasourceResource.service).addConnection(mockDatabaseConnection);
Response mockResponse = mock(Response.class);
doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse();
Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
verify(jdbcDatasourceResource, times(1)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
assertEquals(response, mockResponse);
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testUpdate.
@Test
public void testUpdate() throws Exception {
DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
doReturn("").when(mockDatabaseConnection).getPassword();
doReturn("id").when(mockDatabaseConnection).getName();
IDatabaseConnection mockSavedConn = mock(IDatabaseConnection.class);
doReturn(mockSavedConn).when(jdbcDatasourceResource.service).getConnectionByName("id");
doReturn("password").when(mockSavedConn).getPassword();
doReturn(true).when(jdbcDatasourceResource.service).updateConnection(mockDatabaseConnection);
doNothing().when(jdbcDatasourceResource).validateAccess();
Response mockResponse = mock(Response.class);
doReturn(mockResponse).when(jdbcDatasourceResource).buildOkResponse();
Response response = jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
verify(jdbcDatasourceResource, times(1)).addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
assertEquals(response, mockResponse);
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class JdbcDatasourceResourceTest method testAddOrUpdateNoPublishPermission.
@Test
public void testAddOrUpdateNoPublishPermission() throws Exception {
doThrow(new PentahoAccessControlException()).when(jdbcDatasourceResource).validateAccess();
DatabaseConnection mockDatabaseConnection = mock(DatabaseConnection.class);
try {
jdbcDatasourceResource.addOrUpdate(mockDatabaseConnection.getName(), mockDatabaseConnection);
fail();
} catch (WebApplicationException e) {
assertEquals(401, e.getResponse().getStatus());
}
verify(jdbcDatasourceResource.service, never()).addConnection(any());
verify(jdbcDatasourceResource.service, never()).updateConnection(any());
}
use of org.pentaho.database.model.DatabaseConnection in project data-access by pentaho.
the class QueryDatasource method onFinish.
@Override
public void onFinish(XulServiceCallback<IDatasourceSummary> callback) {
String name = datasourceModel.getDatasourceName().replace(".", "_").replace(" ", "_");
String query = datasourceModel.getQuery();
DatabaseConnection conn = (DatabaseConnection) AutobeanUtilities.connectionBeanToImpl(datasourceModel.getSelectedRelationalConnection());
datasourceService.generateQueryDomain(name, query, conn, DatasourceDTOUtil.generateDTO(datasourceModel), callback);
}
Aggregations