Search in sources :

Example 1 with DatasourceModel

use of org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel in project data-access by pentaho.

the class GwtDatasourceEditorEntryPoint method showEditDatabaseDialog.

public void showEditDatabaseDialog(final DialogListener dialogListener, final String databaseName) {
    String cacheBuster = String.valueOf(new java.util.Date().getTime());
    String url = ConnectionController.getServiceURL("get", new String[][] { { "name", databaseName }, { "ts", cacheBuster } });
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    builder.setHeader("Accept", "application/json");
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                Window.alert(exception.toString());
            }

            @SuppressWarnings("deprecation")
            public void onResponseReceived(Request request, Response response) {
                IDatabaseConnection conn = null;
                if (response.getStatusCode() == Response.SC_OK) {
                    AutoBean<IDatabaseConnection> bean = AutoBeanCodex.decode(connectionAutoBeanFactory, IDatabaseConnection.class, response.getText());
                    conn = bean.as();
                }
                ConnectionController connectionController = wizard.getConnectionController();
                connectionController.init();
                DatasourceModel datasourceModel = connectionController.getDatasourceModel();
                if (datasourceModel == null) {
                    datasourceModel = new DatasourceModel();
                }
                datasourceModel.setSelectedRelationalConnection(conn);
                // This is important for edit mode of datasource model
                datasourceModel.setEditing(true);
                connectionController.setDatasourceModel(datasourceModel);
                connectionController.showEditConnectionDialog(dialogListener, conn);
            }
        });
    } catch (Exception e) {
        Window.alert("Cannot edit datasource");
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) AutoBean(com.google.web.bindery.autobean.shared.AutoBean) XulException(org.pentaho.ui.xul.XulException) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) DatasourceModel(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel) RequestCallback(com.google.gwt.http.client.RequestCallback) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ConnectionController(org.pentaho.platform.dataaccess.datasource.wizard.controllers.ConnectionController)

Example 2 with DatasourceModel

use of org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel in project data-access by pentaho.

the class DSWDatasourceServiceImplTest method testDeSerializeModelStateValidString.

@Test
public void testDeSerializeModelStateValidString() throws Exception {
    PentahoSystem.registerObjectFactory(new TestObjectFactory());
    DatasourceModel datasourceModel = spy(new DatasourceModel());
    doReturn("testdatasource").when(datasourceModel).generateTableName();
    datasourceModel.setDatasourceName("testDatasource");
    datasourceModel.setDatasourceType(DatasourceType.CSV);
    DatasourceDTO dto = DatasourceDTO.generateDTO(datasourceModel);
    assertNotNull(dto);
    String serializedDTO = dswService.serializeModelState(dto);
    dswService.deSerializeModelState(serializedDTO);
}
Also used : DatasourceModel(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel) TestObjectFactory(org.pentaho.platform.engine.core.TestObjectFactory) Mockito.anyString(org.mockito.Mockito.anyString) DatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO) Test(org.junit.Test)

Example 3 with DatasourceModel

use of org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel in project data-access by pentaho.

the class GwtDatasourceEditorEntryPoint method showDatabaseDialog.

public void showDatabaseDialog(final DialogListener<IDatabaseConnection> listener) {
    ConnectionController connectionController = wizard.getConnectionController();
    connectionController.init();
    DatasourceModel datasourceModel = connectionController.getDatasourceModel();
    if (datasourceModel == null) {
        datasourceModel = new DatasourceModel();
    }
    connectionController.setDatasourceModel(datasourceModel);
    connectionController.showAddConnectionDialog(listener);
}
Also used : DatasourceModel(org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel) ConnectionController(org.pentaho.platform.dataaccess.datasource.wizard.controllers.ConnectionController)

Aggregations

DatasourceModel (org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceModel)3 ConnectionController (org.pentaho.platform.dataaccess.datasource.wizard.controllers.ConnectionController)2 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 AutoBean (com.google.web.bindery.autobean.shared.AutoBean)1 Test (org.junit.Test)1 Mockito.anyString (org.mockito.Mockito.anyString)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1 DatasourceDTO (org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO)1 TestObjectFactory (org.pentaho.platform.engine.core.TestObjectFactory)1 XulException (org.pentaho.ui.xul.XulException)1