Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions TM1py/Services/ElementService.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,36 @@ def get_attribute_of_elements(self, dimension_name: str, hierarchy_name: str, at
rows_and_values = self._retrieve_mdx_rows_and_values(mdx, element_unique_names=element_unique_names)
return self._extract_dict_from_rows_and_values(rows_and_values, exclude_empty_cells=exclude_empty_cells)

@require_version("11.8.023")
def element_lock(self, dimension_name: str, hierarchy_name: str, element_name: str, **kwargs) -> Response:
""" Lock element
:param dimension_name: Name of dimension.
:param hierarchy_name: Name of hierarchy.
:param element_name: Name of element to lock.
:return: response
"""
url = format_url(
"/Dimensions('{}')/Hierarchies('{}')/Elements('{}')/tm1.Lock",
dimension_name,
hierarchy_name,
element_name)
return self._rest.POST(url, '', **kwargs)

@require_version("11.8.023")
def element_unlock(self, dimension_name: str, hierarchy_name: str, element_name: str, **kwargs) -> Response:
""" Unlock element
:param dimension_name: Name of dimension.
:param hierarchy_name: Name of hierarchy.
:param element_name: Name of element to unlock.
:return: response
"""
url = format_url(
"/Dimensions('{}')/Hierarchies('{}')/Elements('{}')/tm1.Unlock",
dimension_name,
hierarchy_name,
element_name)
return self._rest.POST(url, '', **kwargs)

@staticmethod
def _extract_dict_from_rows_and_values(
rows_and_values: CaseAndSpaceInsensitiveTuplesDict,
Expand Down
24 changes: 24 additions & 0 deletions Tests/ElementService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pathlib import Path
from uuid import uuid1

from mdxpy import MdxBuilder

from TM1py.Exceptions import TM1pyRestException, TM1pyException
from TM1py.Objects import Dimension, Hierarchy, Element, ElementAttribute
from TM1py.Services import TM1Service
Expand Down Expand Up @@ -1026,6 +1028,28 @@ def test_get_element_types(self):
}
self.assertEqual(expected, element_types)

@skip_if_insufficient_version(version="11.8.023")
def test_element_lock_and_unlock(self):
self.tm1.elements.element_lock(dimension_name=self.dimension_name,
hierarchy_name=self.hierarchy_name,
element_name='1991')

query = MdxBuilder.from_cube(self.attribute_cube_name)
query.add_member_tuple_to_columns(
f"[{self.dimension_name}].[1991]",
f"[{self.attribute_cube_name}].[Previous Year]")

with self.assertRaises(TM1pyException):
self.tm1.cubes.cells.write_value('3000', self.attribute_cube_name, ('1991', 'Previous Year'))
self.assertEqual(self.tm1.cells.execute_mdx_values(mdx=query.to_mdx()), ['1990'])


self.tm1.elements.element_unlock(dimension_name=self.dimension_name,
hierarchy_name=self.hierarchy_name,
element_name='1991')
self.tm1.cubes.cells.write_value('4000', self.attribute_cube_name, ('1991', 'Previous Year'))
self.assertEqual(self.tm1.cells.execute_mdx_values(mdx=query.to_mdx()), ['4000'])

def test_get_element_types_from_all_hierarchies_with_single_hierarchy(self):
expected = {
"No Year": "Numeric",
Expand Down