Skip to content

Commit add6b18

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

File tree

3 files changed

+134
-134
lines changed

3 files changed

+134
-134
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ public Optional<CaseFieldDefinition> getSubfieldDefinition(String fieldName) {
375375
return Optional.empty();
376376
}
377377

378-
private Optional<CaseFieldDefinition> findFieldInComplexOrCollection(FieldTypeDefinition fieldType, String fieldName) {
378+
private Optional<CaseFieldDefinition> findFieldInComplexOrCollection(FieldTypeDefinition fieldType,
379+
String fieldName) {
379380
for (CaseFieldDefinition caseField : fieldType.getComplexFields()) {
380381
if (caseField.getId().equals(fieldName)) {
381382
return Optional.of(caseField);

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

+4-4
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
*/

src/test/java/uk/gov/hmcts/ccd/domain/service/common/ConditionalFieldRestorerTest.java

+128-129
Original file line numberDiff line numberDiff line change
@@ -4068,53 +4068,53 @@ private CaseFieldDefinition caseCategoryFieldWithNestedListWithCreatePermissionW
40684068
void shouldAddMissingCollectionFieldsInNestedCollections() {
40694069
// Nested collection of collections payload
40704070
final String existingDataString = """
4071-
{
4072-
"caseCategory": {
4073-
"list_items": [
4074-
{
4075-
"id": "123456",
4076-
"value": {
4077-
"nested_wrapper": {
4078-
"nested_list": [
4079-
{
4080-
"id": "nested_1",
4081-
"value": {
4082-
"code": "NestedTest1",
4083-
"label": "NestedLabel1"
4084-
}
4085-
},
4086-
{
4087-
"id": "nested_2",
4088-
"value": {
4089-
"code": "NestedTest2",
4090-
"label": "NestedLabel2"
4071+
{
4072+
"caseCategory": {
4073+
"list_items": [
4074+
{
4075+
"id": "123456",
4076+
"value": {
4077+
"nested_wrapper": {
4078+
"nested_list": [
4079+
{
4080+
"id": "nested_1",
4081+
"value": {
4082+
"code": "NestedTest1",
4083+
"label": "NestedLabel1"
4084+
}
4085+
},
4086+
{
4087+
"id": "nested_2",
4088+
"value": {
4089+
"code": "NestedTest2",
4090+
"label": "NestedLabel2"
4091+
}
40914092
}
4092-
}
4093-
]
4093+
]
4094+
}
40944095
}
40954096
}
4096-
}
4097-
]
4097+
]
4098+
}
40984099
}
4099-
}
4100-
""";
4100+
""";
41014101

41024102
final String newDataString = """
4103-
{
4104-
"caseCategory": {
4105-
"list_items": [
4106-
{
4107-
"id": "123456",
4108-
"value": {
4109-
"nested_wrapper": {
4110-
"nested_list": []
4111-
}
4103+
{
4104+
"caseCategory": {
4105+
"list_items": [
4106+
{
4107+
"id": "123456",
4108+
"value": {
4109+
"nested_wrapper": {
4110+
"nested_list": []
4111+
}
4112+
}
41124113
}
4113-
}
4114-
]
4115-
}
4116-
}
4117-
""";
4114+
]
4115+
}
4116+
}
4117+
""";
41184118

41194119
setupLogging().setLevel(Level.INFO);
41204120

@@ -4148,62 +4148,61 @@ void shouldAddMissingCollectionFieldsInNestedCollections() {
41484148

41494149
@Test
41504150
void shouldAddMissingCollectionSingleFieldInNestedCollections() {
4151-
// Nested collection of collections payload
41524151
final String existingDataString = """
4153-
{
4154-
"caseCategory": {
4155-
"list_items": [
4156-
{
4157-
"id": "123456",
4158-
"value": {
4159-
"nested_wrapper": {
4160-
"nested_list": [
4161-
{
4162-
"id": "nested_1",
4163-
"value": {
4164-
"code": "NestedTest1",
4165-
"label": "NestedLabel1"
4166-
}
4167-
},
4168-
{
4169-
"id": "nested_2",
4170-
"value": {
4171-
"code": "NestedTest2",
4172-
"label": "NestedLabel2"
4152+
{
4153+
"caseCategory": {
4154+
"list_items": [
4155+
{
4156+
"id": "123456",
4157+
"value": {
4158+
"nested_wrapper": {
4159+
"nested_list": [
4160+
{
4161+
"id": "nested_1",
4162+
"value": {
4163+
"code": "NestedTest1",
4164+
"label": "NestedLabel1"
4165+
}
4166+
},
4167+
{
4168+
"id": "nested_2",
4169+
"value": {
4170+
"code": "NestedTest2",
4171+
"label": "NestedLabel2"
4172+
}
41734173
}
4174-
}
4175-
]
4174+
]
4175+
}
41764176
}
41774177
}
4178-
}
4179-
]
4180-
}
4181-
}
4182-
""";
4178+
]
4179+
}
4180+
}
4181+
""";
41834182

41844183
final String newDataString = """
4185-
{
4186-
"caseCategory": {
4187-
"list_items": [
4188-
{
4189-
"id": "123456",
4190-
"value": {
4191-
"nested_wrapper": {
4192-
"nested_list": [
4193-
{
4194-
"id": "nested_2",
4195-
"value": {
4196-
"code": "NestedTest2"
4184+
{
4185+
"caseCategory": {
4186+
"list_items": [
4187+
{
4188+
"id": "123456",
4189+
"value": {
4190+
"nested_wrapper": {
4191+
"nested_list": [
4192+
{
4193+
"id": "nested_2",
4194+
"value": {
4195+
"code": "NestedTest2"
4196+
}
41974197
}
4198-
}
4199-
]
4200-
}
4198+
]
4199+
}
4200+
}
42014201
}
4202-
}
4203-
]
4204-
}
4205-
}
4206-
""";
4202+
]
4203+
}
4204+
}
4205+
""";
42074206

42084207
setupLogging().setLevel(Level.INFO);
42094208

@@ -4238,53 +4237,53 @@ void shouldAddMissingCollectionSingleFieldInNestedCollections() {
42384237
@Test
42394238
void shouldIgnoreMissingCollectionFieldsInNestedCollections() {
42404239
final String existingDataString = """
4241-
{
4242-
"caseCategory": {
4243-
"list_items": [
4244-
{
4245-
"id": "123456",
4246-
"value": {
4247-
"nested_wrapper": {
4248-
"nested_list": [
4249-
{
4250-
"id": "nested_1",
4251-
"value": {
4252-
"code": "NestedTest1",
4253-
"label": "NestedLabel1"
4254-
}
4255-
},
4256-
{
4257-
"id": "nested_2",
4258-
"value": {
4259-
"code": "NestedTest2",
4260-
"label": "NestedLabel2"
4240+
{
4241+
"caseCategory": {
4242+
"list_items": [
4243+
{
4244+
"id": "123456",
4245+
"value": {
4246+
"nested_wrapper": {
4247+
"nested_list": [
4248+
{
4249+
"id": "nested_1",
4250+
"value": {
4251+
"code": "NestedTest1",
4252+
"label": "NestedLabel1"
4253+
}
4254+
},
4255+
{
4256+
"id": "nested_2",
4257+
"value": {
4258+
"code": "NestedTest2",
4259+
"label": "NestedLabel2"
4260+
}
42614261
}
4262-
}
4263-
]
4262+
]
4263+
}
42644264
}
42654265
}
4266-
}
4267-
]
4268-
}
4269-
}
4270-
""";
4266+
]
4267+
}
4268+
}
4269+
""";
42714270

42724271
final String newDataString = """
4273-
{
4274-
"caseCategory": {
4275-
"list_items": [
4276-
{
4277-
"id": "123456",
4278-
"value": {
4279-
"nested_wrapper": {
4280-
"nested_list": []
4281-
}
4272+
{
4273+
"caseCategory": {
4274+
"list_items": [
4275+
{
4276+
"id": "123456",
4277+
"value": {
4278+
"nested_wrapper": {
4279+
"nested_list": []
4280+
}
4281+
}
42824282
}
4283-
}
4284-
]
4285-
}
4286-
}
4287-
""";
4283+
]
4284+
}
4285+
}
4286+
""";
42884287

42894288
setupLogging().setLevel(Level.DEBUG);
42904289

0 commit comments

Comments
 (0)