extractLongNameWithIdentifier(
}
/**
- * Loads all of the codelists by reading codelist files under a given a folder.
+ * Loads the paths of all of the codelists by looking for and reading the codelists index.
+ *
+ * The result is a map which associates information (file path and a placeholder for contents) for
+ * each codelist with its ID.
*
- * @param codelistsDir The folder containing all codelist files
- * @return A map of codelist IDs to codelist contents
+ * @param codelistsDir The folder containing the codelists index and files
+ * @return A map of codelist IDs to pairs of codelist file paths and contents
* @throws IOException If there are failures when discovering and parsing the files
*/
- private Map getCodelistContentsByCodelistIds(final Path codelistsDir)
- throws IOException {
+ private Map> getCodelistInfoByCodelistIds(
+ final Path codelistsDir) throws IOException {
Validate.notNull(codelistsDir, "Undefined codelists directory");
Validate.isTrue(Files.isDirectory(codelistsDir),
MessageFormat.format("Not a directory: {0}", codelistsDir));
- logger.debug("Getting codelist file paths from directory [{}]", codelistsDir);
+ final Path indexFile = Path.of(codelistsDir.toString(), "codelists.json");
- final int depth = 1; // Flat folder, not recursive for now.
+ logger.debug("Loading codelists index from [{}]", indexFile);
+ CodelistsIndex codelistsIndex =
+ createObjectMapper().readValue(indexFile.toFile(), CodelistsIndex.class);
+
+ final Map> result = new HashMap<>();
+ codelistsIndex.getCodelists().stream().forEach((CodelistForIndex codelist) -> {
+ final String codelistId = codelist.getId();
+ final Path codelistPath = Path.of(codelistsDir.toString(), codelist.getFilename());
+
+ logger.trace("Adding path [{}] for codelist [{}]", codelistPath, codelistId);
+ if (!Files.isRegularFile(codelistPath)) {
+ logger.warn("Codelist file [{}] not found. Codelist [{}] will be skipped", codelistPath,
+ codelistId);
+ } else {
+ // We're only interested in populating the codelist filepaths for now.
+ // The contents of each document will be populated for each codelist later, on demand.
+ result.put(codelistId, Pair.of(codelistPath, null));
+ }
+ });
+
+ return result;
- try (Stream walk = Files.walk(codelistsDir, depth)) {
- return walk
- .filter(this::isGenericodeFile)
- .map(Unchecked.function(this::getCodelistIdAndContents))
- .filter(Objects::nonNull)
- .collect(Collectors.toMap(Pair::getKey, Pair::getValue));
- }
}
/**
- * Gets the codelist ID from a codelist file.
+ * Gets the codelist contents from a codelist file.
*
* @param codelistPath The codelist file's path
- * @return The codelist ID and the codelist file's contents as a key/value pair
+ * @return The codelist file's contents
* @throws FileNotFoundException If the codelist file's path is undefined or not an existing file
*/
- private Pair getCodelistIdAndContents(Path codelistPath)
- throws FileNotFoundException {
+ private CodeListDocument getCodelistContents(Path codelistPath) throws FileNotFoundException {
Validate.notNull(codelistPath, "Undefined codelist path");
if (!Files.isRegularFile(codelistPath)) {
throw new FileNotFoundException(codelistPath.toString());
}
- final Optional codelist =
- Optional.ofNullable(GenericodeTools.getMarshaller().read(codelistPath));
-
- if (codelist.isPresent()) {
- // We use the longName as a ID, PK in the the DB.
- // But for the filenames we do not always follow this convention.
- // So we need to map.
- return codelist
- .map(CodeListDocument::getIdentification)
- .map((Identification identification) -> identification.getLongNameAtIndex(0))
- .map(LongName::getValue)
- .map((String longName) -> Pair.of(longName, codelist.get()))
- .orElse(null);
- }
-
- return null;
+ logger.debug("Reading from file [{}]", codelistPath);
+ return Optional.ofNullable(GenericodeTools.getMarshaller().read(codelistPath)).orElse(null);
}
- private boolean isGenericodeFile(final Path path) {
- return path != null
- && Files.isRegularFile(path)
- && GenericodeTools.EXTENSION_DOT_GC
- .equals(MessageFormat.format(".{0}", FilenameUtils.getExtension(path.toString())));
+ private ObjectMapper createObjectMapper() {
+ return new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
@Override
diff --git a/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkCodelistRepositoryTest.java b/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkCodelistRepositoryTest.java
index fee256a..3777cb4 100644
--- a/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkCodelistRepositoryTest.java
+++ b/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkCodelistRepositoryTest.java
@@ -11,14 +11,10 @@
import eu.europa.ted.eforms.sdk.entity.SdkCodelist;
class SdkCodelistRepositoryTest {
- private SdkCodelistRepository repository;
private Identification identification;
@BeforeEach
public void setUp() {
- repository =
- new SdkCodelistRepository("999.0", Path.of("src", "test", "resources", "codelists", "/"));
-
identification = new Identification();
final LongName longName1 = new LongName("test-codelist-parentId");
@@ -31,20 +27,32 @@ public void setUp() {
@Test
void testGetObject() {
- Optional codelist = Optional.ofNullable(repository.get("test-codelist"));
+ final SdkCodelistRepository repository =
+ new SdkCodelistRepository("999.0", Path.of("src", "test", "resources", "codelists", "/"));
+
+ Optional codelist = Optional.ofNullable(repository.get("accessibility"));
- assertEquals("test-codelist", codelist.map(SdkCodelist::getCodelistId).orElse(null));
- assertEquals(Arrays.asList("inc"), codelist.map(SdkCodelist::getCodes).orElse(null));
+ assertEquals("accessibility", codelist.map(SdkCodelist::getCodelistId).orElse(null));
+ assertEquals(Arrays.asList("inc", "n-inc", "n-inc-just"),
+ codelist.map(SdkCodelist::getCodes).orElse(null));
+
+ codelist = Optional.ofNullable(repository.get("criterion"));
+ assertEquals("criterion", codelist.map(SdkCodelist::getCodelistId).orElse(null));
+ assertEquals(Arrays.asList("autorisation", "aver-year-to", "bankr-nat", "bankruptcy"),
+ codelist.map(SdkCodelist::getCodes).orElse(null));
}
@Test
void testGetOrDefaultObjectSdkCodelist() {
- SdkCodelist defaultCodelist =
+ final SdkCodelistRepository repository =
+ new SdkCodelistRepository("999.0", Path.of("src", "test", "resources", "codelists", "/"));
+
+ final SdkCodelist defaultCodelist =
new DummySdkCodelist("default-codelist", "1", Arrays.asList("code1", "code2"), null);
Optional codelist =
- Optional.ofNullable(repository.getOrDefault("test-codelist", defaultCodelist));
- assertEquals("test-codelist", codelist.map(SdkCodelist::getCodelistId).orElse(null));
+ Optional.ofNullable(repository.getOrDefault("accessibility", defaultCodelist));
+ assertEquals("accessibility", codelist.map(SdkCodelist::getCodelistId).orElse(null));
codelist =
Optional.ofNullable(repository.getOrDefault("nonexisting-codelist", defaultCodelist));
diff --git a/src/test/resources/codelists/accessibility.gc b/src/test/resources/codelists/accessibility.gc
new file mode 100644
index 0000000..50b6756
--- /dev/null
+++ b/src/test/resources/codelists/accessibility.gc
@@ -0,0 +1,364 @@
+
+
+
+
+ Accessibility
+ accessibility
+ http://publications.europa.eu/resource/authority/accessibility
+ 20220928-0
+ http://publications.europa.eu/resource/dataset/accessibility
+
+
+ OP
+ Publications Office of the European Union
+
+
+
+
+ Code
+
+
+
+ Name
+
+
+
+ bulLabel
+
+
+
+ spaLabel
+
+
+
+ cesLabel
+
+
+
+ danLabel
+
+
+
+ deuLabel
+
+
+
+ estLabel
+
+
+
+ ellLabel
+
+
+
+ engLabel
+
+
+
+ fraLabel
+
+
+
+ gleLabel
+
+
+
+ hrvLabel
+
+
+
+ itaLabel
+
+
+
+ lavLabel
+
+
+
+ litLabel
+
+
+
+ hunLabel
+
+
+
+ mltLabel
+
+
+
+ nldLabel
+
+
+
+ polLabel
+
+
+
+ porLabel
+
+
+
+ ronLabel
+
+
+
+ slkLabel
+
+
+
+ slvLabel
+
+
+
+ finLabel
+
+
+
+ sweLabel
+
+
+
+
+
+
+ inc
+
+
+ Accessibility criteria for persons with disabilities are included
+
+
+ Включени са критерии за достъпността за лицата с увреждания
+
+
+ Kritéria přístupnosti pro osoby s postižením jsou zahrnuta
+
+
+ Der er anvendt kriterier vedrørende adgangsmuligheder for personer med handicap
+
+
+ Zugänglichkeitskriterien für Menschen mit Behinderungen wurden berücksichtigt
+
+
+ Συμπεριλαμβάνονται κριτήρια προσβασιμότητας για τα άτομα με αναπηρίες
+
+
+ Accessibility criteria for persons with disabilities are included
+
+
+ Se incluyen criterios de accesibilidad para las personas con discapacidad
+
+
+ Lisatud on puuetega inimeste juurdepääsukriteeriumid
+
+
+ Vammaisia koskevat esteettömyysvaatimukset on otettu huomioon
+
+
+ Des critères d’accessibilité pour les personnes handicapées sont appliqués
+
+
+ Tá critéir inrochtaineachta do dhaoine faoi mhíchumas ar áireamh
+
+
+ U obzir su uzeti uvjeti pristupačnosti za osobe s invaliditetom
+
+
+ A fogyatékossággal élő személyekre vonatkozó, akadálymentesítési kritériumok be vannak építve
+
+
+ Sono compresi criteri di accessibilità per le persone con disabilità
+
+
+ Prieinamumo neįgaliesiems kriterijai įtraukti
+
+
+ Ir iekļauti kritēriji par pieejamību personām ar invaliditāti
+
+
+ Il-kriterji ta’ aċċessibbiltà għall-persuni b’diżabbiltà huma inklużi
+
+
+ Er zijn criteria opgenomen inzake de toegankelijkheid voor personen met een handicap
+
+
+ Kryteria dostępności dla osób niepełnosprawnych zostały uwzględnione
+
+
+ Os critérios de acessibilidade para as pessoas com deficiência estão incluídos
+
+
+ Sunt incluse criterii de accesibilitate pentru persoanele cu handicap
+
+
+ Kritériá prístupnosti pre osoby so zdravotným postihnutím sú zahrnuté
+
+
+ Vključeni so pogoji dostopnosti za invalidne osebe
+
+
+ Tillgänglighetskriterier för personer med funktionsnedsättning ingår
+
+
+
+
+ n-inc
+
+
+ Accessibility criteria for persons with disabilities are not included because the procurement is not intended for use by natural persons
+
+
+ Критерии за достъпността за лицата с увреждания не са включени, защото поръчката не е предназначена за използване от физически лица
+
+
+ Kritéria přístupnosti pro osoby s postižením nejsou zahrnuta, neboť zakázka není určena k použití fyzickými osobami
+
+
+ Der er ikke anvendt kriterier vedrørende adgangsmuligheder for personer med handicap, fordi udbuddet ikke er beregnet til at blive anvendt af fysiske personer
+
+
+ Kriterien für die Zugänglichkeit für Menschen mit Behinderungen wurden nicht berücksichtigt, da die Beschaffung nicht für die Nutzung durch natürliche Personen vorgesehen ist
+
+
+ Δεν περιλαμβάνονται κριτήρια προσβασιμότητας για τα άτομα με αναπηρίες επειδή η προμήθεια δεν προορίζεται για χρήση από φυσικά πρόσωπα
+
+
+ Accessibility criteria for persons with disabilities are not included because the procurement is not intended for use by natural persons
+
+
+ No se incluyen criterios de accesibilidad para las personas con discapacidad porque la contratación no está destinada a ser utilizada por personas físicas
+
+
+ Puuetega inimeste juurdepääsukriteeriume pole lisatud, sest hange ei ole mõeldud kasutamiseks füüsilistele isikutele
+
+
+ Vammaisia koskevia esteettömyysvaatimuksia ei ole otettu huomioon, koska hankintaa ei ole tarkoitettu luonnollisten henkilöiden käyttöön
+
+
+ Des critères d’accessibilité pour les personnes handicapées ne sont pas appliqués parce que le marché n’est pas destiné aux personnes physiques
+
+
+ Níl critéir inrochtaineachta do dhaoine faoi mhíchumas ar áireamh mar níl an soláthar beartaithe lena úsáid ag daoine nádúrtha
+
+
+ Uvjeti pristupačnosti za osobe s invaliditetom nisu uzeti u obzir jer javna nabava nije namijenjena fizičkim osobama
+
+
+ A fogyatékossággal élő személyekre vonatkozó, akadálymentesítési kritériumok nincsenek beépítve, mivel a beszerzést nem fogják természetes személyek használni
+
+
+ Non sono compresi criteri di accessibilità per le persone con disabilità perché l'oggetto dell'appalto non è destinato all'uso da parte di persone fisiche
+
+
+ Prieinamumo neįgaliesiems kriterijai neįtraukti, nes nenumatyta, kad pirkimo objektas bus naudojamas fizinių asmenų
+
+
+ Kritēriji par pieejamību personām ar invaliditāti nav iekļauti, jo iepirkums nav paredzēts fiziskām personām
+
+
+ Il-kriterji ta’ aċċessibbiltà għall-persuni b’diżabbiltà ma jkunux inklużi minħabba li l-akkwist ma jkunx maħsub għall-użu minn persuni fiżiċi
+
+
+ Er zijn geen criteria opgenomen inzake de toegankelijkheid voor personen met een handicap, omdat de aanbesteding niet bestemd is voor gebruik door natuurlijke personen
+
+
+ Kryteria dostępności dla osób niepełnosprawnych nie zostały uwzględnione, ponieważ przedmiot zamówienia nie jest przeznaczony dla osób fizycznych
+
+
+ Os critérios de acessibilidade para as pessoas com deficiência não estão incluídos porque o contrato não se destina a pessoas singulares
+
+
+ Nu sunt incluse criterii de accesibilitate pentru persoanele cu handicap, deoarece achizițiile nu sunt destinate a fi utilizate de către persoane fizice
+
+
+ Kritériá prístupnosti pre osoby so zdravotným postihnutím nie sú zahrnuté, keďže zákazka nie je určená na použitie fyzickými osobami
+
+
+ Pogoji dostopnosti za invalidne osebe niso vključeni, ker predmet javnega naročila ni namenjen temu, da bi ga uporabljale fizične osebe
+
+
+ Tillgänglighetskriterier för personer med funktionsnedsättning ingår inte eftersom upphandlingen inte är avsedd att användas av fysiska personer
+
+
+
+
+ n-inc-just
+
+
+ Accessibility criteria for persons with disabilities are not included with the following justification
+
+
+ Критерии за достъпността за лицата с увреждания не са включени, а обосновката е следната
+
+
+ Kritéria přístupnosti pro osoby s postižením nejsou zahrnuta s následujícím odůvodněním
+
+
+ Der er ikke anvendt kriterier vedrørende adgangsmuligheder for personer med handicap med følgende begrundelse
+
+
+ Zugänglichkeitskriterien für Menschen mit Behinderungen wurden mit folgender Begründung nicht berücksichtigt
+
+
+ Δεν περιλαμβάνονται κριτήρια προσβασιμότητας για τα άτομα με αναπηρίες με την ακόλουθη αιτιολόγηση
+
+
+ Accessibility criteria for persons with disabilities are not included with the following justification
+
+
+ No se incluyen criterios de accesibilidad para las personas con discapacidad por la siguiente justificación
+
+
+ Puuetega inimeste juurdepääsukriteeriume ei ole lisatud järgmise põhjendusega
+
+
+ Vammaisia koskevia esteettömyysvaatimuksia ei ole otettu huomioon seuraavin perustein
+
+
+ Des critères d’accessibilité pour les personnes handicapées ne sont pas appliqués avec la justification suivante
+
+
+ Níl critéir inrochtaineachta do dhaoine faoi mhíchumas ar áireamh ar na cúiseanna seo a leanas
+
+
+ Uvjeti pristupačnosti za osobe s invaliditetom nisu uzeti u obzir zbog sljedećeg obrazloženja
+
+
+ A fogyatékossággal élő személyekre vonatkozó, akadálymentesítési kritériumok nincsenek beépítve az alábbi indoklás szerint
+
+
+ Non sono compresi criteri di accessibilità per le persone con disabilità con la giustificazione seguente
+
+
+ Prieinamumo neįgaliesiems kriterijai neįtraukti dėl šių priežasčių
+
+
+ Kritēriji par pieejamību personām ar invaliditāti nav iekļauti ar šādu pamatojumu
+
+
+ Il-kriterji ta’ aċċessibbiltà għall-persuni b’diżabbiltà ma jkunux inklużi bil-ġustifikazzjoni li ġejja
+
+
+ Er zijn geen criteria opgenomen inzake de toegankelijkheid voor personen met een handicap, om de volgende reden
+
+
+ Kryteria dostępności dla osób niepełnosprawnych nie zostały uwzględnione z uwagi na poniższe uzasadnienie
+
+
+ Os critérios de acessibilidade para as pessoas com deficiência não estão incluídos, com a seguinte justificação
+
+
+ Nu sunt incluse criterii de accesibilitate pentru persoanele cu handicap, din următorul motiv
+
+
+ Kritériá prístupnosti pre osoby so zdravotným postihnutím nie sú zahrnuté s nasledujúcim odôvodnením
+
+
+ Pogoji dostopnosti za invalidne osebe niso vključeni iz naslednjih razlogov
+
+
+ Tillgänglighetskriterier för personer med funktionsnedsättning ingår inte med följande motivering
+
+
+
+
diff --git a/src/test/resources/codelists/codelists.json b/src/test/resources/codelists/codelists.json
new file mode 100644
index 0000000..e02661b
--- /dev/null
+++ b/src/test/resources/codelists/codelists.json
@@ -0,0 +1,19 @@
+{
+ "ublVersion" : "2.3",
+ "sdkVersion" : "1.6.0",
+ "metadataDatabase" : {
+ "version" : "1.6.0",
+ "createdOn" : "2023-02-17T12:00:00"
+ },
+ "codelists" : [{
+ "id" : "accessibility",
+ "filename" : "accessibility.gc",
+ "description" : "This table provides a list of options for the use of accessibility criteria for person with disabilities in the technical specifications within the domain of public procurement.",
+ "_label" : "codelist|name|accessibility"
+ }, {
+ "id" : "criterion",
+ "filename" : "criterion.gc",
+ "description" : "This table provides criteria used for public procurement procedures.",
+ "_label" : "codelist|name|criterion"
+ }]
+}
\ No newline at end of file
diff --git a/src/test/resources/codelists/criterion.gc b/src/test/resources/codelists/criterion.gc
new file mode 100644
index 0000000..da36bd7
--- /dev/null
+++ b/src/test/resources/codelists/criterion.gc
@@ -0,0 +1,168 @@
+
+
+
+
+ Criterion
+ criterion
+ http://publications.europa.eu/resource/authority/criterion
+ 20210616-0
+ http://publications.europa.eu/resource/dataset/criterion
+
+
+ OP
+ Publications Office of the European Union
+
+
+
+
+ Code
+
+
+
+ Name
+
+
+
+ bulLabel
+
+
+
+ spaLabel
+
+
+
+ cesLabel
+
+
+
+ danLabel
+
+
+
+ deuLabel
+
+
+
+ estLabel
+
+
+
+ ellLabel
+
+
+
+ engLabel
+
+
+
+ fraLabel
+
+
+
+ gleLabel
+
+
+
+ hrvLabel
+
+
+
+ itaLabel
+
+
+
+ lavLabel
+
+
+
+ litLabel
+
+
+
+ hunLabel
+
+
+
+ mltLabel
+
+
+
+ nldLabel
+
+
+
+ polLabel
+
+
+
+ porLabel
+
+
+
+ ronLabel
+
+
+
+ slkLabel
+
+
+
+ slvLabel
+
+
+
+ finLabel
+
+
+
+ sweLabel
+
+
+
+
+
+
+ autorisation
+
+
+ For service contracts: authorisation of particular organisation needed
+
+
+ For service contracts: authorisation of particular organisation needed
+
+
+
+
+ aver-year-to
+
+
+ Average yearly turnover
+
+
+ Average yearly turnover
+
+
+
+
+ bankr-nat
+
+
+ Analogous situation like bankruptcy under national law
+
+
+ Analogous situation like bankruptcy under national law
+
+
+
+
+ bankruptcy
+
+
+ Bankruptcy
+
+
+ Bankruptcy
+
+
+
+
diff --git a/src/test/resources/codelists/test-codelist.gc b/src/test/resources/codelists/test-codelist.gc
deleted file mode 100644
index 138540e..0000000
--- a/src/test/resources/codelists/test-codelist.gc
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
- TestCodelist
- test-codelist
- http://publications.europa.eu/resource/authority/test-codelist
- 20220928-0
- http://publications.europa.eu/resource/dataset/test-codelist
-
-
- OP
- Publications Office of the European Union
-
-
-
-
- Code
-
-
-
- Name
-
-
-
- bulLabel
-
-
-
-
-
-
- inc
-
-
- TestCodelist criteria for persons with disabilities are included
-
-
- Включени са критерии за достъпността за лицата с увреждания
-
-
-
-