# TED Notice URL Feature ## Übersicht Jedes Dokument in der Datenbank hat jetzt eine automatisch generierte `notice_url` Spalte, die direkt auf die TED-Webseite verlinkt. ## Format ``` https://ted.europa.eu/en/notice/-/detail/{publication_id ohne führende Nullen} ``` **Beispiel:** - `publication_id`: `00786665-2025` - `notice_url`: `https://ted.europa.eu/en/notice/-/detail/786665-2025` ## Automatische Generierung Die URL wird automatisch beim Speichern eines Dokuments generiert: ```java @PrePersist @PreUpdate private void generateNoticeUrl() { if (publicationId != null && !publicationId.isEmpty()) { String cleanId = publicationId.replaceFirst("^0+", ""); this.noticeUrl = "https://ted.europa.eu/en/notice/-/detail/" + cleanId; } } ``` ## Datenbankstruktur ### Spalte ```sql ALTER TABLE ted.procurement_document ADD COLUMN notice_url VARCHAR(255); CREATE INDEX idx_doc_notice_url ON ted.procurement_document(notice_url); ``` ### Existierende Datensätze URLs für existierende Datensätze werden automatisch generiert: ```sql UPDATE ted.procurement_document SET notice_url = 'https://ted.europa.eu/en/notice/-/detail/' || REGEXP_REPLACE(publication_id, '^0+', '') WHERE publication_id IS NOT NULL AND notice_url IS NULL; ``` ## Verwendung ### Repository-Abfrage ```java // Nach URL suchen Optional doc = repository.findByNoticeUrl( "https://ted.europa.eu/en/notice/-/detail/786665-2025" ); ``` ### Entity-Zugriff ```java ProcurementDocument doc = new ProcurementDocument(); doc.setPublicationId("00786665-2025"); // notice_url wird automatisch beim Speichern generiert repository.save(doc); // URL abrufen String url = doc.getNoticeUrl(); // "https://ted.europa.eu/en/notice/-/detail/786665-2025" ``` ### REST API Beispiel ```json { "id": "20fde305-844b-46b7-bb72-93e86381978d", "publicationId": "00786665-2025", "noticeUrl": "https://ted.europa.eu/en/notice/-/detail/786665-2025", "buyerName": "Example Organization", "projectTitle": "Construction Services" } ``` ## Vorteile ✅ **Direkte Verlinkung** zur offiziellen TED-Webseite ✅ **Automatische Generierung** - keine manuelle Pflege nötig ✅ **Indiziert** für schnelle Suche ✅ **Konsistentes Format** - einheitliche URLs ✅ **Integration** in REST API und Such-Ergebnisse ## SQL-Abfragen ### URL für Publication ID generieren ```sql SELECT publication_id, 'https://ted.europa.eu/en/notice/-/detail/' || REGEXP_REPLACE(publication_id, '^0+', '') AS notice_url FROM ted.procurement_document WHERE publication_id = '00786665-2025'; ``` ### Alle URLs anzeigen ```sql SELECT publication_id, notice_url, buyer_name, project_title FROM ted.procurement_document WHERE notice_url IS NOT NULL ORDER BY created_at DESC LIMIT 10; ``` ### Nach URL-Pattern suchen ```sql SELECT * FROM ted.procurement_document WHERE notice_url LIKE '%/786665-2025'; ``` ## Migration Beim Hinzufügen des Features wurden: 1. ✅ Spalte `notice_url` zur Tabelle hinzugefügt 2. ✅ Index `idx_doc_notice_url` erstellt 3. ✅ URLs für alle existierenden Datensätze generiert 4. ✅ Entity-Klasse mit automatischer Generierung erweitert 5. ✅ Repository-Methode `findByNoticeUrl()` hinzugefügt ## Hinweise - Die URL wird **nur** generiert wenn `publication_id` vorhanden ist - Führende Nullen werden automatisch entfernt (`00786665` → `786665`) - Die URL wird bei jedem Update aktualisiert (falls sich `publication_id` ändert) - Die Spalte ist **nicht** `NOT NULL` da alte Datensätze möglicherweise keine `publication_id` haben