Skip to content

Commit ee625a7

Browse files
committed
Revert "Merge pull request gooddata#961 from Tjev/cq-1080"
This reverts commit c11a4d2, reversing changes made to b1e24a7.
1 parent c11a4d2 commit ee625a7

File tree

4 files changed

+17
-306
lines changed

4 files changed

+17
-306
lines changed

gooddata-sdk/gooddata_sdk/utils.py

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from enum import Enum, auto
1010
from pathlib import Path
1111
from shutil import rmtree
12-
from typing import Any, Callable, NamedTuple, Optional, Union, cast, no_type_check
12+
from typing import Any, Callable, NamedTuple, Union, cast, no_type_check
1313
from warnings import warn
1414
from xml.etree import ElementTree as ET
1515

@@ -43,25 +43,6 @@ class HttpMethod(Enum):
4343
PATCH = auto()
4444

4545

46-
class ObjRefType(Enum):
47-
"""Enum representing valid tiger object reference types."""
48-
49-
ATTRIBUTE = "attribute"
50-
METRIC = "metric"
51-
LABEL = "label"
52-
DATASET = "dataset"
53-
FACT = "fact"
54-
55-
56-
UI_TO_TIGER_REF_TYPE = {
57-
"attribute": ObjRefType.ATTRIBUTE,
58-
"measure": ObjRefType.METRIC,
59-
"displayForm": ObjRefType.LABEL,
60-
"dataSet": ObjRefType.DATASET,
61-
"fact": ObjRefType.FACT,
62-
}
63-
64-
6546
def id_obj_to_key(id_obj: IdObjType) -> str:
6647
"""
6748
Given an object containing an id+type pair, this function will return a string key.
@@ -415,47 +396,28 @@ def read_json(path: Union[str, Path]) -> Any:
415396
return json.loads(f.read())
416397

417398

418-
def ref_extract_obj_id(ref: dict[str, Any], default_type: Optional[ObjRefType] = None) -> ObjId:
399+
def ref_extract_obj_id(ref: dict[str, Any]) -> ObjId:
419400
"""
420401
Extracts ObjId from a ref dictionary.
421-
422-
The ref dictionary will most likely conform to one of two forms:
423-
- ui-sdk -> ref: { identifier: str, type: str }
424-
- tiger -> ref: { identifier: { id: str, type: str } }
425-
426402
:param ref: the ref to extract from
427-
:param default_type: the type of the object to fall back to in case of string identifier
428403
:return: the extracted ObjId
429404
:raises ValueError: if the ref is not an identifier
430405
"""
431-
identifier = ref.get("identifier")
432-
if not identifier:
433-
raise ValueError("invalid ref. must be identifier")
434-
435-
if isinstance(identifier, str):
436-
if default_type:
437-
return ObjId(id=identifier, type=default_type.value)
438-
439-
ui_type = ref.get("type")
440-
if not ui_type or ui_type not in UI_TO_TIGER_REF_TYPE:
441-
raise ValueError("UI objRef type is not recognized and fallback type is not provided")
442-
443-
converted_type = UI_TO_TIGER_REF_TYPE[ui_type].value
444-
return ObjId(id=identifier, type=converted_type)
406+
if "identifier" in ref:
407+
return ObjId(id=ref["identifier"]["id"], type=ref["identifier"]["type"])
445408

446-
return ObjId(id=identifier["id"], type=identifier["type"])
409+
raise ValueError("invalid ref. must be identifier")
447410

448411

449-
def ref_extract(ref: dict[str, Any], default_type: Optional[ObjRefType] = None) -> Union[str, ObjId]:
412+
def ref_extract(ref: dict[str, Any]) -> Union[str, ObjId]:
450413
"""
451414
Extracts an object id from a ref dictionary: either an identifier or a localIdentifier.
452415
:param ref: the ref to extract from
453-
:param default_type: ref type to use in case of ui-sdk form of identifier object
454416
:return: thr extracted object id
455417
:raises ValueError: if the ref is not an identifier or localIdentifier
456418
"""
457419
try:
458-
return ref_extract_obj_id(ref, default_type)
420+
return ref_extract_obj_id(ref)
459421
except ValueError:
460422
pass
461423

gooddata-sdk/gooddata_sdk/visualization.py

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@
2929
PopDatesetMetric,
3030
SimpleMetric,
3131
)
32-
from gooddata_sdk.utils import (
33-
IdObjType,
34-
ObjRefType,
35-
SideLoads,
36-
load_all_entities,
37-
ref_extract,
38-
ref_extract_obj_id,
39-
safeget,
40-
)
32+
from gooddata_sdk.utils import IdObjType, SideLoads, load_all_entities, ref_extract, ref_extract_obj_id, safeget
4133

4234
#
4335
# Conversion from types stored in visualization into the gooddata_afm_client models.
@@ -174,30 +166,23 @@ def _convert_filter_to_computable(filter_obj: dict[str, Any]) -> Filter:
174166
# fallback to use URIs; SDK may be able to create filter with attr elements as uris...
175167
in_values = f["in"]["values"] if "values" in f["in"] else f["in"]["uris"]
176168

177-
return PositiveAttributeFilter(
178-
label=ref_extract(f["displayForm"], ObjRefType.LABEL),
179-
values=in_values,
180-
)
169+
return PositiveAttributeFilter(label=ref_extract(f["displayForm"]), values=in_values)
181170

182171
elif "negativeAttributeFilter" in filter_obj:
183172
f = filter_obj["negativeAttributeFilter"]
184173
# fallback to use URIs; SDK may be able to create filter with attr elements as uris...
185174
not_in_values = f["notIn"]["values"] if "values" in f["notIn"] else f["notIn"]["uris"]
186175

187-
return NegativeAttributeFilter(
188-
label=ref_extract(f["displayForm"], ObjRefType.LABEL),
189-
values=not_in_values,
190-
)
191-
176+
return NegativeAttributeFilter(label=ref_extract(f["displayForm"]), values=not_in_values)
192177
elif "relativeDateFilter" in filter_obj:
193178
f = filter_obj["relativeDateFilter"]
194179

195180
# there is filter present, but uses all time
196181
if ("from" not in f) or ("to" not in f):
197-
return AllTimeFilter(ref_extract_obj_id(f["dataSet"], ObjRefType.DATASET))
182+
return AllTimeFilter(ref_extract_obj_id(f["dataSet"]))
198183

199184
return RelativeDateFilter(
200-
dataset=ref_extract_obj_id(f["dataSet"], ObjRefType.DATASET),
185+
dataset=ref_extract_obj_id(f["dataSet"]),
201186
granularity=_GRANULARITY_CONVERSION[f["granularity"]],
202187
from_shift=f["from"],
203188
to_shift=f["to"],
@@ -206,12 +191,7 @@ def _convert_filter_to_computable(filter_obj: dict[str, Any]) -> Filter:
206191
elif "absoluteDateFilter" in filter_obj:
207192
f = filter_obj["absoluteDateFilter"]
208193

209-
return AbsoluteDateFilter(
210-
dataset=ref_extract_obj_id(f["dataSet"], ObjRefType.DATASET),
211-
from_date=f["from"],
212-
to_date=f["to"],
213-
)
214-
194+
return AbsoluteDateFilter(dataset=ref_extract_obj_id(f["dataSet"]), from_date=f["from"], to_date=f["to"])
215195
elif "measureValueFilter" in filter_obj:
216196
f = filter_obj["measureValueFilter"]
217197

@@ -231,7 +211,6 @@ def _convert_filter_to_computable(filter_obj: dict[str, Any]) -> Filter:
231211
values=c["value"],
232212
treat_nulls_as=treat_values_as_null,
233213
)
234-
235214
elif "range" in condition:
236215
c = condition["range"]
237216
treat_values_as_null = c.get("treatNullValuesAs")
@@ -241,7 +220,6 @@ def _convert_filter_to_computable(filter_obj: dict[str, Any]) -> Filter:
241220
values=(c["from"], c["to"]),
242221
treat_nulls_as=treat_values_as_null,
243222
)
244-
245223
elif "rankingFilter" in filter_obj:
246224
f = filter_obj["rankingFilter"]
247225
# mypy is unable to automatically convert Union[str, ObjId] to Union[str, ObjId, Attribute, Metric]
@@ -276,20 +254,15 @@ def _convert_metric_to_computable(metric: dict[str, Any]) -> Metric:
276254

277255
return SimpleMetric(
278256
local_id=local_id,
279-
item=ref_extract_obj_id(d["item"], ObjRefType.FACT),
257+
item=ref_extract_obj_id(d["item"]),
280258
aggregation=aggregation,
281259
compute_ratio=compute_ratio,
282260
filters=filters,
283261
)
284262

285263
elif "popMeasureDefinition" in measure_def:
286264
d = measure_def["popMeasureDefinition"]
287-
date_attributes = [
288-
PopDate(
289-
attribute=ref_extract_obj_id(d["popAttribute"], ObjRefType.ATTRIBUTE),
290-
periods_ago=1,
291-
),
292-
]
265+
date_attributes = [PopDate(attribute=ref_extract_obj_id(d["popAttribute"]), periods_ago=1)]
293266

294267
return PopDateMetric(
295268
local_id=local_id,
@@ -300,9 +273,7 @@ def _convert_metric_to_computable(metric: dict[str, Any]) -> Metric:
300273
elif "previousPeriodMeasure" in measure_def:
301274
d = measure_def["previousPeriodMeasure"]
302275

303-
date_datasets = [
304-
PopDateDataset(ref_extract(dd["dataSet"], ObjRefType.DATASET), dd["periodsAgo"]) for dd in d["dateDataSets"]
305-
]
276+
date_datasets = [PopDateDataset(ref_extract(dd["dataSet"]), dd["periodsAgo"]) for dd in d["dateDataSets"]]
306277

307278
return PopDatesetMetric(
308279
local_id=local_id,
@@ -423,11 +394,7 @@ def show_all_values(self) -> Optional[bool]:
423394
return self._a.get("showAllValues")
424395

425396
def as_computable(self) -> Attribute:
426-
return Attribute(
427-
local_id=self.local_id,
428-
label=ref_extract(self.label, ObjRefType.LABEL),
429-
show_all_values=self.show_all_values,
430-
)
397+
return Attribute(local_id=self.local_id, label=ref_extract(self.label), show_all_values=self.show_all_values)
431398

432399
def __str__(self) -> str:
433400
return self.__repr__()

gooddata-sdk/tests/table/fixtures/vis_objs/vis_with_ui_refs.json

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)