use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.
the class LegacyDatasourceConverter method unmarshal.
/**
* Convert textual data back into an object.
*
* @param reader The stream to read the text from.
* @param context
* @return The resulting object.
*/
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
MultiTableDatasourceDTO resultDTO = new MultiTableDatasourceDTO();
while (reader.hasMoreChildren()) {
reader.moveDown();
String nodeName = reader.getNodeName();
if (nodeName.equalsIgnoreCase("datasourceName")) {
String value = reader.getValue();
resultDTO.setDatasourceName(value);
} else if (nodeName.equalsIgnoreCase("selectedConnection")) {
String connectionClass = reader.getAttribute("class");
if (connectionClass != null) {
DatabaseConnection databaseConnection = new DatabaseConnection();
if (connectionClass.equals("org.pentaho.platform.dataaccess.datasource.beans.Connection")) {
while (reader.hasMoreChildren()) {
reader.moveDown();
nodeName = reader.getNodeName();
if (reader.getNodeName().equalsIgnoreCase("name")) {
String databaseName = reader.getValue();
databaseConnection.setName(databaseName);
databaseConnection.setId(databaseName);
} else if (reader.getNodeName().equalsIgnoreCase("username")) {
databaseConnection.setUsername(reader.getValue());
} else if (reader.getNodeName().equalsIgnoreCase("password")) {
databaseConnection.setPassword(reader.getValue());
} else if (reader.getNodeName().equalsIgnoreCase("url")) {
ParsedJdbcUrl parsedJdbcUrl = new ParsedJdbcUrl(reader.getValue());
databaseConnection.setHostname(parsedJdbcUrl.getHostname());
databaseConnection.setDatabasePort(parsedJdbcUrl.getPort());
databaseConnection.setDatabaseName(parsedJdbcUrl.getDatabaseName());
databaseConnection.setDatabaseType(resolveDatabaseType(parsedJdbcUrl.getJdbcPrefix()));
}
reader.moveUp();
}
resultDTO.setSelectedConnection(databaseConnection);
} else {
// instantiate the class specified
try {
Class databaseConnectionClass = Class.forName(connectionClass);
IDatabaseConnection databaseConnectionInstance = (IDatabaseConnection) context.convertAnother(resultDTO, databaseConnectionClass);
resultDTO.setSelectedConnection(databaseConnectionInstance);
} catch (ClassNotFoundException e) {
// not going to work anyway, set empty connection for now
resultDTO.setSelectedConnection(new DatabaseConnection());
}
}
}
} else if (nodeName.equalsIgnoreCase("schemaModel")) {
SchemaModel schemaModel = (SchemaModel) context.convertAnother(resultDTO, SchemaModel.class);
if (schemaModel != null) {
resultDTO.setSchemaModel(schemaModel);
}
} else if (nodeName.equalsIgnoreCase("selectedTables")) {
List<String> selectedTables = (List<String>) context.convertAnother(resultDTO, ArrayList.class);
if (selectedTables != null) {
resultDTO.setSelectedTables(selectedTables);
}
} else if (nodeName.equalsIgnoreCase("doOlap")) {
resultDTO.setDoOlap(Boolean.valueOf(reader.getValue()));
}
reader.moveUp();
}
return resultDTO;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.
the class MultiTableDatasource method onFinish.
@Override
public void onFinish(final XulServiceCallback<IDatasourceSummary> callback) {
if (this.validator.allTablesJoined()) {
String dsName = this.wizardModel.getDatasourceName();
MultiTableDatasourceDTO dto = this.joinGuiModel.createMultiTableDatasourceDTO(dsName);
dto.setSelectedConnection(this.connection);
joinSelectionServiceGwtImpl.serializeJoins(dto, this.connection, new XulServiceCallback<IDatasourceSummary>() {
public void success(IDatasourceSummary retVal) {
callback.success(retVal);
}
public void error(String message, Throwable error) {
MessageHandler.getInstance().closeWaitingDialog();
MessageHandler.getInstance().showErrorDetailsDialog(MessageHandler.getString("ERROR"), MessageHandler.getString("multitable.ERROR_SAVING_MODEL"), error.getLocalizedMessage());
}
});
} else {
MessageHandler.getInstance().closeWaitingDialog();
XulDialog wizardDialog = (XulDialog) document.getElementById("main_wizard_window");
wizardDialog.show();
this.displayErrors(this.validator.getError());
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.
the class LegacyDatasourceConverterTest method testStreamConverter.
@Test
public void testStreamConverter() throws Exception {
sampleDTOFile = new File(SAMPLE_FILE_PATH);
inputStream = new FileInputStream(sampleDTOFile);
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, DEFAULT_ENCODING);
dtoStr = writer.toString();
try {
if (inputStream != null)
inputStream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
XStream xs = new XStream();
xs.registerConverter(new LegacyDatasourceConverter());
MultiTableDatasourceDTO resultDTO = (MultiTableDatasourceDTO) xs.fromXML(dtoStr);
System.out.println(resultDTO.toString());
}
use of org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO in project data-access by pentaho.
the class MultitableGuiModel method createMultiTableDatasourceDTO.
public MultiTableDatasourceDTO createMultiTableDatasourceDTO(String dsName) {
MultiTableDatasourceDTO dto = new MultiTableDatasourceDTO();
dto.setDoOlap(this.doOlap);
dto.setDatasourceName(dsName);
List<String> selectedTables = new ArrayList<String>();
for (JoinTableModel tbl : this.selectedTables) {
selectedTables.add(tbl.getName());
}
dto.setSelectedTables(selectedTables);
SchemaModel schema = new SchemaModel();
schema.setJoins(this.getJoins());
schema.setFactTable(this.factTable);
dto.setSchemaModel(schema);
return dto;
}
Aggregations