Beispiel #1
0
    def get_all(self, cube_name: str, **kwargs) -> Tuple[List[View], List[View]]:
        """ Get all public and private views from cube.

        :param cube_name: String, name of the cube.
        :return: 2 Lists of TM1py.View instances: private views, public views
        """
        private_views, public_views = [], []
        for view_type in ('PrivateViews', 'Views'):
            url = format_url(
                "/api/v1/Cubes('{}')/{}?$expand="
                "tm1.NativeView/Rows/Subset($expand=Hierarchy($select=Name;"
                "$expand=Dimension($select=Name)),Elements($select=Name);"
                "$select=Expression,UniqueName,Name, Alias),  "
                "tm1.NativeView/Columns/Subset($expand=Hierarchy($select=Name;"
                "$expand=Dimension($select=Name)),Elements($select=Name);"
                "$select=Expression,UniqueName,Name,Alias), "
                "tm1.NativeView/Titles/Subset($expand=Hierarchy($select=Name;"
                "$expand=Dimension($select=Name)),Elements($select=Name);"
                "$select=Expression,UniqueName,Name,Alias), "
                "tm1.NativeView/Titles/Selected($select=Name)",
                cube_name, view_type)
            response = self._rest.GET(url, **kwargs)
            response_as_list = response.json()['value']
            for view_as_dict in response_as_list:
                if view_as_dict['@odata.type'] == '#ibm.tm1.api.v1.MDXView':
                    view = MDXView.from_dict(view_as_dict, cube_name)
                else:
                    view = NativeView.from_dict(view_as_dict, cube_name)
                if view_type == "PrivateViews":
                    private_views.append(view)
                else:
                    public_views.append(view)
        return private_views, public_views
Beispiel #2
0
 def get(self, cube_name: str, view_name: str, private: bool = False, **kwargs) -> View:
     view_type = "PrivateViews" if private else "Views"
     url = format_url("/api/v1/Cubes('{}')/{}('{}')?$expand=*", cube_name, view_type, view_name)
     response = self._rest.GET(url, **kwargs)
     view_as_dict = response.json()
     if "MDX" in view_as_dict:
         return MDXView(cube_name=cube_name, view_name=view_name, MDX=view_as_dict["MDX"])
     else:
         return self.get_native_view(cube_name=cube_name, view_name=view_name, private=private)
Beispiel #3
0
 def get(self, cube_name, view_name, private=False):
     view_type = "PrivateViews" if private else "Views"
     request = "/api/v1/Cubes('{}')/{}('{}')?$expand=*".format(
         cube_name, view_type, view_name)
     response = self._rest.GET(request)
     view_as_dict = response.json()
     if "MDX" in view_as_dict:
         return MDXView(cube_name=cube_name,
                        view_name=view_name,
                        MDX=view_as_dict["MDX"])
     else:
         return self.get_native_view(cube_name=cube_name,
                                     view_name=view_name,
                                     private=private)
Beispiel #4
0
    def get_mdx_view(self, cube_name: str, view_name: str, private: bool = False, **kwargs) -> MDXView:
        """ Get an MDXView from TM1 Server

        :param cube_name: String, name of the cube
        :param view_name: String, name of the MDX view
        :param private: boolean

        :return: instance of TM1py.MDXView
        """
        view_type = 'PrivateViews' if private else 'Views'
        url = format_url("/api/v1/Cubes('{}')/{}('{}')?$expand=*", cube_name, view_type, view_name)
        response = self._rest.GET(url, **kwargs)
        mdx_view = MDXView.from_json(view_as_json=response.text)
        return mdx_view
Beispiel #5
0
    def get_mdx_view(self, cube_name, view_name, private=True):
        """ Get an MDXView from TM1 Server

        :param cube_name: String, name of the cube
        :param view_name: String, name of the MDX view
        :param private: boolean

        :return: instance of TM1py.MDXView
        """
        view_type = 'PrivateViews' if private else 'Views'
        request = "/api/v1/Cubes('{}')/{}('{}')?$expand=*".format(cube_name, view_type, view_name)
        response = self._rest.GET(request)
        mdx_view = MDXView.from_json(view_as_json=response.text)
        return mdx_view