-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load LDM from BIRD website content, and use codes #1345
- Loading branch information
1 parent
70b1b68
commit 6c4cd45
Showing
7 changed files
with
302 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
bird/birdseed_creator/src/entry_points/sddmodel_to_datamodel_ldm.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# coding=UTF-8# | ||
# Copyright (c) 2020 Bird Software Solutions Ltd | ||
# This program and the accompanying materials | ||
# are made available under the terms of the Eclipse Public License 2.0 | ||
# which accompanies this distribution, and is available at | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Neil Mackenzie - initial API and implementation | ||
# | ||
''' | ||
Created on 25 April 2022 | ||
''' | ||
|
||
from entry_points.website_to_sddmodel import RunWebsiteToSDDModel | ||
from context.context import Context | ||
from context.sdd_context import SDDContext | ||
from process_steps.sddmodel_to_datamodel.translate_sddmodel_to_datamodel import TranslateSDDModelToDataModel | ||
from persister.persist_to_file import PersistToFile | ||
from utils.ldm_relationship_enricher import LDMRelationshipEnricher | ||
|
||
|
||
class RunSDDModelToDataModelLDM: | ||
|
||
def run(self,context,sdd_context): | ||
context.persist_to_regdna = True | ||
context.load_eil_from_website = True | ||
context.load_ldm = True | ||
TranslateSDDModelToDataModel().do_import(context,sdd_context) | ||
LDMRelationshipEnricher.enrich(self,context) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
sdd_context = SDDContext() | ||
context = Context() | ||
context.file_directory = '/workspaces/efbt/bird/birdseed_creator/resources' | ||
context.output_directory = '/workspaces/efbt/bird/birdseed_creator/results' | ||
sdd_context.file_directory = '/workspaces/efbt/bird/birdseed_creator/resources' | ||
sdd_context.output_directory = '/workspaces/efbt/bird/birdseed_creator/results' | ||
RunWebsiteToSDDModel().run(sdd_context) | ||
RunSDDModelToDataModelLDM().run(context,sdd_context) | ||
persister = PersistToFile() | ||
persister.save_model_as_regdna_file(context) | ||
persister.save_model_as_xmi_file(context) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
bird/birdseed_creator/src/utils/enrich_ldm_with_il_links_from_fe.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# coding=UTF-8# | ||
# Copyright (c) 2020 Bird Software Solutions Ltd | ||
# This program and the accompanying materials | ||
# are made available under the terms of the Eclipse Public License 2.0 | ||
# which accompanies this distribution, and is available at | ||
# https://www.eclipse.org/legal/epl-2.0/ | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# Neil Mackenzie - initial API and implementation | ||
# | ||
import csv | ||
from ldm_utils.utils import Utils | ||
import os | ||
|
||
from regdna import ELAttribute, ELClass, ELEnum, ELEnumLiteral, ELOperation, ELReference, ELAnnotation, ELStringToStringMapEntry | ||
|
||
class InputLayerLinkEnricher(object): | ||
''' | ||
After the Forward Engineering process has been run on the LDM, | ||
SQLDevelepor stores information about how whicj column in the Input | ||
Layer was created by forward engineering an attribute in the LDM. | ||
In SQLdeveloper these are accessed via the 'Impacty analysis' | ||
Feature..so we can see what is the equivelent Input Layer column | ||
for an LDM attribute. | ||
This class is responsable for adding an Annotation to the LDM attribute | ||
to show the name of the linked Input Layer column. The name | ||
is represented in a 'TableName.ColumnName' format. | ||
''' | ||
|
||
def enrich_with_links_to_input_layer_columns(self, context): | ||
''' | ||
Enrich the attributes of classes of our LDM package with an annotation | ||
To show what input layer column is related to LDM attribute. | ||
''' | ||
InputLayerLinkEnricher.create_attribute_to_column_links(self, context) | ||
|
||
def create_attribute_to_column_links(self, context): | ||
file_location = context.file_directory + os.sep + "DM_Mappings.csv" | ||
header_skipped = False | ||
|
||
with open(file_location, encoding='utf-8') as csvfile: | ||
filereader = csv.reader(csvfile, delimiter=',', quotechar='"') | ||
for row in filereader: | ||
if not header_skipped: | ||
header_skipped = True | ||
else: | ||
logical_object_name = row[5] | ||
relational_model_name = row[8] | ||
relational_object_Name = row[11] | ||
entity_name = row[12] | ||
table_name = row[13] | ||
if (relational_model_name == context.input_layer_name): | ||
|
||
# annotate entites | ||
if logical_object_name == entity_name: | ||
ldm_entity = InputLayerLinkEnricher.get_ldm_entity( | ||
self, | ||
context, | ||
Utils.make_valid_id(entity_name)) | ||
|
||
the_entity_annotation = Utils.get_annotation_with_source(ldm_entity, "il_mapping") | ||
if the_entity_annotation is None: | ||
the_entity_annotation = ELAnnotation() | ||
the_entity_annotation_directive = Utils.get_annotation_directive(ldm_entity.eContainer(), "il_mapping") | ||
the_entity_annotation.source = the_entity_annotation_directive | ||
ldm_entity.eAnnotations.append(the_entity_annotation) | ||
|
||
details = the_entity_annotation.details | ||
|
||
il_tables_count = 0 | ||
|
||
for detail in details: | ||
if detail.key.startswith("il_table"): | ||
il_tables_count = il_tables_count + 1 | ||
|
||
detail1 = ELStringToStringMapEntry() | ||
if il_tables_count ==0: | ||
detail1.key = "il_table" | ||
else: | ||
detail1.key = "il_table" + str(il_tables_count) | ||
|
||
detail1.value = table_name | ||
details.append(detail1) | ||
else: | ||
# annotate attributes | ||
ldm_attribute = InputLayerLinkEnricher.get_ldm_attribute( | ||
self, | ||
context, | ||
Utils.make_valid_id(entity_name), | ||
Utils.make_valid_id(logical_object_name)) | ||
# logical_attribute_to_relational_name[ldm_attribute] = table_name + "." + relational_object_Name | ||
if not(ldm_attribute is None): | ||
if isinstance(ldm_attribute,ELAttribute): | ||
the_attribute_annotation = Utils.get_annotation_with_source(ldm_attribute, "il_mapping") | ||
if the_attribute_annotation is None: | ||
the_attribute_annotation = ELAnnotation() | ||
the_attribute_annotation_directive = Utils.get_annotation_directive(ldm_attribute.eContainer().eContainer(), "key") | ||
the_attribute_annotation.source = the_attribute_annotation_directive | ||
ldm_attribute.eAnnotations.append(the_attribute_annotation) | ||
|
||
details = the_attribute_annotation.details | ||
detail1 = ELStringToStringMapEntry() | ||
detail1.key = "il_column" | ||
detail1.value = table_name + "." + relational_object_Name | ||
details.append(detail1) | ||
|
||
if isinstance(ldm_attribute,ELReference): | ||
the_reference_annotation = Utils.get_annotation_with_source(ldm_attribute, "il_mapping") | ||
if the_reference_annotation is None: | ||
the_reference_annotation = ELAnnotation() | ||
the_reference_annotation_directive = Utils.get_annotation_directive(ldm_attribute.eContainer().eContainer(), "key") | ||
the_reference_annotation.source = the_reference_annotation_directive | ||
ldm_attribute.eAnnotations.append(the_reference_annotation) | ||
|
||
details = the_reference_annotation.details | ||
|
||
detail1 = ELStringToStringMapEntry() | ||
detail1.key = "il_column" | ||
detail1.value = relational_object_Name | ||
details.append(detail1) | ||
|
||
|
||
|
||
def get_ldm_attribute(self, context,entity_name,attribute_name): | ||
for eClassifier in context.input_tables_package.eClassifiers: | ||
if isinstance(eClassifier,ELClass): | ||
for feature in eClassifier.eStructuralFeatures: | ||
if isinstance(feature,ELAttribute) and eClassifier.name == entity_name: | ||
if feature.name == attribute_name: | ||
return feature | ||
if isinstance(feature,ELReference): | ||
if feature.name == attribute_name: | ||
return feature | ||
|
||
def get_ldm_entity(self, context,entity_name): | ||
for eClassifier in context.input_tables_package.eClassifiers: | ||
if isinstance(eClassifier,ELClass): | ||
if eClassifier.name == entity_name: | ||
return eClassifier | ||
|
Oops, something went wrong.