Skip to content

Commit f855b82

Browse files
committed
Add handling for nested structures to ensure compatibility with complex and collection types.
1 parent e67c603 commit f855b82

File tree

4 files changed

+1089
-292
lines changed

4 files changed

+1089
-292
lines changed

src/main/java/uk/gov/hmcts/ccd/domain/model/definition/CaseFieldDefinition.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ private boolean isCollection(CommonField caseField) {
360360
&& !caseField.getFieldTypeDefinition().getCollectionFieldTypeDefinition().getComplexFields().isEmpty();
361361
}
362362

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+
*/
363372
public Optional<CaseFieldDefinition> getSubfieldDefinition(String fieldName) {
364373
FieldTypeDefinition fieldType = this.getFieldTypeDefinition();
365374

@@ -369,32 +378,15 @@ public Optional<CaseFieldDefinition> getSubfieldDefinition(String fieldName) {
369378
return complexField;
370379
}
371380

372-
return findFieldInComplexOrCollection(fieldType, fieldName);
373-
}
374-
375-
return Optional.empty();
376-
}
377-
378-
private Optional<CaseFieldDefinition> findFieldInComplexOrCollection(FieldTypeDefinition fieldType, String fieldName) {
379-
for (CaseFieldDefinition caseField : fieldType.getComplexFields()) {
380-
if (caseField.getId().equals(fieldName)) {
381-
return Optional.of(caseField);
382-
}
383-
384-
FieldTypeDefinition nestedFieldType = caseField.getFieldTypeDefinition();
385-
if (nestedFieldType != null) {
386-
Optional<CaseFieldDefinition> nestedField = findFieldInComplexOrCollection(nestedFieldType, fieldName);
387-
if (nestedField.isPresent()) {
388-
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;
389386
}
390387
}
391388
}
392389

393-
FieldTypeDefinition collectionFieldType = fieldType.getCollectionFieldTypeDefinition();
394-
if (collectionFieldType != null) {
395-
return findFieldInComplexOrCollection(collectionFieldType, fieldName);
396-
}
397-
398390
return Optional.empty();
399391
}
400392

src/main/java/uk/gov/hmcts/ccd/domain/service/common/ConditionalFieldRestorer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
/**
2626
* The ConditionalFieldRestorer is responsible for evaluating and handling fields
2727
* that are missing from sanitized data based on field-level permissions.
28-
* <p>
29-
* It processes the data as follows:
28+
*
29+
* <p>It processes the data as follows:
3030
* - Identifies fields missing from the sanitized client request by comparing
3131
* it with existing data.
3232
* - Checks whether the missing fields are excluded due to restricted field
@@ -35,8 +35,8 @@
3535
* allow it (e.g., Create permission is granted even when Read is restricted).
3636
* - Ensures compliance with access control rules defined at the field level
3737
* to maintain data integrity.
38-
* <p>
39-
* This class operates as an intermediate step in the data sanitization and
38+
*
39+
* <p>This class operates as an intermediate step in the data sanitization and
4040
* merge process, addressing incomplete field data while adhering to field-level
4141
* permission constraints.
4242
*/

0 commit comments

Comments
 (0)