use of org.pentaho.metadata.model.concept.types.LocalizedString 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.concept.types.LocalizedString 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.concept.types.LocalizedString in project data-access by pentaho.
the class MetadataServiceUtil method createCdaJson.
/**
* Returns a CDA JSON representation of a query result set
*
* @param resultSet
* @return
* @throws JSONException
*/
public String createCdaJson(final IPentahoResultSet resultSet, String locale) throws JSONException {
if (resultSet == null) {
return null;
}
JSONObject json = new JSONObject();
// Generate the metadata
final JSONArray metadataArray = new JSONArray();
final int columnCount = resultSet.getColumnCount();
final int rowCount = resultSet.getRowCount();
for (int i = 0; i < columnCount; i++) {
JSONObject info = new JSONObject();
// $NON-NLS-1$
info.put("colIndex", i);
// $NON-NLS-1$
info.put("colName", resultSet.getMetaData().getColumnHeaders()[0][i]);
DataType type = (DataType) resultSet.getMetaData().getAttribute(0, i, IPhysicalColumn.DATATYPE_PROPERTY);
// $NON-NLS-1$
info.put("colType", type.getName().toUpperCase());
LocalizedString name = (LocalizedString) resultSet.getMetaData().getAttribute(0, i, Concept.NAME_PROPERTY);
if (name != null && locale != null) {
// $NON-NLS-1$
info.put("colLabel", name.getString(locale));
}
metadataArray.put(info);
}
// $NON-NLS-1$
json.put("metadata", metadataArray);
// add the rows of data
final JSONArray valuesArray = new JSONArray();
for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
final JSONArray rowArray = new JSONArray();
valuesArray.put(rowArray);
for (int colIdx = 0; colIdx < columnCount; colIdx++) {
rowArray.put(resultSet.getValueAt(rowIdx, colIdx));
}
}
// $NON-NLS-1$
json.put("resultset", valuesArray);
return json.toString();
}
use of org.pentaho.metadata.model.concept.types.LocalizedString in project data-access by pentaho.
the class MetadataServiceTest method getMarshallableResultSet.
private MarshallableResultSet getMarshallableResultSet() {
// Build the IPentahoResultSet
Object[][] result = new Object[1][COLUMNS];
result[0][0] = COLUMN_NAME;
Object[] values = new Object[1];
values[0] = RESULT;
LocalizedString localizedString = mock(LocalizedString.class);
when(localizedString.getString(anyString())).thenReturn(COLUMN_NAME);
IPentahoMetaData iPentahoMetaData = mock(IPentahoMetaData.class);
when(iPentahoMetaData.getColumnHeaders()).thenReturn(result);
when(iPentahoMetaData.getAttribute(anyInt(), anyInt(), eq(IPhysicalColumn.DATATYPE_PROPERTY))).thenReturn(DataType.STRING);
when(iPentahoMetaData.getAttribute(anyInt(), anyInt(), eq(Concept.NAME_PROPERTY))).thenReturn(localizedString);
IPentahoResultSet iPentahoResultSet = mock(IPentahoResultSet.class);
when(iPentahoResultSet.getRowCount()).thenReturn(ROWS);
when(iPentahoResultSet.getColumnCount()).thenReturn(COLUMNS);
when(iPentahoResultSet.getMetaData()).thenReturn(iPentahoMetaData);
when(iPentahoResultSet.next()).thenReturn(values).thenReturn(null);
when(metadataService.executeQuery(anyString(), any(Integer.class))).thenReturn(iPentahoResultSet);
// Build the MarshallableResultSet
MarshallableResultSet marshallableResultSet = mock(MarshallableResultSet.class);
doCallRealMethod().when(marshallableResultSet).setResultSet(any(IPentahoResultSet.class));
when(marshallableResultSet.getRows()).thenCallRealMethod();
when(marshallableResultSet.getColumnNames()).thenCallRealMethod();
return marshallableResultSet;
}
use of org.pentaho.metadata.model.concept.types.LocalizedString 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;
}
Aggregations