Search in sources :

Example 71 with IDatabaseConnection

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;
}
Also used : DefaultDatabaseConnectionList(org.pentaho.ui.database.event.DefaultDatabaseConnectionList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 72 with IDatabaseConnection

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;
}
Also used : ArrayList(java.util.ArrayList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 73 with IDatabaseConnection

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;
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 74 with IDatabaseConnection

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;
}
Also used : Element(com.google.gwt.xml.client.Element) Node(com.google.gwt.xml.client.Node) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Document(com.google.gwt.xml.client.Document)

Example 75 with IDatabaseConnection

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);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Aggregations

IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)99 Test (org.junit.Test)29 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)29 ArrayList (java.util.ArrayList)18 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 RequestException (com.google.gwt.http.client.RequestException)14 Request (com.google.gwt.http.client.Request)13 RequestBuilder (com.google.gwt.http.client.RequestBuilder)13 RequestCallback (com.google.gwt.http.client.RequestCallback)13 Response (com.google.gwt.http.client.Response)13 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)13 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)11 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)9 List (java.util.List)8 Response (javax.ws.rs.core.Response)8 Path (javax.ws.rs.Path)7 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 Facet (org.codehaus.enunciate.Facet)5 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)5