Пример #1
0
    def __init__(self, **kwargs):
        self._tm1_rest = RestService(**kwargs)

        # instantiate all Services
        self.annotations = AnnotationService(self._tm1_rest)
        self.cells = CellService(self._tm1_rest)
        self.chores = ChoreService(self._tm1_rest)
        self.cubes = CubeService(self._tm1_rest)
        self.dimensions = DimensionService(self._tm1_rest)
        self.elements = ElementService(self._tm1_rest)
        self.hierarchies = HierarchyService(self._tm1_rest)
        self.monitoring = MonitoringService(self._tm1_rest)
        self.power_bi = PowerBiService(self._tm1_rest)
        self.processes = ProcessService(self._tm1_rest)
        self.security = SecurityService(self._tm1_rest)
        self.server = ServerService(self._tm1_rest)
        self.subsets = SubsetService(self._tm1_rest)
        self.applications = ApplicationService(self._tm1_rest)
        self.views = ViewService(self._tm1_rest)
Пример #2
0
 def _instantiate_services(self):
     self.annotations = AnnotationService(self._tm1_rest)
     self.cells = CellService(self._tm1_rest)
     self.chores = ChoreService(self._tm1_rest)
     self.cubes = CubeService(self._tm1_rest)
     self.dimensions = DimensionService(self._tm1_rest)
     self.elements = ElementService(self._tm1_rest)
     self.git = GitService(self._tm1_rest)
     self.hierarchies = HierarchyService(self._tm1_rest)
     self.monitoring = MonitoringService(self._tm1_rest)
     self.power_bi = PowerBiService(self._tm1_rest)
     self.processes = ProcessService(self._tm1_rest)
     self.security = SecurityService(self._tm1_rest)
     self.server = ServerService(self._tm1_rest)
     self.subsets = SubsetService(self._tm1_rest)
     self.applications = ApplicationService(self._tm1_rest)
     self.views = ViewService(self._tm1_rest)
     self.sandboxes = SandboxService(self._tm1_rest)
     self.git = GitService(self._tm1_rest)
Пример #3
0
class DimensionService(ObjectService):
    """ Service to handle Object Updates for TM1 Dimensions
    
    """
    def __init__(self, rest, name):
        super().__init__(rest)
        self.hierarchies = HierarchyService(rest)
        self.subsets = SubsetService(rest)
        self.name = name

    def create(self, dimension):
        """ create a dimension

        :param dimension: instance of TM1py.Dimension
        :return: response
        """
        # If Dimension exists. throw Exception
        if self.exists(dimension.name):
            raise Exception("Dimension already exists")
        # If not all subsequent calls successfull -> undo everything that has been done in this function
        try:
            # create Dimension, Hierarchies, Elements, Edges etc.
            request = "/api/v1/Dimensions"
            response = self._rest.POST(request, dimension.body)
            # create Hierarchies
            self.hierarchies.update(dimension.hierarchies[0])
            for hierarchy in dimension.hierarchies[1:]:
                self.hierarchies.create(hierarchy)
        except TM1pyException as e:
            # undo everything if problem in step 1 or 2
            if self.exists(dimension.name):
                self._rest.DELETE_dimension(dimension.name)
            raise e
        return response

    def get(self, dimension_name):
        """ Get a Dimension

        :param dimension_name:
        :return:
        """
        request = "/api/v1/Dimensions('{}')?$expand=Hierarchies($expand=*)".format(
            dimension_name)
        dimension_as_json = self._rest.GET(request)
        return Dimension.from_json(dimension_as_json)

    def update(self, dimension):
        """ Update an existing dimension

        :param dimension: instance of TM1py.Dimension
        :return: None
        """
        # update Hierarchies
        for hierarchy in dimension:
            self.hierarchies.update(hierarchy)

    def delete(self, dimension_name):
        """ Delete a dimension

        :param dimension_name: Name of the dimension
        :return:
        """
        request = '/api/v1/Dimensions(\'{}\')'.format(dimension_name)
        return self._rest.DELETE(request)

    def exists(self, dimension_name):
        """ Check if dimension exists
        
        :return: 
        """
        request = "/api/v1/Dimensions('{}')".format(dimension_name)
        return super(DimensionService, self).exists(request)

    def get_all_names(self):
        """Ask TM1 Server for list with all dimension names

        :Returns:
            List of Strings
        """
        response = self._rest.GET('/api/v1/Dimensions?$select=Name', '')
        dimensions = json.loads(response)['value']
        list_dimensions = list(entry['Name'] for entry in dimensions)
        return list_dimensions
Пример #4
0
 def __init__(self, rest, name):
     super().__init__(rest)
     self.hierarchies = HierarchyService(rest)
     self.subsets = SubsetService(rest)
     self.name = name