use of org.pentaho.agilebi.modeler.models.SchemaModel 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.agilebi.modeler.models.SchemaModel in project data-access by pentaho.
the class SerializeMultiTableServiceIT method getSchema.
private SchemaModel getSchema() {
List<JoinRelationshipModel> joins = new ArrayList<JoinRelationshipModel>();
JoinTableModel joinTable1 = new JoinTableModel();
joinTable1.setName("CUSTOMERS");
JoinTableModel joinTable2 = new JoinTableModel();
joinTable2.setName("PRODUCTS");
JoinRelationshipModel join1 = new JoinRelationshipModel();
JoinFieldModel lField1 = new JoinFieldModel();
lField1.setName("CUSTOMERNAME");
lField1.setParentTable(joinTable1);
join1.setLeftKeyFieldModel(lField1);
JoinFieldModel rField1 = new JoinFieldModel();
rField1.setName("PRODUCTCODE");
rField1.setParentTable(joinTable2);
join1.setRightKeyFieldModel(rField1);
joins.add(join1);
SchemaModel model = new SchemaModel();
model.setJoins(joins);
return model;
}
use of org.pentaho.agilebi.modeler.models.SchemaModel in project data-access by pentaho.
the class JoinMetadataIT method getSchemaModel.
private SchemaModel getSchemaModel() {
List<JoinRelationshipModel> joins = new ArrayList<JoinRelationshipModel>();
JoinTableModel joinTable1 = new JoinTableModel();
joinTable1.setName("CUSTOMERS");
JoinTableModel joinTable2 = new JoinTableModel();
joinTable2.setName("PRODUCTS");
JoinRelationshipModel join1 = new JoinRelationshipModel();
JoinFieldModel lField1 = new JoinFieldModel();
lField1.setName("CUSTOMERNAME");
lField1.setParentTable(joinTable1);
join1.setLeftKeyFieldModel(lField1);
JoinFieldModel rField1 = new JoinFieldModel();
rField1.setName("PRODUCTCODE");
rField1.setParentTable(joinTable2);
join1.setRightKeyFieldModel(rField1);
joins.add(join1);
SchemaModel model = new SchemaModel();
model.setJoins(joins);
return model;
}
use of org.pentaho.agilebi.modeler.models.SchemaModel 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