use of org.pentaho.metadata.model.concept.types.LocaleType 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.LocaleType 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.LocaleType in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
SqlDataSource dataSource = new SqlDataSource();
dataSource.setDatabaseName(CONNECTION_NAME);
SqlPhysicalTable sqlTable = new SqlPhysicalTable();
sqlTable.setTargetTable(VALID_QUERY);
SqlPhysicalModel sqlModel = new SqlPhysicalModel();
sqlModel.addPhysicalTable(sqlTable);
sqlModel.setDatasource(dataSource);
analysisModel = new LogicalModel();
analysisModel.setId(LOGICAL_MODEL_ID_ANALYSIS);
analysisModel.setProperty(DSWDatasourceServiceImpl.LM_PROP_VISIBLE, LOGICAL_MODEL_CONTEXTNAME);
reportingModel = new LogicalModel();
reportingModel.setId(LOGICAL_MODEL_ID_REPORTING);
domain2Models = new Domain();
domain2Models.setId(DOMAIN_ID_2MODELS);
domain2Models.addLogicalModel(analysisModel);
domain2Models.addLogicalModel(reportingModel);
domain2Models.setLocales(Arrays.asList(new LocaleType("en_US", "Test locale")));
domain2Models.addPhysicalModel(sqlModel);
Set<String> domains = new TreeSet<String>();
domains.add(DOMAIN_ID_2MODELS);
doReturn(domain2Models).when(domainRepository).getDomain(DOMAIN_ID_2MODELS);
doReturn(domains).when(domainRepository).getDomainIds();
doAnswer(new Answer<Object>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
final String modelId = (String) invocation.getArguments()[1];
final LogicalModel modelToRemove = domain2Models.findLogicalModel(modelId);
domain2Models.getLogicalModels().remove(modelToRemove);
return null;
}
}).when(domainRepository).removeModel(anyString(), anyString());
workspace2Models = mock(ModelerWorkspace.class);
when(workspace2Models.getLogicalModel(ModelerPerspective.ANALYSIS)).thenReturn(analysisModel);
when(workspace2Models.getLogicalModel(ModelerPerspective.REPORTING)).thenReturn(reportingModel);
dswService = spy(new DSWDatasourceServiceImpl(mock(ConnectionServiceImpl.class)));
doNothing().when(dswService).checkSqlQueriesSupported(anyString());
dswService.setMetadataDomainRepository(domainRepository);
Object[][] coumnHeaders = new Object[][] { columns };
SQLMetaData metadata = mock(SQLMetaData.class);
when(metadata.getColumnHeaders()).thenReturn(coumnHeaders);
when(metadata.getJDBCColumnTypes()).thenReturn(columnTypes);
IPentahoResultSet resultSet = mock(IPentahoResultSet.class);
when(resultSet.getMetaData()).thenReturn(metadata);
doReturn(resultSet).when(sqlConnection).executeQuery(matches("(.*" + VALID_QUERY + ".*)"));
when(sqlConnection.executeQuery(matches("(.*" + QUERY_COLUMN_ALREADY_EXIST + ".*)"))).thenThrow(new SQLException("Reason", "S0021", 21));
doReturn(nativeConnection).when(sqlConnection).getNativeConnection();
MondrianCatalog catalog = mock(MondrianCatalog.class);
doReturn(catalog).when(mondrianService).getCatalog(anyString(), any(IPentahoSession.class));
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(IMondrianCatalogService.class)) {
return mondrianService;
}
if (invocation.getArguments()[0].equals(IPentahoConnection.class)) {
return sqlConnection;
}
if (invocation.getArguments()[0].equals(IMetadataDomainRepository.class)) {
return domainRepository;
}
return null;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
IPentahoSession pentahoSessionMock = mock(IPentahoSession.class);
when(pentahoSessionMock.getName()).thenReturn("sessionName");
PentahoSessionHolder.setSession(pentahoSessionMock);
}
use of org.pentaho.metadata.model.concept.types.LocaleType in project pentaho-platform by pentaho.
the class SolutionFolderIT method testMultiLocaleFileDiscovery.
/**
* Tests MetadataDomainRepository.getLocalePropertyFilenames() when one xmi file and several property file exists in
* the metadata folder.
* Update: Get locales with use Domain.getLocaleCodes()
*/
@Test
public void testMultiLocaleFileDiscovery() {
try {
Domain steelWheels = loadDomain(STEEL_WHEELS, "./" + LEGACY_XMI_FILENAME);
// get count of current locales
final int previousLocaleSize = steelWheels.getLocaleCodes().length;
// add new locales
steelWheels.addLocale(new LocaleType("EN_US", LEGACY_XMI_FILENAME.substring(0, LEGACY_XMI_FILENAME.indexOf('.'))));
steelWheels.addLocale(new LocaleType("EN_GB", LEGACY_XMI_FILENAME.substring(0, LEGACY_XMI_FILENAME.indexOf('.'))));
steelWheels.addLocale(new LocaleType("NO_BOK", LEGACY_XMI_FILENAME.substring(0, LEGACY_XMI_FILENAME.indexOf('.'))));
// get the list of codes to import
String[] localizationFiles = steelWheels.getLocaleCodes();
// test the localization filenames for correctness
ArrayList<String> solutionFileNames = new ArrayList<String>();
for (String solutionFile : localizationFiles) {
solutionFileNames.add(solutionFile);
}
assertNotNull(localizationFiles);
assertEquals(previousLocaleSize + 3, localizationFiles.length);
assertTrue(solutionFileNames.contains("EN_US"));
assertTrue(solutionFileNames.contains("EN_GB"));
assertTrue(solutionFileNames.contains("NO_BOK"));
} catch (IOException ioe) {
fail(ioe.getMessage());
} catch (DomainStorageException dse) {
fail(dse.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.pentaho.metadata.model.concept.types.LocaleType in project pentaho-platform by pentaho.
the class SolutionFolderIT method testOneLocaleFileDiscovery.
/**
* Tests MetadataDomainRepository.getLocalePropertyFilenames() when one xmi resource is in the meta data folder with
* one property file.
* Update: Test Domain.getLocaleCodes() when we added the new locale on existing domain.
*/
@Test
public void testOneLocaleFileDiscovery() {
try {
final Domain steelWheels = loadDomain(STEEL_WHEELS, "./" + LEGACY_XMI_FILENAME);
// get a list of locale codes
final int initialLocaleSize = steelWheels.getLocaleCodes().length;
// add new locale
steelWheels.addLocale(new LocaleType("en_US", "Test locale"));
int localizationNewSize = steelWheels.getLocaleCodes().length;
// we expect a the size of previous list + 1
assertNotNull(localizationNewSize);
assertEquals(localizationNewSize, initialLocaleSize + 1);
} catch (IOException ioe) {
fail(ioe.getMessage());
} catch (DomainStorageException dse) {
fail(dse.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations