def get(self, dimension_name: str, **kwargs) -> Dimension: """ Get a Dimension :param dimension_name: :return: """ url = format_url("/api/v1/Dimensions('{}')?$expand=Hierarchies($expand=*)", dimension_name) response = self._rest.GET(url, **kwargs) return Dimension.from_json(response.text)
def get(self, dimension_name): """ Get a Dimension :param dimension_name: :return: """ request = "/api/v1/Dimensions('{}')?$expand=Hierarchies($expand=*)".format(dimension_name) response = self._rest.GET(request) return Dimension.from_json(response.text)
def update(self, dimension: Dimension, **kwargs): """ Update an existing dimension :param dimension: instance of TM1py.Dimension :return: None """ # delete hierarchies that have been removed from the dimension object hierarchies_to_be_removed = CaseAndSpaceInsensitiveSet( *self.hierarchies.get_all_names(dimension.name, **kwargs)) for hierarchy in dimension.hierarchy_names: hierarchies_to_be_removed.discard(hierarchy) # update all Hierarchies except for the implicitly maintained 'Leaves' Hierarchy for hierarchy in dimension: if not case_and_space_insensitive_equals(hierarchy.name, "Leaves"): if self.hierarchies.exists(hierarchy.dimension_name, hierarchy.name, **kwargs): self.hierarchies.update(hierarchy, **kwargs) else: self.hierarchies.create(hierarchy, **kwargs) # Edge case: elements in leaves hierarchy that do not exist in other hierarchies if "Leaves" in dimension: existing_leaves = CaseAndSpaceInsensitiveSet( self.hierarchies.elements.get_leaf_element_names( dimension.name, "Leaves")) leaves_to_create = list() for leaf in dimension.get_hierarchy("Leaves"): if leaf.name not in existing_leaves: leaves_to_create.append(leaf) if leaves_to_create: self.hierarchies.elements.add_elements( dimension_name=dimension.name, hierarchy_name="Leaves", elements=leaves_to_create) for hierarchy_name in hierarchies_to_be_removed: if not case_and_space_insensitive_equals(hierarchy_name, "Leaves"): self.hierarchies.delete(dimension_name=dimension.name, hierarchy_name=hierarchy_name, **kwargs)