@@ -11,7 +11,13 @@ from typing import Any, ClassVar, Dict, List, Optional, TypeVar
1111
1212from pydantic import Field, StrictStr, root_validator, validator
1313
14- from pyatlan.model.core import Announcement, AtlanObject, CustomMetadata, Classification, Meaning
14+ from pyatlan.model.core import (
15+ Announcement,
16+ AtlanObject,
17+ CustomMetadata,
18+ Classification,
19+ Meaning,
20+ )
1521from pyatlan.model.enums import (
1622 ADLSAccessTier,
1723 ADLSAccountStatus,
@@ -37,7 +43,7 @@ from pyatlan.model.enums import (
3743 QueryUsernameStrategy,
3844 SourceCostUnitType,
3945 GoogleDatastudioAssetType,
40- PowerbiEndorsement
46+ PowerbiEndorsement,
4147)
4248from pyatlan.model.internal import AtlasServer, Internal
4349from pyatlan.model.structs import (
@@ -55,9 +61,10 @@ from pyatlan.model.structs import (
5561 PopularityInsights,
5662 SourceTagAttribute,
5763)
58- from pyatlan.utils import next_id
64+ from pyatlan.utils import next_id, validate_required_fields
5965from urllib.parse import quote, unquote
6066
67+
6168def validate_single_required_field(field_names: list[str], values: list[Any]):
6269 indexes = [idx for idx, value in enumerate(values) if value is not None]
6370 if not indexes:
@@ -70,39 +77,8 @@ def validate_single_required_field(field_names: list[str], values: list[Any]):
7077 f"Only one of the following parameters are allowed: {', '.join(names)}"
7178 )
7279
73- def validate_required_fields(field_names: list[str], values: list[Any]):
74- for field_name, value in zip(field_names, values):
75- if value is None:
76- raise ValueError(f"{field_name} is required")
77- if isinstance(value, str) and not value.strip():
78- raise ValueError(f"{field_name} cannot be blank")
79- if isinstance(value, list) and len(value) == 0:
80- raise ValueError(f"{field_name} cannot be an empty list")
81- {% - macro gen_properties (attribute_defs , additional_names =[]) %}
82- _convience_properties: ClassVar[list[str]] = [
83- {% - for attribute_def in attribute_defs %}
84- "{{ attribute_def.name | to_snake_case }}",
85- {% - endfor %}
86- {% - for name in additional_names %}
87- "{{ name }}",
88- {% - endfor %} ]
89-
90- {% - for attribute_def in attribute_defs %}
91- {% - set type = attribute_def .typeName | get_type %}
92- {% - set property_type %}{% if attribute_def .isOptional %} Optional[{% endif %} {{type}}{% if attribute_def .isOptional %} ]{% endif %}{% endset %}
93- {% - set property_name = attribute_def .name | to_snake_case %}
94- @property
95- def {{ property_name }}(self)->{{ property_type }}:
96- return self.attributes.{{ property_name }}
97-
98- @{{ property_name }}.setter
99- def {{ property_name }}(self, {{ property_name }}:{{ property_type }}):
100- if self.attributes is None:
101- self.attributes = self.Attributes()
102- self.attributes.{{ property_name }} = {{ property_name }}
10380
104- {% - endfor %}
105- {% endmacro %}
81+ {% from 'macros.jinja2' import gen_properties %}
10682SelfAsset = TypeVar("SelfAsset", bound="Asset")
10783{% for entity_def in entity_defs %}
10884{% - set super_classes = ['AtlanObject' ] if not entity_def .super_types else entity_def .super_types -%}
@@ -367,11 +343,20 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
367343 {% - if entity_def .name == "Badge" %}
368344 @classmethod
369345 # @validate_arguments()
370- def create(cls, *, name: StrictStr, cm_name: str, cm_attribute: str) -> Badge:
371- validate_required_fields(["name", "cm_name", "cm_attribute"], [name])
346+ def create(
347+ cls,
348+ *,
349+ name: StrictStr,
350+ cm_name: str,
351+ cm_attribute: str,
352+ badge_conditions: list[BadgeCondition],
353+ ) -> Badge:
372354 return cls(
373355 attributes=Badge.Attributes.create(
374- name=name, cm_name=cm_name, cm_attribute=cm_attribute
356+ name=name,
357+ cm_name=cm_name,
358+ cm_attribute=cm_attribute,
359+ badge_conditions=badge_conditions,
375360 )
376361 )
377362 {% - elif entity_def .name == "Readme" %}
@@ -540,10 +525,16 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
540525 @classmethod
541526 # @validate_arguments()
542527 def create(
543- cls, *, name: StrictStr, cm_name: str, cm_attribute: str
528+ cls,
529+ *,
530+ name: StrictStr,
531+ cm_name: str,
532+ cm_attribute: str,
533+ badge_conditions: list[BadgeCondition],
544534 ) -> Badge.Attributes:
545535 validate_required_fields(
546- ["name", "cm_name", "cm_attribute"], [name, cm_name, cm_attribute]
536+ ["name", "cm_name", "cm_attribute", "badge_conditions"],
537+ [name, cm_name, cm_attribute, badge_conditions],
547538 )
548539 from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
549540
@@ -555,6 +546,7 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
555546 name=name,
556547 qualified_name=f"badges/global/{cm_id}.{cm_attr_id}",
557548 badge_metadata_attribute=f"{cm_id}.{cm_attr_id}",
549+ badge_conditions=badge_conditions,
558550 )
559551 {% - elif entity_def .name == "Readme" %}
560552 @classmethod
0 commit comments