Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragos0000 committed Jan 26, 2024
1 parent 504c338 commit e45fb57
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 16,865 deletions.
18 changes: 16 additions & 2 deletions ted_sws/core/model/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Email: [email protected]

""" """
from enum import Enum
from typing import List, Optional

from pydantic import Field
Expand Down Expand Up @@ -55,6 +56,17 @@ class EncodedValue(NamedTuple):
value: str = None


class NoticeSource(str, Enum):
"""
Holds source of notice
"""
STANDARD_FORM = "standard_forms"
ELECTRONIC_FORM = "eforms"

def __str__(self):
return self.value


class NormalisedMetadata(Metadata):
"""
Stores notice normalised metadata
Expand All @@ -81,7 +93,7 @@ class NormalisedMetadata(Metadata):
eforms_subtype: str
xsd_version: Optional[str]
published_in_cellar_counter: int = Field(default=0)
is_eform: Optional[bool] = False
notice_source: Optional[NoticeSource] = NoticeSource.STANDARD_FORM
eform_sdk_version: Optional[str]


Expand All @@ -106,8 +118,10 @@ class NormalisedMetadataView(Metadata):
legal_basis_directive: str
form_number: str
eforms_subtype: str
xsd_version: str
xsd_version: Optional[str]
published_in_cellar_counter: int = Field(default=0)
notice_source: Optional[NoticeSource] = NoticeSource.STANDARD_FORM
eform_sdk_version: Optional[str]



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import pandas as pd

from ted_sws.core.model.metadata import NormalisedMetadata, LanguageTaggedString
from ted_sws.core.model.metadata import NormalisedMetadata, LanguageTaggedString, NoticeSource
from ted_sws.notice_metadata_processor.model.metadata import ExtractedMetadata
from ted_sws.notice_metadata_processor.services.metadata_constraints import filter_df_by_variables
from ted_sws.resources.mapping_files_registry import MappingFilesRegistry
Expand Down Expand Up @@ -37,7 +37,7 @@
NOTICE_TYPE_KEY = "notice_type"
XSD_VERSION_KEY = "xsd_version"
EFORM_SDK_VERSION_KEY = "eform_sdk_version"
IS_EFORM_KEY = "is_eform"
NOTICE_SOURCE_KEY = "notice_source"
ENGLISH_LANGUAGE_TAG = "EN"
mapping_registry = MappingFilesRegistry()

Expand Down Expand Up @@ -258,7 +258,7 @@ def normalise_metadata(self, extracted_metadata: ExtractedMetadata) -> Normalise
LEGAL_BASIS_DIRECTIVE_KEY: get_map_value(mapping=legal_basis_map, value=legal_basis),
E_FORMS_SUBTYPE_KEY: str(eforms_subtype),
XSD_VERSION_KEY: extracted_metadata.xml_schema_version,
IS_EFORM_KEY: False
NOTICE_SOURCE_KEY: NoticeSource.STANDARD_FORM
}

return NormalisedMetadata(**metadata)
Expand Down Expand Up @@ -341,7 +341,7 @@ def normalise_metadata(self, extracted_metadata: ExtractedMetadata) -> Normalise
value=legal_basis),
E_FORMS_SUBTYPE_KEY: extracted_metadata.extracted_notice_subtype,
EFORM_SDK_VERSION_KEY: extracted_metadata.xml_schema_version,
IS_EFORM_KEY: True
NOTICE_SOURCE_KEY: NoticeSource.ELECTRONIC_FORM
}

return NormalisedMetadata(**metadata)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import semantic_version

from ted_sws.core.model.metadata import NormalisedMetadata
from ted_sws.core.model.metadata import NormalisedMetadata, NoticeSource
from ted_sws.core.model.notice import Notice
from ted_sws.core.model.transform import MappingSuite
from ted_sws.data_manager.adapters.repository_abc import MappingSuiteRepositoryABC, NoticeRepositoryABC
Expand Down Expand Up @@ -48,8 +48,10 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada
eform_subtype = notice_metadata.eforms_subtype
notice_publication_date = datetime.datetime.fromisoformat(notice_metadata.publication_date)

if notice_metadata.is_eform:
if notice_metadata.notice_source == NoticeSource.ELECTRONIC_FORM:
notice_xsd_version = notice_metadata.eform_sdk_version
# eform sdk version value in metadata example: eforms-sdk-1.7 or eforms-sdk-1.7.9
# we need to extract only the version i.e 1.7 or 1.7.9
eforms_sdk_version = notice_xsd_version.rsplit('-', 1)[1]
constraint_version_range = [format_version_with_zero_patch(version) for version in
constraints[EFORMS_SDK_VERSIONS_KEY]]
Expand All @@ -67,7 +69,7 @@ def check_package(mapping_suite: MappingSuite, notice_metadata: NormalisedMetada
constraints[E_FORMS_SUBTYPE_KEY]]
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
return in_date_range and in_version_range and covered_eform_type


def notice_eligibility_checker(notice: Notice, mapping_suite_repository: MappingSuiteRepositoryABC) -> Tuple:
Expand Down
47 changes: 23 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
NOTICE_NUMBER_KEY, PUBLICATION_DATE_KEY, OJS_NUMBER_KEY, OJS_TYPE_KEY, BUYER_CITY_KEY, BUYER_NAME_KEY, LANGUAGE_KEY, \
BUYER_COUNTRY_KEY, EU_INSTITUTION_KEY, SENT_DATE_KEY, DEADLINE_DATE_KEY, NOTICE_TYPE_KEY, FORM_TYPE_KEY, \
PLACE_OF_PERFORMANCE_KEY, EXTRACTED_LEGAL_BASIS_KEY, FORM_NUMBER_KEY, LEGAL_BASIS_DIRECTIVE_KEY, \
E_FORMS_SUBTYPE_KEY, XSD_VERSION_KEY
E_FORMS_SUBTYPE_KEY, XSD_VERSION_KEY, EFORM_SDK_VERSION_KEY, NOTICE_SOURCE_KEY

from tests import TEST_DATA_PATH
from tests.fakes.fake_repository import FakeNoticeRepository
Expand Down Expand Up @@ -215,30 +215,29 @@ def normalised_metadata_object():
@pytest.fixture
def eform_normalised_metadata_object():
data = {
"title": [LanguageTaggedString(text="Eteläisen Salon liikuntapaikkojen hoidon hankinta", language="FIN")],
"long_title": [
TITLE_KEY: [LanguageTaggedString(text="Eteläisen Salon liikuntapaikkojen hoidon hankinta", language="FIN")],
LONG_TITLE_KEY: [
LanguageTaggedString(text="FIN :: Eteläisen Salon liikuntapaikkojen hoidon hankinta", language="FIN")],
"notice_publication_number": "00622690-2023",
"publication_date": "2023-10-13T00:00:00",
"ojs_issue_number": "198/2023",
"ojs_type": "S",
"city_of_buyer": None,
"name_of_buyer": None,
"original_language": None,
"country_of_buyer": None,
"eu_institution": None,
"document_sent_date": "2023-10-12T00:00:00",
"deadline_for_submission": None,
"notice_type": "http://publications.europa.eu/resource/authority/notice-type/cn-standard",
"form_type": "http://publications.europa.eu/resource/authority/form-type/competition",
"place_of_performance": ["http://data.europa.eu/nuts/code/FI1C1"],
"extracted_legal_basis_directive": "http://publications.europa.eu/resource/authority/legal-basis/32014L0024",
"legal_basis_directive": "http://publications.europa.eu/resource/authority/legal-basis/32014L0024",
"form_number": "",
"eforms_subtype": "16",
"eform_sdk_version": "eforms-sdk-1.7",
"published_in_cellar_counter": 0,
"is_eform": True
NOTICE_NUMBER_KEY: "00622690-2023",
PUBLICATION_DATE_KEY: "2023-10-13T00:00:00",
OJS_NUMBER_KEY: "198/2023",
OJS_TYPE_KEY: "S",
BUYER_CITY_KEY: None,
BUYER_NAME_KEY: None,
LANGUAGE_KEY: None,
BUYER_COUNTRY_KEY: None,
EU_INSTITUTION_KEY: None,
SENT_DATE_KEY: "2023-10-12T00:00:00",
DEADLINE_DATE_KEY: None,
NOTICE_TYPE_KEY: "http://publications.europa.eu/resource/authority/notice-type/cn-standard",
FORM_TYPE_KEY: "http://publications.europa.eu/resource/authority/form-type/competition",
PLACE_OF_PERFORMANCE_KEY: ["http://data.europa.eu/nuts/code/FI1C1"],
EXTRACTED_LEGAL_BASIS_KEY: "http://publications.europa.eu/resource/authority/legal-basis/32014L0024",
LEGAL_BASIS_DIRECTIVE_KEY: "http://publications.europa.eu/resource/authority/legal-basis/32014L0024",
FORM_NUMBER_KEY: "",
E_FORMS_SUBTYPE_KEY: "16",
EFORM_SDK_VERSION_KEY: "eforms-sdk-1.7",
NOTICE_SOURCE_KEY: "eforms"
}

return NormalisedMetadata(**data)
Expand Down

This file was deleted.

Loading

0 comments on commit e45fb57

Please sign in to comment.