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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static uk.gov.hmcts.reform.wataskmanagementapi.domain.DecisionTable.WA_TASK_CONFIGURATION;
import static uk.gov.hmcts.reform.wataskmanagementapi.domain.DecisionTable.WA_TASK_PERMISSIONS;
import static uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.CamundaValue.jsonValue;
import static uk.gov.hmcts.reform.wataskmanagementapi.services.utils.DmnConfigFieldUtils.cleanFieldsWithInternalDefaults;

@Slf4j
@Component
Expand Down Expand Up @@ -108,21 +109,7 @@ private List<ConfigurationDmnEvaluationResponse> performEvaluateConfigurationDmn
new DmnRequest<>(new DecisionTableRequest(jsonValue(caseData), jsonValue(taskAttributes)))
);

/**
* Loop through each field in dmnConfigFieldsWithInternalDefaults and check if the field is equal to the
* name from dmnResponse. If the name is present, then get the value of the field. Check if the value is
* null or empty for that field if yes then remove the field from the dmnResponse so that it won't override
* existing value.
*/

dmnConfigFieldsWithInternalDefaults.forEach(
field ->
dmnResponse.removeIf(response -> {
String nameValue = response.getName().getValue();
String responseValue = response.getValue() != null ? response.getValue().getValue() : null;
return field.equals(nameValue) && (responseValue == null || responseValue.isEmpty());
})
);
cleanFieldsWithInternalDefaults(dmnConfigFieldsWithInternalDefaults, dmnResponse);

return dmnResponse.stream().map(response -> {
if (fieldsToExcludeFromTrim.contains(response.getName().getValue())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package uk.gov.hmcts.reform.wataskmanagementapi.services.utils;

import uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.ConfigurationDmnEvaluationResponse;

import java.util.List;

public class DmnConfigFieldUtils {

private DmnConfigFieldUtils() {

}

public static void cleanFieldsWithInternalDefaults(
List<String> dmnConfigFieldsWithInternalDefaults,
List<ConfigurationDmnEvaluationResponse> dmnResponse
) {

/**
* Loop through each field in dmnConfigFieldsWithInternalDefaults and check if the field is equal to the
* name from dmnResponse. If the name is present, then get the value of the field. Check if the value is
* null or empty for that field if yes then remove the field from the dmnResponse so that it won't override
* existing value.
*/

dmnConfigFieldsWithInternalDefaults.forEach(
field ->
dmnResponse.removeIf(response -> {
String nameValue = response.getName().getValue();
String responseValue = response.getValue() != null ? response.getValue().getValue() : null;
return field.equals(nameValue) && (responseValue == null || responseValue.isEmpty());
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package uk.gov.hmcts.reform.wataskmanagementapi.services.utils;

import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.CamundaValue;
import uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.ConfigurationDmnEvaluationResponse;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;


class DmnConfigFieldUtilTest {

@Test
void should_remove_field_with_null_value() {
List<ConfigurationDmnEvaluationResponse> responses = new ArrayList<>();
ConfigurationDmnEvaluationResponse configurationDmnEvaluationResponse =
new ConfigurationDmnEvaluationResponse();
configurationDmnEvaluationResponse.setName(new CamundaValue<>("field1", "String"));
configurationDmnEvaluationResponse.setValue(null);
responses.add(configurationDmnEvaluationResponse);
List<String> fields = List.of("field1");

DmnConfigFieldUtils.cleanFieldsWithInternalDefaults(fields, responses);

assertTrue(responses.isEmpty());
}

@Test
void should_remove_field_with_empty_value() {
List<ConfigurationDmnEvaluationResponse> responses = new ArrayList<>();
ConfigurationDmnEvaluationResponse configurationDmnEvaluationResponse =
new ConfigurationDmnEvaluationResponse();
configurationDmnEvaluationResponse.setName(new CamundaValue<>("field1", "String"));
configurationDmnEvaluationResponse.setValue(new CamundaValue<>("", "String"));
responses.add(configurationDmnEvaluationResponse);
List<String> fields = List.of("field1");

DmnConfigFieldUtils.cleanFieldsWithInternalDefaults(fields, responses);

assertTrue(responses.isEmpty());
}

@Test
void should_not_remove_field_with_non_empty_value() {
List<ConfigurationDmnEvaluationResponse> responses = new ArrayList<>();
ConfigurationDmnEvaluationResponse configurationDmnEvaluationResponse =
new ConfigurationDmnEvaluationResponse();
configurationDmnEvaluationResponse.setName(new CamundaValue<>("field1", "String"));
configurationDmnEvaluationResponse.setValue(new CamundaValue<>("someValue", "String"));
responses.add(configurationDmnEvaluationResponse);
List<String> fields = List.of("field1");

DmnConfigFieldUtils.cleanFieldsWithInternalDefaults(fields, responses);

assertFalse(responses.isEmpty());
assertEquals("someValue", responses.getFirst().getValue().getValue());
}

}