|
27 | 27 | from pyatlan_v9.model.transform import register_asset |
28 | 28 |
|
29 | 29 | from .adf_related import ( |
| 30 | + RelatedAdfActivity, |
30 | 31 | RelatedAdfDataflow, |
31 | 32 | RelatedAdfDataset, |
32 | 33 | RelatedAdfLinkedservice, |
@@ -302,6 +303,74 @@ def __post_init__(self) -> None: |
302 | 303 |
|
303 | 304 | _QUALIFIED_NAME_PATTERN: ClassVar[re.Pattern] = re.compile(r"^.+/[^/]+/[^/]+$") |
304 | 305 |
|
| 306 | + def validate(self, for_creation: bool = False) -> None: |
| 307 | + """ |
| 308 | + Dry-run validation of this AdfActivity instance. |
| 309 | +
|
| 310 | + Checks that required fields (type_name, name, qualified_name) are set. |
| 311 | + When ``for_creation=True``, also checks hierarchy-specific fields |
| 312 | + (parent references, denormalized attributes) needed to create this asset. |
| 313 | +
|
| 314 | + This is purely opt-in and is NOT called by any serde path — only by |
| 315 | + explicit user invocation (e.g., validating JSONL before sending to Atlan). |
| 316 | +
|
| 317 | + Args: |
| 318 | + for_creation: If True, also validate fields required for asset creation. |
| 319 | +
|
| 320 | + Raises: |
| 321 | + ValueError: If any required fields are missing or invalid. |
| 322 | + """ |
| 323 | + errors: list[str] = [] |
| 324 | + if self.type_name is UNSET: |
| 325 | + errors.append("type_name is required") |
| 326 | + if self.name is UNSET: |
| 327 | + errors.append("name is required") |
| 328 | + if self.qualified_name is UNSET or self.qualified_name is None: |
| 329 | + errors.append("qualified_name is required") |
| 330 | + elif not self._QUALIFIED_NAME_PATTERN.match(self.qualified_name): |
| 331 | + errors.append( |
| 332 | + f"qualified_name '{self.qualified_name}' does not match expected " |
| 333 | + f"pattern: {self._QUALIFIED_NAME_PATTERN.pattern}" |
| 334 | + ) |
| 335 | + if for_creation: |
| 336 | + if self.connection_qualified_name is UNSET: |
| 337 | + errors.append("connection_qualified_name is required for creation") |
| 338 | + if self.adf_pipeline is UNSET: |
| 339 | + errors.append("adf_pipeline is required for creation") |
| 340 | + if self.adf_pipeline_qualified_name is UNSET: |
| 341 | + errors.append("adf_pipeline_qualified_name is required for creation") |
| 342 | + if errors: |
| 343 | + raise ValueError(f"AdfActivity validation failed: {errors}") |
| 344 | + |
| 345 | + def minimize(self) -> "AdfActivity": |
| 346 | + """ |
| 347 | + Return a minimal copy of this AdfActivity with only updater-required fields. |
| 348 | +
|
| 349 | + Calls :meth:`validate` first to ensure the instance is valid, then |
| 350 | + returns a new AdfActivity with only the fields needed for an update |
| 351 | + (qualified_name, name, and any type-specific additional fields). |
| 352 | +
|
| 353 | + Returns: |
| 354 | + A new AdfActivity instance with only the minimum required fields. |
| 355 | + """ |
| 356 | + self.validate() |
| 357 | + return AdfActivity(qualified_name=self.qualified_name, name=self.name) |
| 358 | + |
| 359 | + def relate(self) -> "RelatedAdfActivity": |
| 360 | + """ |
| 361 | + Create a :class:`RelatedAdfActivity` reference from this instance. |
| 362 | +
|
| 363 | + Returns a lightweight reference suitable for use in relationship |
| 364 | + attributes. Prefers ``guid`` if set, otherwise falls back to |
| 365 | + ``qualified_name``. |
| 366 | +
|
| 367 | + Returns: |
| 368 | + A RelatedAdfActivity reference to this asset. |
| 369 | + """ |
| 370 | + if self.guid is not UNSET: |
| 371 | + return RelatedAdfActivity(guid=self.guid) |
| 372 | + return RelatedAdfActivity(qualified_name=self.qualified_name) |
| 373 | + |
305 | 374 | # ========================================================================= |
306 | 375 | # Optimized Serialization Methods (override Asset base class) |
307 | 376 | # ========================================================================= |
|
0 commit comments