Search in sources :

Example 6 with Category

use of org.pentaho.metadata.model.Category 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 7 with Category

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

the class MetadataServiceTest method initialize.

@Before
public void initialize() {
    List<Category> categoryList = new ArrayList();
    Category category = mock(Category.class);
    when(category.getId()).thenReturn(CATEGORY_ID);
    categoryList.add(category);
    LogicalColumn logicalColumn = mock(LogicalColumn.class);
    when(logicalColumn.getId()).thenReturn(COLUMN_ID);
    when(logicalColumn.getDataType()).thenReturn(DataType.STRING);
    when(category.findLogicalColumn(anyString())).thenReturn(logicalColumn);
    logicalModel = mock(LogicalModel.class);
    when(logicalModel.getId()).thenReturn(LOGICAL_MODEL_ID);
    when(logicalModel.getName(anyString())).thenReturn(LOGICAL_MODEL_NAME);
    when(logicalModel.getCategories()).thenReturn(categoryList);
    when(logicalModel.findLogicalColumn(anyString())).thenReturn(logicalColumn);
    when(logicalModel.getProperty(anyString())).thenReturn(null);
    logicalModel2 = mock(LogicalModel.class);
    when(logicalModel2.getId()).thenReturn(LOGICAL_MODEL_2_ID);
    when(logicalModel2.getName(anyString())).thenReturn(LOGICAL_MODEL_2_NAME);
    when(logicalModel2.getProperty(anyString())).thenReturn(null);
    Domain domainOnlyReportingModel = new Domain();
    domainOnlyReportingModel.setId(DOMAIN_ID);
    domainOnlyReportingModel.setLogicalModels(new ArrayList<LogicalModel>() {

        {
            add(logicalModel2);
        }

        {
            add(logicalModel);
        }
    });
    iMetadataDomainRepository = mock(IMetadataDomainRepository.class);
    when(iMetadataDomainRepository.getDomain(DOMAIN_ID)).thenReturn(domainOnlyReportingModel);
    Set<String> domains = new HashSet<String>();
    domains.add(DOMAIN_ID);
    when(iMetadataDomainRepository.getDomainIds()).thenReturn(domains);
    metadataService = mock(MetadataService.class);
    when(metadataService.getMetadataRepository()).thenReturn(iMetadataDomainRepository);
    metadataServiceUtil = mock(MetadataServiceUtil.class);
    when(metadataServiceUtil.getMetadataRepository()).thenReturn(iMetadataDomainRepository);
    when(metadataServiceUtil.createThinModel(any(LogicalModel.class), anyString())).thenCallRealMethod();
    when(metadataService.getMetadataServiceUtil()).thenReturn(metadataServiceUtil);
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) IMetadataDomainRepository(org.pentaho.metadata.repository.IMetadataDomainRepository) Matchers.anyString(org.mockito.Matchers.anyString) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalModel(org.pentaho.metadata.model.LogicalModel) Domain(org.pentaho.metadata.model.Domain) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 8 with Category

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

the class DatasourceModel method copyOverMetadata.

/**
 * This is a utility method that looks into an old domain for the same column ids, and then copies over the old
 * metadata into the new.
 *
 * @param oldDomain
 * @param newDomain
 */
public void copyOverMetadata(Domain oldDomain, Domain newDomain) {
    Category category = newDomain.getLogicalModels().get(0).getCategories().get(0);
    LogicalModel oldModel = oldDomain.getLogicalModels().get(0);
    for (LogicalColumn column : category.getLogicalColumns()) {
        LogicalColumn oldColumn = oldModel.findLogicalColumn(column.getId());
        if (oldColumn != null) {
            column.setDataType(oldColumn.getDataType());
            column.setName(oldColumn.getName());
            column.setAggregationList(oldColumn.getAggregationList());
            column.setAggregationType(oldColumn.getAggregationType());
        }
    }
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category)

Aggregations

Category (org.pentaho.metadata.model.Category)8 LogicalModel (org.pentaho.metadata.model.LogicalModel)8 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)7 Domain (org.pentaho.metadata.model.Domain)6 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)6 ArrayList (java.util.ArrayList)4 LogicalTable (org.pentaho.metadata.model.LogicalTable)3 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)3 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)3 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)3 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)3 List (java.util.List)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2 AggregationType (org.pentaho.metadata.model.concept.types.AggregationType)2 LocaleType (org.pentaho.metadata.model.concept.types.LocaleType)2 BusinessData (org.pentaho.platform.dataaccess.datasource.beans.BusinessData)2 HashSet (java.util.HashSet)1