Search in sources :

Example 16 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project data-access by pentaho.

the class GuiStateModelTest method test.

@Test
public void test() {
    GuiStateModel guiStateModel = new GuiStateModel();
    Assert.assertEquals(0, guiStateModel.getConnections().size());
    Assert.assertEquals(false, guiStateModel.isRelationalValidated());
    IDatabaseConnection connection = new DatabaseConnection();
    connection.setAccessType(DatabaseAccessType.NATIVE);
    // connection.setDriverClass("org.hsqldb.jdbcDriver");
    connection.setName("SampleData");
    connection.setPassword("password");
    // connection.setUrl("jdbc:hsqldb:file:target/test-classes/solution1/system/data/sampledata");
    connection.setUsername("pentaho_user");
    List<IDatabaseConnection> connectionList = new ArrayList<IDatabaseConnection>();
    connectionList.add(connection);
    guiStateModel.setConnections(connectionList);
    guiStateModel.setPreviewLimit("10");
    guiStateModel.validateRelational();
    Assert.assertEquals(true, guiStateModel.isRelationalPreviewValidated());
    // Assert.assertEquals(false, relationalModel.isValidated());
    LogicalColumn logColumn = new LogicalColumn();
    logColumn.setDataType(DataType.NUMERIC);
    List<AggregationType> aggTypeList = new ArrayList<AggregationType>();
    aggTypeList.add(AggregationType.AVERAGE);
    logColumn.setAggregationList(aggTypeList);
    logColumn.setName(new LocalizedString("En", "Column1"));
    BusinessData businessData = new BusinessData();
    List<List<String>> dataSample = new ArrayList<List<String>>();
    List<String> rowData = new ArrayList<String>();
    rowData.add("Data1");
    rowData.add("Data2");
    rowData.add("Data3");
    rowData.add("Data4");
    dataSample.add(rowData);
    String locale = LocaleHelper.getLocale().toString();
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select * from customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setTargetColumn("customername");
    column.setName(new LocalizedString(locale, "Customer Name"));
    column.setDescription(new LocalizedString(locale, "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    table.getPhysicalColumns().add(column);
    LogicalModel logicalModel = new LogicalModel();
    model.setId("MODEL");
    model.setName(new LocalizedString(locale, "My Model"));
    model.setDescription(new LocalizedString(locale, "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId("LC_CUSTOMERNAME");
    logicalColumn.setPhysicalColumn(column);
    logicalTable.addLogicalColumn(logicalColumn);
    Category mainCategory = new Category();
    mainCategory.setId("CATEGORY");
    mainCategory.setName(new LocalizedString(locale, "Category"));
    mainCategory.addLogicalColumn(logicalColumn);
    logicalModel.getCategories().add(mainCategory);
    Domain domain = new Domain();
    domain.addPhysicalModel(model);
    domain.addLogicalModel(logicalModel);
    List<LocaleType> localeTypeList = new ArrayList<LocaleType>();
    localeTypeList.add(new LocaleType("Code", "Locale Description"));
    domain.setLocales(localeTypeList);
    businessData.setData(dataSample);
    businessData.setDomain(domain);
    guiStateModel.setLogicalModels(domain.getLogicalModels());
    guiStateModel.setLocaleCode("en");
    Assert.assertEquals(true, guiStateModel.isRelationalValidated());
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable) LogicalModel(org.pentaho.metadata.model.LogicalModel) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocaleType(org.pentaho.metadata.model.concept.types.LocaleType) 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) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 17 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project data-access by pentaho.

the class MultitableGuiModel method generateLogicalRelationships.

@Deprecated
public List<LogicalRelationship> generateLogicalRelationships(List<JoinRelationshipModel> joins) {
    String locale = LocalizedString.DEFAULT_LOCALE;
    List<LogicalRelationship> logicalRelationships = new ArrayList<LogicalRelationship>();
    for (JoinRelationshipModel join : joins) {
        LogicalTable fromTable = new LogicalTable();
        fromTable.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getParentTable().getName()));
        LogicalTable toTable = new LogicalTable();
        toTable.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getParentTable().getName()));
        LogicalColumn fromColumn = new LogicalColumn();
        fromColumn.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getName()));
        LogicalColumn toColumn = new LogicalColumn();
        toColumn.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getName()));
        LogicalRelationship logicalRelationship = new LogicalRelationship();
        logicalRelationship.setFromTable(fromTable);
        logicalRelationship.setToTable(toTable);
        logicalRelationship.setFromColumn(fromColumn);
        logicalRelationship.setToColumn(toColumn);
        logicalRelationships.add(logicalRelationship);
    }
    return logicalRelationships;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) ArrayList(java.util.ArrayList) JoinRelationshipModel(org.pentaho.agilebi.modeler.models.JoinRelationshipModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalRelationship(org.pentaho.metadata.model.LogicalRelationship)

Example 18 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class StarModelerPerspective method deleteSharedDimension.

/**
 * Delete a shared dimension in the domain
 *
 * @param domain the domain to delete the dimension from
 * @param modelName the name of the dimension to delete
 */
private boolean deleteSharedDimension(Shell shell, StarDomain starDomain, String locale, String modelName) {
    LogicalTable logicalTable = findSharedDimension(starDomain, locale, modelName);
    if (logicalTable != null) {
        // TODO: show warning dialog.
        // 
        starDomain.getSharedDimensions().remove(logicalTable);
        starDomain.setChanged(true);
        return true;
    }
    return false;
}
Also used : LogicalTable(org.pentaho.metadata.model.LogicalTable)

Example 19 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class StarModelerPerspective method refreshDimensionsList.

protected void refreshDimensionsList(StarDomain starDomain, TableView dimensionsList) {
    dimensionsList.clearAll();
    for (LogicalTable table : starDomain.getSharedDimensions()) {
        TableItem item = new TableItem(dimensionsList.table, SWT.NONE);
        item.setText(1, Const.NVL(table.getName(defaultLocale), ""));
        item.setText(2, Const.NVL(table.getDescription(defaultLocale), ""));
    }
    dimensionsList.removeEmptyRows();
    dimensionsList.setRowNums();
    dimensionsList.optWidth(true);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) LogicalTable(org.pentaho.metadata.model.LogicalTable)

Example 20 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class StarModelerPerspective method newSharedDimension.

/**
 * Create a new shared dimension in the domain
 *
 * @param domain the domain to create the new model in
 */
private boolean newSharedDimension(Shell shell, StarDomain starDomain) {
    LogicalTable dimensionTable = new LogicalTable();
    dimensionTable.setName(new LocalizedString(defaultLocale, "Shared dimension"));
    DimensionTableDialog dialog = new DimensionTableDialog(shell, dimensionTable, defaultLocale);
    if (dialog.open() != null) {
        starDomain.getSharedDimensions().add(dimensionTable);
        starDomain.setChanged(true);
        return true;
    }
    return false;
}
Also used : LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Aggregations

LogicalTable (org.pentaho.metadata.model.LogicalTable)34 Test (org.junit.Test)14 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)13 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)12 LogicalModel (org.pentaho.metadata.model.LogicalModel)11 ArrayList (java.util.ArrayList)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)6 Domain (org.pentaho.metadata.model.Domain)5 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)5 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)5 TableType (org.pentaho.metadata.model.concept.types.TableType)5 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 KettleException (org.pentaho.di.core.exception.KettleException)3 TransMeta (org.pentaho.di.trans.TransMeta)3 Category (org.pentaho.metadata.model.Category)3 LogicalRelationship (org.pentaho.metadata.model.LogicalRelationship)3 List (java.util.List)2 TableItem (org.eclipse.swt.widgets.TableItem)2 Matchers.anyString (org.mockito.Matchers.anyString)2