Example #1
0
    def run_subset_application(self, private):
        app = SubsetApplication(self.tm1py_app_folder, self.application_name,
                                self.dimension_names[0],
                                self.dimension_names[0], self.subset_name)
        self.tm1.applications.create(application=app, private=private)
        app_retrieved = self.tm1.applications.get(app.path,
                                                  app.application_type,
                                                  app.name,
                                                  private=private)
        self.assertEqual(app, app_retrieved)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.SUBSET,
            private=private)
        self.assertTrue(exists)

        self.tm1.applications.delete(app.path,
                                     app.application_type,
                                     app.name,
                                     private=private)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.SUBSET,
            private=private)
        self.assertFalse(exists)
Example #2
0
    def run_test_subset_application(self, private):
        app = SubsetApplication(TM1PY_APP_FOLDER, APPLICATION_NAME,
                                DIMENSION_NAMES[0], DIMENSION_NAMES[0],
                                SUBSET_NAME)
        self.tm1.applications.create(application=app, private=private)
        app_retrieved = self.tm1.applications.get(app.path,
                                                  app.application_type,
                                                  app.name,
                                                  private=private)
        self.assertEqual(app, app_retrieved)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.SUBSET,
            private=private)
        self.assertTrue(exists)

        self.tm1.applications.delete(app.path,
                                     app.application_type,
                                     app.name,
                                     private=private)
        exists = self.tm1.applications.exists(
            app.path,
            name=app.name,
            application_type=ApplicationTypes.SUBSET,
            private=private)
        self.assertFalse(exists)
Example #3
0
    def get(self,
            path: str,
            application_type: Union[str, ApplicationTypes],
            name: str,
            private: bool = False,
            **kwargs) -> Application:
        """ Retrieve Planning Analytics Application

        :param path: path with forward slashes
        :param application_type: str or ApplicationType from Enum
        :param name:
        :param private:
        :return:
        """
        # raise ValueError if not a valid ApplicationType
        application_type = ApplicationTypes(application_type)

        # documents require special treatment
        if application_type == ApplicationTypes.DOCUMENT:
            return self.get_document(path=path,
                                     name=name,
                                     private=private,
                                     **kwargs)

        if not application_type == ApplicationTypes.FOLDER:
            name += application_type.suffix

        contents = 'PrivateContents' if private else 'Contents'
        mid = ""
        if path.strip() != '':
            mid = "".join([
                format_url("/Contents('{}')", element)
                for element in path.split('/')
            ])

        base_url = format_url("/api/v1/Contents('Applications')" + mid + "/" +
                              contents + "('{application_name}')",
                              application_name=name)

        if application_type == ApplicationTypes.CUBE:
            response = self._rest.GET(url=base_url +
                                      "?$expand=Cube($select=Name)",
                                      **kwargs)
            return CubeApplication(path=path,
                                   name=name,
                                   cube_name=response.json()["Cube"]["Name"])

        elif application_type == ApplicationTypes.CHORE:
            response = self._rest.GET(url=base_url +
                                      "?$expand=Chore($select=Name)",
                                      **kwargs)
            return ChoreApplication(
                path=path,
                name=name,
                chore_name=response.json()["Chore"]["Name"])

        elif application_type == ApplicationTypes.DIMENSION:
            response = self._rest.GET(url=base_url +
                                      "?$expand=Dimension($select=Name)",
                                      **kwargs)
            return DimensionApplication(
                path=path,
                name=name,
                dimension_name=response.json()["Dimension"]["Name"])

        elif application_type == ApplicationTypes.FOLDER:
            # implicit TM1pyException if application doesn't exist
            self._rest.GET(url=base_url, **kwargs)
            return FolderApplication(path=path, name=name)

        elif application_type == ApplicationTypes.LINK:
            # implicit TM1pyException if application doesn't exist
            self._rest.GET(url=base_url, **kwargs)
            response = self._rest.GET(base_url + "?$expand=*", **kwargs)
            return LinkApplication(path=path,
                                   name=name,
                                   url=response.json()["URL"])

        elif application_type == ApplicationTypes.PROCESS:
            response = self._rest.GET(url=base_url +
                                      "?$expand=Process($select=Name)",
                                      **kwargs)
            return ProcessApplication(
                path=path,
                name=name,
                process_name=response.json()["Process"]["Name"])

        elif application_type == ApplicationTypes.SUBSET:
            url = "".join([
                base_url,
                "?$expand=Subset($select=Name;$expand=Hierarchy($select=Name;$expand=Dimension($select=Name)))"
            ])
            response = self._rest.GET(url=url, **kwargs)
            return SubsetApplication(
                path=path,
                name=name,
                dimension_name=response.json()["Subset"]["Hierarchy"]
                ["Dimension"]["Name"],
                hierarchy_name=response.json()["Subset"]["Hierarchy"]["Name"],
                subset_name=response.json()["Subset"]["Name"])

        elif application_type == ApplicationTypes.VIEW:
            response = self._rest.GET(
                url=base_url +
                "?$expand=View($select=Name;$expand=Cube($select=Name))",
                **kwargs)
            return ViewApplication(
                path=path,
                name=name,
                cube_name=response.json()["View"]["Cube"]["Name"],
                view_name=response.json()["View"]["Name"])
Example #4
0
    def get(self, path, application_type, name, private=False):
        """ Retrieve Planning Analytics Application

        :param path:
        :param application_type:
        :param name:
        :param private:
        :return:
        """
        # raise ValueError if not a valid ApplicationType
        application_type = ApplicationTypes(application_type)

        # documents require special treatment
        if application_type == ApplicationTypes.DOCUMENT:
            return self.get_document(path=path, name=name, private=private)

        if not application_type == ApplicationTypes.FOLDER:
            name += application_type.suffix

        contents = 'PrivateContents' if private else 'Contents'
        mid = ""
        if path.strip() != '':
            mid = "".join([
                "/Contents('{}')".format(element)
                for element in path.split('/')
            ])
        base_url = "/api/v1/Contents('Applications'){dynamic_mid}/{contents}('{application_name}')".format(
            dynamic_mid=mid, contents=contents, application_name=name)

        if application_type == ApplicationTypes.CUBE:
            response = self._rest.GET(base_url + "?$expand=Cube($select=Name)")
            return CubeApplication(path=path,
                                   name=name,
                                   cube_name=response.json()["Cube"]["Name"])

        elif application_type == ApplicationTypes.CHORE:
            response = self._rest.GET(base_url +
                                      "?$expand=Chore($select=Name)")
            return ChoreApplication(
                path=path,
                name=name,
                chore_name=response.json()["Chore"]["Name"])

        elif application_type == ApplicationTypes.DIMENSION:
            response = self._rest.GET(base_url +
                                      "?$expand=Dimension($select=Name)")
            return DimensionApplication(
                path=path,
                name=name,
                dimension_name=response.json()["Dimension"]["Name"])

        elif application_type == ApplicationTypes.FOLDER:
            # implicit TM1pyException if doesn't exist
            self._rest.GET(base_url)
            return FolderApplication(path=path, name=name)

        elif application_type == ApplicationTypes.LINK:
            # implicit TM1pyException if doesn't exist
            self._rest.GET(base_url)
            response = self._rest.GET(base_url + "?$expand=*")
            return LinkApplication(path=path,
                                   name=name,
                                   url=response.json()["URL"])

        elif application_type == ApplicationTypes.PROCESS:
            response = self._rest.GET(base_url +
                                      "?$expand=Process($select=Name)")
            return ProcessApplication(
                path=path,
                name=name,
                process_name=response.json()["Process"]["Name"])

        elif application_type == ApplicationTypes.SUBSET:
            response = self._rest.GET(
                base_url +
                "?$expand=Subset($select=Name;$expand=Hierarchy($select=Name;$expand=Dimension($select=Name)))"
            )
            return SubsetApplication(
                path=path,
                name=name,
                dimension_name=response.json()["Subset"]["Hierarchy"]
                ["Dimension"]["Name"],
                hierarchy_name=response.json()["Subset"]["Hierarchy"]["Name"],
                subset_name=response.json()["Subset"]["Name"])

        elif application_type == ApplicationTypes.VIEW:
            response = self._rest.GET(
                base_url +
                "?$expand=View($select=Name;$expand=Cube($select=Name))")
            return ViewApplication(
                path=path,
                name=name,
                cube_name=response.json()["View"]["Cube"]["Name"],
                view_name=response.json()["View"]["Name"])