Commit c43be567 authored by mouadh's avatar mouadh

Avoid consecutive if-statements

parent d9973b89
...@@ -1520,8 +1520,9 @@ class XmlaDiscoverTools(): ...@@ -1520,8 +1520,9 @@ class XmlaDiscoverTools():
""") """)
def discover_literals_response(self, request): def discover_literals_response(self, request):
if request.Properties.PropertyList.Content == 'SchemaData': if request.Properties.PropertyList.Content == 'SchemaData' \
if request.Properties.PropertyList.Format == 'Tabular': and request.Properties.PropertyList.Format == 'Tabular':
return etree.fromstring(""" return etree.fromstring("""
<return> <return>
<root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" <root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"
...@@ -1645,8 +1646,9 @@ class XmlaDiscoverTools(): ...@@ -1645,8 +1646,9 @@ class XmlaDiscoverTools():
""") """)
def discover_mdschema_sets_response(self, request): def discover_mdschema_sets_response(self, request):
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue \
if request.Properties.PropertyList.Catalog is not None: and 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 etree.fromstring("""
<return> <return>
...@@ -1659,8 +1661,9 @@ class XmlaDiscoverTools(): ...@@ -1659,8 +1661,9 @@ class XmlaDiscoverTools():
""") """)
def discover_mdschema_kpis_response(self, request): def discover_mdschema_kpis_response(self, request):
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue \
if request.Properties.PropertyList.Catalog is not None: and 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 etree.fromstring("""
<return> <return>
...@@ -1693,8 +1696,8 @@ class XmlaDiscoverTools(): ...@@ -1693,8 +1696,8 @@ class XmlaDiscoverTools():
""".format(_catalogues)) """.format(_catalogues))
def discover_mdschema_cubes_response(self, request): def discover_mdschema_cubes_response(self, request):
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue \
if request.Properties.PropertyList.Catalog is not None: and request.Properties.PropertyList.Catalog is not None:
self.change_catalogue(request.Properties.PropertyList.Catalog) self.change_catalogue(request.Properties.PropertyList.Catalog)
if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue:
return etree.fromstring(""" return etree.fromstring("""
...@@ -1785,11 +1788,11 @@ class XmlaDiscoverTools(): ...@@ -1785,11 +1788,11 @@ class XmlaDiscoverTools():
def discover_mdschema_measures__response(self, request): def discover_mdschema_measures__response(self, request):
measures = "" measures = ""
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue and \
if request.Restrictions.RestrictionList.MEASURE_VISIBILITY == 3: request.Restrictions.RestrictionList.MEASURE_VISIBILITY == 3 and\
if 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)
for mes in self.executer.measures: for mes in self.executer.measures:
measures += """ measures += """
<row> <row>
...@@ -1809,6 +1812,7 @@ class XmlaDiscoverTools(): ...@@ -1809,6 +1812,7 @@ class XmlaDiscoverTools():
</row> </row>
""".format(self.selected_catalogue, """.format(self.selected_catalogue,
self.selected_catalogue, mes) self.selected_catalogue, mes)
return etree.fromstring(""" return etree.fromstring("""
<return> <return>
<root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" <root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"
...@@ -1821,21 +1825,19 @@ class XmlaDiscoverTools(): ...@@ -1821,21 +1825,19 @@ class XmlaDiscoverTools():
""".format(measures)) """.format(measures))
def discover_mdschema_dimensions_response(self, request): def discover_mdschema_dimensions_response(self, request):
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue and\
if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue: request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue and \
if 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)
rows = "" rows = ""
ord = 1 ord = 1
for tables in self.executer.get_all_tables_names( for tables in self.executer.get_all_tables_names(ignore_fact=True):
ignore_fact=True):
# TODO in another idea, change this # TODO in another idea, change this
# TO CHANGE NAME DISPLAY THAT EXISTS IN CONFIG FILE # TO CHANGE NAME DISPLAY THAT EXISTS IN CONFIG FILE
if MdxEngine.dimension_display_name != []: if MdxEngine.dimension_display_name != [] and tables in MdxEngine.dimension_display_name:
if tables in MdxEngine.dimension_display_name:
continue continue
rows += """ rows += """
<row> <row>
...@@ -1884,13 +1886,13 @@ class XmlaDiscoverTools(): ...@@ -1884,13 +1886,13 @@ class XmlaDiscoverTools():
def discover_mdschema_hierarchies_response(self, request): def discover_mdschema_hierarchies_response(self, request):
# Enumeration of hierarchies in all dimensions # Enumeration of hierarchies in all dimensions
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue and \
if 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)
if request.Restrictions.RestrictionList.HIERARCHY_VISIBILITY == 3: if request.Restrictions.RestrictionList.HIERARCHY_VISIBILITY == 3:
rows = "" rows = ""
for table_name, df in self.executer.tables_loaded.items(): for table_name, df in self.executer.tables_loaded.items():
# column = XmlaProvider.executer.get_columns_to_index(tables, 1, 0)[0]
if table_name == self.executer.facts: if table_name == self.executer.facts:
continue continue
rows += """ rows += """
...@@ -1917,7 +1919,6 @@ class XmlaDiscoverTools(): ...@@ -1917,7 +1919,6 @@ class XmlaDiscoverTools():
</row> </row>
""".format(self.selected_catalogue, table_name, """.format(self.selected_catalogue, table_name,
df.columns[0], df.iloc[0][0]) df.columns[0], df.iloc[0][0])
# self.executer.get_attribute_column_rm_id(tables, column, 0))
rows += """ rows += """
<row> <row>
...@@ -1954,6 +1955,7 @@ class XmlaDiscoverTools(): ...@@ -1954,6 +1955,7 @@ class XmlaDiscoverTools():
</root> </root>
</return> </return>
""".format(rows)) """.format(rows))
if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue:
rows = "" rows = ""
for table_name, df in self.executer.tables_loaded.items(): for table_name, df in self.executer.tables_loaded.items():
...@@ -2019,11 +2021,11 @@ class XmlaDiscoverTools(): ...@@ -2019,11 +2021,11 @@ class XmlaDiscoverTools():
def discover_mdschema_levels__response(self, request): def discover_mdschema_levels__response(self, request):
# TODO fix levels in the same table (with xml file maybe) !!!!!!!!! # TODO fix levels in the same table (with xml file maybe) !!!!!!!!!
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue and \
if request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue: request.Restrictions.RestrictionList.CATALOG_NAME == self.selected_catalogue and \
if 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)
rows = "" rows = ""
for tables in self.executer.get_all_tables_names( for tables in self.executer.get_all_tables_names(
ignore_fact=True): ignore_fact=True):
...@@ -2084,8 +2086,9 @@ class XmlaDiscoverTools(): ...@@ -2084,8 +2086,9 @@ class XmlaDiscoverTools():
</return>""".format(rows)) </return>""".format(rows))
def discover_mdschema_measuresgroups_response(self, request): def discover_mdschema_measuresgroups_response(self, request):
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue and \
if 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 etree.fromstring("""
<return> <return>
...@@ -2106,8 +2109,9 @@ class XmlaDiscoverTools(): ...@@ -2106,8 +2109,9 @@ class XmlaDiscoverTools():
""".format(self.selected_catalogue)) """.format(self.selected_catalogue))
def discover_mdschema_measuresgroups_dimensions_response(self, request): def discover_mdschema_measuresgroups_dimensions_response(self, request):
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue and \
if 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)
rows = "" rows = ""
for tables in self.executer.get_all_tables_names( for tables in self.executer.get_all_tables_names(
...@@ -2138,8 +2142,10 @@ class XmlaDiscoverTools(): ...@@ -2138,8 +2142,10 @@ class XmlaDiscoverTools():
""".format(rows)) """.format(rows))
def discover_mdschema_properties_response(self, request): def discover_mdschema_properties_response(self, request):
if request.Restrictions.RestrictionList.PROPERTY_TYPE == 2:
if request.Properties.PropertyList.Catalog is not None: if request.Restrictions.RestrictionList.PROPERTY_TYPE == 2 and \
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 etree.fromstring("""
<return> <return>
...@@ -2249,6 +2255,7 @@ class XmlaDiscoverTools(): ...@@ -2249,6 +2255,7 @@ class XmlaDiscoverTools():
</return> </return>
""".format(self.selected_catalogue, """.format(self.selected_catalogue,
mdschema_properties_properties_xsd)) mdschema_properties_properties_xsd))
elif request.Restrictions.RestrictionList.PROPERTY_TYPE == 1: elif request.Restrictions.RestrictionList.PROPERTY_TYPE == 1:
return etree.fromstring(""" return etree.fromstring("""
<return> <return>
...@@ -2262,10 +2269,11 @@ class XmlaDiscoverTools(): ...@@ -2262,10 +2269,11 @@ class XmlaDiscoverTools():
def discover_mdschema_members_response(self, request): def discover_mdschema_members_response(self, request):
# Enumeration of hierarchies in all dimensions # Enumeration of hierarchies in all dimensions
if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue: if request.Restrictions.RestrictionList.CUBE_NAME == self.selected_catalogue and \
if request.Properties.PropertyList.Catalog is not None: request.Properties.PropertyList.Catalog is not None and \
request.Restrictions.RestrictionList.TREE_OP == 8:
self.change_catalogue(request.Properties.PropertyList.Catalog) self.change_catalogue(request.Properties.PropertyList.Catalog)
if request.Restrictions.RestrictionList.TREE_OP == 8:
separed_tuple = request.Restrictions.RestrictionList.MEMBER_UNIQUE_NAME.split( separed_tuple = request.Restrictions.RestrictionList.MEMBER_UNIQUE_NAME.split(
".") ".")
joined = ".".join(separed_tuple[:-1]) joined = ".".join(separed_tuple[:-1])
...@@ -2293,8 +2301,7 @@ class XmlaDiscoverTools(): ...@@ -2293,8 +2301,7 @@ class XmlaDiscoverTools():
<MEMBER_NAME>""" + last_attribut + """</MEMBER_NAME> <MEMBER_NAME>""" + last_attribut + """</MEMBER_NAME>
<MEMBER_UNIQUE_NAME>{3}</MEMBER_UNIQUE_NAME> <MEMBER_UNIQUE_NAME>{3}</MEMBER_UNIQUE_NAME>
<MEMBER_TYPE>1</MEMBER_TYPE> <MEMBER_TYPE>1</MEMBER_TYPE>
<MEMBER_CAPTION>""" + last_attribut + <MEMBER_CAPTION>""" + last_attribut + """</MEMBER_CAPTION>
"""</MEMBER_CAPTION>
<CHILDREN_CARDINALITY>1</CHILDREN_CARDINALITY> <CHILDREN_CARDINALITY>1</CHILDREN_CARDINALITY>
<PARENT_LEVEL>0</PARENT_LEVEL> <PARENT_LEVEL>0</PARENT_LEVEL>
<PARENT_COUNT>0</PARENT_COUNT> <PARENT_COUNT>0</PARENT_COUNT>
......
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