-
Notifications
You must be signed in to change notification settings - Fork 5
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
added test package and refactored logic for eligibility checker #516
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,31 @@ | |
from ted_sws.core.model.transform import MappingSuite | ||
from ted_sws.data_manager.adapters.repository_abc import MappingSuiteRepositoryABC, NoticeRepositoryABC | ||
from ted_sws.mapping_suite_processor.services.conceptual_mapping_generate_metadata import START_DATE_KEY, END_DATE_KEY, \ | ||
MIN_XSD_VERSION_KEY, MAX_XSD_VERSION_KEY, E_FORMS_SUBTYPE_KEY | ||
MIN_XSD_VERSION_KEY, MAX_XSD_VERSION_KEY, E_FORMS_SUBTYPE_KEY, EFORMS_SDK_VERSIONS_KEY | ||
|
||
|
||
def format_version_with_zero_patch(version_string:str) -> semantic_version.Version: | ||
""" | ||
This will take a string version (1.7 or 1.7.6) and will transform it to a semantic version with 0 as patch | ||
1.7 -> 1.7.0 | ||
1.7.6 -> 1.7.0 | ||
""" | ||
parsed_version = semantic_version.Version.coerce(version_string) | ||
return semantic_version.Version(major=parsed_version.major, minor=parsed_version.minor, patch=0) | ||
|
||
|
||
def is_date_in_range(publication_date, constraint_start_date_value, constraint_end_date_value) -> bool: | ||
""" | ||
This will return True or False if publication_date is in range looking at the start and end date constraints in the | ||
metadata of a mapping suite | ||
""" | ||
if not constraint_start_date_value and not constraint_end_date_value: | ||
return True | ||
|
||
start_date = datetime.datetime.fromisoformat(constraint_start_date_value[0]) | ||
end_date = datetime.datetime.fromisoformat( | ||
constraint_end_date_value[0] if constraint_end_date_value else datetime.datetime.now().isoformat()) | ||
return start_date <= publication_date <= end_date | ||
|
||
|
||
def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetadata): | ||
|
@@ -18,22 +42,29 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada | |
:param mapping_suite: | ||
:return: | ||
""" | ||
|
||
constraints = mapping_suite.metadata_constraints.constraints | ||
|
||
eform_subtype = notice_metadata.eforms_subtype | ||
notice_publication_date = datetime.datetime.fromisoformat(notice_metadata.publication_date) | ||
notice_xsd_version = notice_metadata.xsd_version | ||
|
||
end_date = constraints[END_DATE_KEY][0] if constraints[END_DATE_KEY] else datetime.datetime.now().isoformat() | ||
constraint_start_date = datetime.datetime.fromisoformat(constraints[START_DATE_KEY][0]) | ||
constraint_end_date = datetime.datetime.fromisoformat(end_date) | ||
constraint_min_xsd_version = constraints[MIN_XSD_VERSION_KEY][0] | ||
constraint_max_xsd_version = constraints[MAX_XSD_VERSION_KEY][0] | ||
if notice_metadata.is_eform: | ||
notice_xsd_version = notice_metadata.eform_sdk_version | ||
eforms_sdk_version = notice_xsd_version.rsplit('-', 1)[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this split need to be explained, maybe we need to use a template or regex selector instead of unclear split. |
||
constraint_version_range = [format_version_with_zero_patch(version) for version in | ||
constraints[EFORMS_SDK_VERSIONS_KEY]] | ||
in_version_range = format_version_with_zero_patch(eforms_sdk_version) in constraint_version_range | ||
else: | ||
notice_xsd_version = notice_metadata.xsd_version | ||
constraint_min_xsd_version = constraints[MIN_XSD_VERSION_KEY][0] | ||
constraint_max_xsd_version = constraints[MAX_XSD_VERSION_KEY][0] | ||
in_version_range = constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version | ||
|
||
in_date_range = is_date_in_range(publication_date=notice_publication_date, | ||
constraint_start_date_value=constraints[START_DATE_KEY], | ||
constraint_end_date_value=constraints[END_DATE_KEY]) | ||
eform_subtype_constraint_values = [str(eforms_subtype_value) for eforms_subtype_value in | ||
constraints[E_FORMS_SUBTYPE_KEY]] | ||
|
||
in_date_range = constraint_start_date <= notice_publication_date <= constraint_end_date | ||
in_version_range = constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version | ||
covered_eform_type = eform_subtype in eform_subtype_constraint_values | ||
|
||
return True if in_date_range and in_version_range and covered_eform_type else False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace: |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"identifier": "package_EF16", | ||
"title": "Package EF16 v1.2", | ||
"description": "This is the conceptual mapping for bla bla bla", | ||
"mapping_version": "3.0.0-alpha.1", | ||
"ontology_version": "4.0.0", | ||
"metadata_constraints": { | ||
"constraints": { | ||
"min_xsd_version": ["R2.0.9.S04.E01"], | ||
"max_xsd_version": ["R2.0.9.S04.E01"], | ||
"eforms_subtype": [ | ||
"16", | ||
"10", | ||
"11", | ||
"12", | ||
"13", | ||
"X1", | ||
"T1" | ||
], | ||
"start_date": null, | ||
"end_date": null, | ||
"eforms_sdk_versions": [ | ||
"1.3", | ||
"1.4", | ||
"1.5", | ||
"1.6", | ||
"1.7", | ||
"1.8", | ||
"1.9", | ||
"1.10" | ||
] | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to change this flag to a field:
notice_source: Optional[NoticeSource] = NoticeSource.STANDART_FORMS
and for NoticeSource as example:
`class NoticeSource(str, Enum):
STANDART_FORMS = "standart_forms"
ELECTRONIC_FORMS = "eforms"
`