Skip to content

dimensions

wdadaptivepy service for Adaptive's Dimensions.

DimensionService

Create, retrieve, and modify Adaptive Dimensions.

Attributes:

Name Type Description
Dimension

wdadaptivepy Dimension

Source code in src/wdadaptivepy/services/dimensions.py
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
class DimensionService:
    """Create, retrieve, and modify Adaptive Dimensions.

    Attributes:
        Dimension: wdadaptivepy Dimension

    """

    def __init__(self, xml_api: XMLApi) -> None:
        """Initialize DimensionService.

        Args:
            xml_api: wdadaptivepy XMLApi

        """
        self.__xml_api = xml_api
        self.Dimension = Dimension

    def get_all(
        self,
        *,
        attributes: bool = True,
        dimension_values: bool = True,
        display_name_enabled: bool = True,
    ) -> MetadataList[Dimension]:
        """Retrieve all Dimensions from Adaptive.

        Args:
            attributes: Adaptive Attributes
            dimension_values: Adaptive Dimension Values
            display_name_enabled: Adaptive Display Name Enabled

        Returns:
            adaptive Dimensions

        """
        include = ET.Element(
            "include",
            attrib={
                "attributes": str(bool_to_str_true_false(attributes)),
                "dimensionValues": str(bool_to_str_true_false(dimension_values)),
                "displayNameEnabled": str(bool_to_str_true_false(display_name_enabled)),
            },
        )

        response = self.__xml_api.make_xml_request(
            method="exportDimensions",
            payload=include,
        )
        return MetadataList[Dimension](Dimension.from_xml(xml=response))

    def preview_update(
        self,
        dimensions: Sequence[Dimension],
        *,
        hide_password: bool = True,
    ) -> ET.Element:
        """Generate Dimension update XML API call for review.

        Args:
            dimensions: wdadaptivepy Dimensions to update
            hide_password: Prevent password from being displayed

        Returns:
            XML API body

        """
        updated_dimensions = Dimension.to_xml("update", dimensions)
        # ET.indent(updated_dimensions)
        # with open("test_dimensions.xml", "w", encoding="utf-8") as fp:
        #     fp.write(ET.tostring(updated_dimensions, encoding="unicode"))
        return self.__xml_api.preview_xml_request(
            method="importDimensions",
            payload=updated_dimensions,
            hide_password=hide_password,
        )

    def get(  # NOQA: PLR0913
        self,
        dimensions: Sequence[Dimension] = [],
        dimension_ids: Sequence[int] = [],
        dimension_names: Sequence[str] = [],
        *,
        attributes: bool = True,
        dimension_values: bool = True,
        display_name_enabled: bool = True,
    ) -> MetadataList[Dimension]:
        """Retrieve Dimensions from Adaptive with additional filters.

        Args:
            dimensions: Adaptive Dimensions
            dimension_ids: Adaptive Dimension IDs
            dimension_names: Adaptive Dimension Names
            attributes: Adaptive Attributes
            dimension_values: Adaptive Dimension Values
            display_name_enabled: Adaptive Display Name Enabled

        Returns:
            adaptive Dimensions

        """
        ids: list[int] = []
        if dimensions:
            ids.extend(
                [dimension.id for dimension in dimensions if dimension.id is not None],
            )
        elif dimension_ids:
            ids.extend(dimension_ids)
        elif dimension_names:
            all_dimensions = self.get_all(dimension_values=False)
            for name in dimension_names:
                ids.extend(
                    [
                        dimension.id
                        for dimension in all_dimensions
                        if dimension.name == name and dimension.id is not None
                    ],
                )
        else:
            raise ValueError
        if not ids:
            raise ValueError

        include = ET.Element(
            "include",
            attrib={
                "dimensionIDs": ",".join(str(dimension_id) for dimension_id in ids),
                "attributes": str(bool_to_str_true_false(attributes)),
                "dimensionValues": str(bool_to_str_true_false(dimension_values)),
                "displayNameEnabled": str(bool_to_str_true_false(display_name_enabled)),
            },
        )

        response = self.__xml_api.make_xml_request(
            method="exportDimensions",
            payload=include,
        )
        return MetadataList[Dimension](Dimension.from_xml(xml=response))

    def from_json(self, data: str) -> MetadataList[Dimension]:
        """Convert JSON to MetadataList of Dimensions.

        Args:
            data: JSON string

        Returns:
            MetadataList of Dimensions

        """
        return MetadataList[Dimension](Dimension.from_json(data=data))

    def from_dict(self, data: Sequence[dict] | dict) -> MetadataList[Dimension]:
        """Convert Python Dictionary to MetadataList of Dimensions.

        Args:
            data: Python Dictionary

        Returns:
            MetadataList of Dimensions

        """
        return MetadataList[Dimension](Dimension.from_dict(data=data))

__init__(xml_api)

Initialize DimensionService.

Parameters:

Name Type Description Default
xml_api XMLApi

wdadaptivepy XMLApi

required
Source code in src/wdadaptivepy/services/dimensions.py
20
21
22
23
24
25
26
27
28
def __init__(self, xml_api: XMLApi) -> None:
    """Initialize DimensionService.

    Args:
        xml_api: wdadaptivepy XMLApi

    """
    self.__xml_api = xml_api
    self.Dimension = Dimension

from_dict(data)

Convert Python Dictionary to MetadataList of Dimensions.

Parameters:

Name Type Description Default
data Sequence[dict] | dict

Python Dictionary

required

Returns:

Type Description
MetadataList[Dimension]

MetadataList of Dimensions

Source code in src/wdadaptivepy/services/dimensions.py
163
164
165
166
167
168
169
170
171
172
173
def from_dict(self, data: Sequence[dict] | dict) -> MetadataList[Dimension]:
    """Convert Python Dictionary to MetadataList of Dimensions.

    Args:
        data: Python Dictionary

    Returns:
        MetadataList of Dimensions

    """
    return MetadataList[Dimension](Dimension.from_dict(data=data))

from_json(data)

Convert JSON to MetadataList of Dimensions.

Parameters:

Name Type Description Default
data str

JSON string

required

Returns:

Type Description
MetadataList[Dimension]

MetadataList of Dimensions

Source code in src/wdadaptivepy/services/dimensions.py
151
152
153
154
155
156
157
158
159
160
161
def from_json(self, data: str) -> MetadataList[Dimension]:
    """Convert JSON to MetadataList of Dimensions.

    Args:
        data: JSON string

    Returns:
        MetadataList of Dimensions

    """
    return MetadataList[Dimension](Dimension.from_json(data=data))

get(dimensions=[], dimension_ids=[], dimension_names=[], *, attributes=True, dimension_values=True, display_name_enabled=True)

Retrieve Dimensions from Adaptive with additional filters.

Parameters:

Name Type Description Default
dimensions Sequence[Dimension]

Adaptive Dimensions

[]
dimension_ids Sequence[int]

Adaptive Dimension IDs

[]
dimension_names Sequence[str]

Adaptive Dimension Names

[]
attributes bool

Adaptive Attributes

True
dimension_values bool

Adaptive Dimension Values

True
display_name_enabled bool

Adaptive Display Name Enabled

True

Returns:

Type Description
MetadataList[Dimension]

adaptive Dimensions

Source code in src/wdadaptivepy/services/dimensions.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def get(  # NOQA: PLR0913
    self,
    dimensions: Sequence[Dimension] = [],
    dimension_ids: Sequence[int] = [],
    dimension_names: Sequence[str] = [],
    *,
    attributes: bool = True,
    dimension_values: bool = True,
    display_name_enabled: bool = True,
) -> MetadataList[Dimension]:
    """Retrieve Dimensions from Adaptive with additional filters.

    Args:
        dimensions: Adaptive Dimensions
        dimension_ids: Adaptive Dimension IDs
        dimension_names: Adaptive Dimension Names
        attributes: Adaptive Attributes
        dimension_values: Adaptive Dimension Values
        display_name_enabled: Adaptive Display Name Enabled

    Returns:
        adaptive Dimensions

    """
    ids: list[int] = []
    if dimensions:
        ids.extend(
            [dimension.id for dimension in dimensions if dimension.id is not None],
        )
    elif dimension_ids:
        ids.extend(dimension_ids)
    elif dimension_names:
        all_dimensions = self.get_all(dimension_values=False)
        for name in dimension_names:
            ids.extend(
                [
                    dimension.id
                    for dimension in all_dimensions
                    if dimension.name == name and dimension.id is not None
                ],
            )
    else:
        raise ValueError
    if not ids:
        raise ValueError

    include = ET.Element(
        "include",
        attrib={
            "dimensionIDs": ",".join(str(dimension_id) for dimension_id in ids),
            "attributes": str(bool_to_str_true_false(attributes)),
            "dimensionValues": str(bool_to_str_true_false(dimension_values)),
            "displayNameEnabled": str(bool_to_str_true_false(display_name_enabled)),
        },
    )

    response = self.__xml_api.make_xml_request(
        method="exportDimensions",
        payload=include,
    )
    return MetadataList[Dimension](Dimension.from_xml(xml=response))

get_all(*, attributes=True, dimension_values=True, display_name_enabled=True)

Retrieve all Dimensions from Adaptive.

Parameters:

Name Type Description Default
attributes bool

Adaptive Attributes

True
dimension_values bool

Adaptive Dimension Values

True
display_name_enabled bool

Adaptive Display Name Enabled

True

Returns:

Type Description
MetadataList[Dimension]

adaptive Dimensions

Source code in src/wdadaptivepy/services/dimensions.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def get_all(
    self,
    *,
    attributes: bool = True,
    dimension_values: bool = True,
    display_name_enabled: bool = True,
) -> MetadataList[Dimension]:
    """Retrieve all Dimensions from Adaptive.

    Args:
        attributes: Adaptive Attributes
        dimension_values: Adaptive Dimension Values
        display_name_enabled: Adaptive Display Name Enabled

    Returns:
        adaptive Dimensions

    """
    include = ET.Element(
        "include",
        attrib={
            "attributes": str(bool_to_str_true_false(attributes)),
            "dimensionValues": str(bool_to_str_true_false(dimension_values)),
            "displayNameEnabled": str(bool_to_str_true_false(display_name_enabled)),
        },
    )

    response = self.__xml_api.make_xml_request(
        method="exportDimensions",
        payload=include,
    )
    return MetadataList[Dimension](Dimension.from_xml(xml=response))

preview_update(dimensions, *, hide_password=True)

Generate Dimension update XML API call for review.

Parameters:

Name Type Description Default
dimensions Sequence[Dimension]

wdadaptivepy Dimensions to update

required
hide_password bool

Prevent password from being displayed

True

Returns:

Type Description
Element

XML API body

Source code in src/wdadaptivepy/services/dimensions.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def preview_update(
    self,
    dimensions: Sequence[Dimension],
    *,
    hide_password: bool = True,
) -> ET.Element:
    """Generate Dimension update XML API call for review.

    Args:
        dimensions: wdadaptivepy Dimensions to update
        hide_password: Prevent password from being displayed

    Returns:
        XML API body

    """
    updated_dimensions = Dimension.to_xml("update", dimensions)
    # ET.indent(updated_dimensions)
    # with open("test_dimensions.xml", "w", encoding="utf-8") as fp:
    #     fp.write(ET.tostring(updated_dimensions, encoding="unicode"))
    return self.__xml_api.preview_xml_request(
        method="importDimensions",
        payload=updated_dimensions,
        hide_password=hide_password,
    )