Skip to content

Commit 4b4206d

Browse files
committed
feat(LAB-3887): add isJsonProcessingEnabled support to cloud storage SDK
1 parent 8c0cf47 commit 4b4206d

5 files changed

Lines changed: 56 additions & 2 deletions

File tree

src/kili/adapters/kili_api_gateway/cloud_storage/mappers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ def data_connection_where_mapper(filters: DataConnectionFilters) -> dict:
3131

3232
def add_data_connection_data_mapper(data: AddDataConnectionKiliAPIGatewayInput) -> dict:
3333
"""Build the GraphQL DataConnectionInput variable to be sent in an operation."""
34-
return {
34+
result = {
3535
"exclude": data.exclude,
3636
"include": data.include,
3737
"integrationId": data.integration_id,
3838
"prefix": data.prefix,
3939
"projectId": data.project_id,
4040
"selectedFolders": data.selected_folders,
4141
}
42+
if data.is_json_processing_enabled is not None:
43+
result["isJsonProcessingEnabled"] = data.is_json_processing_enabled
44+
return result
4245

4346

4447
def compute_data_connection_difference_data_mapper(

src/kili/adapters/kili_api_gateway/cloud_storage/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AddDataConnectionKiliAPIGatewayInput:
1919
exclude: Optional[list[str]]
2020
include: Optional[list[str]]
2121
integration_id: DataIntegrationId
22+
is_json_processing_enabled: Optional[bool]
2223
prefix: Optional[str]
2324
project_id: ProjectId
2425
selected_folders: Optional[list[str]]

src/kili/presentation/client/cloud_storage.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def cloud_storage_connections(
4444
project_id: Optional[str] = None,
4545
fields: ListOrTuple[str] = (
4646
"id",
47+
"isJsonProcessingEnabled",
4748
"lastCheck",
4849
"numberOfAssets",
4950
"selectedFolders",
@@ -65,6 +66,7 @@ def cloud_storage_connections(
6566
project_id: Optional[str] = None,
6667
fields: ListOrTuple[str] = (
6768
"id",
69+
"isJsonProcessingEnabled",
6870
"lastCheck",
6971
"numberOfAssets",
7072
"selectedFolders",
@@ -86,6 +88,7 @@ def cloud_storage_connections(
8688
project_id: Optional[str] = None,
8789
fields: ListOrTuple[str] = (
8890
"id",
91+
"isJsonProcessingEnabled",
8992
"lastCheck",
9093
"numberOfAssets",
9194
"selectedFolders",
@@ -116,7 +119,7 @@ def cloud_storage_connections(
116119
117120
Examples:
118121
>>> kili.cloud_storage_connections(project_id="789465123")
119-
[{'id': '123456789', 'lastCheck': '2023-02-21T14:49:35.606Z', 'numberOfAssets': 42, 'selectedFolders': ['folder1', 'folder2'], 'projectId': '789465123'}]
122+
[{'id': '123456789', 'isJsonProcessingEnabled': False, 'lastCheck': '2023-02-21T14:49:35.606Z', 'numberOfAssets': 42, 'selectedFolders': ['folder1', 'folder2'], 'projectId': '789465123'}]
120123
"""
121124
if (
122125
cloud_storage_connection_id is None
@@ -303,6 +306,7 @@ def add_cloud_storage_connection(
303306
prefix: Optional[str] = None,
304307
include: Optional[list[str]] = None,
305308
exclude: Optional[list[str]] = None,
309+
is_json_processing_enabled: Optional[bool] = None,
306310
) -> dict:
307311
"""Connect a cloud storage to a project. More details about parameters
308312
can be found in the [documentation](https://docs.kili-technology.com/docs/filtering-assets-from-cloud-storage).
@@ -316,6 +320,9 @@ def add_cloud_storage_connection(
316320
prefix: Filter files to synchronize based on their base path.
317321
include: List of pattern used to include files based on their path.
318322
exclude: List of pattern used to exclude files based on their path.
323+
is_json_processing_enabled: Whether JSON file synchronization is enabled.
324+
When True, JSON files are processed during synchronization
325+
to extract text content or create layered images.
319326
320327
Returns:
321328
A dict with the DataConnection Id.
@@ -333,6 +340,7 @@ def add_cloud_storage_connection(
333340
prefix=prefix,
334341
include=include,
335342
exclude=exclude,
343+
is_json_processing_enabled=is_json_processing_enabled,
336344
)["id"]
337345

338346
return {"id": data_connection_id}

src/kili/use_cases/cloud_storage/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def add_data_connection(
8181
prefix: Optional[str] = None,
8282
include: Optional[list[str]] = None,
8383
exclude: Optional[list[str]] = None,
84+
is_json_processing_enabled: Optional[bool] = None,
8485
) -> dict:
8586
"""Add data connection to a project."""
8687
if (
@@ -96,6 +97,7 @@ def add_data_connection(
9697
exclude=exclude,
9798
include=include,
9899
integration_id=data_integration_id,
100+
is_json_processing_enabled=is_json_processing_enabled,
99101
prefix=prefix,
100102
project_id=project_id,
101103
selected_folders=selected_folders,

tests/integration/adapters/kili_api_gateway/test_cloud_storage.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
DataConnectionComputeDifferencesKiliAPIGatewayInput,
44
DataIntegrationFilters,
55
)
6+
from kili.adapters.kili_api_gateway.cloud_storage.mappers import add_data_connection_data_mapper
67
from kili.adapters.kili_api_gateway.cloud_storage.operations import (
78
GQL_COUNT_DATA_INTEGRATIONS,
89
get_compute_data_connection_differences_mutation,
910
)
11+
from kili.adapters.kili_api_gateway.cloud_storage.types import AddDataConnectionKiliAPIGatewayInput
1012
from kili.adapters.kili_api_gateway.kili_api_gateway import KiliAPIGateway
1113
from kili.core.graphql.graphql_client import GraphQLClient
1214
from kili.domain.cloud_storage import DataConnectionId, DataIntegrationId
@@ -83,3 +85,41 @@ def test_given_gateway_when_calling_count_data_integrations_then_it_works(
8385
}
8486
},
8587
)
88+
89+
90+
def test_add_data_connection_mapper_includes_json_processing_when_set():
91+
# Given
92+
data = AddDataConnectionKiliAPIGatewayInput(
93+
exclude=None,
94+
include=None,
95+
integration_id=DataIntegrationId("fake_integration_id"),
96+
is_json_processing_enabled=True,
97+
prefix=None,
98+
project_id="fake_proj_id",
99+
selected_folders=None,
100+
)
101+
102+
# When
103+
result = add_data_connection_data_mapper(data)
104+
105+
# Then
106+
assert result["isJsonProcessingEnabled"] is True
107+
108+
109+
def test_add_data_connection_mapper_excludes_json_processing_when_none():
110+
# Given
111+
data = AddDataConnectionKiliAPIGatewayInput(
112+
exclude=None,
113+
include=None,
114+
integration_id=DataIntegrationId("fake_integration_id"),
115+
is_json_processing_enabled=None,
116+
prefix=None,
117+
project_id="fake_proj_id",
118+
selected_folders=None,
119+
)
120+
121+
# When
122+
result = add_data_connection_data_mapper(data)
123+
124+
# Then
125+
assert "isJsonProcessingEnabled" not in result

0 commit comments

Comments
 (0)