use of org.pentaho.metadata.model.LogicalColumn 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.LogicalColumn in project data-access by pentaho.
the class MetadataServiceUtil method createColumn.
/**
* Creates a lightweight, serializable Column object from a logical model column
*
* @param m
* @param c
* @return
*/
private Column createColumn(LogicalModel m, LogicalColumn c, org.pentaho.metadata.model.Category category) {
Column col = new Column();
col.setName(c.getName(getLocale()));
col.setId(c.getId());
if (c.getFieldType() != null) {
col.setFieldType(c.getFieldType().name());
} else {
// $NON-NLS-1$
col.setFieldType("UNKNOWN");
}
col.setType(c.getDataType().getName().toUpperCase());
col.setCategory(category.getId());
// set the aggregation fields for the column
List<AggregationType> possibleAggs = c.getAggregationList();
List<String> aggTypes = new ArrayList<String>();
if (possibleAggs != null) {
for (AggregationType agg : possibleAggs) {
aggTypes.add(agg.name());
}
}
// There might be a default agg, but no agg list. If so, add it to the list.
AggregationType defaultAggType = AggregationType.NONE;
if (c.getAggregationType() != null) {
defaultAggType = c.getAggregationType();
}
if (!aggTypes.contains(defaultAggType)) {
aggTypes.add(defaultAggType.name());
}
col.setAggTypes(aggTypes);
col.setDefaultAggType(defaultAggType.name());
col.setSelectedAggType(defaultAggType.name());
// set the alignment
DataType dataType = c.getDataType();
FieldType fieldType = c.getFieldType();
// $NON-NLS-1$
Object obj = c.getProperty("alignment");
if (obj instanceof Alignment) {
if (obj == Alignment.LEFT) {
col.setHorizontalAlignment(Alignment.LEFT.toString());
} else if (obj == Alignment.RIGHT) {
col.setHorizontalAlignment(Alignment.RIGHT.toString());
} else if (obj == Alignment.CENTERED) {
col.setHorizontalAlignment(Alignment.CENTERED.toString());
}
} else if (fieldType == FieldType.FACT) {
col.setHorizontalAlignment(Alignment.RIGHT.toString());
} else if (fieldType == FieldType.OTHER && dataType == DataType.NUMERIC) {
col.setHorizontalAlignment(Alignment.RIGHT.toString());
} else {
col.setHorizontalAlignment(Alignment.LEFT.toString());
}
// set the format mask
// $NON-NLS-1$
obj = c.getProperty("mask");
if (obj != null) {
col.setFormatMask((String) obj);
}
return col;
}
use of org.pentaho.metadata.model.LogicalColumn 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.LogicalColumn 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.LogicalColumn 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