Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP-4334 make processing for method for transform for single value match that of multiple values #324

Merged
merged 8 commits into from
Feb 15, 2024
22 changes: 15 additions & 7 deletions tcex/api/tc/ti_transform/transform_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections.abc import Callable
from datetime import datetime
from inspect import signature
from typing import Any
from typing import Any, cast

# third-party
import jmespath
Expand Down Expand Up @@ -157,6 +157,7 @@ def _process(self):
self._process_security_labels(self.transform.security_labels or [])
self._process_tags(self.transform.tags or [])

# date fields
# date fields
self._process_metadata_datetime('dateAdded', self.transform.date_added)
self._process_metadata_datetime('lastModified', self.transform.last_modified)
Expand All @@ -167,6 +168,13 @@ def _process(self):
self._process_metadata_datetime(
'externalLastModified', self.transform.external_last_modified
)
self._process_metadata_datetime('firstSeen', self.transform.first_seen)
self._process_metadata_datetime('lastSeen', self.transform.first_seen)
self._process_metadata_datetime('externalDateAdded', self.transform.external_date_added)
self._process_metadata_datetime('externalDateExpires', self.transform.external_date_expires)
self._process_metadata_datetime(
'externalLastModified', self.transform.external_last_modified
)

# xid
self._process_metadata('xid', self.transform.xid)
Expand Down Expand Up @@ -466,12 +474,12 @@ def _transform_value(self, metadata: MetadataTransformModel | None) -> str | Non

for t in metadata.transform or []:
# pass value to static_map or callable, but never both
if isinstance(value, str):
if t.filter_map is not None:
value = self._transform_value_map(value, t.filter_map, True)
elif t.static_map is not None:
value = self._transform_value_map(value, t.static_map)
elif value is not None and callable(t.method):
value = cast(Any, value) # due to line 472, we know value is not None.
if t.filter_map is not None:
value = self._transform_value_map(value, t.filter_map, True)
elif t.static_map is not None:
value = self._transform_value_map(value, t.static_map)
elif callable(t.method):
value = self._transform_value_callable(value, t.method, t.kwargs)

# ensure only a string value or None is returned (set to default if required)
Expand Down
Loading