Search in sources :

Example 1 with LogicalModel

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

the class JobGeneratorTest method testGenerateDimensionTransformations.

@Test
public void testGenerateDimensionTransformations() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    when(jobGenerator.domain.getLogicalModels()).thenReturn(new LinkedList<LogicalModel>() {

        {
            add(logicalModel);
        }
    });
    final LogicalTable logicalTable = mock(LogicalTable.class);
    when(logicalTable.getProperty(eq(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME))).thenReturn("test_table_name");
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable);
        }
    });
    when(logicalTable.getProperty(eq(DefaultPropertyID.TABLE_TYPE.getId()))).thenReturn(TableType.DIMENSION);
    when(logicalTable.getProperty(eq(DefaultIDs.LOGICAL_TABLE_DIMENSION_TYPE))).thenReturn(DimensionType.JUNK_DIMENSION.name());
    final List<TransMeta> transMetas = jobGenerator.generateDimensionTransformations();
    assertNotNull(transMetas);
    assertEquals(1, transMetas.size());
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) TransMeta(org.pentaho.di.trans.TransMeta) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 2 with LogicalModel

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

the class JobGeneratorTest method testGetUniqueLogicalTables.

@Test
public void testGetUniqueLogicalTables() throws Exception {
    final LogicalModel logicalModel = mock(LogicalModel.class);
    when(jobGenerator.domain.getLogicalModels()).thenReturn(new LinkedList<LogicalModel>() {

        {
            add(logicalModel);
        }
    });
    final LogicalTable logicalTable = mock(LogicalTable.class);
    when(logicalTable.getProperty(eq(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME))).thenReturn("test_table_name");
    when(logicalModel.getLogicalTables()).thenReturn(new LinkedList<LogicalTable>() {

        {
            add(logicalTable);
        }
    });
    final List<LogicalTable> uniqueLogicalTables = jobGenerator.getUniqueLogicalTables();
    assertNotNull(uniqueLogicalTables);
    assertEquals(1, uniqueLogicalTables.size());
    assertEquals(logicalTable, uniqueLogicalTables.get(0));
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalTable(org.pentaho.metadata.model.LogicalTable) Test(org.junit.Test)

Example 3 with LogicalModel

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

the class StarModelerPerspective method deleteModel.

/**
 * Delete a model in the domain
 *
 * @param domain the domain to delete the model from
 * @param modelName the name of the model to delete
 */
private boolean deleteModel(Shell shell, StarDomain starDomain, String locale, String modelName) {
    LogicalModel logicalModel = findLogicalTable(starDomain.getDomain(), locale, modelName);
    if (logicalModel != null) {
        // TODO: show warning dialog.
        // 
        starDomain.getDomain().getLogicalModels().remove(logicalModel);
        starDomain.setChanged(true);
        return true;
    }
    return false;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel)

Example 4 with LogicalModel

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

the class StarModelerPerspective method refreshModelsList.

protected void refreshModelsList(StarDomain starDomain, TableView modelsList) {
    modelsList.clearAll();
    for (LogicalModel model : starDomain.getDomain().getLogicalModels()) {
        TableItem item = new TableItem(modelsList.table, SWT.NONE);
        item.setText(1, Const.NVL(model.getName(defaultLocale), ""));
        item.setText(2, Const.NVL(model.getDescription(defaultLocale), ""));
    }
    modelsList.removeEmptyRows();
    modelsList.setRowNums();
    modelsList.optWidth(true);
    Spoon.getInstance().enableMenus();
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) TableItem(org.eclipse.swt.widgets.TableItem)

Example 5 with LogicalModel

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

the class MetadataGenerator method generatePhysicalMetadataModel.

public Domain generatePhysicalMetadataModel() throws KettleException {
    // First do some checking and lookups...
    // 
    String targetDatabaseName = ConceptUtil.getString(logicalDomain, DefaultIDs.DOMAIN_TARGET_DATABASE);
    if (Utils.isEmpty(targetDatabaseName)) {
        throw new KettleException("Please specify a target database!");
    }
    DatabaseMeta targetDatabaseMeta = DatabaseMeta.findDatabase(databases, targetDatabaseName);
    if (targetDatabaseMeta == null) {
        throw new KettleException("Target database with name '" + targetDatabaseName + "' can't be found!");
    }
    // Now start creation of a new domain with physical underpinning.
    // 
    Domain domain = new Domain();
    // Copy the domain information...
    // 
    domain.setId(createId("DOMAIN", null, domain));
    domain.setName(logicalDomain.getName());
    domain.setDescription(logicalDomain.getDescription());
    // 
    for (LogicalModel logicalModel : logicalDomain.getLogicalModels()) {
        // Copy model information...
        // 
        LogicalModel model = new LogicalModel();
        model.setId(createId("MODEL", domain, model));
        model.setName(logicalModel.getName());
        model.setDescription(logicalModel.getDescription());
        // Create a physical model...
        // 
        SqlPhysicalModel sqlModel = new SqlPhysicalModel();
        sqlModel.setDatasource(createSqlDataSource(targetDatabaseMeta));
        model.setPhysicalModel(sqlModel);
        for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
            LogicalTable table = new LogicalTable();
            table.setId(createId("LOGICAL_TABLE", logicalModel, logicalTable));
            table.setName(logicalTable.getName());
            table.setDescription(logicalTable.getDescription());
            String targetTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
            SqlPhysicalTable sqlTable = new SqlPhysicalTable(sqlModel);
            table.setPhysicalTable(sqlTable);
            // Copy name & description from physical level...
            // 
            sqlTable.setId(createId("PHYSICAL_TABLE", logicalModel, logicalTable));
            sqlTable.setName(logicalTable.getName());
            sqlTable.setDescription(logicalTable.getDescription());
            sqlTable.setTableType(ConceptUtil.getTableType(logicalTable));
            sqlTable.setTargetSchema(targetDatabaseMeta.getPreferredSchemaName());
            sqlTable.setTargetTable(targetTable);
        }
    }
    return domain;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LogicalModel(org.pentaho.metadata.model.LogicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

Aggregations

LogicalModel (org.pentaho.metadata.model.LogicalModel)53 Domain (org.pentaho.metadata.model.Domain)29 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)14 Test (org.junit.Test)13 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)11 LogicalTable (org.pentaho.metadata.model.LogicalTable)11 ArrayList (java.util.ArrayList)10 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)9 Category (org.pentaho.metadata.model.Category)8 Matchers.anyString (org.mockito.Matchers.anyString)7 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)7 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)6 IMetadataDomainRepository (org.pentaho.metadata.repository.IMetadataDomainRepository)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)5 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)5 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)5 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)5 IOException (java.io.IOException)4 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4