cognite-neat 0.76.1__py3-none-any.whl → 0.76.3__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 cognite-neat might be problematic. Click here for more details.
- cognite/neat/_version.py +1 -1
- cognite/neat/app/api/routers/core.py +1 -1
- cognite/neat/app/api/routers/rules.py +1 -1
- cognite/neat/graph/extractors/_mock_graph_generator.py +2 -2
- cognite/neat/rules/_shared.py +1 -1
- cognite/neat/rules/analysis/_information_rules.py +3 -3
- cognite/neat/rules/exporters/_base.py +1 -1
- cognite/neat/rules/exporters/_rules2dms.py +8 -49
- cognite/neat/rules/exporters/_rules2excel.py +71 -40
- cognite/neat/rules/exporters/_rules2ontology.py +2 -2
- cognite/neat/rules/exporters/_rules2yaml.py +1 -1
- cognite/neat/rules/exporters/_validation.py +2 -2
- cognite/neat/rules/importers/_base.py +1 -1
- cognite/neat/rules/importers/_dms2rules.py +93 -108
- cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py +1 -1
- cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py +2 -3
- cognite/neat/rules/importers/_owl2rules/_owl2classes.py +1 -1
- cognite/neat/rules/importers/_owl2rules/_owl2metadata.py +2 -2
- cognite/neat/rules/importers/_owl2rules/_owl2properties.py +1 -1
- cognite/neat/rules/importers/_owl2rules/_owl2rules.py +1 -1
- cognite/neat/rules/importers/_spreadsheet2rules.py +87 -62
- cognite/neat/rules/importers/_yaml2rules.py +3 -3
- cognite/neat/rules/issues/base.py +5 -0
- cognite/neat/rules/issues/dms.py +65 -0
- cognite/neat/rules/models/__init__.py +27 -0
- cognite/neat/rules/models/dms/__init__.py +18 -0
- cognite/neat/rules/models/dms/_converter.py +140 -0
- cognite/neat/rules/models/dms/_exporter.py +405 -0
- cognite/neat/rules/models/dms/_rules.py +379 -0
- cognite/neat/rules/models/{rules/_dms_rules_write.py → dms/_rules_input.py} +42 -33
- cognite/neat/rules/models/{rules/_dms_schema.py → dms/_schema.py} +36 -4
- cognite/neat/rules/models/dms/_serializer.py +126 -0
- cognite/neat/rules/models/dms/_validation.py +288 -0
- cognite/neat/rules/models/{rules/_domain_rules.py → domain.py} +1 -0
- cognite/neat/rules/models/information/__init__.py +3 -0
- cognite/neat/rules/models/information/_converter.py +195 -0
- cognite/neat/rules/models/{rules/_information_rules.py → information/_rules.py} +35 -202
- cognite/neat/workflows/steps/data_contracts.py +1 -1
- cognite/neat/workflows/steps/lib/current/rules_exporter.py +10 -3
- cognite/neat/workflows/steps/lib/current/rules_importer.py +1 -1
- cognite/neat/workflows/steps/lib/current/rules_validator.py +1 -2
- {cognite_neat-0.76.1.dist-info → cognite_neat-0.76.3.dist-info}/METADATA +1 -1
- {cognite_neat-0.76.1.dist-info → cognite_neat-0.76.3.dist-info}/RECORD +51 -44
- cognite/neat/rules/models/rules/__init__.py +0 -14
- cognite/neat/rules/models/rules/_dms_architect_rules.py +0 -1255
- /cognite/neat/rules/models/{rules/_base.py → _base.py} +0 -0
- /cognite/neat/rules/models/{rdfpath.py → _rdfpath.py} +0 -0
- /cognite/neat/rules/models/{rules/_types → _types}/__init__.py +0 -0
- /cognite/neat/rules/models/{rules/_types → _types}/_base.py +0 -0
- /cognite/neat/rules/models/{rules/_types → _types}/_field.py +0 -0
- {cognite_neat-0.76.1.dist-info → cognite_neat-0.76.3.dist-info}/LICENSE +0 -0
- {cognite_neat-0.76.1.dist-info → cognite_neat-0.76.3.dist-info}/WHEEL +0 -0
- {cognite_neat-0.76.1.dist-info → cognite_neat-0.76.3.dist-info}/entry_points.txt +0 -0
cognite/neat/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.76.
|
|
1
|
+
__version__ = "0.76.3"
|
|
@@ -9,7 +9,7 @@ from fastapi import APIRouter, UploadFile
|
|
|
9
9
|
|
|
10
10
|
from cognite.neat.app.api.configuration import NEAT_APP
|
|
11
11
|
from cognite.neat.rules import exporters, importers
|
|
12
|
-
from cognite.neat.rules.models
|
|
12
|
+
from cognite.neat.rules.models import DMSRules, RoleTypes
|
|
13
13
|
|
|
14
14
|
router = APIRouter()
|
|
15
15
|
|
|
@@ -12,7 +12,7 @@ from cognite.neat.legacy.rules import importers as legacy_importers
|
|
|
12
12
|
from cognite.neat.legacy.rules.models._base import EntityTypes
|
|
13
13
|
from cognite.neat.legacy.rules.models.rules import Class, Classes, Metadata, Properties, Property, Rules
|
|
14
14
|
from cognite.neat.rules import importers
|
|
15
|
-
from cognite.neat.rules.models
|
|
15
|
+
from cognite.neat.rules.models import RoleTypes
|
|
16
16
|
from cognite.neat.workflows.steps.data_contracts import RulesData
|
|
17
17
|
from cognite.neat.workflows.steps.lib.current.rules_exporter import RulesToExcel
|
|
18
18
|
from cognite.neat.workflows.steps.lib.current.rules_importer import ExcelToRules
|
|
@@ -14,10 +14,10 @@ from rdflib import RDF, Literal, Namespace, URIRef
|
|
|
14
14
|
|
|
15
15
|
from cognite.neat.graph.models import Triple
|
|
16
16
|
from cognite.neat.rules.analysis import InformationArchitectRulesAnalysis
|
|
17
|
+
from cognite.neat.rules.models import DMSRules, InformationRules
|
|
17
18
|
from cognite.neat.rules.models.data_types import DataType
|
|
18
19
|
from cognite.neat.rules.models.entities import ClassEntity, EntityTypes
|
|
19
|
-
from cognite.neat.rules.models.
|
|
20
|
-
from cognite.neat.rules.models.rules._information_rules import InformationProperty
|
|
20
|
+
from cognite.neat.rules.models.information import InformationProperty
|
|
21
21
|
from cognite.neat.utils.utils import remove_namespace
|
|
22
22
|
|
|
23
23
|
from ._base import BaseExtractor
|
cognite/neat/rules/_shared.py
CHANGED
|
@@ -7,10 +7,10 @@ from typing import Any, cast
|
|
|
7
7
|
import pandas as pd
|
|
8
8
|
from pydantic import ValidationError
|
|
9
9
|
|
|
10
|
+
from cognite.neat.rules.models import SchemaCompleteness
|
|
11
|
+
from cognite.neat.rules.models._rdfpath import TransformationRuleType
|
|
10
12
|
from cognite.neat.rules.models.entities import ClassEntity, EntityTypes, ParentClassEntity, ReferenceEntity
|
|
11
|
-
from cognite.neat.rules.models.
|
|
12
|
-
from cognite.neat.rules.models.rules._base import SchemaCompleteness
|
|
13
|
-
from cognite.neat.rules.models.rules._information_rules import InformationClass, InformationProperty, InformationRules
|
|
13
|
+
from cognite.neat.rules.models.information import InformationClass, InformationProperty, InformationRules
|
|
14
14
|
from cognite.neat.utils.utils import get_inheritance_path
|
|
15
15
|
|
|
16
16
|
from ._base import BaseAnalysis, DataModelingScenario
|
|
@@ -6,7 +6,7 @@ from typing import Generic, TypeVar
|
|
|
6
6
|
from cognite.client import CogniteClient
|
|
7
7
|
|
|
8
8
|
from cognite.neat.rules._shared import Rules
|
|
9
|
-
from cognite.neat.rules.models
|
|
9
|
+
from cognite.neat.rules.models import DMSRules, InformationRules, RoleTypes
|
|
10
10
|
|
|
11
11
|
from ._models import UploadResult
|
|
12
12
|
|
|
@@ -11,10 +11,8 @@ from cognite.client.exceptions import CogniteAPIError
|
|
|
11
11
|
from cognite.neat.rules import issues
|
|
12
12
|
from cognite.neat.rules._shared import Rules
|
|
13
13
|
from cognite.neat.rules.issues import IssueList
|
|
14
|
-
from cognite.neat.rules.models
|
|
15
|
-
from cognite.neat.rules.models.
|
|
16
|
-
from cognite.neat.rules.models.rules._dms_architect_rules import DMSContainer, DMSRules
|
|
17
|
-
from cognite.neat.rules.models.rules._dms_schema import DMSSchema, PipelineSchema
|
|
14
|
+
from cognite.neat.rules.models import InformationRules
|
|
15
|
+
from cognite.neat.rules.models.dms import DMSRules, DMSSchema, PipelineSchema
|
|
18
16
|
from cognite.neat.utils.cdf_loaders import (
|
|
19
17
|
ContainerLoader,
|
|
20
18
|
DataModelingLoader,
|
|
@@ -116,47 +114,9 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
116
114
|
dms_rules = rules.as_dms_architect_rules()
|
|
117
115
|
else:
|
|
118
116
|
raise ValueError(f"{type(rules).__name__} cannot be exported to DMS")
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
dms_rules.reference and dms_rules.metadata.external_id != dms_rules.reference.metadata.external_id
|
|
117
|
+
return dms_rules.as_schema(
|
|
118
|
+
include_ref=True, include_pipeline=self.export_pipeline, instance_space=self.instance_space
|
|
122
119
|
)
|
|
123
|
-
is_new_model = dms_rules.reference is None
|
|
124
|
-
if is_new_model or is_solution_model:
|
|
125
|
-
return dms_rules.as_schema(False, self.export_pipeline, self.instance_space)
|
|
126
|
-
|
|
127
|
-
# This is an extension of an existing model.
|
|
128
|
-
reference_rules = cast(DMSRules, dms_rules.reference).model_copy(deep=True)
|
|
129
|
-
reference_schema = reference_rules.as_schema(include_ref=False, include_pipeline=self.export_pipeline)
|
|
130
|
-
|
|
131
|
-
# Todo Move this to an appropriate location
|
|
132
|
-
# Merging Reference with User Rules
|
|
133
|
-
combined_rules = dms_rules.model_copy(deep=True)
|
|
134
|
-
existing_containers = {container.class_ for container in combined_rules.containers or []}
|
|
135
|
-
if combined_rules.containers is None:
|
|
136
|
-
combined_rules.containers = SheetList[DMSContainer](data=[])
|
|
137
|
-
for container in reference_rules.containers or []:
|
|
138
|
-
if container.class_ not in existing_containers:
|
|
139
|
-
container.reference = None
|
|
140
|
-
combined_rules.containers.append(container)
|
|
141
|
-
existing_views = {view.class_ for view in combined_rules.views}
|
|
142
|
-
for view in reference_rules.views:
|
|
143
|
-
if view.class_ not in existing_views:
|
|
144
|
-
view.reference = None
|
|
145
|
-
combined_rules.views.append(view)
|
|
146
|
-
existing_properties = {(property_.class_, property_.property_) for property_ in combined_rules.properties}
|
|
147
|
-
for property_ in reference_rules.properties:
|
|
148
|
-
if (property_.class_, property_.property_) not in existing_properties:
|
|
149
|
-
property_.reference = None
|
|
150
|
-
combined_rules.properties.append(property_)
|
|
151
|
-
|
|
152
|
-
schema = combined_rules.as_schema(True, self.export_pipeline, self.instance_space)
|
|
153
|
-
|
|
154
|
-
if dms_rules.metadata.extension in (ExtensionCategory.addition, ExtensionCategory.reshape):
|
|
155
|
-
# We do not freeze views as they might be changed, even for addition,
|
|
156
|
-
# in case, for example, new properties are added. The validation will catch this.
|
|
157
|
-
schema.frozen_ids.update(set(reference_schema.containers.as_ids()))
|
|
158
|
-
schema.frozen_ids.update(set(reference_schema.node_types.as_ids()))
|
|
159
|
-
return schema
|
|
160
120
|
|
|
161
121
|
def delete_from_cdf(self, rules: Rules, client: CogniteClient, dry_run: bool = False) -> Iterable[UploadResult]:
|
|
162
122
|
schema, to_export = self._prepare_schema_and_exporters(rules, client)
|
|
@@ -165,8 +125,7 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
165
125
|
# as they are sorted in the order of creation and we need to delete them in reverse order
|
|
166
126
|
for all_items, loader in reversed(to_export):
|
|
167
127
|
all_item_ids = loader.get_ids(all_items)
|
|
168
|
-
|
|
169
|
-
item_ids = [item_id for item_id in all_item_ids if item_id not in schema.frozen_ids]
|
|
128
|
+
item_ids = [item_id for item_id in all_item_ids]
|
|
170
129
|
cdf_items = loader.retrieve(item_ids)
|
|
171
130
|
cdf_item_by_id = {loader.get_id(item): item for item in cdf_items}
|
|
172
131
|
items = [item for item in all_items if loader.get_id(item) in item_ids]
|
|
@@ -200,7 +159,7 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
200
159
|
yield UploadResult(
|
|
201
160
|
name=loader.resource_name,
|
|
202
161
|
deleted=deleted,
|
|
203
|
-
skipped=
|
|
162
|
+
skipped=0,
|
|
204
163
|
failed_deleted=failed_deleted,
|
|
205
164
|
error_messages=error_messages,
|
|
206
165
|
)
|
|
@@ -215,8 +174,7 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
215
174
|
for all_items, loader in to_export:
|
|
216
175
|
issue_list = IssueList()
|
|
217
176
|
all_item_ids = loader.get_ids(all_items)
|
|
218
|
-
|
|
219
|
-
item_ids = [item_id for item_id in all_item_ids if item_id not in schema.frozen_ids]
|
|
177
|
+
item_ids = [item_id for item_id in all_item_ids]
|
|
220
178
|
cdf_items = loader.retrieve(item_ids)
|
|
221
179
|
cdf_item_by_id = {loader.get_id(item): item for item in cdf_items}
|
|
222
180
|
items = [item for item in all_items if loader.get_id(item) in item_ids]
|
|
@@ -243,6 +201,7 @@ class DMSExporter(CDFExporter[DMSSchema]):
|
|
|
243
201
|
|
|
244
202
|
created = len(to_create)
|
|
245
203
|
failed_created = 0
|
|
204
|
+
skipped = 0
|
|
246
205
|
|
|
247
206
|
if self.existing_handling in ["update", "force"]:
|
|
248
207
|
changed = len(to_update)
|
|
@@ -12,8 +12,16 @@ from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
|
|
|
12
12
|
from openpyxl.worksheet.worksheet import Worksheet
|
|
13
13
|
|
|
14
14
|
from cognite.neat.rules._shared import Rules
|
|
15
|
-
from cognite.neat.rules.models
|
|
16
|
-
|
|
15
|
+
from cognite.neat.rules.models import (
|
|
16
|
+
DataModelType,
|
|
17
|
+
DMSRules,
|
|
18
|
+
DomainRules,
|
|
19
|
+
ExtensionCategory,
|
|
20
|
+
InformationRules,
|
|
21
|
+
RoleTypes,
|
|
22
|
+
SchemaCompleteness,
|
|
23
|
+
SheetEntity,
|
|
24
|
+
)
|
|
17
25
|
|
|
18
26
|
from ._base import BaseExporter
|
|
19
27
|
|
|
@@ -29,11 +37,18 @@ class ExcelExporter(BaseExporter[Workbook]):
|
|
|
29
37
|
new_model_id: The new model ID to use for the exported spreadsheet. This is only applicable if the input
|
|
30
38
|
rules have 'is_reference' set. If provided, the model ID will be used to automatically create the
|
|
31
39
|
new metadata sheet in the Excel file.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
dump_as: This determines how the rules are written to the Excel file. An Excel file has up to three sets of
|
|
41
|
+
sheets: user, last, and reference. The user sheets are used for inputting rules from a user. The last sheets
|
|
42
|
+
are used for the last version of the same model as the user, while the reference sheets are used for
|
|
43
|
+
the model the user is building on. The options are:
|
|
44
|
+
* "user": The rules are written to the user sheets. This is used when you want to modify the rules
|
|
45
|
+
directly and potentially change the model. This is useful when you have imported the data model
|
|
46
|
+
from outside CDF and you want to modify it before you write it to CDF.
|
|
47
|
+
* "last": The rules are written to the last sheets. This is used when you want to extend the rules,
|
|
48
|
+
but have validation that you are not breaking the existing model. This is used when you want to
|
|
49
|
+
change a model that has already been published to CDF and that model is in production.
|
|
50
|
+
* "reference": The rules are written to the reference sheets. This is typically used when you want to build
|
|
51
|
+
a new solution on top of an enterprise model.
|
|
37
52
|
|
|
38
53
|
The following styles are available:
|
|
39
54
|
|
|
@@ -45,7 +60,7 @@ class ExcelExporter(BaseExporter[Workbook]):
|
|
|
45
60
|
"""
|
|
46
61
|
|
|
47
62
|
Style = Literal["none", "minimal", "default", "maximal"]
|
|
48
|
-
|
|
63
|
+
DumpOptions = Literal["user", "last", "reference"]
|
|
49
64
|
_main_header_by_sheet_name: ClassVar[dict[str, str]] = {
|
|
50
65
|
"Properties": "Definition of Properties per Class",
|
|
51
66
|
"Classes": "Definition of Classes",
|
|
@@ -53,21 +68,24 @@ class ExcelExporter(BaseExporter[Workbook]):
|
|
|
53
68
|
"Containers": "Definition of Containers",
|
|
54
69
|
}
|
|
55
70
|
style_options = get_args(Style)
|
|
71
|
+
dump_options = get_args(DumpOptions)
|
|
56
72
|
|
|
57
73
|
def __init__(
|
|
58
74
|
self,
|
|
59
75
|
styling: Style = "default",
|
|
60
76
|
output_role: RoleTypes | None = None,
|
|
61
77
|
new_model_id: tuple[str, str, str] | None = None,
|
|
62
|
-
|
|
78
|
+
dump_as: DumpOptions = "user",
|
|
63
79
|
):
|
|
64
80
|
if styling not in self.style_options:
|
|
65
81
|
raise ValueError(f"Invalid styling: {styling}. Valid options are {self.style_options}")
|
|
82
|
+
if dump_as not in self.dump_options:
|
|
83
|
+
raise ValueError(f"Invalid dump_as: {dump_as}. Valid options are {self.dump_options}")
|
|
66
84
|
self.styling = styling
|
|
67
85
|
self._styling_level = self.style_options.index(styling)
|
|
68
86
|
self.output_role = output_role
|
|
69
87
|
self.new_model_id = new_model_id
|
|
70
|
-
self.
|
|
88
|
+
self.dump_as = dump_as
|
|
71
89
|
|
|
72
90
|
def export_to_file(self, rules: Rules, filepath: Path) -> None:
|
|
73
91
|
"""Exports transformation rules to excel file."""
|
|
@@ -84,41 +102,48 @@ class ExcelExporter(BaseExporter[Workbook]):
|
|
|
84
102
|
# Remove default sheet named "Sheet"
|
|
85
103
|
workbook.remove(workbook["Sheet"])
|
|
86
104
|
|
|
87
|
-
|
|
105
|
+
dumped_user_rules: dict[str, Any]
|
|
106
|
+
dumped_last_rules: dict[str, Any] | None = None
|
|
88
107
|
dumped_reference_rules: dict[str, Any] | None = None
|
|
89
|
-
if self.
|
|
108
|
+
if self.dump_as != "user":
|
|
90
109
|
# Writes empty reference sheets
|
|
91
|
-
|
|
110
|
+
dumped_user_rules = {
|
|
92
111
|
"Metadata": self._create_metadata_sheet_user_rules(rules),
|
|
93
112
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
113
|
+
|
|
114
|
+
if self.dump_as == "last":
|
|
115
|
+
dumped_last_rules = rules.model_dump(by_alias=True)
|
|
116
|
+
if rules.reference:
|
|
117
|
+
dumped_reference_rules = rules.reference.model_dump(by_alias=True)
|
|
118
|
+
elif self.dump_as == "reference":
|
|
119
|
+
dumped_reference_rules = rules.reference_self().model_dump(by_alias=True)
|
|
98
120
|
else:
|
|
99
|
-
|
|
121
|
+
dumped_user_rules = rules.model_dump(by_alias=True)
|
|
122
|
+
if rules.last:
|
|
123
|
+
dumped_last_rules = rules.last.model_dump(by_alias=True)
|
|
100
124
|
if rules.reference:
|
|
101
125
|
dumped_reference_rules = rules.reference.model_dump(by_alias=True)
|
|
102
126
|
|
|
103
|
-
self._write_metadata_sheet(workbook,
|
|
104
|
-
self._write_sheets(workbook,
|
|
127
|
+
self._write_metadata_sheet(workbook, dumped_user_rules["Metadata"])
|
|
128
|
+
self._write_sheets(workbook, dumped_user_rules, rules)
|
|
129
|
+
if dumped_last_rules:
|
|
130
|
+
self._write_sheets(workbook, dumped_last_rules, rules, sheet_prefix="Last")
|
|
131
|
+
|
|
105
132
|
if dumped_reference_rules:
|
|
106
|
-
|
|
107
|
-
self.
|
|
133
|
+
prefix = "Ref"
|
|
134
|
+
self._write_sheets(workbook, dumped_reference_rules, rules, sheet_prefix=prefix)
|
|
135
|
+
self._write_metadata_sheet(workbook, dumped_reference_rules["Metadata"], sheet_prefix=prefix)
|
|
108
136
|
|
|
109
137
|
if self._styling_level > 0:
|
|
110
138
|
self._adjust_column_widths(workbook)
|
|
111
139
|
|
|
112
140
|
return workbook
|
|
113
141
|
|
|
114
|
-
def _write_sheets(self, workbook: Workbook, dumped_rules: dict[str, Any], rules: Rules,
|
|
142
|
+
def _write_sheets(self, workbook: Workbook, dumped_rules: dict[str, Any], rules: Rules, sheet_prefix: str = ""):
|
|
115
143
|
for sheet_name, headers in rules.headers_by_sheet(by_alias=True).items():
|
|
116
|
-
if sheet_name in ("Metadata", "prefixes", "Reference", "
|
|
144
|
+
if sheet_name in ("Metadata", "prefixes", "Reference", "Last"):
|
|
117
145
|
continue
|
|
118
|
-
|
|
119
|
-
sheet = workbook.create_sheet(f"Ref{sheet_name}")
|
|
120
|
-
else:
|
|
121
|
-
sheet = workbook.create_sheet(sheet_name)
|
|
146
|
+
sheet = workbook.create_sheet(f"{sheet_prefix}{sheet_name}")
|
|
122
147
|
|
|
123
148
|
main_header = self._main_header_by_sheet_name[sheet_name]
|
|
124
149
|
sheet.append([main_header] + [""] * (len(headers) - 1))
|
|
@@ -164,17 +189,14 @@ class ExcelExporter(BaseExporter[Workbook]):
|
|
|
164
189
|
for cell in sheet["2"]:
|
|
165
190
|
cell.font = Font(bold=True, size=14)
|
|
166
191
|
|
|
167
|
-
def _write_metadata_sheet(self, workbook: Workbook, metadata: dict[str, Any],
|
|
192
|
+
def _write_metadata_sheet(self, workbook: Workbook, metadata: dict[str, Any], sheet_prefix: str = "") -> None:
|
|
168
193
|
# Excel does not support timezone in datetime strings
|
|
169
194
|
if isinstance(metadata.get("created"), datetime):
|
|
170
195
|
metadata["created"] = metadata["created"].replace(tzinfo=None)
|
|
171
196
|
if isinstance(metadata.get("updated"), datetime):
|
|
172
197
|
metadata["updated"] = metadata["updated"].replace(tzinfo=None)
|
|
173
198
|
|
|
174
|
-
|
|
175
|
-
metadata_sheet = workbook.create_sheet("RefMetadata")
|
|
176
|
-
else:
|
|
177
|
-
metadata_sheet = workbook.create_sheet("Metadata")
|
|
199
|
+
metadata_sheet = workbook.create_sheet(f"{sheet_prefix}Metadata")
|
|
178
200
|
for key, value in metadata.items():
|
|
179
201
|
metadata_sheet.append([key, value])
|
|
180
202
|
|
|
@@ -235,25 +257,29 @@ class ExcelExporter(BaseExporter[Workbook]):
|
|
|
235
257
|
# Excel does not support timezone in datetime strings
|
|
236
258
|
now_iso = datetime.now().replace(tzinfo=None).isoformat()
|
|
237
259
|
is_info = isinstance(rules, InformationRules)
|
|
238
|
-
is_dms =
|
|
239
|
-
is_extension = self.new_model_id is not None
|
|
240
|
-
is_solution =
|
|
260
|
+
is_dms = isinstance(rules, DMSRules)
|
|
261
|
+
is_extension = self.new_model_id is not None or rules.reference is not None
|
|
262
|
+
is_solution = rules.metadata.data_model_type == DataModelType.solution
|
|
241
263
|
|
|
242
|
-
if is_solution:
|
|
264
|
+
if is_solution and self.new_model_id:
|
|
243
265
|
metadata["prefix" if is_info else "space"] = self.new_model_id[0] # type: ignore[index]
|
|
244
266
|
metadata["title" if is_info else "externalId"] = self.new_model_id[1] # type: ignore[index]
|
|
245
267
|
metadata["version"] = self.new_model_id[2] # type: ignore[index]
|
|
268
|
+
elif is_solution and self.dump_as == "reference" and rules.reference:
|
|
269
|
+
metadata["prefix" if is_info else "space"] = "YOUR_PREFIX"
|
|
270
|
+
metadata["title" if is_info else "externalId"] = "YOUR_TITLE"
|
|
271
|
+
metadata["version"] = "1"
|
|
246
272
|
else:
|
|
247
273
|
metadata["prefix" if is_info else "space"] = existing_model_id[0]
|
|
248
274
|
metadata["title" if is_info else "externalId"] = existing_model_id[1]
|
|
249
275
|
metadata["version"] = existing_model_id[2]
|
|
250
276
|
|
|
251
|
-
if is_solution and is_info:
|
|
277
|
+
if is_solution and is_info and self.new_model_id:
|
|
252
278
|
metadata["namespace"] = f"http://purl.org/{self.new_model_id[0]}/" # type: ignore[index]
|
|
253
279
|
elif is_info:
|
|
254
280
|
metadata["namespace"] = existing_metadata["namespace"]
|
|
255
281
|
|
|
256
|
-
if is_solution and is_dms:
|
|
282
|
+
if is_solution and is_dms and self.new_model_id:
|
|
257
283
|
metadata["name"] = self.new_model_id[1] # type: ignore[index]
|
|
258
284
|
|
|
259
285
|
if is_solution:
|
|
@@ -279,6 +305,11 @@ class ExcelExporter(BaseExporter[Workbook]):
|
|
|
279
305
|
else:
|
|
280
306
|
metadata["schema"] = SchemaCompleteness.complete.value
|
|
281
307
|
|
|
282
|
-
|
|
308
|
+
if is_solution:
|
|
309
|
+
metadata["dataModelType"] = DataModelType.solution.value
|
|
310
|
+
else:
|
|
311
|
+
metadata["dataModelType"] = DataModelType.enterprise.value
|
|
283
312
|
|
|
313
|
+
metadata["extension"] = ExtensionCategory.addition.value
|
|
314
|
+
metadata["role"] = (self.output_role and self.output_role.value) or rules.metadata.role.value
|
|
284
315
|
return metadata
|
|
@@ -11,10 +11,10 @@ from rdflib.collection import Collection as GraphCollection
|
|
|
11
11
|
from cognite.neat.constants import DEFAULT_NAMESPACE as NEAT_NAMESPACE
|
|
12
12
|
from cognite.neat.rules import exceptions
|
|
13
13
|
from cognite.neat.rules.analysis import InformationArchitectRulesAnalysis
|
|
14
|
+
from cognite.neat.rules.models import DMSRules
|
|
14
15
|
from cognite.neat.rules.models.data_types import DataType
|
|
15
16
|
from cognite.neat.rules.models.entities import ClassEntity, EntityTypes
|
|
16
|
-
from cognite.neat.rules.models.
|
|
17
|
-
from cognite.neat.rules.models.rules._information_rules import (
|
|
17
|
+
from cognite.neat.rules.models.information import (
|
|
18
18
|
InformationClass,
|
|
19
19
|
InformationMetadata,
|
|
20
20
|
InformationProperty,
|
|
@@ -4,8 +4,8 @@ from typing import Literal, overload
|
|
|
4
4
|
|
|
5
5
|
from cognite.neat.exceptions import wrangle_warnings
|
|
6
6
|
from cognite.neat.rules import exceptions
|
|
7
|
-
from cognite.neat.rules.models
|
|
8
|
-
from cognite.neat.rules.models.
|
|
7
|
+
from cognite.neat.rules.models import InformationRules
|
|
8
|
+
from cognite.neat.rules.models._types._base import DMS_PROPERTY_ID_COMPLIANCE_REGEX, VIEW_ID_COMPLIANCE_REGEX
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@overload
|
|
@@ -11,7 +11,7 @@ from rdflib import Namespace
|
|
|
11
11
|
|
|
12
12
|
from cognite.neat.rules._shared import Rules
|
|
13
13
|
from cognite.neat.rules.issues.base import IssueList, NeatValidationError, ValidationWarning
|
|
14
|
-
from cognite.neat.rules.models
|
|
14
|
+
from cognite.neat.rules.models import DMSRules, InformationRules, RoleTypes
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class BaseImporter(ABC):
|