use of org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary 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.sources.query.QueryDatasourceSummary in project data-access by pentaho.
the class InMemoryDSWDatasourceServiceImpl method generateQueryDomain.
@Override
public QueryDatasourceSummary generateQueryDomain(String name, String query, DatabaseConnection connection, DatasourceDTO datasourceDTO) throws DatasourceServiceException {
ModelerWorkspace modelerWorkspace = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), getGeoContext());
ModelerService modelerService = new ModelerService();
modelerWorkspace.setModelName(name);
try {
Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
SerializedResultSet resultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(connection.getName(), query, Integer.parseInt("10"), null);
SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getPermittedRoleList(), getPermittedUserList(), getDefaultAcls(), "joe");
Domain domain = sqlModelGenerator.generate();
modelerWorkspace.setDomain(domain);
modelerWorkspace.getWorkspaceHelper().autoModelFlat(modelerWorkspace);
modelerWorkspace.setModelName(datasourceDTO.getDatasourceName());
modelerWorkspace.getWorkspaceHelper().populateDomain(modelerWorkspace);
domain.getLogicalModels().get(0).setProperty("datasourceModel", serializeModelState(datasourceDTO));
domain.getLogicalModels().get(0).setProperty("DatasourceType", "SQL-DS");
QueryDatasourceSummary summary = new QueryDatasourceSummary();
modelerService.serializeModels(domain, modelerWorkspace.getModelName());
summary.setDomain(domain);
return summary;
} catch (SQLModelGeneratorException smge) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
smge);
} catch (QueryValidationException e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (ModelerException e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
e);
} catch (Exception e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
e);
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary in project data-access by pentaho.
the class DSWDatasourceServiceImplTest method testGenerateQueryDomain.
private void testGenerateQueryDomain(String modelName, String query, List<String> roleList, List<String> userList) throws DatasourceServiceException {
ModelInfo modelInfo = mock(ModelInfo.class);
when(modelInfo.getFileInfo()).thenReturn(mock(CsvFileInfo.class));
DatasourceDTO datasourceDTO = new DatasourceDTO();
datasourceDTO.setConnectionName(CONNECTION_NAME);
datasourceDTO.setDatasourceName(CONNECTION_NAME);
datasourceDTO.setCsvModelInfo(modelInfo);
DatabaseConnection connectionSpy = spy(new DatabaseConnection());
connectionSpy.setName(CONNECTION_NAME);
connectionSpy.setDatabaseName("[database name 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setDatabasePort("123456");
connectionSpy.setHostname("[hostname 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setPassword("[password 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setUsername("[username 接続 <;>!@#$%^&*()_-=+.,]");
connectionSpy.setDatabaseType(mock(IDatabaseType.class));
doReturn(modelerService).when(dswService).createModelerService();
doReturn(true).when(dswService).hasDataAccessPermission();
doReturn(roleList).when(dswService).getPermittedRoleList();
doReturn(userList).when(dswService).getPermittedUserList();
doReturn(null).when(dswService).getGeoContext();
doReturn(1).when(dswService).getDefaultAcls();
QueryDatasourceSummary summary = dswService.generateQueryDomain(modelName, query, connectionSpy, datasourceDTO);
try {
verify(dswService).executeQuery("[connection 接続 <;>!@#$%^&*()_-=+.,]", query, "1");
} catch (Exception e) {
e.printStackTrace();
}
verify(connectionSpy).setName("[connection 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy).setDatabaseName("[database name 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy, times(2)).setDatabasePort("123456");
verify(connectionSpy).setHostname("[hostname 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy).setPassword("[password 接続 <;>!@#$%^&*()_-=+.,]");
verify(connectionSpy).setUsername("[username 接続 <;>!@#$%^&*()_-=+.,]");
assertNotNull(summary);
assertNotNull(summary.getDomain());
assertEquals(CONNECTION_NAME, summary.getDomain().getId());
}
use of org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary in project data-access by pentaho.
the class DSWDatasourceServiceImpl method generateQueryDomain.
@Override
public QueryDatasourceSummary generateQueryDomain(String name, String query, DatabaseConnection connection, DatasourceDTO datasourceDTO) throws DatasourceServiceException {
ModelerWorkspace modelerWorkspace = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), getGeoContext());
ModelerService modelerService = createModelerService();
modelerWorkspace.setModelName(name);
try {
UtilHtmlSanitizer.getInstance().sanitizeConnectionParameters(connection);
executeQuery(UtilHtmlSanitizer.getInstance().safeEscapeHtml(datasourceDTO.getConnectionName()), query, "1");
Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
SerializedResultSet resultSet = DatasourceServiceHelper.getSerializeableResultSet(connection.getName(), query, 10, PentahoSessionHolder.getSession());
SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getEffectivePermittedUserList(securityEnabled), getPermittedRoleList(), getDefaultAcls(), (PentahoSessionHolder.getSession() != null) ? PentahoSessionHolder.getSession().getName() : null);
Domain domain = sqlModelGenerator.generate();
domain.getPhysicalModels().get(0).setId(connection.getName());
modelerWorkspace.setDomain(domain);
modelerWorkspace.getWorkspaceHelper().autoModelFlat(modelerWorkspace);
modelerWorkspace.getWorkspaceHelper().autoModelRelationalFlat(modelerWorkspace);
modelerWorkspace.setModelName(datasourceDTO.getDatasourceName());
modelerWorkspace.getWorkspaceHelper().populateDomain(modelerWorkspace);
domain.getLogicalModels().get(0).setProperty("datasourceModel", serializeModelState(datasourceDTO));
domain.getLogicalModels().get(0).setProperty("DatasourceType", "SQL-DS");
QueryDatasourceSummary summary = new QueryDatasourceSummary();
prepareForSerializaton(domain);
modelerService.serializeModels(domain, modelerWorkspace.getModelName());
summary.setDomain(domain);
return summary;
} catch (SQLModelGeneratorException smge) {
logger.error(// $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), // $NON-NLS-1$
smge);
} catch (QueryValidationException e) {
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (ModelerException e) {
logger.error(// $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (SqlQueriesNotSupportedException e) {
// $NON-NLS-1$
throw new DatasourceServiceException(e.getLocalizedMessage(), e);
} catch (Exception e) {
logger.error(// $NON-NLS-1$
Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0011_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), // $NON-NLS-1$
e);
}
}
Aggregations