Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -31,30 +31,33 @@
public class SdkDataTypeRepository extends HashMap<String, SdkDataType> {
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<String, SdkDataType> 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");
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,45 @@

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());
assertEquals("currency", amount.getAttributeType());
}

@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());
Expand All @@ -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());
Expand All @@ -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());
}
}
}
Loading