Search in sources :

Example 6 with IDatasourceInfo

use of org.pentaho.platform.dataaccess.datasource.IDatasourceInfo in project data-access by pentaho.

the class DatasourceAdminDialogController method removeDatasourceAccept.

@Bindable
public void removeDatasourceAccept() {
    final IDatasourceInfo dsInfo = datasourceAdminDialogModel.getSelectedDatasource();
    manager.remove(dsInfo, new XulServiceCallback<Boolean>() {

        @Override
        public void success(Boolean isOk) {
            if (isOk) {
                refreshDatasourceList();
                editDatasourceMenuItem.setDisabled(true);
            } else {
                Window.alert(messageBundle.getString("datasourceAdminDialogController.COULD_NOT_REMOVE") + ": " + dsInfo.getId());
            }
        }

        @Override
        public void error(String message, Throwable error) {
            Window.alert(messageBundle.getString("datasourceAdminDialogController.ERROR_REMOVING") + ": " + dsInfo.getId() + "." + messageBundle.getString("ERROR") + "=" + error.getLocalizedMessage());
        }
    });
    removeDatasourceConfirmationDialog.hide();
}
Also used : IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 7 with IDatasourceInfo

use of org.pentaho.platform.dataaccess.datasource.IDatasourceInfo in project data-access by pentaho.

the class MainWizardController method finish.

@Bindable
public // TODO: migrate to CSV datasource
void finish() {
    if (finishButton.isDisabled()) {
        return;
    }
    finishButton.setDisabled(true);
    final String datasourceName = this.wizardModel.getDatasourceName();
    // Validating whether the datasource name contains any illegal characters
    if (isDatasourceNameValid(datasourceName)) {
        UIDatasourceServiceManager manager = UIDatasourceServiceManager.getInstance();
        manager.getIds(new XulServiceCallback<List<IDatasourceInfo>>() {

            @Override
            public void success(List<IDatasourceInfo> datasourceInfos) {
                finishButton.setDisabled(false);
                boolean isEditing = wizardModel.isEditing();
                List<String> datasourceNames = new ArrayList<String>();
                for (IDatasourceInfo datasourceInfo : datasourceInfos) {
                    if (datasourceInfo.getType().equals("Data Source Wizard") || datasourceInfo.getType().equals("Analysis")) {
                        datasourceNames.add(datasourceInfo.getName());
                    }
                }
                if (datasourceNames.contains(datasourceName) && !isEditing) {
                    showWarningDialog();
                } else {
                    setFinished();
                }
            }

            @Override
            public void error(String s, Throwable throwable) {
                finishButton.setDisabled(false);
                throwable.printStackTrace();
                MessageHandler.getInstance().showErrorDialog(throwable.getMessage());
            }
        });
    } else {
        finishButton.setDisabled(false);
        MessageHandler.getInstance().showErrorDialog("Error", // $NON-NLS-1$
        MessageHandler.getString("DatasourceEditor.ERROR_0005_INVALID_DATASOURCE_NAME", NameUtils.reservedCharListForDisplay(" ")), // $NON-NLS-1$
        true);
    }
}
Also used : XulMenuList(org.pentaho.ui.xul.components.XulMenuList) ArrayList(java.util.ArrayList) List(java.util.List) IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo) UIDatasourceServiceManager(org.pentaho.platform.dataaccess.datasource.ui.service.UIDatasourceServiceManager) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 8 with IDatasourceInfo

use of org.pentaho.platform.dataaccess.datasource.IDatasourceInfo in project data-access by pentaho.

the class DatasourceSelectionDialogController method internalInit.

private void internalInit() {
    try {
        // $NON-NLS-1$
        datasourceListbox = (XulListbox) safeGetElementById(document, "datasourceListbox");
        // $NON-NLS-1$
        datasourceSelectionDialog = (XulDialog) safeGetElementById(document, "datasourceSelectionDialog");
        removeDatasourceConfirmationDialog = (XulDialog) safeGetElementById(document, // $NON-NLS-1$
        "removeDatasourceConfirmationDialog");
        XulButton acceptButton = null;
        try {
            // $NON-NLS-1$
            acceptButton = (XulButton) safeGetElementById(document, "datasourceSelectionDialog_accept");
        } catch (Exception e) {
        // this might not be available
        }
        // $NON-NLS-1$
        addDatasourceButton = (XulButton) safeGetElementById(document, "addDatasource");
        // $NON-NLS-1$
        editDatasourceButton = (XulButton) safeGetElementById(document, "editDatasource");
        // $NON-NLS-1$
        removeDatasourceButton = (XulButton) safeGetElementById(document, "removeDatasource");
        manager = UIDatasourceServiceManager.getInstance();
        manager.getIds(new XulServiceCallback<List<IDatasourceInfo>>() {

            @Override
            public void success(List<IDatasourceInfo> infoList) {
                DatasourceSelectionDialogController.this.datasourceInfos = infoList;
            }

            @Override
            public void error(String message, Throwable error) {
            }
        });
        bf.setBindingType(Binding.Type.ONE_WAY);
        bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "logicalModelSummaries", datasourceListbox, // $NON-NLS-1$ //$NON-NLS-2$
        "elements");
        bf.setBindingType(Binding.Type.ONE_WAY);
        // $NON-NLS-1$
        bf.createBinding(// $NON-NLS-1$
        datasourceListbox, // $NON-NLS-1$
        "selectedIndex", DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, // $NON-NLS-1$
        "selectedIndex");
        // setup binding to disable accept button until user selects a datasource
        bf.setBindingType(Binding.Type.ONE_WAY);
        if (acceptButton != null) {
            BindingConvertor<Integer, Boolean> acceptButtonConvertor = new BindingConvertor<Integer, Boolean>() {

                @Override
                public Boolean sourceToTarget(final Integer value) {
                    return value > -1;
                }

                @Override
                public Integer targetToSource(final Boolean value) {
                    throw new UnsupportedOperationException();
                }
            };
            bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "selectedIndex", // $NON-NLS-1$
            acceptButton, "!disabled", // $NON-NLS-1$
            acceptButtonConvertor);
        }
        // setup binding to disable remove datasource button until user selects a datasource
        bf.setBindingType(Binding.Type.ONE_WAY);
        BindingConvertor<Integer, Boolean> removeDatasourceButtonConvertor = new BindingConvertor<Integer, Boolean>() {

            @Override
            public Boolean sourceToTarget(final Integer value) {
                boolean active = false;
                if (value > -1) {
                    LogicalModelSummary summary = (LogicalModelSummary) datasourceListbox.getSelectedItem();
                    if (datasourceInfos.size() > 0) {
                        for (int i = 0; i < datasourceInfos.size(); i++) {
                            IDatasourceInfo datasourceInfo = datasourceInfos.get(i);
                            if (datasourceInfo.getId().equals(summary.getDomainId())) {
                                active = datasourceInfo.isEditable();
                                break;
                            }
                        }
                    }
                }
                return active && administrator;
            }

            @Override
            public Integer targetToSource(final Boolean value) {
                throw new UnsupportedOperationException();
            }
        };
        removeDatasourceButtonBinding = bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "selectedIndex", // $NON-NLS-1$
        removeDatasourceButton, "!disabled", // $NON-NLS-1$
        removeDatasourceButtonConvertor);
        BindingConvertor<Integer, Boolean> editDatasourceButtonConvertor = new BindingConvertor<Integer, Boolean>() {

            @Override
            public Boolean sourceToTarget(final Integer value) {
                boolean active = false;
                if (value > -1) {
                    LogicalModelSummary summary = (LogicalModelSummary) datasourceListbox.getSelectedItem();
                    if (datasourceInfos.size() > 0) {
                        for (int i = 0; i < datasourceInfos.size(); i++) {
                            IDatasourceInfo datasourceInfo = datasourceInfos.get(i);
                            if (datasourceInfo.getId().equals(summary.getDomainId())) {
                                active = datasourceInfo.isEditable();
                                break;
                            }
                        }
                    }
                }
                return active && administrator;
            }

            @Override
            public Integer targetToSource(final Boolean value) {
                throw new UnsupportedOperationException();
            }
        };
        editDatasourceButtonBinding = bf.createBinding(DatasourceSelectionDialogController.this.datasourceSelectionDialogModel, "selectedIndex", // $NON-NLS-1$
        editDatasourceButton, "!disabled", // $NON-NLS-1$
        editDatasourceButtonConvertor);
        datasourceListbox.setSelectedIndex(-1);
        // workaround for bug in some XulListbox implementations (doesn't fire event on setSelectedIndex call)
        DatasourceSelectionDialogController.this.datasourceSelectionDialogModel.setSelectedIndex(-1);
    } catch (Exception e) {
        e.printStackTrace();
        // $NON-NLS-1$
        showMessagebox("Error", e.getLocalizedMessage());
    }
}
Also used : BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException) LogicalModelSummary(org.pentaho.platform.dataaccess.datasource.beans.LogicalModelSummary) XulButton(org.pentaho.ui.xul.components.XulButton) ArrayList(java.util.ArrayList) List(java.util.List) IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)

Example 9 with IDatasourceInfo

use of org.pentaho.platform.dataaccess.datasource.IDatasourceInfo in project data-access by pentaho.

the class JSUIDatasourceService method getIds.

@Override
public final void getIds(XulServiceCallback<List<IDatasourceInfo>> callback) {
    List<IDatasourceInfo> datasourceInfoList = new ArrayList<IDatasourceInfo>();
    JsArray<JavaScriptObject> infos = getDelegateIds(this.datasourceServiceObject);
    for (int i = 0; i < infos.length(); i++) {
        JSDatasourceInfo info = new JSDatasourceInfo(infos.get(i));
        datasourceInfoList.add(new DatasourceInfo(info.getName(), info.getName(), info.getType(), info.isEditable(), info.isRemovable(), info.isImportable(), info.isExportable()));
    }
    callback.success(datasourceInfoList);
}
Also used : IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo) DatasourceInfo(org.pentaho.platform.dataaccess.datasource.DatasourceInfo) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ArrayList(java.util.ArrayList) IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)

Example 10 with IDatasourceInfo

use of org.pentaho.platform.dataaccess.datasource.IDatasourceInfo 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

IDatasourceInfo (org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)10 ArrayList (java.util.ArrayList)5 Bindable (org.pentaho.ui.xul.stereotype.Bindable)5 List (java.util.List)3 DatasourceInfo (org.pentaho.platform.dataaccess.datasource.DatasourceInfo)3 RequestException (com.google.gwt.http.client.RequestException)2 LogicalModelSummary (org.pentaho.platform.dataaccess.datasource.beans.LogicalModelSummary)2 XulException (org.pentaho.ui.xul.XulException)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 Response (com.google.gwt.http.client.Response)1 Element (com.google.gwt.xml.client.Element)1 NodeList (com.google.gwt.xml.client.NodeList)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1 Domain (org.pentaho.metadata.model.Domain)1 DSWUIDatasourceService (org.pentaho.platform.dataaccess.datasource.ui.service.DSWUIDatasourceService)1 IUIDatasourceAdminService (org.pentaho.platform.dataaccess.datasource.ui.service.IUIDatasourceAdminService)1 JdbcDatasourceService (org.pentaho.platform.dataaccess.datasource.ui.service.JdbcDatasourceService)1