use of org.pentaho.metadata.model.LogicalTable 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.LogicalTable in project data-access by pentaho.
the class MultitableGuiModel method generateLogicalRelationships.
@Deprecated
public List<LogicalRelationship> generateLogicalRelationships(List<JoinRelationshipModel> joins) {
String locale = LocalizedString.DEFAULT_LOCALE;
List<LogicalRelationship> logicalRelationships = new ArrayList<LogicalRelationship>();
for (JoinRelationshipModel join : joins) {
LogicalTable fromTable = new LogicalTable();
fromTable.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getParentTable().getName()));
LogicalTable toTable = new LogicalTable();
toTable.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getParentTable().getName()));
LogicalColumn fromColumn = new LogicalColumn();
fromColumn.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getName()));
LogicalColumn toColumn = new LogicalColumn();
toColumn.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getName()));
LogicalRelationship logicalRelationship = new LogicalRelationship();
logicalRelationship.setFromTable(fromTable);
logicalRelationship.setToTable(toTable);
logicalRelationship.setFromColumn(fromColumn);
logicalRelationship.setToColumn(toColumn);
logicalRelationships.add(logicalRelationship);
}
return logicalRelationships;
}
use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class StarModelerPerspective method deleteSharedDimension.
/**
* Delete a shared dimension in the domain
*
* @param domain the domain to delete the dimension from
* @param modelName the name of the dimension to delete
*/
private boolean deleteSharedDimension(Shell shell, StarDomain starDomain, String locale, String modelName) {
LogicalTable logicalTable = findSharedDimension(starDomain, locale, modelName);
if (logicalTable != null) {
// TODO: show warning dialog.
//
starDomain.getSharedDimensions().remove(logicalTable);
starDomain.setChanged(true);
return true;
}
return false;
}
use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class StarModelerPerspective method refreshDimensionsList.
protected void refreshDimensionsList(StarDomain starDomain, TableView dimensionsList) {
dimensionsList.clearAll();
for (LogicalTable table : starDomain.getSharedDimensions()) {
TableItem item = new TableItem(dimensionsList.table, SWT.NONE);
item.setText(1, Const.NVL(table.getName(defaultLocale), ""));
item.setText(2, Const.NVL(table.getDescription(defaultLocale), ""));
}
dimensionsList.removeEmptyRows();
dimensionsList.setRowNums();
dimensionsList.optWidth(true);
}
use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.
the class StarModelerPerspective method newSharedDimension.
/**
* Create a new shared dimension in the domain
*
* @param domain the domain to create the new model in
*/
private boolean newSharedDimension(Shell shell, StarDomain starDomain) {
LogicalTable dimensionTable = new LogicalTable();
dimensionTable.setName(new LocalizedString(defaultLocale, "Shared dimension"));
DimensionTableDialog dialog = new DimensionTableDialog(shell, dimensionTable, defaultLocale);
if (dialog.open() != null) {
starDomain.getSharedDimensions().add(dimensionTable);
starDomain.setChanged(true);
return true;
}
return false;
}
Aggregations