use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class DataSourceWizardServiceTest method testRemoveDSWError.
@Test
public void testRemoveDSWError() throws Exception {
Domain mockDomain = mock(Domain.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
LogicalModel mockLogicalModel = mock(LogicalModel.class);
String mockObject = "not null";
String dswId = "dswId";
// Test 1
ConnectionServiceException cse = new ConnectionServiceException();
doThrow(cse).when(dataSourceWizardService).ensureDataAccessPermissionCheck();
try {
dataSourceWizardService.removeDSW("dswId");
fail();
} catch (PentahoAccessControlException pace) {
// expected
}
// Test 2
DatasourceServiceException mockDatasourceServiceException = mock(DatasourceServiceException.class);
doNothing().when(dataSourceWizardService).ensureDataAccessPermissionCheck();
doReturn(dswId).when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId);
doReturn(mockDomain).when(dataSourceWizardService.metadataDomainRepository).getDomain(dswId);
doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
doNothing().when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
doThrow(mockDatasourceServiceException).when(dataSourceWizardService.dswService).deleteLogicalModel(null, null);
dataSourceWizardService.removeDSW("dswId");
verify(dataSourceWizardService, times(2)).removeDSW("dswId");
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class MultitableDatasourceService method retrieveSchemas.
public List<String> retrieveSchemas(IDatabaseConnection connection) throws DatasourceServiceException {
List<String> schemas = new ArrayList<String>();
try {
DatabaseMeta databaseMeta = this.getDatabaseMeta(connection);
Database database = new Database(null, databaseMeta);
database.connect();
Map<String, Collection<String>> tableMap = database.getTableMap(null, this.isDataServicesConnection(connection) ? new HashMap<String, String>() {
{
put("STREAMING", "N");
}
} : null);
// database.getSchemas()
Set<String> schemaNames = tableMap.keySet();
schemas.addAll(schemaNames);
database.disconnect();
} catch (KettleDatabaseException e) {
logger.error("Error creating database object", e);
throw new DatasourceServiceException(e);
} catch (ConnectionServiceException e) {
logger.error("Error getting database meta", e);
throw new DatasourceServiceException(e);
}
return schemas;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class MultitableDatasourceService method deSerializeModelState.
public MultiTableDatasourceDTO deSerializeModelState(String dtoStr) throws DatasourceServiceException {
try {
XStream xs = new XStream();
xs.registerConverter(new LegacyDatasourceConverter());
return (MultiTableDatasourceDTO) xs.fromXML(dtoStr);
} catch (Exception e) {
logger.error(e);
throw new DatasourceServiceException(e);
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class MultitableDatasourceService method serializeJoins.
public IDatasourceSummary serializeJoins(MultiTableDatasourceDTO dto, IDatabaseConnection connection) throws DatasourceServiceException {
try {
ModelerService modelerService = new ModelerService();
modelerService.initKettle();
DSWDatasourceServiceImpl datasourceService = new DSWDatasourceServiceImpl();
GeoContext geoContext = datasourceService.getGeoContext();
DatabaseMeta databaseMeta = this.getDatabaseMeta(connection);
MultiTableModelerSource multiTable = new MultiTableModelerSource(databaseMeta, dto.getSchemaModel(), dto.getDatasourceName(), dto.getSelectedTables(), geoContext);
Domain domain = multiTable.generateDomain(dto.isDoOlap());
String modelState = serializeModelState(dto);
for (LogicalModel lm : domain.getLogicalModels()) {
lm.setProperty("datasourceModel", modelState);
lm.setProperty("DatasourceType", "MULTI-TABLE-DS");
// BISERVER-6450 - add security settings to the logical model
applySecurity(lm);
}
modelerService.serializeModels(domain, dto.getDatasourceName(), dto.isDoOlap());
QueryDatasourceSummary summary = new QueryDatasourceSummary();
summary.setDomain(domain);
return summary;
} catch (Exception e) {
logger.error("Error serializing joins", e);
throw new DatasourceServiceException(e);
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException in project data-access by pentaho.
the class DatasourceInMemoryServiceHelper method getSerializeableResultSet.
public static SerializedResultSet getSerializeableResultSet(String connectionName, String query, int rowLimit, IPentahoSession session) throws DatasourceServiceException {
SerializedResultSet serializedResultSet = null;
SQLConnection sqlConnection = null;
try {
sqlConnection = getConnection(connectionName);
sqlConnection.setMaxRows(rowLimit);
sqlConnection.setReadOnly(true);
IPentahoResultSet resultSet = sqlConnection.executeQuery(query);
MarshallableResultSet marshallableResultSet = new MarshallableResultSet();
marshallableResultSet.setResultSet(resultSet);
IPentahoMetaData ipmd = resultSet.getMetaData();
if (ipmd instanceof SQLMetaData) {
// Hack warning - get JDBC column types
// TODO: Need to generalize this amongst all IPentahoResultSets
SQLMetaData smd = (SQLMetaData) ipmd;
int[] columnTypes = smd.getJDBCColumnTypes();
List<List<String>> data = new ArrayList<List<String>>();
for (MarshallableRow row : marshallableResultSet.getRows()) {
String[] rowData = row.getCell();
List<String> rowDataList = new ArrayList<String>(rowData.length);
for (int j = 0; j < rowData.length; j++) {
rowDataList.add(rowData[j]);
}
data.add(rowDataList);
}
serializedResultSet = new SerializedResultSet(columnTypes, marshallableResultSet.getColumnNames().getColumnName(), data);
}
} catch (Exception e) {
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} finally {
if (sqlConnection != null) {
sqlConnection.close();
}
}
return serializedResultSet;
}
Aggregations