Skip to content

Commit

Permalink
CIV-0000 Fix hearing notices not generating (#4669)
Browse files Browse the repository at this point in the history
* Added a workaround to fix hearing notices not generating. Switch from using RuntimeService service provided by camunda org library to directly calling camunda rest to retrieve process variables.
---------

Co-authored-by: GarethLancaster <[email protected]>
  • Loading branch information
Gareth40343 and Gareth40342 authored May 15, 2024
1 parent ad3435a commit c030edf
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package uk.gov.hmcts.reform.civil.service.camunda;

import org.camunda.community.rest.client.model.VariableValueDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.HashMap;

@FeignClient(name = "camunda-rest-engine-api", url = "${feign.client.config.processInstance.url}")
public interface CamundaRuntimeApi {

@GetMapping("process-instance/{processInstanceId}/variables")
HashMap<String, VariableValueDto> getProcessVariables(
@PathVariable("processInstanceId") String processInstanceId,
@RequestHeader("ServiceAuthorization") String serviceAuthorization
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.gov.hmcts.reform.civil.service.camunda;

import lombok.RequiredArgsConstructor;
import org.camunda.community.rest.client.model.VariableValueDto;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;

import java.util.HashMap;
import java.util.Map;

/*
* There is currently an issue with the getVariables with using the RunTimeService in org.camunda.community.
* This class was created to handle retrieving camunda process variables directly.
* */
@Component
@RequiredArgsConstructor
public class CamundaRuntimeClient {

private final AuthTokenGenerator authTokenGenerator;
private final CamundaRuntimeApi camundaRestEngineApi;

@SuppressWarnings("unchecked")
public Map<String, Object> getProcessVariables(String processInstanceId) {
HashMap<String, VariableValueDto> variablesResponse = camundaRestEngineApi.getProcessVariables(processInstanceId, authTokenGenerator.generate());
HashMap parsedResponse = new HashMap<String, Object>();
variablesResponse.entrySet().stream().forEach(entry -> parsedResponse.put(entry.getKey(), entry.getValue().getValue()));
return parsedResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import lombok.RequiredArgsConstructor;
import org.camunda.bpm.engine.RuntimeService;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.civil.service.camunda.CamundaRuntimeClient;

@Service
@RequiredArgsConstructor
public class HearingNoticeCamundaService {

private final RuntimeService runtimeService;
private final CamundaRuntimeClient camundaClient;
private final ObjectMapper mapper;

public HearingNoticeVariables getProcessVariables(String processInstanceId) {
return mapper.convertValue(runtimeService.getVariables(processInstanceId), HearingNoticeVariables.class);
return mapper.convertValue(camundaClient.getProcessVariables(processInstanceId), HearingNoticeVariables.class);
}

public void setProcessVariables(String processInstanceId, HearingNoticeVariables variables) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package uk.gov.hmcts.reform.civil.service.camunda;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;

import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@SpringBootTest(classes = {
JacksonAutoConfiguration.class,
CamundaRuntimeClient.class
})
class CamundaRuntimeClientTest {

@MockBean
private CamundaRuntimeApi camundaApi;

@MockBean
private AuthTokenGenerator authTokenGenerator;

@Autowired
private CamundaRuntimeClient camundaClient;

@Autowired
ObjectMapper mapper;

@Test
void shouldReturnExpectedParsedResponse() {
String authToken = "auth-token";
String processInstanceId = "process-instance-id";

when(authTokenGenerator.generate()).thenReturn(authToken);
when(camundaApi.getProcessVariables(processInstanceId, authToken)).thenReturn(mapper.convertValue(Map.of(
"caseId", Map.of(
"type", "Long",
"value", "1713874015833902",
"valueInfo", Map.of()),
"hearingId", Map.of(
"type", "String",
"value", "2000005721",
"valueInfo", Map.of()),
"flowState", Map.of(
"type", "String",
"value", "MAIN.FULL_DEFENCE_PROCEED",
"valueInfo", Map.of()),
"flowFlags", Map.of(
"type", "Object",
"value", Map.of(
"BULK_CLAIM_ENABLED", true,
"SDO_ENABLED", true
),
"valueInfo", Map.of(
"objectTypeName", "java.util.HashMap<java.lang.Object,java.lang.Object>",
"serializationDataFormat", "application/json"
))
), new TypeReference<>() {}));

Map actual = camundaClient.getProcessVariables(processInstanceId);

Map expected = Map.of(
"caseId", "1713874015833902",
"hearingId", "2000005721",
"flowState", "MAIN.FULL_DEFENCE_PROCEED",
"flowFlags", Map.of(
"BULK_CLAIM_ENABLED", true,
"SDO_ENABLED", true
));

assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.civil.service.camunda.CamundaRuntimeClient;
import uk.gov.hmcts.reform.hmc.model.unnotifiedhearings.HearingDay;

import java.time.LocalDateTime;
Expand All @@ -30,6 +31,8 @@ public class HearingNoticeCamundaServiceTest {
private ObjectMapper mapper;
@MockBean
private RuntimeService runtimeService;
@MockBean
private CamundaRuntimeClient runtimeClient;
@Autowired
private HearingNoticeCamundaService hearingNoticeCamundaService;

Expand All @@ -52,7 +55,7 @@ void shouldReturnExpectedProcessVariables() {
.days(List.of(hearingDay))
.build();

when(runtimeService.getVariables(PROCESS_INSTANCE_ID)).thenReturn(expected.toMap(mapper));
when(runtimeClient.getProcessVariables(PROCESS_INSTANCE_ID)).thenReturn(expected.toMap(mapper));
HearingNoticeVariables actual = hearingNoticeCamundaService.getProcessVariables(PROCESS_INSTANCE_ID);

assertEquals(expected, actual);
Expand Down

0 comments on commit c030edf

Please sign in to comment.