Skip to content
Open
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 @@ -7,6 +7,7 @@ public class SdkConstants {
public static final String FIELDS_JSON_XML_STRUCTURE_KEY = "xmlStructure";
public static final String FIELDS_JSON_FIELDS_KEY = "fields";

public static final String NOTICE_TYPES_JSON_SUBTYPES_KEY = "noticeSubTypes";
public static final String NOTICE_TYPES_JSON_DOCUMENT_TYPES_KEY = "documentTypes";
public static final String NOTICE_TYPES_JSON_DOCUMENT_TYPE_KEY = "documentType";
public static final String NOTICE_TYPES_JSON_NAMESPACE_KEY = "namespace";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package eu.europa.ted.eforms.sdk.component;

/**
* Enumeration of component types that can be registered with the SDK component factory.
* Enumeration of component types that can be registered with the SDK component
* factory.
*/
public enum SdkComponentType {
FIELD, NODE, CODELIST, EFX_EXPRESSION_TRANSLATOR, EFX_TEMPLATE_TRANSLATOR, SYMBOL_RESOLVER, SCRIPT_GENERATOR, MARKUP_GENERATOR;
FIELD, NODE, CODELIST, NOTICE_TYPE, EFX_EXPRESSION_TRANSLATOR, EFX_TEMPLATE_TRANSLATOR, EFX_RULES_TRANSLATOR,
SYMBOL_RESOLVER, SCRIPT_GENERATOR, MARKUP_GENERATOR, VALIDATOR_GENERATOR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public static SdkNode getSdkNode(String sdkVersion, JsonNode node) throws Instan
return SdkEntityFactory.INSTANCE.getComponentImpl(sdkVersion, SdkComponentType.NODE,
SdkNode.class, node);
}

public static SdkNoticeSubtype getSdkNoticeSubtype(final String sdkVersion, final JsonNode json)
throws InstantiationException {
return SdkEntityFactory.INSTANCE.getComponentImpl(sdkVersion, SdkComponentType.NOTICE_TYPE,
SdkNoticeSubtype.class, json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ public int hashCode() {

@Override
public String toString() {
return "SdkField [id=" + id + "]";
return id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package eu.europa.ted.eforms.sdk.entity;

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

/**
* Represents a notice subtype from the SDK's notice-types.json file.
*/
public abstract class SdkNoticeSubtype implements Comparable<SdkNoticeSubtype> {
private final String subTypeId;
private final String documentType;
private final String type;

protected SdkNoticeSubtype(String subTypeId, String documentType, String type) {
this.subTypeId = subTypeId;
this.documentType = documentType;
this.type = type;
}

protected SdkNoticeSubtype(JsonNode json) {
this.subTypeId = json.get("subTypeId").asText(null);
this.documentType = json.get("documentType").asText(null);
this.type = json.get("type").asText(null);
Comment on lines +21 to +23
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JsonNode constructor does not validate that required JSON fields (subTypeId, documentType, type) exist before accessing them. If json.get("subTypeId") returns null, calling asText(null) on it will throw a NullPointerException. Consider adding null checks or using safer accessor methods like json.has("subTypeId") before accessing, consistent with how SdkNode handles optional fields (see SdkNode.java:27).

Suggested change
this.subTypeId = json.get("subTypeId").asText(null);
this.documentType = json.get("documentType").asText(null);
this.type = json.get("type").asText(null);
if (json == null) {
throw new IllegalArgumentException("json must not be null when creating SdkNoticeSubtype");
}
JsonNode subTypeIdNode = json.get("subTypeId");
JsonNode documentTypeNode = json.get("documentType");
JsonNode typeNode = json.get("type");
if (subTypeIdNode == null || documentTypeNode == null || typeNode == null) {
throw new IllegalArgumentException("Missing required fields (subTypeId, documentType, type) in notice subtype JSON: " + json);
}
this.subTypeId = subTypeIdNode.asText(null);
this.documentType = documentTypeNode.asText(null);
this.type = typeNode.asText(null);

Copilot uses AI. Check for mistakes.
}

/**
* Returns the notice subtype ID (e.g., "1", "3", "CEI", "E1", "X01").
* This is the primary identifier used for phase generation.
*/
public String getId() {
return subTypeId;
}
Comment on lines +30 to +32
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getId() method returns subTypeId which can be null (set via asText(null) in the JsonNode constructor at line 21). This could cause NullPointerException in callers who expect a non-null value, such as in SdkNoticeTypeRepository.java:26 where it's used as a map key, and in the compareTo method. Consider validating that critical fields like subTypeId are non-null after construction, or document that null is a valid return value.

Copilot uses AI. Check for mistakes.

public String getSubTypeId() {
return subTypeId;
}

public String getDocumentType() {
return documentType;
}

public String getType() {
return type;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
SdkNoticeSubtype other = (SdkNoticeSubtype) obj;
return Objects.equals(subTypeId, other.subTypeId);
}

@Override
public int compareTo(SdkNoticeSubtype o) {
return this.subTypeId.compareTo(o.subTypeId);
}
Comment on lines +62 to +64
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compareTo method can throw a NullPointerException if subTypeId is null. The JsonNode constructor (line 21) uses asText(null) which can return null. Consider adding null safety checks or using Objects.compare with a null-safe comparator, similar to how SdkCodelist handles this (see SdkCodelist.java:67-69).

Copilot uses AI. Check for mistakes.

@Override
public int hashCode() {
return Objects.hash(subTypeId);
}

@Override
public String toString() {
return subTypeId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package eu.europa.ted.eforms.sdk.repository;

import java.nio.file.Path;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import eu.europa.ted.eforms.sdk.SdkConstants;
import eu.europa.ted.eforms.sdk.entity.SdkEntityFactory;
import eu.europa.ted.eforms.sdk.entity.SdkNoticeSubtype;

/**
* Repository for SDK notice types loaded from notice-types.json.
* Maps notice subtype IDs (e.g., "1", "3", "CEI", "E1", "X01") to SdkNoticeSubtype objects.
*/
public class SdkNoticeTypeRepository extends MapFromJson<SdkNoticeSubtype> {
private static final long serialVersionUID = 1L;

public SdkNoticeTypeRepository(String sdkVersion, Path jsonPath) throws InstantiationException {
super(sdkVersion, jsonPath);
}

@Override
protected void populateMap(final JsonNode json) throws InstantiationException {
final ArrayNode noticeSubtypes = (ArrayNode) json.get(SdkConstants.NOTICE_TYPES_JSON_SUBTYPES_KEY);
for (final JsonNode noticeSubtype : noticeSubtypes) {
final SdkNoticeSubtype sdkNoticeSubtype = SdkEntityFactory.getSdkNoticeSubtype(sdkVersion, noticeSubtype);
put(sdkNoticeSubtype.getId(), sdkNoticeSubtype);
}
}
}
Loading