Commit 66fae1d5 authored by mouadh's avatar mouadh

generate_resp function

parent 5b866b98
...@@ -310,6 +310,30 @@ class XmlaDiscoverTools(): ...@@ -310,6 +310,30 @@ class XmlaDiscoverTools():
return get_props(discover_preperties_xsd, '', '', '', '', '', '') return get_props(discover_preperties_xsd, '', '', '', '', '', '')
def discover_schema_rowsets_response(self, request): def discover_schema_rowsets_response(self, request):
def generate_resp(rows):
xml = xmlwitch.Builder()
with xml['return']:
with xml.root(str(discover_schema_rowsets_xsd), xmlns="urn:schemas-microsoft-com:xml-analysis:rowset",
**{'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'}):
for resp_row in rows:
with xml.row:
xml.SchemaGuid(resp_row['SchemaGuid'])
for idx, restriction in enumerate(resp_row['restrictions']['restriction_names']):
with xml.Restrictions:
xml.Name(restriction)
xml.Type(resp_row['restrictions']['restriction_types'][idx])
xml.RestrictionsMask(resp_row['RestrictionsMask'])
html_parser = HTMLParser.HTMLParser()
xml = html_parser.unescape(str(xml))
return xml
if request.Restrictions.RestrictionList.SchemaName == "MDSCHEMA_HIERARCHIES" and \ if request.Restrictions.RestrictionList.SchemaName == "MDSCHEMA_HIERARCHIES" and \
request.Properties.PropertyList.Catalog is not None: request.Properties.PropertyList.Catalog is not None:
self.change_catalogue(request.Properties.PropertyList.Catalog) self.change_catalogue(request.Properties.PropertyList.Catalog)
...@@ -333,130 +357,49 @@ class XmlaDiscoverTools(): ...@@ -333,130 +357,49 @@ class XmlaDiscoverTools():
'unsignedShort', 'unsignedShort',
'unsignedShort'] 'unsignedShort']
xml = xmlwitch.Builder() rows = [{'SchemaName': 'MDSCHEMA_HIERARCHIES',
'SchemaGuid': 'C8B522DA-5CF3-11CE-ADE5-00AA0044773D',
'restrictions': {'restriction_names': restriction_names,
'restriction_types': restriction_types},
'RestrictionsMask': '511'
}
]
with xml.root(str(discover_schema_rowsets_xsd), xmlns="urn:schemas-microsoft-com:xml-analysis:rowset", return generate_resp(rows)
**{'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'}):
with xml.row:
xml.SchemaName('MDSCHEMA_HIERARCHIES')
xml.SchemaGuid('C8B522DA-5CF3-11CE-ADE5-00AA0044773D')
for idx, restriction in enumerate(restriction_names):
with xml.Restrictions:
xml.Name(restriction)
xml.Type(restriction_types[idx])
xml.RestrictionsMask('511')
html_parser = HTMLParser.HTMLParser()
xml = html_parser.unescape(str(xml))
return """
<return>
{0}
</return>
""".format(xml)
# return etree.fromstring("""
# <return>
# <root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"
# xmlns:xsd="http://www.w3.org/2001/XMLSchema"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
# """ + discover_schema_rowsets_xsd + """
# <row>
# <SchemaName>MDSCHEMA_HIERARCHIES</SchemaName>
# <SchemaGuid>C8B522DA-5CF3-11CE-ADE5-00AA0044773D</SchemaGuid>
# <Restrictions>
# <Name>CATALOG_NAME</Name>
# <Type>string</Type>
# </Restrictions>
# <Restrictions>
# <Name>SCHEMA_NAME</Name>
# <Type>string</Type>
# </Restrictions>
# <Restrictions>
# <Name>CUBE_NAME</Name>
# <Type>string</Type>
# </Restrictions>
# <Restrictions>
# <Name>DIMENSION_UNIQUE_NAME</Name>
# <Type>string</Type>
# </Restrictions>
# <Restrictions>
# <Name>HIERARCHY_NAME</Name>
# <Type>string</Type>
# </Restrictions>
# <Restrictions>
# <Name>HIERARCHY_UNIQUE_NAME</Name>
# <Type>string</Type>
# </Restrictions>
# <Restrictions>
# <Name>HIERARCHY_ORIGIN</Name>
# <Type>unsignedShort</Type>
# </Restrictions>
# <Restrictions>
# <Name>CUBE_SOURCE</Name>
# <Type>unsignedShort</Type>
# </Restrictions>
# <Restrictions>
# <Name>HIERARCHY_VISIBILITY</Name>
# <Type>unsignedShort</Type>
# </Restrictions>
# <RestrictionsMask>511</RestrictionsMask>
# </row>
# </root>
# </return>
# """)
if request.Restrictions.RestrictionList.SchemaName == 'MDSCHEMA_MEASURES' and \ if request.Restrictions.RestrictionList.SchemaName == 'MDSCHEMA_MEASURES' and \
request.Properties.PropertyList.Catalog is not None: request.Properties.PropertyList.Catalog is not None:
self.change_catalogue(request.Properties.PropertyList.Catalog) self.change_catalogue(request.Properties.PropertyList.Catalog)
return etree.fromstring("""
<return>
<root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" restriction_names = ['CATALOG_NAME',
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 'SCHEMA_NAME',
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 'CUBE_NAME',
""" + discover_schema_rowsets_xsd + """ 'MEASURE_NAME',
<row> 'MEASURE_UNIQUE_NAME',
<SchemaName>MDSCHEMA_MEASURES</SchemaName> 'MEASUREGROUP_NAME',
<SchemaGuid>C8B522DC-5CF3-11CE-ADE5-00AA0044773D</SchemaGuid> 'CUBE_SOURCE',
<Restrictions> 'MEASURE_VISIBILITY']
<Name>CATALOG_NAME</Name> restriction_types = ['string',
<Type>string</Type> 'string',
</Restrictions> 'string',
<Restrictions> 'string',
<Name>SCHEMA_NAME</Name> 'string',
<Type>string</Type> 'string',
</Restrictions> 'unsignedShort',
<Restrictions> 'unsignedShort']
<Name>CUBE_NAME</Name>
<Type>string</Type> rows = [{'SchemaName': 'MDSCHEMA_MEASURES',
</Restrictions> 'SchemaGuid': 'C8B522DC-5CF3-11CE-ADE5-00AA0044773D',
<Restrictions> 'restrictions': {'restriction_names': restriction_names,
<Name>MEASURE_NAME</Name> 'restriction_types': restriction_types},
<Type>string</Type> 'RestrictionsMask': '255'
</Restrictions> }
<Restrictions> ]
<Name>MEASURE_UNIQUE_NAME</Name>
<Type>string</Type> return generate_resp(rows)
</Restrictions>
<Restrictions>
<Name>MEASUREGROUP_NAME</Name>
<Type>string</Type>
</Restrictions>
<Restrictions>
<Name>CUBE_SOURCE</Name>
<Type>unsignedShort</Type>
</Restrictions>
<Restrictions>
<Name>MEASURE_VISIBILITY</Name>
<Type>unsignedShort</Type>
</Restrictions>
<RestrictionsMask>255</RestrictionsMask>
</row>
</root>
</return>
""")
# TODO delete # TODO delete
if request.Properties.PropertyList.Catalog is not None: if request.Properties.PropertyList.Catalog is not None:
return etree.fromstring(""" return etree.fromstring("""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment