Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/mx_1517 add mapping connector #5

Merged
merged 9 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- configure open-code synchronization workflow
- add mapping connector

### Changes

Expand Down
42 changes: 42 additions & 0 deletions assets/mappings/__final__/test_mapping/access-platform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
contact:
- fieldInPrimarySource: n/a
mappingRules:
- forValues:
- Roland Resolved
rule: Match value using ldap extractor.
identifierInPrimarySource:
- fieldInPrimarySource: n/a
mappingRules:
- setValues:
- "sumo-db"
rule: Use value as it is.
technicalAccessibility:
- fieldInPrimarySource: n/a
mappingRules:
- setValues:
- https://mex.rki.de/item/technical-accessibility-1
comment: internal
title:
- fieldInPrimarySource: n/a
mappingRules:
- setValues:
- language: de
value: SUMO Datenbank
unitInCharge:
- fieldInPrimarySource: n/a
mappingRules:
- forValues:
- Abteilung
rule: Use value to match with identifier in /raw-data/organigram/organizational-units.json.
hadPrimarySource:
- fieldInPrimarySource: n/a
mappingRules:
- rule: "Assign 'stable target id' of primary source with identifier 'nokeda' in /raw-data/primary-sources/primary-sources.json."
identifier:
- fieldInPrimarySource: n/a
mappingRules:
- rule: Assign identifier.
stableTargetId:
- fieldInPrimarySource: n/a
mappingRules:
- rule: Assign 'stable target id' of merged item.
Empty file added mex/mapping/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions mex/mapping/extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import yaml
from pydantic import BaseModel

from mex.common.models.mapping import MAPPING_MODEL_BY_EXTRACTED_CLASS_NAME
from mex.common.types import AssetsPath


def extract_mapping_model(path: AssetsPath, model_type: type[BaseModel]) -> BaseModel:
"""Return a mapping model with default values.

Args:
path: path to mapping json
model_type: model type of BaseModel to be extracted

Returns:
BaseModel with default values
"""
model = MAPPING_MODEL_BY_EXTRACTED_CLASS_NAME[model_type.__name__]
with open(path, "r", encoding="utf-8") as f:
yaml_model = yaml.safe_load(f)
return model.model_validate(yaml_model)
10 changes: 10 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added tests/mapping/__init__.py
Empty file.
88 changes: 88 additions & 0 deletions tests/mapping/test_extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from mex.common.models import ExtractedAccessPlatform
from mex.common.types import AssetsPath, TechnicalAccessibility, TextLanguage
from mex.mapping.extract import extract_mapping_model


def test_get_mapping_model() -> None:
mapping_path = AssetsPath(
"assets/mappings/__final__/test_mapping/access-platform.yaml"
)

mapping_model = extract_mapping_model(mapping_path, ExtractedAccessPlatform)

expected = {
"identifier": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [{"rule": "Assign identifier."}],
}
],
"hadPrimarySource": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [
{
"rule": "Assign 'stable target id' of primary source with identifier 'nokeda' in /raw-data/primary-sources/primary-sources.json."
}
],
}
],
"identifierInPrimarySource": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [
{"setValues": ["sumo-db"], "rule": "Use value as it is."}
],
}
],
"stableTargetId": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [
{"rule": "Assign 'stable target id' of merged item."}
],
}
],
"contact": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [
{
"forValues": ["Roland Resolved"],
"rule": "Match value using ldap extractor.",
}
],
}
],
"technicalAccessibility": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [{"setValues": [TechnicalAccessibility["INTERNAL"]]}],
"comment": "internal",
}
],
"title": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [
{
"setValues": [
{"value": "SUMO Datenbank", "language": TextLanguage.DE}
]
}
],
}
],
"unitInCharge": [
{
"fieldInPrimarySource": "n/a",
"mappingRules": [
{
"forValues": ["Abteilung"],
"rule": "Use value to match with identifier in /raw-data/organigram/organizational-units.json.",
}
],
}
],
}
assert mapping_model.model_dump(exclude_defaults=True) == expected
Loading