use of org.pentaho.metadata.model.LogicalModel in project pentaho-kettle by pentaho.
the class ModelMetaStoreUtil method buildLogicalModel.
/**
* Inflate a logical model from a metastore element.
*
* @param metaStore The metastore to read from
* @param element The element to read from
* @return The Logical Model
* @throws MetaStoreException in case something goes wrong
*/
public static LogicalModel buildLogicalModel(IMetaStore metaStore, IMetaStoreElement element) throws MetaStoreException {
try {
LogicalModel model = new LogicalModel();
model.setName(new LocalizedString(defaultLocale, element.getName()));
model.setDescription(new LocalizedString(defaultLocale, getChildString(element, Attribute.ID_MODEL_DESCRIPTION.id)));
return model;
} catch (Exception e) {
throw new MetaStoreException("Unable to inflate logical model from metastore element", e);
}
}
use of org.pentaho.metadata.model.LogicalModel in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepositoryTest method testGetDomain.
public void testGetDomain() throws Exception {
try {
domainRepositorySpy.getDomain(null);
fail("Null domainID should throw exception");
} catch (Exception success) {
// ignored
}
try {
domainRepositorySpy.getDomain("");
fail("Empty domainID should throw exception");
} catch (Exception success) {
// ignored
}
doReturn(false).when(aclNodeHelper).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
assertNull(domainRepositorySpy.getDomain("doesn't exist"));
doNothing().when(aclNodeHelper).removeAclFor(any(RepositoryFile.class));
domainRepositorySpy.removeDomain("steel-wheels_test");
domainRepositorySpy.removeDomain(STEEL_WHEELS);
domainRepositorySpy.removeDomain(SAMPLE_DOMAIN_ID);
doReturn(true).when(aclNodeHelper).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
final MockDomain originalDomain = new MockDomain(SAMPLE_DOMAIN_ID);
domainRepositorySpy.storeDomain(originalDomain, false);
final Domain testDomain1 = domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID);
assertNotNull(testDomain1);
assertEquals(SAMPLE_DOMAIN_ID, testDomain1.getId());
originalDomain.addLogicalModel("MODEL 1");
originalDomain.addLogicalModel("MODEL 2");
domainRepositorySpy.storeDomain(originalDomain, true);
final Domain testDomain2 = domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID);
assertNotNull(testDomain2);
final List<LogicalModel> logicalModels = testDomain2.getLogicalModels();
assertEquals(2, logicalModels.size());
assertTrue("MODEL 1".equals(logicalModels.get(0).getId()) || "MODEL 1".equals(logicalModels.get(1).getId()));
assertTrue("MODEL 2".equals(logicalModels.get(0).getId()) || "MODEL 2".equals(logicalModels.get(1).getId()));
}
use of org.pentaho.metadata.model.LogicalModel 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;
}
use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.
the class DatasourceModelTest method contructRelationalModel.
private GuiStateModel contructRelationalModel(GuiStateModel guiStateModel) {
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();
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.setLocaleCode("en");
guiStateModel.setLogicalModels(domain.getLogicalModels());
guiStateModel.validateRelational();
return guiStateModel;
}
use of org.pentaho.metadata.model.LogicalModel 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());
}
Aggregations