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());
}
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);
}
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());
}
}
}
Aggregations