55
66from ted_sws .core .model .metadata import NormalisedMetadata , NoticeSource
77from ted_sws .core .model .notice import Notice
8- from ted_sws .core .model .transform import MappingSuite
8+ from ted_sws .core .model .transform import MappingSuite , MappingSuiteType
99from ted_sws .data_manager .adapters .repository_abc import MappingSuiteRepositoryABC , NoticeRepositoryABC
1010from ted_sws .mapping_suite_processor .services .conceptual_mapping_generate_metadata import START_DATE_KEY , END_DATE_KEY , \
1111 MIN_XSD_VERSION_KEY , MAX_XSD_VERSION_KEY , E_FORMS_SUBTYPE_KEY , EFORMS_SDK_VERSIONS_KEY
1212
1313
14- def format_version_with_zero_patch (version_string :str ) -> semantic_version .Version :
14+ def format_version_with_zero_patch (version_string : str ) -> semantic_version .Version :
1515 """
1616 This will take a string version (1.7 or 1.7.6) and will transform it to a semantic version with 0 as patch
1717 1.7 -> 1.7.0
@@ -35,6 +35,25 @@ def is_date_in_range(publication_date, constraint_start_date_value, constraint_e
3535 return start_date <= publication_date <= end_date
3636
3737
38+ def is_version_in_range (notice_metadata : NormalisedMetadata , mapping_suite : MappingSuite ) -> bool :
39+ constraints = mapping_suite .metadata_constraints .constraints
40+ if mapping_suite .mapping_type == MappingSuiteType .ELECTRONIC_FORMS and notice_metadata .notice_source == NoticeSource .ELECTRONIC_FORM :
41+ notice_xsd_version = notice_metadata .eform_sdk_version
42+ # eform sdk version value in metadata example: eforms-sdk-1.7 or eforms-sdk-1.7.9
43+ # we need to extract only the version i.e 1.7 or 1.7.9
44+ eforms_sdk_version = notice_xsd_version .rsplit ('-' , 1 )[1 ]
45+ constraint_version_range = [format_version_with_zero_patch (version ) for version in
46+ constraints [EFORMS_SDK_VERSIONS_KEY ]]
47+ return format_version_with_zero_patch (eforms_sdk_version ) in constraint_version_range
48+ elif mapping_suite .mapping_type == MappingSuiteType .STANDARD_FORMS and notice_metadata .notice_source == NoticeSource .STANDARD_FORM :
49+ notice_xsd_version = notice_metadata .xsd_version
50+ constraint_min_xsd_version = constraints [MIN_XSD_VERSION_KEY ][0 ]
51+ constraint_max_xsd_version = constraints [MAX_XSD_VERSION_KEY ][0 ]
52+ return constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version
53+
54+ return False
55+
56+
3857def check_package (mapping_suite : MappingSuite , notice_metadata : NormalisedMetadata ):
3958 """
4059 Check if mapping suite is valid for notice
@@ -47,20 +66,7 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada
4766
4867 eform_subtype = notice_metadata .eforms_subtype
4968 notice_publication_date = datetime .datetime .fromisoformat (notice_metadata .publication_date )
50-
51- if notice_metadata .notice_source == NoticeSource .ELECTRONIC_FORM :
52- notice_xsd_version = notice_metadata .eform_sdk_version
53- # eform sdk version value in metadata example: eforms-sdk-1.7 or eforms-sdk-1.7.9
54- # we need to extract only the version i.e 1.7 or 1.7.9
55- eforms_sdk_version = notice_xsd_version .rsplit ('-' , 1 )[1 ]
56- constraint_version_range = [format_version_with_zero_patch (version ) for version in
57- constraints [EFORMS_SDK_VERSIONS_KEY ]]
58- in_version_range = format_version_with_zero_patch (eforms_sdk_version ) in constraint_version_range
59- else :
60- notice_xsd_version = notice_metadata .xsd_version
61- constraint_min_xsd_version = constraints [MIN_XSD_VERSION_KEY ][0 ]
62- constraint_max_xsd_version = constraints [MAX_XSD_VERSION_KEY ][0 ]
63- in_version_range = constraint_min_xsd_version <= notice_xsd_version <= constraint_max_xsd_version
69+ in_version_range = is_version_in_range (notice_metadata = notice_metadata , mapping_suite = mapping_suite )
6470
6571 in_date_range = is_date_in_range (publication_date = notice_publication_date ,
6672 constraint_start_date_value = constraints [START_DATE_KEY ],
0 commit comments