Search in sources :

Example 1 with IDatabaseConnectionList

use of org.pentaho.ui.database.event.IDatabaseConnectionList 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 2 with IDatabaseConnectionList

use of org.pentaho.ui.database.event.IDatabaseConnectionList in project data-access by pentaho.

the class AnalysisImportDialogController method reloadConnections.

private void reloadConnections() {
    String cacheBuster = "?ts=" + new java.util.Date().getTime();
    RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getBaseURL() + "list" + cacheBuster);
    listConnectionBuilder.setHeader("Content-Type", "application/json");
    listConnectionBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        listConnectionBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                exception.printStackTrace();
                MessageHandler.getInstance().showErrorDialog(exception.getMessage());
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
                List<IDatabaseConnection> databaseConnections = bean.as().getDatabaseConnections();
                List<IDatabaseConnection> standardDatabaseConnections = new ArrayList();
                // take anything except connections where STANDARD_CONNECTION == false
                for (IDatabaseConnection databaseConnection : databaseConnections) {
                    if ((databaseConnection.getAttributes() == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == null) || (databaseConnection.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == Boolean.TRUE.toString())) {
                        standardDatabaseConnections.add(databaseConnection);
                    }
                }
                importDialogModel.setConnectionList(standardDatabaseConnections);
            }
        });
    } catch (RequestException e) {
        MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), "DatasourceEditor.ERROR_0004_CONNECTION_SERVICE_NULL");
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) AutoBean(com.google.web.bindery.autobean.shared.AutoBean) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) XulMenuList(org.pentaho.ui.xul.components.XulMenuList) List(java.util.List) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 3 with IDatabaseConnectionList

use of org.pentaho.ui.database.event.IDatabaseConnectionList in project data-access by pentaho.

the class ConnectionController method reloadConnections.

public void reloadConnections() {
    String cacheBuster = String.valueOf(new java.util.Date().getTime());
    String[][] params = new String[][] { { "ts", cacheBuster } };
    RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getServiceURL("list", params));
    listConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        listConnectionBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), MessageHandler.getString("DatasourceEditor.ERROR_0002_UNABLE_TO_SHOW_DIALOG", exception.getLocalizedMessage()));
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
                List<IDatabaseConnection> connectionBeanList = bean.as().getDatabaseConnections();
                List<IDatabaseConnection> connectionImplList = new ArrayList<IDatabaseConnection>();
                for (IDatabaseConnection connectionBean : connectionBeanList) {
                    try {
                        // take anything except connections where STANDARD_CONNECTION == false
                        if ((connectionBean.getAttributes() == null) || (connectionBean.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == null) || (connectionBean.getAttributes().get(ATTRIBUTE_STANDARD_CONNECTION) == Boolean.TRUE.toString())) {
                            connectionImplList.add(AutobeanUtilities.connectionBeanToImpl(connectionBean));
                        }
                    } catch (Exception e) {
                    // skip invalid connections that couldn't be converted to IDatabaseConnection
                    }
                }
                if (datasourceModel != null) {
                    datasourceModel.getGuiStateModel().setConnections(connectionImplList);
                }
            }
        });
    } catch (RequestException e) {
        MessageHandler.getInstance().showErrorDialog(MessageHandler.getString("ERROR"), "DatasourceEditor.ERROR_0004_CONNECTION_SERVICE_NULL");
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) AutoBean(com.google.web.bindery.autobean.shared.AutoBean) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 4 with IDatabaseConnectionList

use of org.pentaho.ui.database.event.IDatabaseConnectionList in project data-access by pentaho.

the class JdbcDatasourceService method getIds.

@Override
public void getIds(final XulServiceCallback<List<IDatasourceInfo>> callback) {
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, getMetadataBaseURL() + "getDatasourcePermissions");
    requestBuilder.setHeader("Content-Type", "application/json");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                callback.error(exception.getMessage(), exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getText().equals("EDIT")) {
                    String cacheBuster = "?ts=" + new java.util.Date().getTime();
                    RequestBuilder listConnectionBuilder = new RequestBuilder(RequestBuilder.GET, getBaseURL() + "list" + cacheBuster);
                    listConnectionBuilder.setHeader("Content-Type", "application/json");
                    try {
                        listConnectionBuilder.sendRequest(null, new RequestCallback() {

                            @Override
                            public void onError(Request request, Throwable exception) {
                                callback.error(exception.getMessage(), exception);
                            }

                            @Override
                            public void onResponseReceived(Request request, Response response) {
                                AutoBean<IDatabaseConnectionList> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnectionList.class, response.getText());
                                List<IDatabaseConnection> connections = bean.as().getDatabaseConnections();
                                List<IDatasourceInfo> datasourceInfos = new ArrayList<IDatasourceInfo>();
                                for (IDatabaseConnection connection : connections) {
                                    // check attributes to make sure we only return "standard" connections which can be managed
                                    Map<String, String> attributes = connection.getAttributes();
                                    if (attributes.containsKey(ATTRIBUTE_STANDARD_CONNECTION)) {
                                        if (attributes.get(ATTRIBUTE_STANDARD_CONNECTION).equals(Boolean.FALSE.toString())) {
                                            continue;
                                        }
                                    }
                                    datasourceInfos.add(new DatasourceInfo(connection.getName(), connection.getName(), TYPE, editable, removable, importable, exportable));
                                }
                                callback.success(datasourceInfos);
                            }
                        });
                    } catch (RequestException e) {
                        callback.error(e.getMessage(), e);
                    }
                }
            }
        });
    } catch (RequestException e) {
        callback.error(e.getMessage(), e);
    }
}
Also used : IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo) DatasourceInfo(org.pentaho.platform.dataaccess.datasource.DatasourceInfo) RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)

Aggregations

IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)4 IDatabaseConnectionList (org.pentaho.ui.database.event.IDatabaseConnectionList)4 Request (com.google.gwt.http.client.Request)3 RequestBuilder (com.google.gwt.http.client.RequestBuilder)3 RequestCallback (com.google.gwt.http.client.RequestCallback)3 RequestException (com.google.gwt.http.client.RequestException)3 Response (com.google.gwt.http.client.Response)3 ArrayList (java.util.ArrayList)3 AutoBean (com.google.web.bindery.autobean.shared.AutoBean)2 List (java.util.List)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Facet (org.codehaus.enunciate.Facet)1 DatasourceInfo (org.pentaho.platform.dataaccess.datasource.DatasourceInfo)1 IDatasourceInfo (org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)1 DefaultDatabaseConnectionList (org.pentaho.ui.database.event.DefaultDatabaseConnectionList)1 XulMenuList (org.pentaho.ui.xul.components.XulMenuList)1