Skip to content

Commit bd42454

Browse files
Merge pull request #758 from gooddata/cbon-lx-432-filterby-exactfilter-options-for-collectLabelElement-api
feat: Support filterBy and exactFilter options for collectLabelElement API
2 parents 0efba91 + 202d323 commit bd42454

File tree

5 files changed

+197
-0
lines changed

5 files changed

+197
-0
lines changed

gooddata-sdk/gooddata_sdk/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
ExportRequest,
6868
ExportSettings,
6969
)
70+
from gooddata_sdk.catalog.filter_by import CatalogFilterBy
7071
from gooddata_sdk.catalog.identifier import (
7172
CatalogAssigneeIdentifier,
7273
CatalogDatasetWorkspaceDataFilterIdentifier,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# (C) 2024 GoodData Corporation
2+
from __future__ import annotations
3+
4+
from typing import Type
5+
6+
import attr
7+
from gooddata_api_client.model.filter_by import FilterBy
8+
9+
from gooddata_sdk.catalog.base import Base
10+
11+
12+
@attr.s(auto_attribs=True, kw_only=True)
13+
class CatalogFilterBy(Base):
14+
label_type: str
15+
16+
@staticmethod
17+
def client_class() -> Type[FilterBy]:
18+
return FilterBy

gooddata-sdk/gooddata_sdk/catalog/workspace/content_service.py

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from gooddata_sdk.catalog.catalog_service_base import CatalogServiceBase
1313
from gooddata_sdk.catalog.data_source.validation.data_source import DataSourceValidator
1414
from gooddata_sdk.catalog.depends_on import CatalogDependsOn, CatalogDependsOnDateFilter
15+
from gooddata_sdk.catalog.filter_by import CatalogFilterBy
1516
from gooddata_sdk.catalog.types import ValidObjects
1617
from gooddata_sdk.catalog.validate_by_item import CatalogValidateByItem
1718
from gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model import (
@@ -564,6 +565,8 @@ def get_label_elements(
564565
label_id: LabelElementsInputType,
565566
depends_on: Optional[List[DependsOnItem]] = None,
566567
validate_by: Optional[List[CatalogValidateByItem]] = None,
568+
exact_filter: Optional[List[str]] = None,
569+
filter_by: Optional[CatalogFilterBy] = None,
567570
) -> List[str]:
568571
"""
569572
Get existing values for a label.
@@ -580,6 +583,11 @@ def get_label_elements(
580583
Optional parameter specifying dependencies on other labels or date filters.
581584
validate_by (Optional[List[CatalogValidateByItem]]):
582585
Optional parameter specifying validation metrics, attributes, labels or facts.
586+
exact_filter (Optional[List[str]]):
587+
Optional parameter specifying exact filter values.
588+
filter_by (Optional[CatalogFilterBy]):
589+
Optional parameter specifying which label is used for filtering - primary or requested.
590+
If omitted the server will use the default value of "REQUESTED"
583591
Returns:
584592
list of label values
585593
"""
@@ -597,6 +605,13 @@ def get_label_elements(
597605
request = ElementsRequest(
598606
label=label_id, depends_on=[d.to_api() for d in depends_on], validate_by=[v.to_api() for v in validate_by]
599607
)
608+
609+
if exact_filter is not None:
610+
request.exact_filter = exact_filter
611+
612+
if filter_by is not None:
613+
request.filter_by = filter_by.to_api()
614+
600615
# TODO - fix return type of Paging.next in Backend + add support for this API to SDK
601616
values = self._actions_api.compute_label_elements_post(workspace_id, request, _check_return_type=False)
602617
return [v["title"] for v in values["elements"]]

gooddata-sdk/tests/catalog/fixtures/workspace_content/label_elements.yaml

+150
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,153 @@ interactions:
368368
offset: 0
369369
next: null
370370
cacheId: 7fe933d079b4018b591f0cd7ea30185f
371+
- request:
372+
method: POST
373+
uri: http://localhost:3000/api/v1/actions/workspaces/demo/execution/collectLabelElements
374+
body:
375+
label: order_status
376+
dependsOn:
377+
- label: order_status
378+
values:
379+
- Canceled
380+
- Delivered
381+
complementFilter: false
382+
validateBy: [ ]
383+
headers:
384+
Accept:
385+
- application/json
386+
Accept-Encoding:
387+
- br, gzip, deflate
388+
Content-Type:
389+
- application/json
390+
X-GDC-VALIDATE-RELATIONS:
391+
- 'true'
392+
X-Requested-With:
393+
- XMLHttpRequest
394+
response:
395+
status:
396+
code: 200
397+
message: OK
398+
headers:
399+
Cache-Control:
400+
- no-cache, no-store, max-age=0, must-revalidate
401+
Content-Length:
402+
- '261'
403+
Content-Type:
404+
- application/json
405+
DATE: *id001
406+
Expires:
407+
- '0'
408+
Featurepolicy:
409+
- geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr
410+
'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope
411+
'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none';
412+
Pragma:
413+
- no-cache
414+
Referrer-Policy:
415+
- same-origin
416+
Set-Cookie:
417+
- SPRING_REDIRECT_URI=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00
418+
GMT; HttpOnly; SameSite=Lax
419+
Vary:
420+
- Origin
421+
- Access-Control-Request-Method
422+
- Access-Control-Request-Headers
423+
X-Content-Type-Options:
424+
- nosniff
425+
X-Frame-Options:
426+
- SAMEORIGIN
427+
X-GDC-TRACE-ID: *id001
428+
X-Xss-Protection:
429+
- 1; mode=block
430+
body:
431+
string:
432+
primaryLabel:
433+
id: order_status
434+
type: label
435+
elements:
436+
- title: Canceled
437+
primaryTitle: Canceled
438+
- title: Delivered
439+
primaryTitle: Delivered
440+
paging:
441+
total: 2
442+
count: 2
443+
offset: 0
444+
next: null
445+
cacheId: 11c8c486e7cc0402e6f14bc0dd3f1d35
446+
- request:
447+
method: POST
448+
uri: http://localhost:3000/api/v1/actions/workspaces/demo/execution/collectLabelElements
449+
body:
450+
label: customer_name
451+
dependsOn: [ ]
452+
validateBy: [ ]
453+
exactFilter:
454+
- 'C-02AZUA9H'
455+
- 'C-0159TVP7'
456+
filterBy:
457+
labelType: PRIMARY
458+
headers:
459+
Accept:
460+
- application/json
461+
Accept-Encoding:
462+
- br, gzip, deflate
463+
Content-Type:
464+
- application/json
465+
X-GDC-VALIDATE-RELATIONS:
466+
- 'true'
467+
X-Requested-With:
468+
- XMLHttpRequest
469+
response:
470+
status:
471+
code: 200
472+
message: OK
473+
headers:
474+
Cache-Control:
475+
- no-cache, no-store, max-age=0, must-revalidate
476+
Content-Length:
477+
- '273'
478+
Content-Type:
479+
- application/json
480+
DATE: *id001
481+
Expires:
482+
- '0'
483+
Featurepolicy:
484+
- geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr
485+
'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope
486+
'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none';
487+
Pragma:
488+
- no-cache
489+
Referrer-Policy:
490+
- same-origin
491+
Set-Cookie:
492+
- SPRING_REDIRECT_URI=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00
493+
GMT; HttpOnly; SameSite=Lax
494+
Vary:
495+
- Origin
496+
- Access-Control-Request-Method
497+
- Access-Control-Request-Headers
498+
X-Content-Type-Options:
499+
- nosniff
500+
X-Frame-Options:
501+
- SAMEORIGIN
502+
X-GDC-TRACE-ID: *id001
503+
X-Xss-Protection:
504+
- 1; mode=block
505+
body:
506+
string:
507+
primaryLabel:
508+
id: customer_id
509+
type: label
510+
elements:
511+
- title: Jennifer Miller
512+
primaryTitle: C-02AZUA9H
513+
- title: William Ross
514+
primaryTitle: C-0159TVP7
515+
paging:
516+
total: 2
517+
count: 2
518+
offset: 0
519+
next: null
520+
cacheId: 940798a736c77273652b9cfd53254528

gooddata-sdk/tests/catalog/test_catalog_workspace_content.py

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CatalogDependsOn,
1717
CatalogDependsOnDateFilter,
1818
CatalogEntityIdentifier,
19+
CatalogFilterBy,
1920
CatalogValidateByItem,
2021
CatalogWorkspace,
2122
DataSourceValidator,
@@ -407,6 +408,18 @@ def test_label_elements(test_config):
407408
test_config["workspace"], "order_status", [depends_on_date_relative], []
408409
)
409410
assert label_values == []
411+
exact_filter = None
412+
filter_by = None
413+
label_values = sdk.catalog_workspace_content.get_label_elements(
414+
test_config["workspace"], "order_status", [depends_on], [], exact_filter, filter_by
415+
)
416+
assert label_values == ["Canceled", "Delivered"]
417+
exact_filter = ["C-02AZUA9H", "C-0159TVP7"]
418+
filter_by: CatalogFilterBy = CatalogFilterBy(label_type="PRIMARY")
419+
label_values = sdk.catalog_workspace_content.get_label_elements(
420+
test_config["workspace"], "customer_name", [], [], exact_filter, filter_by
421+
)
422+
assert label_values == ["Jennifer Miller", "William Ross"]
410423

411424

412425
@gd_vcr.use_cassette(str(_fixtures_dir / "explicit_workspace_data_filter.yaml"))

0 commit comments

Comments
 (0)