Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
TEDEFO-4319 Add privacy settings and data types#44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68 src/main/java/eu/europa/ted/eforms/sdk/entity/SdkDataType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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; | ||
| import java.util.Objects; | ||
| /** | ||
| * 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. | ||
| */ | ||
| public class SdkDataType { | ||
| private final String id; | ||
| private final String privacyMask; | ||
| @SuppressWarnings("unused") | ||
| private SdkDataType() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| public SdkDataType(final String id, final String privacyMask) { | ||
| this.id = id; | ||
| this.privacyMask = privacyMask; | ||
| } | ||
| public String getId() { | ||
| return this.id; | ||
| } | ||
| public String getPrivacyMask() { | ||
| return this.privacyMask; | ||
| } | ||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| SdkDataType other = (SdkDataType) obj; | ||
| return Objects.equals(this.id, other.id); | ||
| } | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(this.id); | ||
| } | ||
| @Override | ||
| public String toString() { | ||
| return this.id; | ||
| } | ||
| } |
123 changes: 112 additions & 11 deletions
123 src/main/java/eu/europa/ted/eforms/sdk/entity/SdkField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -13,9 +13,82 @@ public abstract class SdkField implements Comparable<SdkField> { | ||
| private final String type; | ||
| private final String codelistId; | ||
| private final boolean repeatable; | ||
| private final String privacyCode; | ||
| private final PrivacySettings privacySettings; | ||
| private SdkNode parentNode; | ||
| private XPathInfo xpathInfo; | ||
| /** | ||
| * Privacy settings for fields that can be withheld from publication. | ||
| */ | ||
| public static class PrivacySettings { | ||
| private final String privacyCodeFieldId; | ||
| private final String justificationCodeFieldId; | ||
| private final String justificationDescriptionFieldId; | ||
| private final String publicationDateFieldId; | ||
| private SdkField privacyCodeField; | ||
| private SdkField justificationCodeField; | ||
| private SdkField justificationDescriptionField; | ||
| private SdkField publicationDateField; | ||
| public PrivacySettings(final String privacyCodeFieldId, | ||
| final String justificationCodeFieldId, final String justificationDescriptionFieldId, | ||
| final String publicationDateFieldId) { | ||
| this.privacyCodeFieldId = privacyCodeFieldId; | ||
| this.justificationCodeFieldId = justificationCodeFieldId; | ||
| this.justificationDescriptionFieldId = justificationDescriptionFieldId; | ||
| this.publicationDateFieldId = publicationDateFieldId; | ||
| } | ||
| public String getPrivacyCodeFieldId() { | ||
| return this.privacyCodeFieldId; | ||
| } | ||
| public String getJustificationCodeFieldId() { | ||
| return this.justificationCodeFieldId; | ||
| } | ||
| public String getJustificationDescriptionFieldId() { | ||
| return this.justificationDescriptionFieldId; | ||
| } | ||
| public String getPublicationDateFieldId() { | ||
| return this.publicationDateFieldId; | ||
| } | ||
| public SdkField getPrivacyCodeField() { | ||
| return this.privacyCodeField; | ||
| } | ||
| public void setPrivacyCodeField(SdkField privacyCodeField) { | ||
| this.privacyCodeField = privacyCodeField; | ||
| } | ||
| public SdkField getJustificationCodeField() { | ||
| return this.justificationCodeField; | ||
| } | ||
| public void setJustificationCodeField(SdkField justificationCodeField) { | ||
| this.justificationCodeField = justificationCodeField; | ||
| } | ||
| public SdkField getJustificationDescriptionField() { | ||
| return this.justificationDescriptionField; | ||
| } | ||
| public void setJustificationDescriptionField(SdkField justificationDescriptionField) { | ||
| this.justificationDescriptionField = justificationDescriptionField; | ||
| } | ||
| public SdkField getPublicationDateField() { | ||
| return this.publicationDateField; | ||
| } | ||
| public void setPublicationDateField(SdkField publicationDateField) { | ||
| this.publicationDateField = publicationDateField; | ||
| } | ||
| } | ||
| @SuppressWarnings("unused") | ||
| private SdkField() { | ||
| throw new UnsupportedOperationException(); | ||
| @@ -36,6 +109,8 @@ protected SdkField(final String id, final String type, final String parentNodeId | ||
| this.type = type; | ||
| this.codelistId = codelistId; | ||
| this.repeatable = repeatable; | ||
| this.privacyCode = null; | ||
| this.privacySettings = null; | ||
| } | ||
| protected SdkField(final JsonNode fieldNode) { | ||
| @@ -46,6 +121,9 @@ protected SdkField(final JsonNode fieldNode) { | ||
| this.type = fieldNode.get("type").asText(null); | ||
| this.codelistId = extractCodelistId(fieldNode); | ||
| this.repeatable = extractRepeatable(fieldNode); | ||
| final JsonNode privacyNode = fieldNode.get("privacy"); | ||
| this.privacyCode = privacyNode != null ? privacyNode.get("code").asText(null) : null; | ||
| this.privacySettings = extractPrivacy(privacyNode); | ||
| } | ||
| protected String extractCodelistId(final JsonNode fieldNode) { | ||
| @@ -76,36 +154,59 @@ protected boolean extractRepeatable(final JsonNode fieldNode) { | ||
| return valueNode.asBoolean(false); | ||
| } | ||
| protected PrivacySettings extractPrivacy(final JsonNode privacyNode) { | ||
| if (privacyNode == null) { | ||
| return null; | ||
| } | ||
| final String privacyCodeFieldId = privacyNode.get("unpublishedFieldId").asText(null); | ||
| final String justificationCodeFieldId = privacyNode.get("reasonCodeFieldId").asText(null); | ||
| final String justificationDescriptionFieldId = | ||
| privacyNode.get("reasonDescriptionFieldId").asText(null); | ||
| final String publicationDateFieldId = privacyNode.get("publicationDateFieldId").asText(null); | ||
rousso marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return new PrivacySettings(privacyCodeFieldId, justificationCodeFieldId, | ||
| justificationDescriptionFieldId, publicationDateFieldId); | ||
| } | ||
| public String getId() { | ||
| return id; | ||
| return this.id; | ||
| } | ||
| public String getParentNodeId() { | ||
| return parentNodeId; | ||
| return this.parentNodeId; | ||
| } | ||
| public String getXpathAbsolute() { | ||
| return xpathAbsolute; | ||
| return this.xpathAbsolute; | ||
| } | ||
| public String getXpathRelative() { | ||
| return xpathRelative; | ||
| return this.xpathRelative; | ||
| } | ||
| public String getType() { | ||
| return type; | ||
| return this.type; | ||
| } | ||
| public String getCodelistId() { | ||
| return codelistId; | ||
| return this.codelistId; | ||
| } | ||
| public boolean isRepeatable() { | ||
| return repeatable; | ||
| return this.repeatable; | ||
| } | ||
| public String getPrivacyCode() { | ||
| return this.privacyCode; | ||
| } | ||
| public PrivacySettings getPrivacySettings() { | ||
| return this.privacySettings; | ||
| } | ||
| public SdkNode getParentNode() { | ||
| return parentNode; | ||
| return this.parentNode; | ||
| } | ||
| public void setParentNode(SdkNode parentNode) { | ||
| @@ -144,16 +245,16 @@ public boolean equals(Object obj) { | ||
| return false; | ||
| } | ||
| SdkField other = (SdkField) obj; | ||
| return Objects.equals(id, other.id); | ||
| return Objects.equals(this.id, other.id); | ||
| } | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(id); | ||
| return Objects.hash(this.id); | ||
| } | ||
| @Override | ||
| public String toString() { | ||
| return id; | ||
| return this.id; | ||
| } | ||
| } | ||
60 changes: 60 additions & 0 deletions
60 src/main/java/eu/europa/ted/eforms/sdk/repository/SdkDataTypeRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.repository; | ||
| import java.util.HashMap; | ||
| import eu.europa.ted.eforms.sdk.entity.SdkDataType; | ||
| /** | ||
| * 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. | ||
| */ | ||
| public class SdkDataTypeRepository extends HashMap<String, SdkDataType> { | ||
| private static final long serialVersionUID = 1L; | ||
| /** | ||
| * 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. | ||
| */ | ||
| public static SdkDataTypeRepository createDefault() { | ||
| SdkDataTypeRepository repository = new SdkDataTypeRepository(); | ||
| repository.addType("text", "unpublished"); | ||
| repository.addType("text-multilingual", "unpublished"); | ||
| repository.addType("code", "unpublished"); | ||
| repository.addType("internal-code", "unpublished"); | ||
| repository.addType("id", "unpublished"); | ||
| repository.addType("id-ref", "unpublished"); | ||
| repository.addType("phone", "unpublished"); | ||
| repository.addType("email", "unpublished"); | ||
| repository.addType("url", "unpublished"); | ||
| repository.addType("date", "1970-01-01Z"); | ||
| repository.addType("zoned-date", "1970-01-01Z"); | ||
| repository.addType("time", "00:00:00Z"); | ||
| repository.addType("zoned-time", "00:00:00Z"); | ||
| repository.addType("indicator", "0"); | ||
| repository.addType("integer", "-1"); | ||
| repository.addType("number", "-1"); | ||
| repository.addType("amount", "-1"); | ||
| repository.addType("measure", "-1"); | ||
| return repository; | ||
| } | ||
| private void addType(String id, String privacyMask) { | ||
| this.put(id, new SdkDataType(id, privacyMask)); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23 src/main/java/eu/europa/ted/eforms/sdk/repository/SdkFieldRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,6 +32,8 @@ protected void populateMap(final JsonNode json, final Object... context) | ||
| : null; | ||
| final ArrayNode fields = (ArrayNode) json.get(SdkConstants.FIELDS_JSON_FIELDS_KEY); | ||
| // First pass: create all field entities and add them to the map | ||
| for (final JsonNode field : fields) { | ||
| final SdkField sdkField = SdkEntityFactory.getSdkField(sdkVersion, field); | ||
| put(sdkField.getId(), sdkField); | ||
| @@ -40,5 +42,26 @@ protected void populateMap(final JsonNode json, final Object... context) | ||
| sdkField.setParentNode(nodes.get(sdkField.getParentNodeId())); | ||
| } | ||
| } | ||
| // Second pass: resolve privacy field references | ||
| for (final SdkField sdkField : this.values()) { | ||
| if (sdkField.getPrivacySettings() != null) { | ||
| SdkField.PrivacySettings privacy = sdkField.getPrivacySettings(); | ||
| if (privacy.getPrivacyCodeFieldId() != null) { | ||
| privacy.setPrivacyCodeField(this.get(privacy.getPrivacyCodeFieldId())); | ||
| } | ||
| if (privacy.getJustificationCodeFieldId() != null) { | ||
| privacy.setJustificationCodeField(this.get(privacy.getJustificationCodeFieldId())); | ||
| } | ||
| if (privacy.getJustificationDescriptionFieldId() != null) { | ||
| privacy.setJustificationDescriptionField( | ||
| this.get(privacy.getJustificationDescriptionFieldId())); | ||
| } | ||
| if (privacy.getPublicationDateFieldId() != null) { | ||
| privacy.setPublicationDateField(this.get(privacy.getPublicationDateFieldId())); | ||
| } | ||
rousso marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.