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
1 change: 1 addition & 0 deletions src/main/java/eu/europa/ted/eforms/sdk/SdkConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SdkConstants {
public static final String NODES_JSON_FILE_NAME = "nodes.json";
public static final String FIELDS_JSON_FILE_NAME = "fields.json";
public static final String DATA_TYPES_JSON_FILE_NAME = "data-types.json";
public static final String DATA_TYPES_JSON_DATA_TYPES_KEY = "dataTypes";
public static final String BUSINESS_TERMS_JSON_FILE_NAME = "business-terms.json";
public static final String BUSINESS_ENTITIES_PROPERTIES_JSON_FILE_NAME = "business-entities-properties.json";
public static final String BUSINESS_ENTITIES_HIERARCHIES_JSON_FILE_NAME = "business-entities-hierarchies.json";
Expand Down
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, EFX_EXPRESSION_TRANSLATOR, EFX_TEMPLATE_TRANSLATOR, EFX_RULES_TRANSLATOR,
FIELD, NODE, CODELIST, NOTICE_TYPE, DATA_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;
}
55 changes: 53 additions & 2 deletions src/main/java/eu/europa/ted/eforms/sdk/entity/SdkDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@
package eu.europa.ted.eforms.sdk.entity;

import java.util.Objects;
import com.fasterxml.jackson.databind.JsonNode;

/**
* Represents an eForms SDK data type.
*
* Each field in the SDK has a type (e.g., "text", "date", "amount"). This entity captures
* type-level metadata such as the privacy masking value. Currently hardcoded; will be loaded from
* data-types.json when it is added to the SDK.
* type-level metadata such as the privacy masking value, the attribute that the fields of the type
* carry (e.g., the currency of an amount) with its data type, and the code list of the data types
* whose values come from one. Currently hardcoded; will be loaded from data-types.json when it is
* added to the SDK.
*/
public class SdkDataType {
private final String id;
private final String privacyMask;
private final String attributeName;
private final String attributeType;
private final String listName;

@SuppressWarnings("unused")
private SdkDataType() {
Expand All @@ -34,6 +40,27 @@ private SdkDataType() {
public SdkDataType(final String id, final String privacyMask) {
this.id = id;
this.privacyMask = privacyMask;
this.attributeName = null;
this.attributeType = null;
this.listName = null;
}

/**
* Creates a data type from its entry in data-types.json.
*/
protected SdkDataType(final JsonNode dataType) {
this.id = dataType.get("type").asText(null);
this.privacyMask =
dataType.hasNonNull("maskingValue") ? dataType.get("maskingValue").asText(null) : null;
final JsonNode attribute = dataType.get("attribute");
this.attributeName = attribute != null && attribute.hasNonNull("name")
? attribute.get("name").asText(null)
: null;
this.attributeType = attribute != null && attribute.hasNonNull("type")
? attribute.get("type").asText(null)
: null;
this.listName =
dataType.hasNonNull("listName") ? dataType.get("listName").asText(null) : null;
}

public String getId() {
Expand All @@ -44,6 +71,30 @@ public String getPrivacyMask() {
return this.privacyMask;
}

/**
* Returns the name of the attribute that the fields of this data type carry (e.g., "currencyID"
* for an amount), or null if they carry none.
*/
public String getAttributeName() {
return this.attributeName;
}

/**
* Returns the data type of the attribute that the fields of this data type carry (e.g., "currency"
* for an amount), or null if they carry none.
*/
public String getAttributeType() {
return this.attributeType;
}

/**
* Returns the name of the root code list that the values of this data type come from (e.g.,
* "timeperiod" for a duration unit), or null if they come from none.
*/
public String getListName() {
return this.listName;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,46 @@
*/
package eu.europa.ted.eforms.sdk.repository;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.HashMap;
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.
*
* Currently uses hardcoded type definitions. When data-types.json is added to the SDK, this class
* will be updated to load type metadata from JSON.
* Currently uses hardcoded type definitions, in the data-types.json resource of this library.
*/
public class SdkDataTypeRepository extends HashMap<String, SdkDataType> {
private static final long serialVersionUID = 1L;

public SdkDataTypeRepository() {
super();
}

/**
* 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());
}

/**
* 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
public static SdkDataTypeRepository createDefault() {
SdkDataTypeRepository repository = new SdkDataTypeRepository();

Expand Down Expand Up @@ -58,4 +82,21 @@ public static SdkDataTypeRepository createDefault() {
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)) {
return new ObjectMapper().readTree(input);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
132 changes: 132 additions & 0 deletions src/main/resources/eu/europa/ted/eforms/sdk/repository/data-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"dataTypes": [
{
"type": "amount",
"maskingValue": "-1",
"attribute": {
"name": "currencyID",
"type": "currency"
}
},
{
"type": "code",
"maskingValue": "unpublished",
"attribute": {
"name": "listName",
"type": "text"
}
},
{
"type": "currency",
"maskingValue": "unpublished",
"listName": "currency"
},
{
"type": "date",
"maskingValue": "1970-01-01Z"
},
{
"type": "duration",
"maskingValue": "-1",
"attribute": {
"name": "unitCode",
"type": "duration-unit"
}
},
{
"type": "duration-unit",
"maskingValue": "unpublished",
"listName": "timeperiod"
},
{
"type": "email",
"maskingValue": "unpublished"
},
{
"type": "id",
"maskingValue": "unpublished",
"attribute": {
"name": "schemeName",
"type": "text"
}
},
{
"type": "id-ref",
"maskingValue": "unpublished",
"attribute": {
"name": "schemeName",
"type": "text"
}
},
{
"type": "indicator",
"maskingValue": "0"
},
{
"type": "integer",
"maskingValue": "-1"
},
{
"type": "internal-code",
"maskingValue": "unpublished",
"attribute": {
"name": "listName",
"type": "text"
}
},
{
"type": "language",
"maskingValue": "unpublished",
"listName": "language"
},
{
"type": "measure",
"maskingValue": "-1",
"attribute": {
"name": "unitCode",
"type": "measurement-unit"
}
},
{
"type": "measurement-unit",
"maskingValue": "unpublished",
"listName": "measurement-unit"
},
{
"type": "number",
"maskingValue": "-1"
},
{
"type": "phone",
"maskingValue": "unpublished"
},
{
"type": "text",
"maskingValue": "unpublished"
},
{
"type": "text-multilingual",
"maskingValue": "unpublished",
"attribute": {
"name": "languageID",
"type": "language"
}
},
{
"type": "time",
"maskingValue": "00:00:00Z"
},
{
"type": "url",
"maskingValue": "unpublished"
},
{
"type": "zoned-date",
"maskingValue": "1970-01-01Z"
},
{
"type": "zoned-time",
"maskingValue": "00:00:00Z"
}
]
}
Loading
Loading