-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIV-0000 Fix hearing notices not generating (#4669)
* 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
1 parent
ad3435a
commit c030edf
Showing
5 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/uk/gov/hmcts/reform/civil/service/camunda/CamundaRuntimeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/uk/gov/hmcts/reform/civil/service/camunda/CamundaRuntimeClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/test/java/uk/gov/hmcts/reform/civil/service/camunda/CamundaRuntimeClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters