diff --git a/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentType.java b/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentType.java index d6f9a08..a81fbce 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentType.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/component/SdkComponentType.java @@ -5,7 +5,7 @@ * factory. */ public enum SdkComponentType { - FIELD, NODE, CODELIST, NOTICE_TYPE, DATA_TYPE, EFX_EXPRESSION_TRANSLATOR, EFX_TEMPLATE_TRANSLATOR, EFX_RULES_TRANSLATOR, + FIELD, NODE, CODELIST, NOTICE_TYPE, EFX_EXPRESSION_TRANSLATOR, EFX_TEMPLATE_TRANSLATOR, EFX_RULES_TRANSLATOR, EFX_COMPUTE_DEPENDENCY_EXTRACTOR, EFX_VALIDATION_DEPENDENCY_EXTRACTOR, SYMBOL_RESOLVER, SCRIPT_GENERATOR, MARKUP_GENERATOR, VALIDATOR_GENERATOR; } diff --git a/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkDataType.java b/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkDataType.java index 5bac603..4bacdf9 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkDataType.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkDataType.java @@ -48,7 +48,7 @@ public SdkDataType(final String id, final String privacyMask) { /** * Creates a data type from its entry in data-types.json. */ - protected SdkDataType(final JsonNode dataType) { + public SdkDataType(final JsonNode dataType) { this.id = dataType.get("type").asText(null); this.privacyMask = dataType.hasNonNull("maskingValue") ? dataType.get("maskingValue").asText(null) : null; diff --git a/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkEntityFactory.java b/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkEntityFactory.java index e49e5d6..09705d9 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkEntityFactory.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/entity/SdkEntityFactory.java @@ -36,10 +36,4 @@ public static SdkNoticeSubtype getSdkNoticeSubtype(final String sdkVersion, fina return SdkEntityFactory.INSTANCE.getComponentImpl(sdkVersion, SdkComponentType.NOTICE_TYPE, SdkNoticeSubtype.class, json); } - - public static SdkDataType getSdkDataType(final String sdkVersion, final JsonNode dataType) - throws InstantiationException { - return SdkEntityFactory.INSTANCE.getComponentImpl(sdkVersion, SdkComponentType.DATA_TYPE, - SdkDataType.class, dataType); - } } diff --git a/src/main/java/eu/europa/ted/eforms/sdk/entity/v1/SdkDataTypeV1.java b/src/main/java/eu/europa/ted/eforms/sdk/entity/v1/SdkDataTypeV1.java deleted file mode 100644 index 6f42fc7..0000000 --- a/src/main/java/eu/europa/ted/eforms/sdk/entity/v1/SdkDataTypeV1.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2026 European Union - * - * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European - * Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in - * compliance with the Licence. You may obtain a copy of the Licence at: - * https://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software distributed under the Licence - * is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the Licence for the specific language governing permissions and limitations under - * the Licence. - */ -package eu.europa.ted.eforms.sdk.entity.v1; - -import com.fasterxml.jackson.databind.JsonNode; -import eu.europa.ted.eforms.sdk.component.SdkComponent; -import eu.europa.ted.eforms.sdk.component.SdkComponentType; -import eu.europa.ted.eforms.sdk.entity.SdkDataType; - -@SdkComponent(versions = {"1"}, componentType = SdkComponentType.DATA_TYPE) -public class SdkDataTypeV1 extends SdkDataType { - - public SdkDataTypeV1(final JsonNode dataType) { - super(dataType); - } -} diff --git a/src/main/java/eu/europa/ted/eforms/sdk/entity/v2/SdkDataTypeV2.java b/src/main/java/eu/europa/ted/eforms/sdk/entity/v2/SdkDataTypeV2.java deleted file mode 100644 index 52e7758..0000000 --- a/src/main/java/eu/europa/ted/eforms/sdk/entity/v2/SdkDataTypeV2.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2026 European Union - * - * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European - * Commission – subsequent versions of the EUPL (the "Licence"); You may not use this work except in - * compliance with the Licence. You may obtain a copy of the Licence at: - * https://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software distributed under the Licence - * is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the Licence for the specific language governing permissions and limitations under - * the Licence. - */ -package eu.europa.ted.eforms.sdk.entity.v2; - -import com.fasterxml.jackson.databind.JsonNode; -import eu.europa.ted.eforms.sdk.component.SdkComponent; -import eu.europa.ted.eforms.sdk.component.SdkComponentType; -import eu.europa.ted.eforms.sdk.entity.v1.SdkDataTypeV1; - -@SdkComponent(versions = {"2"}, componentType = SdkComponentType.DATA_TYPE) -public class SdkDataTypeV2 extends SdkDataTypeV1 { - - public SdkDataTypeV2(final JsonNode dataType) { - super(dataType); - } -} diff --git a/src/main/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepository.java b/src/main/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepository.java index 3a7220c..31de339 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepository.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepository.java @@ -17,11 +17,11 @@ import java.io.InputStream; import java.io.UncheckedIOException; import java.util.HashMap; +import java.util.Map; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.europa.ted.eforms.sdk.SdkConstants; import eu.europa.ted.eforms.sdk.entity.SdkDataType; -import eu.europa.ted.eforms.sdk.entity.SdkEntityFactory; /** * Repository of SDK data types. @@ -31,30 +31,33 @@ public class SdkDataTypeRepository extends HashMap { private static final long serialVersionUID = 1L; + /** + * Creates the repository of the data types, with their privacy masks, the attributes that their + * fields carry, and the code lists of their values. They are read from the data-types.json + * resource of this library, which has the format of fields/fwd/data-types.json in SDK 2. The + * data types are the same for every SDK version. + */ public SdkDataTypeRepository() { - super(); + for (final JsonNode dataType : readResource().get(SdkConstants.DATA_TYPES_JSON_DATA_TYPES_KEY)) { + final SdkDataType sdkDataType = new SdkDataType(dataType); + this.put(sdkDataType.getId(), sdkDataType); + } } - /** - * Creates the repository of the data types of the given SDK version, with their privacy masks and - * the attributes that their fields carry. They are read from the data-types.json resource of - * this library, which has the format of fields/fwd/data-types.json in SDK 2. SDK 1 has no such - * file, so this is where its data types come from. - */ - public SdkDataTypeRepository(final String sdkVersion) throws InstantiationException { - this.populateMap(sdkVersion, readResource()); + private SdkDataTypeRepository(final Map dataTypes) { + super(dataTypes); } /** * Creates a repository with the default set of SDK data types and their privacy masks. This is a * temporary approach until data-types.json is available in the SDK. * - * @deprecated Use {@link #SdkDataTypeRepository(String)}, which creates the data types of the - * given SDK version, with the attributes that their fields carry. + * @deprecated Use {@link #SdkDataTypeRepository()}, which also gives the attributes that the + * fields of each data type carry. */ @Deprecated public static SdkDataTypeRepository createDefault() { - SdkDataTypeRepository repository = new SdkDataTypeRepository(); + SdkDataTypeRepository repository = new SdkDataTypeRepository(Map.of()); repository.addType("text", "unpublished"); repository.addType("text-multilingual", "unpublished"); @@ -83,14 +86,6 @@ private void addType(String id, String privacyMask) { this.put(id, new SdkDataType(id, privacyMask)); } - private void populateMap(final String sdkVersion, final JsonNode json) - throws InstantiationException { - for (final JsonNode dataType : json.get(SdkConstants.DATA_TYPES_JSON_DATA_TYPES_KEY)) { - final SdkDataType sdkDataType = SdkEntityFactory.getSdkDataType(sdkVersion, dataType); - this.put(sdkDataType.getId(), sdkDataType); - } - } - private static JsonNode readResource() { try (InputStream input = SdkDataTypeRepository.class.getResourceAsStream(SdkConstants.DATA_TYPES_JSON_FILE_NAME)) { diff --git a/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepositoryTest.java b/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepositoryTest.java index c17d753..8c66b92 100644 --- a/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepositoryTest.java +++ b/src/test/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepositoryTest.java @@ -15,32 +15,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.Set; import org.junit.jupiter.api.Test; import eu.europa.ted.eforms.sdk.entity.SdkDataType; -import eu.europa.ted.eforms.sdk.entity.v1.SdkDataTypeV1; -import eu.europa.ted.eforms.sdk.entity.v2.SdkDataTypeV2; class SdkDataTypeRepositoryTest { @Test - void testSdk1DataTypes() throws InstantiationException { - assertEquals(SdkDataTypeV1.class, new SdkDataTypeRepository("1.10.0").get("amount").getClass()); + void testAllDataTypesAreLoaded() { + assertEquals(23, new SdkDataTypeRepository().size()); } @Test - void testSdk2DataTypes() throws InstantiationException { - assertEquals(SdkDataTypeV2.class, - new SdkDataTypeRepository("eforms-sdk-2.0").get("amount").getClass()); - } - - @Test - void testAllDataTypesAreLoaded() throws InstantiationException { - assertEquals(23, new SdkDataTypeRepository("2.0.0").size()); - } - - @Test - void testAmountHasCurrencyAttribute() throws InstantiationException { - SdkDataType amount = new SdkDataTypeRepository("2.0.0").get("amount"); + void testAmountHasCurrencyAttribute() { + SdkDataType amount = new SdkDataTypeRepository().get("amount"); assertEquals("-1", amount.getPrivacyMask()); assertEquals("currencyID", amount.getAttributeName()); @@ -48,24 +36,24 @@ void testAmountHasCurrencyAttribute() throws InstantiationException { } @Test - void testDurationAndMeasureHaveTheirOwnUnits() throws InstantiationException { - SdkDataTypeRepository repository = new SdkDataTypeRepository("2.0.0"); + void testDurationAndMeasureHaveTheirOwnUnits() { + SdkDataTypeRepository repository = new SdkDataTypeRepository(); assertEquals("duration-unit", repository.get("duration").getAttributeType()); assertEquals("measurement-unit", repository.get("measure").getAttributeType()); } @Test - void testCodelistOfTheUnitsOfDuration() throws InstantiationException { - SdkDataTypeRepository repository = new SdkDataTypeRepository("2.0.0"); + void testCodelistOfTheUnitsOfDuration() { + SdkDataTypeRepository repository = new SdkDataTypeRepository(); assertEquals("timeperiod", repository.get(repository.get("duration").getAttributeType()).getListName()); } @Test - void testTypesWithRootCodelist() throws InstantiationException { - SdkDataTypeRepository repository = new SdkDataTypeRepository("2.0.0"); + void testTypesWithRootCodelist() { + SdkDataTypeRepository repository = new SdkDataTypeRepository(); assertEquals("currency", repository.get("currency").getListName()); assertEquals("timeperiod", repository.get("duration-unit").getListName()); @@ -75,8 +63,8 @@ void testTypesWithRootCodelist() throws InstantiationException { } @Test - void testAttributeOfTypeText() throws InstantiationException { - SdkDataTypeRepository repository = new SdkDataTypeRepository("2.0.0"); + void testAttributeOfTypeText() { + SdkDataTypeRepository repository = new SdkDataTypeRepository(); assertEquals("listName", repository.get("code").getAttributeName()); assertEquals("text", repository.get("code").getAttributeType()); @@ -86,12 +74,29 @@ void testAttributeOfTypeText() throws InstantiationException { } @Test - void testTypeWithoutAttribute() throws InstantiationException { - SdkDataType date = new SdkDataTypeRepository("2.0.0").get("date"); + void testTypeWithoutAttribute() { + SdkDataType date = new SdkDataTypeRepository().get("date"); assertEquals("1970-01-01Z", date.getPrivacyMask()); assertNull(date.getAttributeName()); assertNull(date.getAttributeType()); assertNull(date.getListName()); } + + @Test + @SuppressWarnings("deprecation") + void testCreateDefault_HasTheOriginalTypesWithTheirMasksOnly() { + final SdkDataTypeRepository defaults = SdkDataTypeRepository.createDefault(); + final SdkDataTypeRepository dataTypes = new SdkDataTypeRepository(); + + assertEquals(Set.of("text", "text-multilingual", "code", "internal-code", "id", "id-ref", "phone", + "email", "url", "date", "zoned-date", "time", "zoned-time", "indicator", "integer", "number", + "amount", "measure", "duration"), defaults.keySet()); + for (final SdkDataType dataType : defaults.values()) { + assertEquals(dataTypes.get(dataType.getId()).getPrivacyMask(), dataType.getPrivacyMask()); + assertNull(dataType.getAttributeName()); + assertNull(dataType.getAttributeType()); + assertNull(dataType.getListName()); + } + } }