Refactor TED Calendar and EForm Structure for Enhanced Functionality

- Updated the GetOJS function to accept a base URL parameter, improving flexibility in constructing the calendar URL.
- Removed the deprecated eform.go file, streamlining the codebase by eliminating unused components.
- Introduced new eform structures for BusinessRegistrationInformationNotice, ContractNotice, ContractAwardNotice, and PriorInformationNotice, enhancing the handling of TED XML data.
- Implemented mapping functions to convert eform notices to the Tender entity, improving integration with the tender management system.
- Added a service layer to encapsulate business logic related to eform processing, adhering to Clean Architecture principles.
This commit is contained in:
n.nakhostin
2025-09-30 16:51:40 +03:30
parent 05c7eae8a2
commit 44f266189c
9 changed files with 574 additions and 336 deletions
+21 -105
View File
@@ -4,8 +4,11 @@ import (
"encoding/xml"
"fmt"
"strings"
"tm/pkg/notification"
"tm/pkg/xmlparser"
"tm/ted/eform/business_registration_information"
"tm/ted/eform/contract"
"tm/ted/eform/contract_award"
"tm/ted/eform/prior_information"
)
type ParserType string
@@ -18,8 +21,10 @@ const (
)
type TEDParser struct {
Notification notification.SDK
NoticeParser xmlparser.Parser[ContractNotice]
ContractNotice xmlparser.Parser[contract.ContractNotice]
ContractAwardNotice xmlparser.Parser[contract_award.ContractAwardNotice]
PriorInformationNotice xmlparser.Parser[prior_information.PriorInformationNotice]
BusinessRegistrationInformationNotice xmlparser.Parser[business_registration_information.BusinessRegistrationInformationNotice]
}
// NewTEDParser creates a new TED parser
@@ -28,9 +33,16 @@ func NewTEDParser() *TEDParser {
options.MaxSize = 50 * 1024 * 1024 // 50MB limit for TED XML files
options.IgnoreUnknownElements = true // TED XML has many optional fields
parser := xmlparser.NewParser[ContractNotice](options)
contractNoticeParser := xmlparser.NewParser[contract.ContractNotice](options)
contractAwardNoticeParser := xmlparser.NewParser[contract_award.ContractAwardNotice](options)
priorInformationNoticeParser := xmlparser.NewParser[prior_information.PriorInformationNotice](options)
businessRegistrationInformationNoticeParser := xmlparser.NewParser[business_registration_information.BusinessRegistrationInformationNotice](options)
return &TEDParser{
NoticeParser: parser,
ContractNotice: contractNoticeParser,
ContractAwardNotice: contractAwardNoticeParser,
PriorInformationNotice: priorInformationNoticeParser,
BusinessRegistrationInformationNotice: businessRegistrationInformationNoticeParser,
}
}
@@ -45,16 +57,16 @@ func (tp *TEDParser) Parse(content []byte) (interface{}, string, ParserType, err
// Parse based on the detected type
switch ParserType(rootElement) {
case ParserTypeContractNotice:
notice, err := tp.parseContractNotice(content)
notice, err := tp.ContractNotice.ParseBytes(content)
return notice, notice.GetID(), ParserTypeContractNotice, err
case ParserTypeContractAwardNotice:
notice, err := tp.parseContractAwardNotice(content)
notice, err := tp.ContractAwardNotice.ParseBytes(content)
return notice, notice.GetID(), ParserTypeContractAwardNotice, err
case ParserTypePriorInformationNotice:
notice, err := tp.parsePriorInformationNotice(content)
notice, err := tp.PriorInformationNotice.ParseBytes(content)
return notice, notice.GetID(), ParserTypePriorInformationNotice, err
case ParserTypeBusinessRegistrationInformationNotice:
notice, err := tp.parseBusinessRegistrationInformationNotice(content)
notice, err := tp.BusinessRegistrationInformationNotice.ParseBytes(content)
return notice, notice.GetID(), ParserTypeBusinessRegistrationInformationNotice, err
default:
return nil, "", ParserType(""), fmt.Errorf("unsupported notice type: %s", rootElement)
@@ -74,99 +86,3 @@ func detectRootElement(content []byte) (string, error) {
}
}
}
// parseContractNotice parses a ContractNotice
func (tp *TEDParser) parseContractNotice(content []byte) (*ContractNotice, error) {
options := xmlparser.DefaultParserOptions()
options.MaxSize = 50 * 1024 * 1024
options.IgnoreUnknownElements = true
parser := xmlparser.NewParser[ContractNotice](options)
notice, err := parser.ParseBytes(content)
if err != nil {
return nil, err
}
return notice, nil
}
// parseContractAwardNotice parses a ContractAwardNotice
func (tp *TEDParser) parseContractAwardNotice(content []byte) (*ContractAwardNotice, error) {
options := xmlparser.DefaultParserOptions()
options.MaxSize = 50 * 1024 * 1024
options.IgnoreUnknownElements = true
parser := xmlparser.NewParser[ContractAwardNotice](options)
notice, err := parser.ParseBytes(content)
if err != nil {
return nil, err
}
return notice, nil
}
// parsePriorInformationNotice parses a PriorInformationNotice
func (tp *TEDParser) parsePriorInformationNotice(content []byte) (*PriorInformationNotice, error) {
options := xmlparser.DefaultParserOptions()
options.MaxSize = 50 * 1024 * 1024
options.IgnoreUnknownElements = true
parser := xmlparser.NewParser[PriorInformationNotice](options)
notice, err := parser.ParseBytes(content)
if err != nil {
return nil, err
}
return notice, nil
}
// parseBusinessRegistrationInformationNotice parses a BusinessRegistrationInformationNotice
func (tp *TEDParser) parseBusinessRegistrationInformationNotice(content []byte) (*BusinessRegistrationInformationNotice, error) {
options := xmlparser.DefaultParserOptions()
options.MaxSize = 50 * 1024 * 1024
options.IgnoreUnknownElements = true
parser := xmlparser.NewParser[BusinessRegistrationInformationNotice](options)
notice, err := parser.ParseBytes(content)
if err != nil {
return nil, err
}
return notice, nil
}
// GetID returns the contract notice ID
func (cn ContractNotice) GetID() string {
return cn.ID
}
// GetID returns the contract award notice ID
func (can ContractAwardNotice) GetID() string {
return can.ID
}
// GetID returns the prior information notice ID
func (pin PriorInformationNotice) GetID() string {
return pin.ID
}
// GetID returns the business registration information notice ID
func (brin BusinessRegistrationInformationNotice) GetID() string {
return brin.ID
}
// Validate validates the parsed model
func (cn ContractNotice) Validate() error {
return nil
}
// Validate validates the parsed model
func (can ContractAwardNotice) Validate() error {
return nil
}
// Validate validates the parsed model
func (pin PriorInformationNotice) Validate() error {
return nil
}
// Validate validates the parsed model
func (brin BusinessRegistrationInformationNotice) Validate() error {
return nil
}