Search in sources :

Example 31 with LogicalTable

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

the class StarModelPainter method draw.

public void draw() {
    gc.setAntialias(true);
    Point center = new Point(area.x / 2, area.y / 2);
    gc.setBackground(EColor.BACKGROUND);
    gc.setForeground(EColor.BLACK);
    gc.fillRectangle(0, 0, area.x, area.y);
    // gc.drawText("bounds: x="+rect.x+", y="+rect.y+", height="+rect.height+", width="+rect.width, 10, 10);
    List<LogicalTable> tableList = new ArrayList<LogicalTable>();
    tableList.addAll(logicalModel.getLogicalTables());
    // Find the fact...
    // 
    LogicalTable fact = null;
    for (LogicalTable logicalTable : tableList) {
        if (TableType.FACT == ConceptUtil.getTableType(logicalTable)) {
            fact = logicalTable;
        }
    }
    if (fact != null) {
        tableList.remove(fact);
    }
    int maxWidth = Integer.MIN_VALUE;
    for (LogicalTable table : tableList) {
        String name = table.getName(locale);
        if (!Utils.isEmpty(name)) {
            Point p = gc.textExtent(name);
            if (p.x > maxWidth)
                maxWidth = p.x;
        }
    }
    List<TablePoint> points = new ArrayList<TablePoint>();
    if (fact != null) {
        points.add(new TablePoint(fact, center));
    }
    // 
    if (!tableList.isEmpty()) {
        List<TablePoint> dimPoints = getCirclePoints(center, center.x - maxWidth / 2 - 20, center.y - 20, tableList);
        points.addAll(dimPoints);
    }
    // 
    for (LogicalRelationship rel : logicalRelationships) {
        LogicalTable fromTable = rel.getFromTable();
        LogicalTable toTable = rel.getToTable();
        Point from = findPointOfTable(points, fromTable);
        Point to = findPointOfTable(points, toTable);
        if (from != null && to != null) {
            gc.drawLine(from.x, from.y, to.x, to.y);
        }
    }
    // 
    for (TablePoint tablePoint : points) {
        LogicalTable table = tablePoint.logicalTable;
        Point point = tablePoint.point;
        drawCircleName(point, table);
    }
}
Also used : ArrayList(java.util.ArrayList) Point(org.pentaho.di.core.gui.Point) LogicalTable(org.pentaho.metadata.model.LogicalTable) LogicalRelationship(org.pentaho.metadata.model.LogicalRelationship) Point(org.pentaho.di.core.gui.Point)

Example 32 with LogicalTable

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

the class ConceptUtilTest method testFindLogicalColumn.

@Test
public void testFindLogicalColumn() throws Exception {
    final LogicalTable logicalTable = mock(LogicalTable.class);
    final AttributeType attribute = AttributeType.ATTRIBUTE;
    final LogicalColumn logicalColumn1 = mock(LogicalColumn.class);
    when(logicalColumn1.getProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE)).thenReturn(attribute.name());
    final LogicalColumn logicalColumn2 = mock(LogicalColumn.class);
    when(logicalColumn2.getProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE)).thenReturn(attribute.name());
    when(logicalTable.getLogicalColumns()).thenReturn(new LinkedList<LogicalColumn>() {

        {
            add(logicalColumn1);
            add(logicalColumn2);
        }
    });
    assertNull(ConceptUtil.findLogicalColumn(logicalTable, AttributeType.ATTRIBUTE_HISTORICAL));
    final LogicalColumn result = ConceptUtil.findLogicalColumn(logicalTable, attribute);
    assertEquals(logicalColumn1, result);
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 33 with LogicalTable

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

the class ConceptUtilTest method testGetDimensionType.

@Test
public void testGetDimensionType() throws Exception {
    final LogicalTable logicalTable = mock(LogicalTable.class);
    final DimensionType dtDate = DimensionType.DATE;
    when(logicalTable.getProperty(DefaultIDs.LOGICAL_TABLE_DIMENSION_TYPE)).thenReturn(dtDate.name());
    final DimensionType dimensionType = ConceptUtil.getDimensionType(logicalTable);
    assertEquals(dtDate, dimensionType);
}
Also used : LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 34 with LogicalTable

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

the class MetadataQueryComponentIT method getBasicDomain.

public Domain getBasicDomain() {
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    dataSource.setDialectType("HYPERSONIC");
    dataSource.setType(DataSourceType.JNDI);
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    table.setId("PT1");
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select distinct customername, salesrepemployeenumber from customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setId("PC1");
    column.setTargetColumn("CUSTOMERNAME");
    column.setName(new LocalizedString("en_US", "Customer Name"));
    column.setDescription(new LocalizedString("en_US", "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    table.getPhysicalColumns().add(column);
    SqlPhysicalColumn column2 = new SqlPhysicalColumn(table);
    column2.setId("PC2");
    column2.setTargetColumn("SALESREPEMPLOYEENUMBER");
    column2.setName(new LocalizedString("en_US", "Sales Rep"));
    column2.setDescription(new LocalizedString("en_US", "Sales Rep Employee Number"));
    column2.setDataType(DataType.NUMERIC);
    table.getPhysicalColumns().add(column2);
    LogicalModel logicalModel = new LogicalModel();
    logicalModel.setPhysicalModel(model);
    logicalModel.setId("MODEL");
    logicalModel.setName(new LocalizedString("en_US", "My Model"));
    logicalModel.setDescription(new LocalizedString("en_US", "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setId("LT");
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId("LC_CUSTOMERNAME");
    logicalColumn.setPhysicalColumn(column);
    logicalColumn.setLogicalTable(logicalTable);
    logicalTable.addLogicalColumn(logicalColumn);
    LogicalColumn logicalColumn2 = new LogicalColumn();
    logicalColumn2.setId("LC_SALESREP");
    logicalColumn2.setPhysicalColumn(column2);
    logicalColumn2.setLogicalTable(logicalTable);
    logicalTable.addLogicalColumn(logicalColumn2);
    Category mainCategory = new Category();
    mainCategory.setId("CATEGORY");
    mainCategory.setName(new LocalizedString("en_US", "Category"));
    mainCategory.addLogicalColumn(logicalColumn);
    mainCategory.addLogicalColumn(logicalColumn2);
    logicalModel.getCategories().add(mainCategory);
    Domain domain = new Domain();
    domain.setId("DOMAIN");
    domain.addPhysicalModel(model);
    domain.addLogicalModel(logicalModel);
    return domain;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

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