Search in sources :

Example 31 with LogicalModel

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

the class InMemoryDSWDatasourceServiceImpl method getLogicalModels.

public List<LogicalModelSummary> getLogicalModels(String context) throws DatasourceServiceException {
    List<LogicalModelSummary> logicalModelSummaries = new ArrayList<LogicalModelSummary>();
    for (String domainId : getMetadataDomainRepository().getDomainIds()) {
        Domain domain = getMetadataDomainRepository().getDomain(domainId);
        String locale = LocaleHelper.getLocale().toString();
        String[] locales = new String[domain.getLocales().size()];
        for (int i = 0; i < domain.getLocales().size(); i++) {
            locales[i] = domain.getLocales().get(i).getCode();
        }
        locale = LocaleHelper.getClosestLocale(locale, locales);
        for (LogicalModel model : domain.getLogicalModels()) {
            String vis = (String) model.getProperty("visible");
            if (vis != null) {
                String[] visibleContexts = vis.split(",");
                boolean visibleToContext = false;
                for (String c : visibleContexts) {
                    if (context.equals(c.trim())) {
                        visibleToContext = true;
                        break;
                    }
                }
                if (!visibleToContext) {
                    continue;
                }
            }
            logicalModelSummaries.add(new LogicalModelSummary(domainId, model.getId(), model.getName().getString(locale)));
        }
    }
    return logicalModelSummaries;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalModelSummary(org.pentaho.platform.dataaccess.datasource.beans.LogicalModelSummary) ArrayList(java.util.ArrayList) Domain(org.pentaho.metadata.model.Domain)

Example 32 with LogicalModel

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

the class WAQRTransport method createFromMetadata.

public static WAQRTransport createFromMetadata(Domain domain) {
    // this assumes a single logical model with a single logical category
    LogicalModel model = domain.getLogicalModels().get(0);
    Iterator<String> iter = model.getName().getLocales().iterator();
    String locale = iter.next();
    Category category = model.getCategories().get(0);
    String domainId = domain.getId();
    String modelId = model.getId();
    String modelName = model.getName() != null ? model.getName().getString(locale) : null;
    String categoryId = category.getId();
    String categoryName = category.getName() != null ? category.getName().getString(locale) : null;
    String schemaName = model.getName(locale);
    return createDomain(domainId, modelId, modelName, categoryId, categoryName, schemaName);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) Category(org.pentaho.metadata.model.Category)

Example 33 with LogicalModel

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

the class DataAccessServiceTestBase method getDomain.

/**
 * Provide a mock domain
 *
 * @return
 */
private Domain getDomain() {
    LogicalColumn logicalColumn1;
    LogicalColumn logicalColumn2;
    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");
    table.setId("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);
    column.setId("cutomer_customername");
    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.setId("BT_CUSTOMERS");
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    logicalModel.setName(new LocalizedString(locale, "My Model"));
    logicalColumn1 = new LogicalColumn();
    logicalColumn1.setId("LC_CUSTOMERNAME");
    logicalColumn1.setPhysicalColumn(column);
    logicalColumn1.setAggregationType(AggregationType.COUNT);
    logicalColumn1.setLogicalTable(logicalTable);
    logicalColumn1.setDataType(DataType.STRING);
    logicalColumn2 = new LogicalColumn();
    logicalColumn2.setId("LC_CUSTOMERNUMBER");
    logicalColumn2.setAggregationType(AggregationType.COUNT);
    logicalColumn2.setPhysicalColumn(column);
    logicalColumn2.setLogicalTable(logicalTable);
    logicalColumn2.setDataType(DataType.NUMERIC);
    logicalTable.addLogicalColumn(logicalColumn1);
    logicalTable.addLogicalColumn(logicalColumn2);
    Domain thisDomain = new Domain();
    thisDomain.addPhysicalModel(model);
    thisDomain.addLogicalModel(logicalModel);
    return thisDomain;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) 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)

Example 34 with LogicalModel

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

the class StarModelerPerspective method newModel.

/**
 * Create a new model in the domain
 *
 * @param domain the domain to create the new model in
 */
private boolean newModel(Shell shell, StarDomain starDomain) {
    LogicalModel model = new LogicalModel();
    model.setName(new LocalizedString(defaultLocale, "Model"));
    StarModelDialog dialog = new StarModelDialog(shell, model, defaultLocale);
    if (dialog.open() != null) {
        starDomain.getDomain().getLogicalModels().add(model);
        starDomain.setChanged(true);
        return true;
    }
    return false;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 35 with LogicalModel

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

the class JobGenerator method getUniqueLogicalTables.

/**
 * Get a list of all unique physical table names wrapped in their logical tables
 * @return
 */
protected List<LogicalTable> getUniqueLogicalTables() {
    List<LogicalTable> tables = new ArrayList<LogicalTable>();
    List<String> phTabs = new ArrayList<String>();
    for (LogicalModel model : domain.getLogicalModels()) {
        for (LogicalTable table : model.getLogicalTables()) {
            String phTable = ConceptUtil.getString(table, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
            if (!Utils.isEmpty(phTable)) {
                if (!phTabs.contains(phTable)) {
                    phTabs.add(phTable);
                    tables.add(table);
                }
            }
        }
    }
    return tables;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ArrayList(java.util.ArrayList) LogicalTable(org.pentaho.metadata.model.LogicalTable)

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