use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionService method getConnections.
/**
* Returns the list of database connections
*
* @return List of database connections
*
* @throws ConnectionServiceException
*/
@GET
@Path("/list")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public IDatabaseConnectionList getConnections() throws ConnectionServiceException {
IDatabaseConnectionList databaseConnections = new DefaultDatabaseConnectionList();
List<IDatabaseConnection> conns = connectionService.getConnections(true);
databaseConnections.setDatabaseConnections(conns);
return databaseConnections;
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionServiceConcrete method getConnections.
public List<DatabaseConnection> getConnections() throws ConnectionServiceException {
List<IDatabaseConnection> iConnections = service.getConnections();
List<DatabaseConnection> connections = new ArrayList<DatabaseConnection>();
for (IDatabaseConnection iConnection : iConnections) {
hidePassword(iConnection);
connections.add((DatabaseConnection) iConnection);
}
return connections;
}
use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionServiceImpl method getConnections.
public List<IDatabaseConnection> getConnections(boolean hidePassword) throws ConnectionServiceException {
ensureDataAccessPermission();
List<IDatabaseConnection> connectionList = null;
try {
connectionList = datasourceMgmtSvc.getDatasources();
for (IDatabaseConnection conn : connectionList) {
sanitizer.unsanitizeConnectionParameters(conn);
if (hidePassword) {
conn.setPassword(null);
}
}
} catch (DatasourceMgmtServiceException dme) {
String message = Messages.getErrorString(// $NON-NLS-1$
"ConnectionServiceImpl.ERROR_0002_UNABLE_TO_GET_CONNECTION_LIST", dme.getLocalizedMessage());
logger.error(message);
throw new ConnectionServiceException(message, dme);
}
return connectionList;
}
use of org.pentaho.database.model.IDatabaseConnection 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.IDatabaseConnection in project data-access by pentaho.
the class WizardConnectionController method updateConnection.
@Bindable
public void updateConnection() {
RequestBuilder updateConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("update"));
updateConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
updateConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
currentConnection = AutobeanUtilities.connectionBeanToImpl(currentConnection);
datasourceModel.getGuiStateModel().updateConnection(existingConnectionName, currentConnection);
datasourceModel.setSelectedRelationalConnection(currentConnection);
} else if (response.getStatusCode() == Response.SC_INTERNAL_SERVER_ERROR) {
// We assume that this means the connection doesn't exist to
// update so we'll add it
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, ConnectionController.getServiceURL("deletebyname", new String[][] { { "name", previousConnectionName } }));
try {
deleteConnectionBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
datasourceModel.getGuiStateModel().deleteConnection(datasourceModel.getSelectedRelationalConnection().getName());
List<IDatabaseConnection> connections = datasourceModel.getGuiStateModel().getConnections();
if (connections != null && connections.size() > 0) {
datasourceModel.setSelectedRelationalConnection(connections.get(connections.size() - 1));
} else {
datasourceModel.setSelectedRelationalConnection(null);
}
addConnection();
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0002_UNABLE_TO_DELETE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0004_UNABLE_TO_UPDATE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
Aggregations