@@ -360,6 +360,15 @@ private boolean isCollection(CommonField caseField) {
360
360
&& !caseField .getFieldTypeDefinition ().getCollectionFieldTypeDefinition ().getComplexFields ().isEmpty ();
361
361
}
362
362
363
+ /**
364
+ * Retrieves the subfield definition for the specified field name.
365
+ * If the field name corresponds to a subfield within the current field's
366
+ * complex fields or collection field type, the subfield definition is returned.
367
+ * If no match is found, an empty Optional is returned.
368
+ *
369
+ * @param fieldName The name of the subfield to retrieve.
370
+ * @return An Optional containing the matching subfield definition, or empty if no match is found.
371
+ */
363
372
public Optional <CaseFieldDefinition > getSubfieldDefinition (String fieldName ) {
364
373
FieldTypeDefinition fieldType = this .getFieldTypeDefinition ();
365
374
@@ -369,33 +378,15 @@ public Optional<CaseFieldDefinition> getSubfieldDefinition(String fieldName) {
369
378
return complexField ;
370
379
}
371
380
372
- return findFieldInComplexOrCollection (fieldType , fieldName );
373
- }
374
-
375
- return Optional .empty ();
376
- }
377
-
378
- private Optional <CaseFieldDefinition > findFieldInComplexOrCollection (FieldTypeDefinition fieldType ,
379
- String fieldName ) {
380
- for (CaseFieldDefinition caseField : fieldType .getComplexFields ()) {
381
- if (caseField .getId ().equals (fieldName )) {
382
- return Optional .of (caseField );
383
- }
384
-
385
- FieldTypeDefinition nestedFieldType = caseField .getFieldTypeDefinition ();
386
- if (nestedFieldType != null ) {
387
- Optional <CaseFieldDefinition > nestedField = findFieldInComplexOrCollection (nestedFieldType , fieldName );
388
- if (nestedField .isPresent ()) {
389
- return nestedField ;
381
+ FieldTypeDefinition collectionFieldType = fieldType .getCollectionFieldTypeDefinition ();
382
+ if (collectionFieldType != null ) {
383
+ Optional <CaseFieldDefinition > collectionField = collectionFieldType .getComplexFieldById (fieldName );
384
+ if (collectionField .isPresent ()) {
385
+ return collectionField ;
390
386
}
391
387
}
392
388
}
393
389
394
- FieldTypeDefinition collectionFieldType = fieldType .getCollectionFieldTypeDefinition ();
395
- if (collectionFieldType != null ) {
396
- return findFieldInComplexOrCollection (collectionFieldType , fieldName );
397
- }
398
-
399
390
return Optional .empty ();
400
391
}
401
392
0 commit comments