use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException 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.ConnectionServiceException 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.ConnectionServiceException in project data-access by pentaho.
the class DatasourceInMemoryServiceHelper method getConnection.
public static SQLConnection getConnection(String connectionName) throws DatasourceServiceException {
IDatabaseConnection connection = null;
try {
ConnectionServiceImpl service = new ConnectionServiceImpl();
connection = service.getConnectionByName(connectionName);
DatabaseDialectService dialectService = new DatabaseDialectService();
IDatabaseDialect dialect = dialectService.getDialect(connection);
String driverClass = null;
if (connection.getDatabaseType().getShortName().equals("GENERIC")) {
driverClass = connection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS);
} else {
driverClass = dialect.getNativeDriver();
}
return new SQLConnection(driverClass, dialect.getURLWithExtraOptions(connection), connection.getUsername(), connection.getPassword(), null);
} catch (ConnectionServiceException e1) {
return null;
} catch (DatabaseDialectException e) {
return null;
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.
the class DataSourceWizardService method removeDSW.
public void removeDSW(String dswId) throws PentahoAccessControlException {
try {
ensureDataAccessPermissionCheck();
} catch (ConnectionServiceException e) {
throw new PentahoAccessControlException();
}
Domain domain = metadataDomainRepository.getDomain(dswId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
try {
mondrianCatalogService.removeCatalog(catalogRef, getSession());
} catch (MondrianCatalogServiceException e) {
logger.warn("Failed to remove mondrian catalog", e);
}
}
try {
dswService.deleteLogicalModel(domain.getId(), logicalModel.getId());
} catch (DatasourceServiceException ex) {
logger.warn("Failed to remove logical model", ex);
}
metadataDomainRepository.removeDomain(dswId);
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException in project data-access by pentaho.
the class JDBCDatasourceResource method getConnectionIDs.
/**
* Get a list of JDBC datasource IDs.
*
* <p><b>Example Request:</b><br />
* GET pentaho/plugin/data-access/api/datasource/jdbc/connection
* </p>
*
* @return A list of JDBC datasource IDs.
*
* <p><b>Example Response:</b></p>
* <pre function="syntax.xml">
* {
* "Item": [
* {
* "@type": "xs:string",
* "$": "AgileBI"
* },
* {
* "@type": "xs:string",
* "$": "Audit"
* },
* {
* "@type": "xs:string",
* "$": "SampleData"
* },
* {
* "@type": "xs:string",
* "$": "TestDataSourceResource"
* },
* {
* "@type": "xs:string",
* "$": "baseball connection"
* },
* {
* "@type": "xs:string",
* "$": "baseball connection"
* },
* {
* "@type": "xs:string",
* "$": "live_logging_info"
* },
* {
* "@type": "xs:string",
* "$": "pentaho_operations_mart"
* }
* ]
* }
* </pre>
*/
@GET
@Path("/")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully retrieved the list of JDBC datasource IDs"), @ResponseCode(code = 500, condition = "Internal error retrieving JDBC datasource IDs") })
public JaxbList<String> getConnectionIDs() {
List<String> connStrList = new ArrayList<String>();
try {
List<IDatabaseConnection> conns = service.getConnections();
for (IDatabaseConnection conn : conns) {
conn.setPassword(null);
connStrList.add(conn.getName());
}
} catch (ConnectionServiceException e) {
logger.error("Error " + e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
JaxbList<String> connections = new JaxbList<String>(connStrList);
return connections;
}
Aggregations