Search in sources :

Example 1 with MultiTableDatasourceDTO

use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.

the class LegacyDatasourceConverter method unmarshal.

/**
 * Convert textual data back into an object.
 *
 * @param reader  The stream to read the text from.
 * @param context
 * @return The resulting object.
 */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    MultiTableDatasourceDTO resultDTO = new MultiTableDatasourceDTO();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        String nodeName = reader.getNodeName();
        if (nodeName.equalsIgnoreCase("datasourceName")) {
            String value = reader.getValue();
            resultDTO.setDatasourceName(value);
        } else if (nodeName.equalsIgnoreCase("selectedConnection")) {
            String connectionClass = reader.getAttribute("class");
            if (connectionClass != null) {
                DatabaseConnection databaseConnection = new DatabaseConnection();
                if (connectionClass.equals("org.pentaho.platform.dataaccess.datasource.beans.Connection")) {
                    while (reader.hasMoreChildren()) {
                        reader.moveDown();
                        nodeName = reader.getNodeName();
                        if (reader.getNodeName().equalsIgnoreCase("name")) {
                            String databaseName = reader.getValue();
                            databaseConnection.setName(databaseName);
                            databaseConnection.setId(databaseName);
                        } else if (reader.getNodeName().equalsIgnoreCase("username")) {
                            databaseConnection.setUsername(reader.getValue());
                        } else if (reader.getNodeName().equalsIgnoreCase("password")) {
                            databaseConnection.setPassword(reader.getValue());
                        } else if (reader.getNodeName().equalsIgnoreCase("url")) {
                            ParsedJdbcUrl parsedJdbcUrl = new ParsedJdbcUrl(reader.getValue());
                            databaseConnection.setHostname(parsedJdbcUrl.getHostname());
                            databaseConnection.setDatabasePort(parsedJdbcUrl.getPort());
                            databaseConnection.setDatabaseName(parsedJdbcUrl.getDatabaseName());
                            databaseConnection.setDatabaseType(resolveDatabaseType(parsedJdbcUrl.getJdbcPrefix()));
                        }
                        reader.moveUp();
                    }
                    resultDTO.setSelectedConnection(databaseConnection);
                } else {
                    // instantiate the class specified
                    try {
                        Class databaseConnectionClass = Class.forName(connectionClass);
                        IDatabaseConnection databaseConnectionInstance = (IDatabaseConnection) context.convertAnother(resultDTO, databaseConnectionClass);
                        resultDTO.setSelectedConnection(databaseConnectionInstance);
                    } catch (ClassNotFoundException e) {
                        // not going to work anyway, set empty connection for now
                        resultDTO.setSelectedConnection(new DatabaseConnection());
                    }
                }
            }
        } else if (nodeName.equalsIgnoreCase("schemaModel")) {
            SchemaModel schemaModel = (SchemaModel) context.convertAnother(resultDTO, SchemaModel.class);
            if (schemaModel != null) {
                resultDTO.setSchemaModel(schemaModel);
            }
        } else if (nodeName.equalsIgnoreCase("selectedTables")) {
            List<String> selectedTables = (List<String>) context.convertAnother(resultDTO, ArrayList.class);
            if (selectedTables != null) {
                resultDTO.setSelectedTables(selectedTables);
            }
        } else if (nodeName.equalsIgnoreCase("doOlap")) {
            resultDTO.setDoOlap(Boolean.valueOf(reader.getValue()));
        }
        reader.moveUp();
    }
    return resultDTO;
}
Also used : MultiTableDatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO) SchemaModel(org.pentaho.agilebi.modeler.models.SchemaModel) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 2 with MultiTableDatasourceDTO

use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.

the class MultiTableDatasource method onFinish.

@Override
public void onFinish(final XulServiceCallback<IDatasourceSummary> callback) {
    if (this.validator.allTablesJoined()) {
        String dsName = this.wizardModel.getDatasourceName();
        MultiTableDatasourceDTO dto = this.joinGuiModel.createMultiTableDatasourceDTO(dsName);
        dto.setSelectedConnection(this.connection);
        joinSelectionServiceGwtImpl.serializeJoins(dto, this.connection, new XulServiceCallback<IDatasourceSummary>() {

            public void success(IDatasourceSummary retVal) {
                callback.success(retVal);
            }

            public void error(String message, Throwable error) {
                MessageHandler.getInstance().closeWaitingDialog();
                MessageHandler.getInstance().showErrorDetailsDialog(MessageHandler.getString("ERROR"), MessageHandler.getString("multitable.ERROR_SAVING_MODEL"), error.getLocalizedMessage());
            }
        });
    } else {
        MessageHandler.getInstance().closeWaitingDialog();
        XulDialog wizardDialog = (XulDialog) document.getElementById("main_wizard_window");
        wizardDialog.show();
        this.displayErrors(this.validator.getError());
    }
}
Also used : MultiTableDatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO) IDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.IDatasourceSummary) XulDialog(org.pentaho.ui.xul.containers.XulDialog)

Example 3 with MultiTableDatasourceDTO

use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.

the class LegacyDatasourceConverterTest method testStreamConverter.

@Test
public void testStreamConverter() throws Exception {
    sampleDTOFile = new File(SAMPLE_FILE_PATH);
    inputStream = new FileInputStream(sampleDTOFile);
    StringWriter writer = new StringWriter();
    IOUtils.copy(inputStream, writer, DEFAULT_ENCODING);
    dtoStr = writer.toString();
    try {
        if (inputStream != null)
            inputStream.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    XStream xs = new XStream();
    xs.registerConverter(new LegacyDatasourceConverter());
    MultiTableDatasourceDTO resultDTO = (MultiTableDatasourceDTO) xs.fromXML(dtoStr);
    System.out.println(resultDTO.toString());
}
Also used : StringWriter(java.io.StringWriter) MultiTableDatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO) XStream(com.thoughtworks.xstream.XStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 4 with MultiTableDatasourceDTO

use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.

the class MultitableGuiModel method createMultiTableDatasourceDTO.

public MultiTableDatasourceDTO createMultiTableDatasourceDTO(String dsName) {
    MultiTableDatasourceDTO dto = new MultiTableDatasourceDTO();
    dto.setDoOlap(this.doOlap);
    dto.setDatasourceName(dsName);
    List<String> selectedTables = new ArrayList<String>();
    for (JoinTableModel tbl : this.selectedTables) {
        selectedTables.add(tbl.getName());
    }
    dto.setSelectedTables(selectedTables);
    SchemaModel schema = new SchemaModel();
    schema.setJoins(this.getJoins());
    schema.setFactTable(this.factTable);
    dto.setSchemaModel(schema);
    return dto;
}
Also used : MultiTableDatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO) JoinTableModel(org.pentaho.agilebi.modeler.models.JoinTableModel) SchemaModel(org.pentaho.agilebi.modeler.models.SchemaModel) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Aggregations

MultiTableDatasourceDTO (org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO)4 ArrayList (java.util.ArrayList)2 SchemaModel (org.pentaho.agilebi.modeler.models.SchemaModel)2 XStream (com.thoughtworks.xstream.XStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 Test (org.junit.Test)1 JoinTableModel (org.pentaho.agilebi.modeler.models.JoinTableModel)1 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)1 IDatasourceSummary (org.pentaho.platform.dataaccess.datasource.wizard.IDatasourceSummary)1 XulDialog (org.pentaho.ui.xul.containers.XulDialog)1