Search in sources :

Example 1 with SchemaModel

use of org.pentaho.agilebi.modeler.models.SchemaModel 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 SchemaModel

use of org.pentaho.agilebi.modeler.models.SchemaModel in project data-access by pentaho.

the class SerializeMultiTableServiceIT method getSchema.

private SchemaModel getSchema() {
    List<JoinRelationshipModel> joins = new ArrayList<JoinRelationshipModel>();
    JoinTableModel joinTable1 = new JoinTableModel();
    joinTable1.setName("CUSTOMERS");
    JoinTableModel joinTable2 = new JoinTableModel();
    joinTable2.setName("PRODUCTS");
    JoinRelationshipModel join1 = new JoinRelationshipModel();
    JoinFieldModel lField1 = new JoinFieldModel();
    lField1.setName("CUSTOMERNAME");
    lField1.setParentTable(joinTable1);
    join1.setLeftKeyFieldModel(lField1);
    JoinFieldModel rField1 = new JoinFieldModel();
    rField1.setName("PRODUCTCODE");
    rField1.setParentTable(joinTable2);
    join1.setRightKeyFieldModel(rField1);
    joins.add(join1);
    SchemaModel model = new SchemaModel();
    model.setJoins(joins);
    return model;
}
Also used : JoinTableModel(org.pentaho.agilebi.modeler.models.JoinTableModel) SchemaModel(org.pentaho.agilebi.modeler.models.SchemaModel) ArrayList(java.util.ArrayList) JoinFieldModel(org.pentaho.agilebi.modeler.models.JoinFieldModel) JoinRelationshipModel(org.pentaho.agilebi.modeler.models.JoinRelationshipModel)

Example 3 with SchemaModel

use of org.pentaho.agilebi.modeler.models.SchemaModel in project data-access by pentaho.

the class JoinMetadataIT method getSchemaModel.

private SchemaModel getSchemaModel() {
    List<JoinRelationshipModel> joins = new ArrayList<JoinRelationshipModel>();
    JoinTableModel joinTable1 = new JoinTableModel();
    joinTable1.setName("CUSTOMERS");
    JoinTableModel joinTable2 = new JoinTableModel();
    joinTable2.setName("PRODUCTS");
    JoinRelationshipModel join1 = new JoinRelationshipModel();
    JoinFieldModel lField1 = new JoinFieldModel();
    lField1.setName("CUSTOMERNAME");
    lField1.setParentTable(joinTable1);
    join1.setLeftKeyFieldModel(lField1);
    JoinFieldModel rField1 = new JoinFieldModel();
    rField1.setName("PRODUCTCODE");
    rField1.setParentTable(joinTable2);
    join1.setRightKeyFieldModel(rField1);
    joins.add(join1);
    SchemaModel model = new SchemaModel();
    model.setJoins(joins);
    return model;
}
Also used : JoinTableModel(org.pentaho.agilebi.modeler.models.JoinTableModel) SchemaModel(org.pentaho.agilebi.modeler.models.SchemaModel) ArrayList(java.util.ArrayList) JoinFieldModel(org.pentaho.agilebi.modeler.models.JoinFieldModel) JoinRelationshipModel(org.pentaho.agilebi.modeler.models.JoinRelationshipModel)

Example 4 with SchemaModel

use of org.pentaho.agilebi.modeler.models.SchemaModel 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

ArrayList (java.util.ArrayList)4 SchemaModel (org.pentaho.agilebi.modeler.models.SchemaModel)4 JoinTableModel (org.pentaho.agilebi.modeler.models.JoinTableModel)3 JoinFieldModel (org.pentaho.agilebi.modeler.models.JoinFieldModel)2 JoinRelationshipModel (org.pentaho.agilebi.modeler.models.JoinRelationshipModel)2 MultiTableDatasourceDTO (org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO)2 List (java.util.List)1 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)1