11package eu .europa .ted .eforms .sdk .entity ;
22
3+ import java .util .ArrayList ;
4+ import java .util .Collections ;
5+ import java .util .List ;
36import java .util .Objects ;
47import com .fasterxml .jackson .databind .JsonNode ;
58import eu .europa .ted .eforms .xpath .XPathInfo ;
@@ -15,7 +18,12 @@ public abstract class SdkField implements Comparable<SdkField> {
1518 private final boolean repeatable ;
1619 private final String privacyCode ;
1720 private final PrivacySettings privacySettings ;
21+ private final List <String > attributes ;
22+ private final String attributeOf ;
23+ private final String attributeName ;
1824 private SdkNode parentNode ;
25+ private List <SdkField > attributeFields ;
26+ private SdkField attributeOfField ;
1927 private XPathInfo xpathInfo ;
2028
2129 /**
@@ -111,6 +119,9 @@ protected SdkField(final String id, final String type, final String parentNodeId
111119 this .repeatable = repeatable ;
112120 this .privacyCode = null ;
113121 this .privacySettings = null ;
122+ this .attributes = Collections .emptyList ();
123+ this .attributeOf = null ;
124+ this .attributeName = null ;
114125 }
115126
116127 protected SdkField (final JsonNode fieldNode ) {
@@ -124,6 +135,21 @@ protected SdkField(final JsonNode fieldNode) {
124135 final JsonNode privacyNode = fieldNode .get ("privacy" );
125136 this .privacyCode = privacyNode != null ? privacyNode .get ("code" ).asText (null ) : null ;
126137 this .privacySettings = extractPrivacy (privacyNode );
138+ this .attributes = extractAttributes (fieldNode );
139+ this .attributeOf = fieldNode .has ("attributeOf" ) ? fieldNode .get ("attributeOf" ).asText (null ) : null ;
140+ this .attributeName = fieldNode .has ("attributeName" ) ? fieldNode .get ("attributeName" ).asText (null ) : null ;
141+ }
142+
143+ protected List <String > extractAttributes (final JsonNode fieldNode ) {
144+ final JsonNode attributesNode = fieldNode .get ("attributes" );
145+ if (attributesNode == null || !attributesNode .isArray ()) {
146+ return Collections .emptyList ();
147+ }
148+ List <String > result = new ArrayList <>();
149+ for (JsonNode attr : attributesNode ) {
150+ result .add (attr .asText ());
151+ }
152+ return Collections .unmodifiableList (result );
127153 }
128154
129155 protected String extractCodelistId (final JsonNode fieldNode ) {
@@ -193,6 +219,50 @@ public String getCodelistId() {
193219 return this .codelistId ;
194220 }
195221
222+ public List <String > getAttributes () {
223+ return this .attributes ;
224+ }
225+
226+ public String getAttributeOf () {
227+ return this .attributeOf ;
228+ }
229+
230+ public String getAttributeName () {
231+ return this .attributeName ;
232+ }
233+
234+ public List <SdkField > getAttributeFields () {
235+ return this .attributeFields ;
236+ }
237+
238+ public void setAttributeFields (List <SdkField > attributeFields ) {
239+ this .attributeFields = Collections .unmodifiableList (attributeFields );
240+ }
241+
242+ public SdkField getAttributeOfField () {
243+ return this .attributeOfField ;
244+ }
245+
246+ public void setAttributeOfField (SdkField attributeOfField ) {
247+ this .attributeOfField = attributeOfField ;
248+ }
249+
250+ /**
251+ * Returns the attribute field with the given XML attribute name (e.g. "unitCode", "listName"),
252+ * or null if this field has no such attribute.
253+ */
254+ public SdkField getAttributeField (String attrName ) {
255+ if (this .attributeFields == null ) {
256+ return null ;
257+ }
258+ for (SdkField attrField : this .attributeFields ) {
259+ if (attrName .equals (attrField .getAttributeName ())) {
260+ return attrField ;
261+ }
262+ }
263+ return null ;
264+ }
265+
196266 public boolean isRepeatable () {
197267 return this .repeatable ;
198268 }
0 commit comments