|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Any, Optional |
| 4 | + |
| 5 | +from pydantic.v1 import Field, validator |
| 6 | + |
| 7 | +from pyatlan.model.assets import Asset |
| 8 | +from pyatlan.model.assets.relations import RelationshipAttributes |
| 9 | +from pyatlan.model.core import AtlanObject |
| 10 | +from pyatlan.model.enums import SaveSemantic |
| 11 | + |
| 12 | + |
| 13 | +class UserDefRelationship(RelationshipAttributes): |
| 14 | + type_name: str = Field( |
| 15 | + allow_mutation=False, |
| 16 | + default="UserDefRelationship", |
| 17 | + description="Name of the relationship type that defines the relationship.", |
| 18 | + ) |
| 19 | + attributes: UserDefRelationship.Attributes = Field( |
| 20 | + default_factory=lambda: UserDefRelationship.Attributes(), |
| 21 | + description="Map of attributes in the instance and their values", |
| 22 | + ) |
| 23 | + |
| 24 | + class Attributes(AtlanObject): |
| 25 | + from_type_label: Optional[str] = Field( |
| 26 | + default=None, |
| 27 | + alias="fromTypeLabel", |
| 28 | + description="Name for the relationship when referring from endDef2 asset to endDef1 asset.", |
| 29 | + ) |
| 30 | + to_type_label: Optional[str] = Field( |
| 31 | + default=None, |
| 32 | + alias="toTypeLabel", |
| 33 | + description="Name for the relationship when referring from endDef1 asset to endDef2 asset.", |
| 34 | + ) |
| 35 | + |
| 36 | + def __init__(__pydantic_self__, **data: Any) -> None: |
| 37 | + if "attributes" not in data: |
| 38 | + data = {"attributes": data} |
| 39 | + super().__init__(**data) |
| 40 | + __pydantic_self__.__fields_set__.update(["attributes", "type_name"]) |
| 41 | + |
| 42 | + class UserDefRelationshipFrom(Asset): |
| 43 | + type_name: str = Field( |
| 44 | + default="UserDefRelationship", |
| 45 | + description="Name of the relationship type that defines the relationship.", |
| 46 | + ) |
| 47 | + relationship_type: str = Field( |
| 48 | + default="UserDefRelationship", |
| 49 | + const=True, |
| 50 | + description="Fixed typeName for UserDefRelationship.", |
| 51 | + ) |
| 52 | + relationship_attributes: UserDefRelationship = Field( |
| 53 | + default=None, |
| 54 | + description="Attributes of the UserDefRelationship.", |
| 55 | + ) |
| 56 | + |
| 57 | + @validator("type_name") |
| 58 | + def validate_type_name(cls, v): |
| 59 | + return v |
| 60 | + |
| 61 | + def __init__(__pydantic_self__, **data: Any) -> None: |
| 62 | + super().__init__(**data) |
| 63 | + __pydantic_self__.__fields_set__.update(["type_name", "relationship_type"]) |
| 64 | + |
| 65 | + class UserDefRelationshipTo(Asset): |
| 66 | + type_name: str = Field( |
| 67 | + default="UserDefRelationship", |
| 68 | + description="Name of the relationship type that defines the relationship.", |
| 69 | + ) |
| 70 | + relationship_type: str = Field( |
| 71 | + default="UserDefRelationship", |
| 72 | + description="Fixed typeName for UserDefRelationship.", |
| 73 | + ) |
| 74 | + relationship_attributes: UserDefRelationship = Field( |
| 75 | + default=None, |
| 76 | + description="Attributes of the UserDefRelationship.", |
| 77 | + ) |
| 78 | + |
| 79 | + @validator("type_name") |
| 80 | + def validate_type_name(cls, v): |
| 81 | + return v |
| 82 | + |
| 83 | + def __init__(__pydantic_self__, **data: Any) -> None: |
| 84 | + super().__init__(**data) |
| 85 | + __pydantic_self__.__fields_set__.update(["type_name", "relationship_type"]) |
| 86 | + |
| 87 | + def user_def_relationship_to( |
| 88 | + self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE |
| 89 | + ) -> UserDefRelationship.UserDefRelationshipTo: |
| 90 | + if related.guid: |
| 91 | + return UserDefRelationship.UserDefRelationshipTo._create_ref( |
| 92 | + type_name=related.type_name, |
| 93 | + guid=related.guid, |
| 94 | + semantic=semantic, |
| 95 | + relationship_attributes=self, |
| 96 | + ) |
| 97 | + |
| 98 | + # If the related asset does not have a GUID, we use qualifiedName |
| 99 | + return UserDefRelationship.UserDefRelationshipTo._create_ref( |
| 100 | + type_name=related.type_name, |
| 101 | + unique_attributes={"qualifiedName": related.qualified_name}, |
| 102 | + semantic=semantic, |
| 103 | + relationship_attributes=self, |
| 104 | + ) |
| 105 | + |
| 106 | + def user_def_relationship_from( |
| 107 | + self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE |
| 108 | + ) -> UserDefRelationship.UserDefRelationshipFrom: |
| 109 | + if related.guid: |
| 110 | + return UserDefRelationship.UserDefRelationshipfrom._create_ref( |
| 111 | + type_name=related.type_name, |
| 112 | + guid=related.guid, |
| 113 | + semantic=semantic, |
| 114 | + relationship_attributes=self, |
| 115 | + ) |
| 116 | + |
| 117 | + # If the related asset does not have a GUID, we use qualifiedName |
| 118 | + return UserDefRelationship.UserDefRelationshipfrom._create_ref( |
| 119 | + type_name=related.type_name, |
| 120 | + unique_attributes={"qualifiedName": related.qualified_name}, |
| 121 | + semantic=semantic, |
| 122 | + relationship_attributes=self, |
| 123 | + ) |
| 124 | + |
| 125 | + |
| 126 | +UserDefRelationship.UserDefRelationshipTo.update_forward_refs() |
| 127 | +UserDefRelationship.UserDefRelationshipFrom.update_forward_refs() |
| 128 | +UserDefRelationship.update_forward_refs() |
0 commit comments