use of mondrian.xmla.impl.DefaultXmlaResponse in project mondrian by pentaho.
the class XmlaTest method executeRequest.
private Element executeRequest(Element requestElem) {
ByteArrayOutputStream resBuf = new ByteArrayOutputStream();
XmlaRequest request = new DefaultXmlaRequest(requestElem, null, null, null, null);
XmlaResponse response = new DefaultXmlaResponse(resBuf, "UTF-8", Enumeration.ResponseMimeType.SOAP);
handler.process(request, response);
return XmlaUtil.stream2Element(new ByteArrayInputStream(resBuf.toByteArray()));
}
use of mondrian.xmla.impl.DefaultXmlaResponse in project mondrian by pentaho.
the class XmlaUtil method getMetadataRowset.
/**
* Returns a set of column headings and rows for a given metadata request.
*
* <p/>Leverages mondrian's implementation of the XML/A specification, and
* is exposed here for use by mondrian's olap4j driver.
*
* @param connection Connection
* @param methodName Metadata method name per XMLA (e.g. "MDSCHEMA_CUBES")
* @param restrictionMap Restrictions
* @return Set of rows and column headings
*/
public static MetadataRowset getMetadataRowset(final OlapConnection connection, String methodName, final Map<String, Object> restrictionMap) throws OlapException {
RowsetDefinition rowsetDefinition = RowsetDefinition.valueOf(methodName);
final XmlaHandler.ConnectionFactory connectionFactory = new XmlaHandler.ConnectionFactory() {
public OlapConnection getConnection(String catalog, String schema, String roleName, Properties props) throws SQLException {
return connection;
}
public Map<String, Object> getPreConfiguredDiscoverDatasourcesResponse() {
// the "pre configured discover datasources" feature.
return null;
}
};
final XmlaRequest request = new XmlaRequest() {
public Method getMethod() {
return Method.DISCOVER;
}
public Map<String, String> getProperties() {
return Collections.emptyMap();
}
public Map<String, Object> getRestrictions() {
return restrictionMap;
}
public String getStatement() {
return null;
}
public String getRoleName() {
return null;
}
public String getRequestType() {
throw new UnsupportedOperationException();
}
public boolean isDrillThrough() {
throw new UnsupportedOperationException();
}
public Format getFormat() {
throw new UnsupportedOperationException();
}
public String getUsername() {
return null;
}
public String getPassword() {
return null;
}
public String getSessionId() {
return null;
}
};
final Rowset rowset = rowsetDefinition.getRowset(request, new XmlaHandler(connectionFactory, "xmla") {
@Override
public OlapConnection getConnection(XmlaRequest request, Map<String, String> propMap) {
return connection;
}
});
List<Rowset.Row> rowList = new ArrayList<Rowset.Row>();
rowset.populate(new DefaultXmlaResponse(new ByteArrayOutputStream(), Charset.defaultCharset().name(), Enumeration.ResponseMimeType.SOAP), connection, rowList);
MetadataRowset result = new MetadataRowset();
final List<RowsetDefinition.Column> colDefs = new ArrayList<RowsetDefinition.Column>();
for (RowsetDefinition.Column columnDefinition : rowsetDefinition.columnDefinitions) {
if (columnDefinition.type == RowsetDefinition.Type.Rowset) {
// Cube.Dimensions
continue;
}
colDefs.add(columnDefinition);
}
for (Rowset.Row row : rowList) {
Object[] values = new Object[colDefs.size()];
int k = -1;
for (RowsetDefinition.Column colDef : colDefs) {
Object o = row.get(colDef.name);
if (o instanceof List) {
o = toString((List<String>) o);
} else if (o instanceof String[]) {
o = toString(Arrays.asList((String[]) o));
}
values[++k] = o;
}
result.rowList.add(Arrays.asList(values));
}
for (RowsetDefinition.Column colDef : colDefs) {
String columnName = colDef.name;
if (LOWERCASE_PATTERN.matcher(columnName).matches()) {
columnName = Util.camelToUpper(columnName);
}
// VALUE is a SQL reserved word
if (columnName.equals("VALUE")) {
columnName = "PROPERTY_VALUE";
}
result.headerList.add(columnName);
}
return result;
}
Aggregations