dapla-toolbelt-metadata 0.7.0__py3-none-any.whl → 0.7.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dapla-toolbelt-metadata might be problematic. Click here for more details.
- dapla_metadata/datasets/core.py +29 -1
- dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES +3 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py +468 -15
- dapla_metadata/variable_definitions/_generated/vardef_client/api/draft_variable_definitions_api.py +20 -51
- dapla_metadata/variable_definitions/_generated/vardef_client/api/patches_api.py +21 -52
- dapla_metadata/variable_definitions/_generated/vardef_client/api/validity_periods_api.py +13 -33
- dapla_metadata/variable_definitions/_generated/vardef_client/api/variable_definitions_api.py +16 -33
- dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py +5 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py +158 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/language_string_type.py +1 -5
- dapla_metadata/variable_definitions/_generated/vardef_client/models/owner.py +1 -4
- dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_id_response.py +81 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_vardef_id_pair_response.py +84 -0
- dapla_metadata/variable_definitions/_utils/variable_definition_files.py +23 -0
- dapla_metadata/variable_definitions/vardef.py +79 -1
- dapla_metadata/variable_definitions/vardok_id.py +44 -0
- dapla_metadata/variable_definitions/vardok_vardef_id_pair.py +43 -0
- dapla_metadata/variable_definitions/variable_definition.py +5 -18
- {dapla_toolbelt_metadata-0.7.0.dist-info → dapla_toolbelt_metadata-0.7.2.dist-info}/METADATA +1 -1
- {dapla_toolbelt_metadata-0.7.0.dist-info → dapla_toolbelt_metadata-0.7.2.dist-info}/RECORD +22 -17
- {dapla_toolbelt_metadata-0.7.0.dist-info → dapla_toolbelt_metadata-0.7.2.dist-info}/LICENSE +0 -0
- {dapla_toolbelt_metadata-0.7.0.dist-info → dapla_toolbelt_metadata-0.7.2.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Internal Variable Definitions Administration API
|
|
2
|
+
|
|
3
|
+
## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
|
|
4
|
+
|
|
5
|
+
The version of the OpenAPI document: 0.1
|
|
6
|
+
Contact: metadata@ssb.no
|
|
7
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
8
|
+
|
|
9
|
+
Do not edit the class manually.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import pprint
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from pydantic import BaseModel
|
|
19
|
+
from pydantic import ConfigDict
|
|
20
|
+
from pydantic import ValidationError
|
|
21
|
+
from pydantic import field_validator
|
|
22
|
+
from typing_extensions import Self
|
|
23
|
+
|
|
24
|
+
from ..models.complete_response import CompleteResponse
|
|
25
|
+
from ..models.vardok_id_response import VardokIdResponse
|
|
26
|
+
|
|
27
|
+
GETVARDOKVARDEFMAPPINGBYID200RESPONSE_ONE_OF_SCHEMAS = [
|
|
28
|
+
"CompleteResponse",
|
|
29
|
+
"VardokIdResponse",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class GetVardokVardefMappingById200Response(BaseModel):
|
|
34
|
+
"""GetVardokVardefMappingById200Response"""
|
|
35
|
+
|
|
36
|
+
# data type: CompleteResponse
|
|
37
|
+
oneof_schema_1_validator: CompleteResponse | None = None
|
|
38
|
+
# data type: VardokIdResponse
|
|
39
|
+
oneof_schema_2_validator: VardokIdResponse | None = None
|
|
40
|
+
actual_instance: CompleteResponse | VardokIdResponse | None = None
|
|
41
|
+
one_of_schemas: set[str] = {"CompleteResponse", "VardokIdResponse"}
|
|
42
|
+
|
|
43
|
+
model_config = ConfigDict(
|
|
44
|
+
validate_assignment=True,
|
|
45
|
+
protected_namespaces=(),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
49
|
+
if args:
|
|
50
|
+
if len(args) > 1:
|
|
51
|
+
raise ValueError(
|
|
52
|
+
"If a position argument is used, only 1 is allowed to set `actual_instance`"
|
|
53
|
+
)
|
|
54
|
+
if kwargs:
|
|
55
|
+
raise ValueError(
|
|
56
|
+
"If a position argument is used, keyword arguments cannot be used."
|
|
57
|
+
)
|
|
58
|
+
super().__init__(actual_instance=args[0])
|
|
59
|
+
else:
|
|
60
|
+
super().__init__(**kwargs)
|
|
61
|
+
|
|
62
|
+
@field_validator("actual_instance")
|
|
63
|
+
def actual_instance_must_validate_oneof(cls, v):
|
|
64
|
+
instance = GetVardokVardefMappingById200Response.model_construct()
|
|
65
|
+
error_messages = []
|
|
66
|
+
match = 0
|
|
67
|
+
# validate data type: CompleteResponse
|
|
68
|
+
if not isinstance(v, CompleteResponse):
|
|
69
|
+
error_messages.append(
|
|
70
|
+
f"Error! Input type `{type(v)}` is not `CompleteResponse`"
|
|
71
|
+
)
|
|
72
|
+
else:
|
|
73
|
+
match += 1
|
|
74
|
+
# validate data type: VardokIdResponse
|
|
75
|
+
if not isinstance(v, VardokIdResponse):
|
|
76
|
+
error_messages.append(
|
|
77
|
+
f"Error! Input type `{type(v)}` is not `VardokIdResponse`"
|
|
78
|
+
)
|
|
79
|
+
else:
|
|
80
|
+
match += 1
|
|
81
|
+
if match > 1:
|
|
82
|
+
# more than 1 match
|
|
83
|
+
raise ValueError(
|
|
84
|
+
"Multiple matches found when setting `actual_instance` in GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
|
|
85
|
+
+ ", ".join(error_messages)
|
|
86
|
+
)
|
|
87
|
+
if match == 0:
|
|
88
|
+
# no match
|
|
89
|
+
raise ValueError(
|
|
90
|
+
"No match found when setting `actual_instance` in GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
|
|
91
|
+
+ ", ".join(error_messages)
|
|
92
|
+
)
|
|
93
|
+
return v
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_dict(cls, obj: str | dict[str, Any]) -> Self:
|
|
97
|
+
return cls.from_json(json.dumps(obj))
|
|
98
|
+
|
|
99
|
+
@classmethod
|
|
100
|
+
def from_json(cls, json_str: str) -> Self:
|
|
101
|
+
"""Returns the object represented by the json string"""
|
|
102
|
+
instance = cls.model_construct()
|
|
103
|
+
error_messages = []
|
|
104
|
+
match = 0
|
|
105
|
+
|
|
106
|
+
# deserialize data into CompleteResponse
|
|
107
|
+
try:
|
|
108
|
+
instance.actual_instance = CompleteResponse.from_json(json_str)
|
|
109
|
+
match += 1
|
|
110
|
+
except (ValidationError, ValueError) as e:
|
|
111
|
+
error_messages.append(str(e))
|
|
112
|
+
# deserialize data into VardokIdResponse
|
|
113
|
+
try:
|
|
114
|
+
instance.actual_instance = VardokIdResponse.from_json(json_str)
|
|
115
|
+
match += 1
|
|
116
|
+
except (ValidationError, ValueError) as e:
|
|
117
|
+
error_messages.append(str(e))
|
|
118
|
+
|
|
119
|
+
if match > 1:
|
|
120
|
+
# more than 1 match
|
|
121
|
+
raise ValueError(
|
|
122
|
+
"Multiple matches found when deserializing the JSON string into GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
|
|
123
|
+
+ ", ".join(error_messages)
|
|
124
|
+
)
|
|
125
|
+
if match == 0:
|
|
126
|
+
# no match
|
|
127
|
+
raise ValueError(
|
|
128
|
+
"No match found when deserializing the JSON string into GetVardokVardefMappingById200Response with oneOf schemas: CompleteResponse, VardokIdResponse. Details: "
|
|
129
|
+
+ ", ".join(error_messages)
|
|
130
|
+
)
|
|
131
|
+
return instance
|
|
132
|
+
|
|
133
|
+
def to_json(self) -> str:
|
|
134
|
+
"""Returns the JSON representation of the actual instance"""
|
|
135
|
+
if self.actual_instance is None:
|
|
136
|
+
return "null"
|
|
137
|
+
|
|
138
|
+
if hasattr(self.actual_instance, "to_json") and callable(
|
|
139
|
+
self.actual_instance.to_json
|
|
140
|
+
):
|
|
141
|
+
return self.actual_instance.to_json()
|
|
142
|
+
return json.dumps(self.actual_instance)
|
|
143
|
+
|
|
144
|
+
def to_dict(self) -> dict[str, Any] | CompleteResponse | VardokIdResponse | None:
|
|
145
|
+
"""Returns the dict representation of the actual instance"""
|
|
146
|
+
if self.actual_instance is None:
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
if hasattr(self.actual_instance, "to_dict") and callable(
|
|
150
|
+
self.actual_instance.to_dict
|
|
151
|
+
):
|
|
152
|
+
return self.actual_instance.to_dict()
|
|
153
|
+
# primitive type
|
|
154
|
+
return self.actual_instance
|
|
155
|
+
|
|
156
|
+
def to_str(self) -> str:
|
|
157
|
+
"""Returns the string representation of the actual instance"""
|
|
158
|
+
return pprint.pformat(self.model_dump())
|
|
@@ -96,10 +96,6 @@ class LanguageStringType(BaseModel):
|
|
|
96
96
|
return cls.model_validate(obj)
|
|
97
97
|
|
|
98
98
|
_obj = cls.model_validate(
|
|
99
|
-
{
|
|
100
|
-
"nb": obj.get("nb"),
|
|
101
|
-
"nn": obj.get("nn"),
|
|
102
|
-
"en": obj.get("en"),
|
|
103
|
-
}
|
|
99
|
+
{"nb": obj.get("nb"), "nn": obj.get("nn"), "en": obj.get("en")}
|
|
104
100
|
)
|
|
105
101
|
return _obj
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Internal Variable Definitions Administration API
|
|
2
|
+
|
|
3
|
+
## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
|
|
4
|
+
|
|
5
|
+
The version of the OpenAPI document: 0.1
|
|
6
|
+
Contact: metadata@ssb.no
|
|
7
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
8
|
+
|
|
9
|
+
Do not edit the class manually.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import pprint
|
|
16
|
+
import re # noqa: F401
|
|
17
|
+
from typing import Any
|
|
18
|
+
from typing import ClassVar
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel
|
|
21
|
+
from pydantic import ConfigDict
|
|
22
|
+
from pydantic import StrictStr
|
|
23
|
+
from typing_extensions import Self
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class VardokIdResponse(BaseModel):
|
|
27
|
+
"""VardokIdResponse"""
|
|
28
|
+
|
|
29
|
+
vardok_id: StrictStr
|
|
30
|
+
__properties: ClassVar[list[str]] = ["vardok_id"]
|
|
31
|
+
|
|
32
|
+
model_config = ConfigDict(
|
|
33
|
+
populate_by_name=True,
|
|
34
|
+
validate_assignment=True,
|
|
35
|
+
protected_namespaces=(),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def to_str(self) -> str:
|
|
39
|
+
"""Returns the string representation of the model using alias"""
|
|
40
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
41
|
+
|
|
42
|
+
def to_json(self) -> str:
|
|
43
|
+
"""Returns the JSON representation of the model using alias"""
|
|
44
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
45
|
+
return json.dumps(self.to_dict())
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
49
|
+
"""Create an instance of VardokIdResponse from a JSON string"""
|
|
50
|
+
return cls.from_dict(json.loads(json_str))
|
|
51
|
+
|
|
52
|
+
def to_dict(self) -> dict[str, Any]:
|
|
53
|
+
"""Return the dictionary representation of the model using alias.
|
|
54
|
+
|
|
55
|
+
This has the following differences from calling pydantic's
|
|
56
|
+
`self.model_dump(by_alias=True)`:
|
|
57
|
+
|
|
58
|
+
* `None` is only added to the output dict for nullable fields that
|
|
59
|
+
were set at model initialization. Other fields with value `None`
|
|
60
|
+
are ignored.
|
|
61
|
+
"""
|
|
62
|
+
excluded_fields: set[str] = set([])
|
|
63
|
+
|
|
64
|
+
_dict = self.model_dump(
|
|
65
|
+
by_alias=True,
|
|
66
|
+
exclude=excluded_fields,
|
|
67
|
+
exclude_none=True,
|
|
68
|
+
)
|
|
69
|
+
return _dict
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
73
|
+
"""Create an instance of VardokIdResponse from a dict"""
|
|
74
|
+
if obj is None:
|
|
75
|
+
return None
|
|
76
|
+
|
|
77
|
+
if not isinstance(obj, dict):
|
|
78
|
+
return cls.model_validate(obj)
|
|
79
|
+
|
|
80
|
+
_obj = cls.model_validate({"vardok_id": obj.get("vardok_id")})
|
|
81
|
+
return _obj
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Internal Variable Definitions Administration API
|
|
2
|
+
|
|
3
|
+
## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
|
|
4
|
+
|
|
5
|
+
The version of the OpenAPI document: 0.1
|
|
6
|
+
Contact: metadata@ssb.no
|
|
7
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
8
|
+
|
|
9
|
+
Do not edit the class manually.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import pprint
|
|
16
|
+
import re # noqa: F401
|
|
17
|
+
from typing import Any
|
|
18
|
+
from typing import ClassVar
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel
|
|
21
|
+
from pydantic import ConfigDict
|
|
22
|
+
from pydantic import StrictStr
|
|
23
|
+
from typing_extensions import Self
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class VardokVardefIdPairResponse(BaseModel):
|
|
27
|
+
"""VardokVardefIdPairResponse"""
|
|
28
|
+
|
|
29
|
+
vardok_id: StrictStr
|
|
30
|
+
vardef_id: StrictStr
|
|
31
|
+
__properties: ClassVar[list[str]] = ["vardok_id", "vardef_id"]
|
|
32
|
+
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
populate_by_name=True,
|
|
35
|
+
validate_assignment=True,
|
|
36
|
+
protected_namespaces=(),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def to_str(self) -> str:
|
|
40
|
+
"""Returns the string representation of the model using alias"""
|
|
41
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
42
|
+
|
|
43
|
+
def to_json(self) -> str:
|
|
44
|
+
"""Returns the JSON representation of the model using alias"""
|
|
45
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
46
|
+
return json.dumps(self.to_dict())
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def from_json(cls, json_str: str) -> Self | None:
|
|
50
|
+
"""Create an instance of VardokVardefIdPairResponse from a JSON string"""
|
|
51
|
+
return cls.from_dict(json.loads(json_str))
|
|
52
|
+
|
|
53
|
+
def to_dict(self) -> dict[str, Any]:
|
|
54
|
+
"""Return the dictionary representation of the model using alias.
|
|
55
|
+
|
|
56
|
+
This has the following differences from calling pydantic's
|
|
57
|
+
`self.model_dump(by_alias=True)`:
|
|
58
|
+
|
|
59
|
+
* `None` is only added to the output dict for nullable fields that
|
|
60
|
+
were set at model initialization. Other fields with value `None`
|
|
61
|
+
are ignored.
|
|
62
|
+
"""
|
|
63
|
+
excluded_fields: set[str] = set([])
|
|
64
|
+
|
|
65
|
+
_dict = self.model_dump(
|
|
66
|
+
by_alias=True,
|
|
67
|
+
exclude=excluded_fields,
|
|
68
|
+
exclude_none=True,
|
|
69
|
+
)
|
|
70
|
+
return _dict
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
|
|
74
|
+
"""Create an instance of VardokVardefIdPairResponse from a dict"""
|
|
75
|
+
if obj is None:
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
if not isinstance(obj, dict):
|
|
79
|
+
return cls.model_validate(obj)
|
|
80
|
+
|
|
81
|
+
_obj = cls.model_validate(
|
|
82
|
+
{"vardok_id": obj.get("vardok_id"), "vardef_id": obj.get("vardef_id")}
|
|
83
|
+
)
|
|
84
|
+
return _obj
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Utilities for writing and reading existing variable definition files."""
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
+
from io import StringIO
|
|
4
5
|
from os import PathLike
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from typing import Any
|
|
@@ -19,6 +20,7 @@ from dapla_metadata.variable_definitions._utils.files import (
|
|
|
19
20
|
_model_to_yaml_with_comments,
|
|
20
21
|
)
|
|
21
22
|
from dapla_metadata.variable_definitions._utils.files import configure_yaml
|
|
23
|
+
from dapla_metadata.variable_definitions._utils.files import pre_process_data
|
|
22
24
|
|
|
23
25
|
logger = logging.getLogger(__name__)
|
|
24
26
|
|
|
@@ -118,3 +120,24 @@ def _read_file_to_model(
|
|
|
118
120
|
msg = f"Could not read data from {file_path}"
|
|
119
121
|
raise FileNotFoundError(msg)
|
|
120
122
|
return model
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _convert_to_yaml_output(model: BaseModel) -> str:
|
|
126
|
+
"""Convert a Pydantic model to YAML format.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
model: A Pydantic model instance
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
YAML string representation of the model
|
|
133
|
+
"""
|
|
134
|
+
stream = StringIO()
|
|
135
|
+
with YAML(output=stream) as yaml:
|
|
136
|
+
configure_yaml(yaml)
|
|
137
|
+
data = model.model_dump(
|
|
138
|
+
mode="json",
|
|
139
|
+
serialize_as_any=True,
|
|
140
|
+
warnings="error",
|
|
141
|
+
)
|
|
142
|
+
yaml.dump(pre_process_data(data))
|
|
143
|
+
return stream.getvalue()
|
|
@@ -12,9 +12,15 @@ from dapla_metadata.variable_definitions._generated.vardef_client.api.draft_vari
|
|
|
12
12
|
from dapla_metadata.variable_definitions._generated.vardef_client.api.variable_definitions_api import (
|
|
13
13
|
VariableDefinitionsApi,
|
|
14
14
|
)
|
|
15
|
+
from dapla_metadata.variable_definitions._generated.vardef_client.models.complete_response import (
|
|
16
|
+
CompleteResponse,
|
|
17
|
+
)
|
|
15
18
|
from dapla_metadata.variable_definitions._generated.vardef_client.models.draft import (
|
|
16
19
|
Draft,
|
|
17
20
|
)
|
|
21
|
+
from dapla_metadata.variable_definitions._generated.vardef_client.models.vardok_id_response import (
|
|
22
|
+
VardokIdResponse,
|
|
23
|
+
)
|
|
18
24
|
from dapla_metadata.variable_definitions._utils import config
|
|
19
25
|
from dapla_metadata.variable_definitions._utils._client import VardefClient
|
|
20
26
|
from dapla_metadata.variable_definitions._utils.template_files import (
|
|
@@ -29,6 +35,8 @@ from dapla_metadata.variable_definitions._utils.variable_definition_files import
|
|
|
29
35
|
from dapla_metadata.variable_definitions.exceptions import VariableNotFoundError
|
|
30
36
|
from dapla_metadata.variable_definitions.exceptions import vardef_exception_handler
|
|
31
37
|
from dapla_metadata.variable_definitions.exceptions import vardef_file_error_handler
|
|
38
|
+
from dapla_metadata.variable_definitions.vardok_id import VardokId
|
|
39
|
+
from dapla_metadata.variable_definitions.vardok_vardef_id_pair import VardokVardefIdPair
|
|
32
40
|
from dapla_metadata.variable_definitions.variable_definition import VariableDefinition
|
|
33
41
|
|
|
34
42
|
logger = logging.getLogger(__name__)
|
|
@@ -171,6 +179,76 @@ class Vardef:
|
|
|
171
179
|
)
|
|
172
180
|
return migrated_variable
|
|
173
181
|
|
|
182
|
+
@classmethod
|
|
183
|
+
@vardef_exception_handler
|
|
184
|
+
def list_vardok_vardef_mapping(cls) -> list[VardokVardefIdPair]:
|
|
185
|
+
"""List the mapping between vardok and vardef.
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
List[VardokVardefIdPair]: The list with mappings between Vardok and Vardef
|
|
189
|
+
"""
|
|
190
|
+
return [
|
|
191
|
+
VardokVardefIdPair.from_model(definition)
|
|
192
|
+
for definition in DataMigrationApi(
|
|
193
|
+
VardefClient.get_client(),
|
|
194
|
+
).get_vardok_vardef_mapping()
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
@classmethod
|
|
198
|
+
@vardef_exception_handler
|
|
199
|
+
def get_variable_definition_by_vardok_id(
|
|
200
|
+
cls,
|
|
201
|
+
vardok_id: str,
|
|
202
|
+
) -> VariableDefinition:
|
|
203
|
+
"""Get a Variable Definition by its Vardok ID.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
vardok_id (str): The Vardok ID of the desired Variable Definition
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
VariableDefinition: The Variable Definition.
|
|
210
|
+
|
|
211
|
+
Raises:
|
|
212
|
+
TypeError: If the incorrect type is returned.
|
|
213
|
+
"""
|
|
214
|
+
raw_response = DataMigrationApi(
|
|
215
|
+
VardefClient.get_client()
|
|
216
|
+
).get_vardok_vardef_mapping_by_id(
|
|
217
|
+
vardok_id,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
if isinstance(raw_response.actual_instance, CompleteResponse):
|
|
221
|
+
return VariableDefinition.from_model(raw_response.actual_instance)
|
|
222
|
+
msg = "Unexpected response type"
|
|
223
|
+
raise TypeError(msg)
|
|
224
|
+
|
|
225
|
+
@classmethod
|
|
226
|
+
@vardef_exception_handler
|
|
227
|
+
def get_vardok_id_by_short_name(
|
|
228
|
+
cls,
|
|
229
|
+
short_name: str,
|
|
230
|
+
) -> VardokId:
|
|
231
|
+
"""Retrieve a Vardok id by short name.
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
short_name (str): The short name of the desired Variable Definition
|
|
235
|
+
|
|
236
|
+
Raises:
|
|
237
|
+
TypeError: If the incorrect type is returned.
|
|
238
|
+
"""
|
|
239
|
+
variable_definition = cls.get_variable_definition_by_shortname(short_name)
|
|
240
|
+
|
|
241
|
+
raw_response = DataMigrationApi(
|
|
242
|
+
VardefClient.get_client()
|
|
243
|
+
).get_vardok_vardef_mapping_by_id(
|
|
244
|
+
variable_definition.id,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
if isinstance(raw_response.actual_instance, VardokIdResponse):
|
|
248
|
+
return VardokId.from_model(raw_response.actual_instance)
|
|
249
|
+
msg = "Unexpected response type"
|
|
250
|
+
raise TypeError(msg)
|
|
251
|
+
|
|
174
252
|
@classmethod
|
|
175
253
|
@vardef_exception_handler
|
|
176
254
|
def list_variable_definitions(
|
|
@@ -235,7 +313,7 @@ class Vardef:
|
|
|
235
313
|
short_name: str,
|
|
236
314
|
date_of_validity: date | None = None,
|
|
237
315
|
) -> VariableDefinition:
|
|
238
|
-
"""Retrieve a Variable Definition by
|
|
316
|
+
"""Retrieve a Variable Definition by short name.
|
|
239
317
|
|
|
240
318
|
Args:
|
|
241
319
|
short_name (str): The short name of the Variable Definition.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from pydantic import ConfigDict
|
|
5
|
+
from pydantic import PrivateAttr
|
|
6
|
+
|
|
7
|
+
from dapla_metadata.variable_definitions._generated.vardef_client.models.vardok_id_response import (
|
|
8
|
+
VardokIdResponse,
|
|
9
|
+
)
|
|
10
|
+
from dapla_metadata.variable_definitions._utils.variable_definition_files import (
|
|
11
|
+
_convert_to_yaml_output,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class VardokId(VardokIdResponse):
|
|
18
|
+
"""A Vardok id.
|
|
19
|
+
|
|
20
|
+
- Provides access to the Vardok id filed.
|
|
21
|
+
- Provides methods allowing maintenance for nicer output of the Vardok id.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
VardokIdResponse: The Pydantic model superclass, representing a Vardok id response.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
_file_path: Path | None = PrivateAttr(None)
|
|
28
|
+
|
|
29
|
+
model_config = ConfigDict(use_enum_values=True, str_strip_whitespace=True)
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def from_model(
|
|
33
|
+
model: VardokIdResponse,
|
|
34
|
+
) -> "VardokId":
|
|
35
|
+
"""Create a VariableDefinition instance from a CompleteResponse."""
|
|
36
|
+
return VardokId.model_construct(**model.model_dump())
|
|
37
|
+
|
|
38
|
+
def __str__(self) -> str:
|
|
39
|
+
"""Format as indented YAML."""
|
|
40
|
+
return _convert_to_yaml_output(self)
|
|
41
|
+
|
|
42
|
+
def __repr__(self) -> str:
|
|
43
|
+
"""Format as indented YAML."""
|
|
44
|
+
return _convert_to_yaml_output(self)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from pydantic import ConfigDict
|
|
5
|
+
from pydantic import PrivateAttr
|
|
6
|
+
|
|
7
|
+
from dapla_metadata.variable_definitions._generated.vardef_client.models.vardok_vardef_id_pair_response import (
|
|
8
|
+
VardokVardefIdPairResponse,
|
|
9
|
+
)
|
|
10
|
+
from dapla_metadata.variable_definitions._utils.variable_definition_files import (
|
|
11
|
+
_convert_to_yaml_output,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class VardokVardefIdPair(VardokVardefIdPairResponse):
|
|
18
|
+
"""A Vardok id.
|
|
19
|
+
|
|
20
|
+
- Provides access to the fields of a Vardok Vardef id pair.
|
|
21
|
+
- Provides methods allowing for nicer output of the Vardok Vardef id pair.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
VardokVardefIdPairResponse: The Pydantic model superclass, representing a Vardok Vardef id pair response.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
_file_path: Path | None = PrivateAttr(None)
|
|
28
|
+
model_config = ConfigDict(use_enum_values=True, str_strip_whitespace=True)
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def from_model(
|
|
32
|
+
model: VardokVardefIdPairResponse,
|
|
33
|
+
) -> "VardokVardefIdPair":
|
|
34
|
+
"""Create a VardokVardefIdPair instance from a VardokVardefIdPairResponse."""
|
|
35
|
+
return VardokVardefIdPair.model_construct(**model.model_dump())
|
|
36
|
+
|
|
37
|
+
def __str__(self) -> str:
|
|
38
|
+
"""Format as indented YAML."""
|
|
39
|
+
return _convert_to_yaml_output(self)
|
|
40
|
+
|
|
41
|
+
def __repr__(self) -> str:
|
|
42
|
+
"""Format as indented YAML."""
|
|
43
|
+
return _convert_to_yaml_output(self)
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
from datetime import date
|
|
3
|
-
from io import StringIO
|
|
4
3
|
from os import PathLike
|
|
5
4
|
from pathlib import Path
|
|
6
5
|
|
|
7
|
-
import ruamel.yaml
|
|
8
6
|
from pydantic import ConfigDict
|
|
9
7
|
from pydantic import PrivateAttr
|
|
10
8
|
|
|
@@ -34,8 +32,9 @@ from dapla_metadata.variable_definitions._generated.vardef_client.models.variabl
|
|
|
34
32
|
)
|
|
35
33
|
from dapla_metadata.variable_definitions._utils import config
|
|
36
34
|
from dapla_metadata.variable_definitions._utils._client import VardefClient
|
|
37
|
-
from dapla_metadata.variable_definitions._utils.
|
|
38
|
-
|
|
35
|
+
from dapla_metadata.variable_definitions._utils.variable_definition_files import (
|
|
36
|
+
_convert_to_yaml_output,
|
|
37
|
+
)
|
|
39
38
|
from dapla_metadata.variable_definitions._utils.variable_definition_files import (
|
|
40
39
|
_read_file_to_model,
|
|
41
40
|
)
|
|
@@ -399,20 +398,8 @@ class VariableDefinition(CompleteResponse):
|
|
|
399
398
|
|
|
400
399
|
def __str__(self) -> str:
|
|
401
400
|
"""Format as indented YAML."""
|
|
402
|
-
return
|
|
401
|
+
return _convert_to_yaml_output(self)
|
|
403
402
|
|
|
404
403
|
def __repr__(self) -> str:
|
|
405
404
|
"""Format as indented YAML."""
|
|
406
|
-
return
|
|
407
|
-
|
|
408
|
-
def _convert_to_yaml_output(self) -> str:
|
|
409
|
-
stream = StringIO()
|
|
410
|
-
with ruamel.yaml.YAML(output=stream) as yaml:
|
|
411
|
-
configure_yaml(yaml)
|
|
412
|
-
data = self.model_dump(
|
|
413
|
-
mode="json",
|
|
414
|
-
serialize_as_any=True,
|
|
415
|
-
warnings="error",
|
|
416
|
-
)
|
|
417
|
-
yaml.dump(pre_process_data(data))
|
|
418
|
-
return stream.getvalue()
|
|
405
|
+
return _convert_to_yaml_output(self)
|