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 @@ -4,7 +4,6 @@
import lombok.extern.slf4j.Slf4j;
import net.serenitybdd.junit.spring.integration.SpringIntegrationSerenityRunner;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -272,15 +271,6 @@ public void should_not_assign_task_when_assignee_have_incorrect_roles() {
authorizationProvider.deleteAccount(assigneeCaseWorkerWithIncorrectRoles.getAccount().getUsername());
}

/*
*This test covers the scenario where there are multiple assignees with correct roles for a task,
*in which case the task should be assigned to the last assignee returned by the DMN configuration.

*But as the DMN configuration is currently set up to return only one assignee, this test is ignored for now.
*Once the code changes were made to allow multiple assignees to be returned by the DMN configuration,
*this test should be enabled and the assertions should be updated to reflect the expected behaviour.
*/
@Ignore
@Test
public void should_assign_task_to_last_assignee_when_multiple_assignees_with_correct_roles() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1583,14 +1583,33 @@ void should_not_assign_task_when_assignee_have_incorrect_roles() throws Exceptio
}

@Test
void should_assign_task_to_first_assignee_when_multiple_assignees_with_correct_roles() throws Exception {
String firstAssignee = "assignee1";
String secondAssignee = "assignee2";
String dmnAssignees = firstAssignee + "," + secondAssignee;
mockCaseDetailsAndConfigurationForAutoAssign(dmnAssignees);
void should_use_last_dmn_assignee_when_multiple_assignee_rows_are_returned() throws Exception {
when(clientAccessControlService.hasExclusiveAccess(SERVICE_AUTHORIZATION_TOKEN))
.thenReturn(true);

when(caseDetails.getCaseType()).thenReturn("Asylum");
when(caseDetails.getJurisdiction()).thenReturn("IA");
when(caseDetails.getSecurityClassification()).thenReturn("PUBLIC");

when(ccdDataServiceApi.getCase(any(), any(), eq("someCaseId")))
.thenReturn(caseDetails);

when(camundaServiceApi.evaluateConfigurationDmnTable(any(), any(), any(), any()))
.thenReturn(asList(
new ConfigurationDmnEvaluationResponse(stringValue("caseName"), stringValue("someName")),
new ConfigurationDmnEvaluationResponse(stringValue("appealType"), stringValue("protection")),
new ConfigurationDmnEvaluationResponse(stringValue("region"), stringValue("1")),
new ConfigurationDmnEvaluationResponse(stringValue("location"), stringValue("765324")),
new ConfigurationDmnEvaluationResponse(stringValue("locationName"), stringValue("Taylor House")),
new ConfigurationDmnEvaluationResponse(stringValue("workType"), stringValue("decision_making_work")),
new ConfigurationDmnEvaluationResponse(stringValue("caseManagementCategory"),
stringValue("Protection")),
new ConfigurationDmnEvaluationResponse(stringValue("assignee"), stringValue("assignee_1")),
new ConfigurationDmnEvaluationResponse(stringValue("assignee"), stringValue("assignee_2"))
));

when(camundaServiceApi.evaluatePermissionsDmnTable(any(), any(), any(), any()))
.thenReturn(List.of(
.thenReturn(asList(
new PermissionsDmnEvaluationResponse(
stringValue("tribunal-caseworker"),
stringValue("Read,Refer,Own"),
Expand All @@ -1602,42 +1621,35 @@ void should_assign_task_to_first_assignee_when_multiple_assignees_with_correct_r
)
));

when(roleAssignmentServiceApi.getRolesForUser(eq(dmnAssignees), any(), any()))
.thenReturn(new RoleAssignmentResource(emptyList()));
when(roleAssignmentServiceApi.getRolesForUser(eq("assignee_2"), any(), any()))
.thenReturn(new RoleAssignmentResource(List.of(
RoleAssignment.builder()
.id("someId")
.actorIdType(ActorIdType.IDAM)
.actorId("assignee_2")
.roleName("tribunal-caseworker")
.roleCategory(RoleCategory.LEGAL_OPERATIONS)
.grantType(GrantType.SPECIFIC)
.roleType(RoleType.ORGANISATION)
.classification(Classification.PUBLIC)
.authorisations(List.of("IA"))
.build()
)));

when(roleAssignmentServiceApi.queryRoleAssignments(any(), any(), any(), any(), any()))
.thenReturn(ResponseEntity.ok()
.header(TOTAL_RECORDS, "2")
.body(new RoleAssignmentResource(List.of(
RoleAssignment.builder()
.id("id-1")
.actorIdType(ActorIdType.IDAM)
.actorId(firstAssignee)
.roleName("tribunal-caseworker")
.roleCategory(RoleCategory.LEGAL_OPERATIONS)
.grantType(GrantType.SPECIFIC)
.roleType(RoleType.ORGANISATION)
.classification(Classification.PUBLIC)
.authorisations(List.of("IA"))
.build(),
RoleAssignment.builder()
.id("id-2")
.actorIdType(ActorIdType.IDAM)
.actorId(secondAssignee)
.roleName("tribunal-caseworker")
.roleCategory(RoleCategory.LEGAL_OPERATIONS)
.grantType(GrantType.SPECIFIC)
.roleType(RoleType.ORGANISATION)
.classification(Classification.PUBLIC)
.authorisations(List.of("IA"))
.build()
))));
ZonedDateTime createdDate = ZonedDateTime.now();
ZonedDateTime dueDate = createdDate.plusDays(1);
String formattedDueDate = CAMUNDA_DATA_TIME_FORMATTER.format(dueDate);

InitiateTaskRequestMap req = new InitiateTaskRequestMap(
INITIATION,
createTaskAttributes("multipleAssigneeTestTask", "Multiple Assignee Test Task")
Map<String, Object> taskAttributes = Map.of(
TASK_TYPE.value(), "followUpOverdueReasonsForAppeal",
TASK_NAME.value(), "aTaskName",
TITLE.value(), "A test task",
CASE_ID.value(), "someCaseId",
DUE_DATE.value(), formattedDueDate
);

InitiateTaskRequestMap req = new InitiateTaskRequestMap(INITIATION, taskAttributes);

mockMvc.perform(post(ENDPOINT_BEING_TESTED)
.header(AUTHORIZATION, IDAM_AUTHORIZATION_TOKEN)
.header(SERVICE_AUTHORIZATION, SERVICE_AUTHORIZATION_TOKEN)
Expand All @@ -1647,9 +1659,10 @@ void should_assign_task_to_first_assignee_when_multiple_assignees_with_correct_r
status().isCreated(),
content().contentType(APPLICATION_JSON_VALUE),
jsonPath("$.task_id").value(taskId),
jsonPath("$.task_type").value("multipleAssigneeTestTask"),
jsonPath("$.task_type").value("followUpOverdueReasonsForAppeal"),
jsonPath("$.state").value("ASSIGNED"),
jsonPath("$.assignee").value(firstAssignee)
jsonPath("$.assignee").value("assignee_2"),
jsonPath("$.auto_assigned").value(false)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toMap;
import static uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.CamundaVariableDefinition.ASSIGNEE;
import static uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.CamundaVariableDefinition.CASE_TYPE_ID;
import static uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.CamundaVariableDefinition.DUE_DATE;
import static uk.gov.hmcts.reform.wataskmanagementapi.domain.camunda.CamundaVariableDefinition.JURISDICTION;
Expand Down Expand Up @@ -95,6 +96,8 @@ public TaskConfigurationResults getCaseRelatedConfiguration(
isReconfigureRequest,
taskAttributes
);
taskConfigurationDmnResultsAfterUpdate =
normalizeAssigneeConfigurationResults(taskConfigurationDmnResultsAfterUpdate);

List<PermissionsDmnEvaluationResponse> permissionsDmnResults =
dmnEvaluationService.evaluateTaskPermissionsDmn(
Expand Down Expand Up @@ -189,6 +192,22 @@ private ConfigurationDmnEvaluationResponse removeAdditionalFromCamundaName(
return new ConfigurationDmnEvaluationResponse(CamundaValue.stringValue(additionalPropKey), resp.getValue());
}

private List<ConfigurationDmnEvaluationResponse> normalizeAssigneeConfigurationResults(
List<ConfigurationDmnEvaluationResponse> taskConfigurationDmnResults) {
Optional<ConfigurationDmnEvaluationResponse> lastAssigneeResponse = taskConfigurationDmnResults.stream()
.filter(response -> ASSIGNEE.value().equals(response.getName().getValue()))
.reduce((first, second) -> second);

if (lastAssigneeResponse.isEmpty()) {
return taskConfigurationDmnResults;
}

return taskConfigurationDmnResults.stream()
.filter(response -> !ASSIGNEE.value().equals(response.getName().getValue())
|| response == lastAssigneeResponse.get())
.toList();
}

private boolean filterBasedOnCaseAccessCategory(CaseDetails caseDetails,
PermissionsDmnEvaluationResponse dmnResult) {
CamundaValue<String> caseAccessCategory = dmnResult.getCaseAccessCategory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ void should_not_throw_an_exception_and_log_when_dmn_has_null_values() {
assertEquals(Optional.empty(), mappedData.getProcessVariables().get("name2"));
}

@Test
void should_use_last_assignee_when_dmn_returns_multiple_assignee_rows() {
String someCaseId = "someCaseId";

when(ccdDataService.getCaseData(someCaseId)).thenReturn(caseDetails);
when(dmnEvaluationService.evaluateTaskConfigurationDmn("IA", "Asylum", "{}", "{}"))
.thenReturn(asList(
new ConfigurationDmnEvaluationResponse(stringValue("assignee"), stringValue("assignee_1")),
new ConfigurationDmnEvaluationResponse(stringValue("assignee"), stringValue("assignee_2"))
));

TaskConfigurationResults mappedData = caseConfigurationProviderService
.getCaseRelatedConfiguration(someCaseId, Map.of(), false);

assertEquals(Optional.of("assignee_2"), mappedData.getProcessVariables().get("assignee"));
}

@Test
void should_consider_permissions_when_case_access_category_column_matches_with_different_sets() {
String someCaseId = "someCaseId";
Expand Down