diff --git a/charts/am-org-role-mapping-service/Chart.yaml b/charts/am-org-role-mapping-service/Chart.yaml index b6c10f852..a78b2693e 100644 --- a/charts/am-org-role-mapping-service/Chart.yaml +++ b/charts/am-org-role-mapping-service/Chart.yaml @@ -3,12 +3,12 @@ appVersion: "1.0" description: A Helm chart for AM Organisation Role Mapping Service name: am-org-role-mapping-service home: https://github.com/hmcts/am-org-role-mapping-service -version: 0.0.51 +version: 0.0.52 maintainers: - name: Access Management Team dependencies: - name: java - version: 4.2.0 + version: 5.0.0 repository: 'https://hmctspublic.azurecr.io/helm/v1/repo/' - name: servicebus version: 1.0.4 diff --git a/config/owasp/suppressions.xml b/config/owasp/suppressions.xml index 064b8c786..dfc1b8f95 100644 --- a/config/owasp/suppressions.xml +++ b/config/owasp/suppressions.xml @@ -17,4 +17,8 @@ https://tools.hmcts.net/jira/browse/AM-2952 plexus CVE-2022-4245 + + https://tools.hmcts.net/jira/browse/AM-2968 netty + CVE-2023-4586 + diff --git a/src/functionalTest/resources/features/F-004/S-031.td.json b/src/functionalTest/resources/features/F-004/S-031.td.json index 20b1a55ee..e3ddf7b75 100644 --- a/src/functionalTest/resources/features/F-004/S-031.td.json +++ b/src/functionalTest/resources/features/F-004/S-031.td.json @@ -65,7 +65,7 @@ "primaryLocation" : "[[ANYTHING_PRESENT]]", "jurisdiction" : "SSCS", "region" : "[[ANYTHING_PRESENT]]", - "workTypes" : "pre_hearing_work,hearing_work,post_hearing_work,decision_making_work,routine_work,priority" + "workTypes" : "pre_hearing,hearing_work,post_hearing,decision_making_work,routine_work,priority" }, "authorisations" : "[[ANYTHING_PRESENT]]" } diff --git a/src/functionalTest/resources/features/F-004/S-032.td.json b/src/functionalTest/resources/features/F-004/S-032.td.json index 657e105d6..0ba42dbd9 100644 --- a/src/functionalTest/resources/features/F-004/S-032.td.json +++ b/src/functionalTest/resources/features/F-004/S-032.td.json @@ -43,7 +43,7 @@ "primaryLocation" : "[[ANYTHING_PRESENT]]", "jurisdiction" : "SSCS", "region" : "[[ANYTHING_PRESENT]]", - "workTypes" : "pre_hearing_work,hearing_work,post_hearing_work,decision_making_work,routine_work,priority" + "workTypes" : "pre_hearing,hearing_work,post_hearing,decision_making_work,routine_work,priority" }, "authorisations" : "[[ANYTHING_PRESENT]]" }, @@ -66,7 +66,7 @@ "primaryLocation" : "[[ANYTHING_PRESENT]]", "jurisdiction" : "SSCS", "region" : "[[ANYTHING_PRESENT]]", - "workTypes" : "pre_hearing_work,hearing_work,post_hearing_work,decision_making_work,routine_work,priority" + "workTypes" : "pre_hearing,hearing_work,post_hearing,decision_making_work,routine_work,priority" }, "authorisations" : "[[ANYTHING_PRESENT]]" }, diff --git a/src/functionalTest/resources/features/F-005/S-041.td.json b/src/functionalTest/resources/features/F-005/S-041.td.json index ac4c0d288..a38e60185 100644 --- a/src/functionalTest/resources/features/F-005/S-041.td.json +++ b/src/functionalTest/resources/features/F-005/S-041.td.json @@ -36,7 +36,7 @@ "primaryLocation": "21153", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "applications,hearing_work,routine_work,priority" + "workTypes": "applications,hearing_work,routine_work,priority,pre_hearing" } }, { diff --git a/src/functionalTest/resources/features/F-005/S-042.td.json b/src/functionalTest/resources/features/F-005/S-042.td.json index 3a20b13f3..4a510f2fb 100644 --- a/src/functionalTest/resources/features/F-005/S-042.td.json +++ b/src/functionalTest/resources/features/F-005/S-042.td.json @@ -36,7 +36,7 @@ "primaryLocation": "21153", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "pre_hearing_work,post_hearing_work,decision_making_work,applications,hearing_work,routine_work,priority" + "workTypes": "pre_hearing,post_hearing,decision_making_work,applications,hearing_work,routine_work,priority" } }, { diff --git a/src/functionalTest/resources/features/F-005/S-043.td.json b/src/functionalTest/resources/features/F-005/S-043.td.json index fa9e5a13c..e331b3390 100644 --- a/src/functionalTest/resources/features/F-005/S-043.td.json +++ b/src/functionalTest/resources/features/F-005/S-043.td.json @@ -172,7 +172,7 @@ "primaryLocation": "271588", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "pre_hearing_work,post_hearing_work,decision_making_work,applications,hearing_work,routine_work,priority" + "workTypes": "pre_hearing,post_hearing,decision_making_work,applications,hearing_work,routine_work,priority" } }, { @@ -209,7 +209,7 @@ "primaryLocation": "271588", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "pre_hearing_work,post_hearing_work,applications,hearing_work,routine_work,priority,decision_making_work" + "workTypes": "pre_hearing,post_hearing,applications,hearing_work,routine_work,priority,decision_making_work" } }, { diff --git a/src/functionalTest/resources/features/F-005/S-044.td.json b/src/functionalTest/resources/features/F-005/S-044.td.json index fbad5d2cc..68bb79b03 100644 --- a/src/functionalTest/resources/features/F-005/S-044.td.json +++ b/src/functionalTest/resources/features/F-005/S-044.td.json @@ -119,7 +119,7 @@ "primaryLocation" : "[[ANYTHING_PRESENT]]", "jurisdiction" : "SSCS", "region" : "[[ANYTHING_PRESENT]]", - "workTypes" : "pre_hearing_work,post_hearing_work,applications,hearing_work,routine_work,priority,decision_making_work" + "workTypes" : "pre_hearing,post_hearing,applications,hearing_work,routine_work,priority,decision_making_work" } }, { "id" : "[[ANYTHING_PRESENT]]", @@ -137,7 +137,7 @@ "primaryLocation" : "[[ANYTHING_PRESENT]]", "jurisdiction" : "SSCS", "region" :"[[ANYTHING_PRESENT]]", - "workTypes" : "pre_hearing_work,post_hearing_work,applications,hearing_work,routine_work,priority,decision_making_work" + "workTypes" : "pre_hearing,post_hearing,applications,hearing_work,routine_work,priority,decision_making_work" } } ] } diff --git a/src/functionalTest/resources/features/F-006/S-051.td.json b/src/functionalTest/resources/features/F-006/S-051.td.json index 53272a35e..4ee1b66a6 100644 --- a/src/functionalTest/resources/features/F-006/S-051.td.json +++ b/src/functionalTest/resources/features/F-006/S-051.td.json @@ -33,7 +33,7 @@ "primaryLocation": "[[ANYTHING_PRESENT]]", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "pre_hearing_work,post_hearing_work,applications,hearing_work,routine_work,priority,decision_making_work", + "workTypes": "pre_hearing,post_hearing,applications,hearing_work,routine_work,priority,decision_making_work", "substantive" : "Y" } }, @@ -52,7 +52,7 @@ "primaryLocation": "[[ANYTHING_PRESENT]]", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "pre_hearing_work,post_hearing_work,applications,hearing_work,routine_work,priority,decision_making_work", + "workTypes": "pre_hearing,post_hearing,applications,hearing_work,routine_work,priority,decision_making_work", "substantive" : "Y" } } diff --git a/src/functionalTest/resources/features/F-006/S-052.td.json b/src/functionalTest/resources/features/F-006/S-052.td.json index 180ad8282..876784a8e 100644 --- a/src/functionalTest/resources/features/F-006/S-052.td.json +++ b/src/functionalTest/resources/features/F-006/S-052.td.json @@ -33,7 +33,7 @@ "primaryLocation": "[[ANYTHING_PRESENT]]", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "pre_hearing_work,post_hearing_work,decision_making_work,applications,hearing_work,routine_work,priority", + "workTypes": "pre_hearing,post_hearing,decision_making_work,applications,hearing_work,routine_work,priority", "substantive" : "Y" } } diff --git a/src/functionalTest/resources/features/F-006/S-053.td.json b/src/functionalTest/resources/features/F-006/S-053.td.json index b0cc7d8e4..fd54d58ce 100644 --- a/src/functionalTest/resources/features/F-006/S-053.td.json +++ b/src/functionalTest/resources/features/F-006/S-053.td.json @@ -33,7 +33,7 @@ "primaryLocation": "[[ANYTHING_PRESENT]]", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "applications,hearing_work,routine_work,priority", + "workTypes": "applications,hearing_work,routine_work,priority,pre_hearing", "substantive" : "Y" } }, @@ -52,7 +52,7 @@ "primaryLocation": "[[ANYTHING_PRESENT]]", "jurisdiction": "SSCS", "region" : "2", - "workTypes": "applications,hearing_work,routine_work,priority", + "workTypes": "applications,hearing_work,routine_work,priority,pre_hearing", "substantive" : "Y" } } diff --git a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/InvalidRequest.java b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/InvalidRequest.java index 0ae2acc71..20148badb 100644 --- a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/InvalidRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/InvalidRequest.java @@ -7,4 +7,8 @@ public class InvalidRequest extends RuntimeException { public InvalidRequest(String message) { super(message); } + + public InvalidRequest(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/UnprocessableEntityException.java b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/UnprocessableEntityException.java index bd12bbdb5..954b95e98 100644 --- a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/UnprocessableEntityException.java +++ b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/controller/advice/exception/UnprocessableEntityException.java @@ -8,8 +8,7 @@ public class UnprocessableEntityException extends RuntimeException { private static final long serialVersionUID = 7L; - public UnprocessableEntityException(String message) { + public UnprocessableEntityException(String message) { super(message); - } } diff --git a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/BulkAssignmentOrchestrator.java b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/BulkAssignmentOrchestrator.java index ef5c9aec7..048f896d2 100644 --- a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/BulkAssignmentOrchestrator.java +++ b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/BulkAssignmentOrchestrator.java @@ -40,7 +40,8 @@ public ResponseEntity createBulkAssignmentsRequest(UserRequest userReque //Extract and Validate received users List parseRequestService.validateUserRequest(userRequest); - log.info("Validated {} userIds :: {}", userRequest.getUserIds().size(), userRequest.getUserIds()); + log.info("Validated {} userIds of userType {} :: {}", + userRequest.getUserIds().size(), userType, userRequest.getUserIds()); long startTime = System.currentTimeMillis(); Map> userAccessProfiles; //Create userAccessProfiles based upon roleId and service codes diff --git a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumer.java b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumer.java index 1115e3812..c80ddd41c 100644 --- a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumer.java +++ b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumer.java @@ -39,12 +39,10 @@ public class CRDTopicConsumer extends CRDMessagingConfiguration { private BulkAssignmentOrchestrator bulkAssignmentOrchestrator; private OrmDeserializer deserializer; - public CRDTopicConsumer(BulkAssignmentOrchestrator bulkAssignmentOrchestrator, - OrmDeserializer deserializer) { + OrmDeserializer deserializer) { this.bulkAssignmentOrchestrator = bulkAssignmentOrchestrator; this.deserializer = deserializer; - } @Bean @@ -72,9 +70,24 @@ CompletableFuture registerCRDMessageHandlerOnClient(@Autowired @Qualifier( SubscriptionClient receiveClient) throws ServiceBusException, InterruptedException { - log.debug(" Calling registerMessageHandlerOnClient in CRD "); + ExecutorService executorService = Executors.newFixedThreadPool(1); + receiveClient.registerMessageHandler( + getMessageHandler(receiveClient), + new MessageHandlerOptions( + 1, + false, + Duration.ofHours(1), + Duration.ofMinutes(5) + ), + executorService + ); + return null; + + } - IMessageHandler messageHandler = new IMessageHandler() { + public IMessageHandler getMessageHandler(SubscriptionClient receiveClient) { + log.debug(" Calling registerMessageHandlerOnClient in CRD "); + return new IMessageHandler() { // callback invoked when the message handler loop has obtained a message @SneakyThrows @WithSpan(value = "CRD Azure Service Bus Topic", kind = SpanKind.SERVER) @@ -93,42 +106,31 @@ public CompletableFuture onMessageAsync(IMessage message) { log.debug(" getLockToken......{}", message.getLockToken()); } catch (Exception e) { // java.lang.Throwable introduces the Sonar issues - throw new InvalidRequest("Some Network issue"); + log.error("Error processing CRD message from service bus : {}", e.getMessage()); + throw new InvalidRequest("Error processing message from service bus", e); } log.debug("Finally getLockedUntilUtc" + message.getLockedUntilUtc()); return null; } public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) { - log.error("Exception occurred."); - log.error(exceptionPhase + "-" + throwable.getMessage()); + log.error( + "An error occurred when Calling onMessageAsync in CRD. Phase: {}", + exceptionPhase, + throwable + ); } }; - - ExecutorService executorService = Executors.newFixedThreadPool(1); - receiveClient.registerMessageHandler( - messageHandler, new MessageHandlerOptions(1, - false, Duration.ofHours(1), Duration.ofMinutes(5)), - executorService); - return null; - } private void processMessage(List body, AtomicBoolean result) { - - log.info(" Parsing the message in CRD"); UserRequest request = deserializer.deserialize(body); - try { - ResponseEntity response = bulkAssignmentOrchestrator.createBulkAssignmentsRequest(request, - UserType.CASEWORKER); - log.info("----Role Assignment Service Response CRD {}", response.getStatusCode()); - result.set(Boolean.TRUE); - } catch (Exception e) { - log.error("Exception from RAS service : {}", e.getMessage()); - throw e; - } - } + log.debug("Parsing the message from CRD with size :: {}", request.getUserIds().size()); + ResponseEntity response = bulkAssignmentOrchestrator.createBulkAssignmentsRequest(request, + UserType.CASEWORKER); + log.info("Role Assignment Service Response CRD: {}", response.getStatusCode()); + result.set(Boolean.TRUE); + } } - diff --git a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/JRDTopicConsumer.java b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/JRDTopicConsumer.java index 257ac7904..29c42b25d 100644 --- a/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/JRDTopicConsumer.java +++ b/src/main/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/JRDTopicConsumer.java @@ -47,7 +47,6 @@ public JRDTopicConsumer(BulkAssignmentOrchestrator bulkAssignmentOrchestrator, OrmDeserializer deserializer) { this.bulkAssignmentOrchestrator = bulkAssignmentOrchestrator; this.deserializer = deserializer; - } @Bean @@ -75,9 +74,24 @@ CompletableFuture registerJRDMessageHandlerOnClient(@Autowired @Qualifier( SubscriptionClient receiveClient) throws ServiceBusException, InterruptedException { - log.info(" Calling registerMessageHandlerOnClient in JRD "); + ExecutorService executorService = Executors.newFixedThreadPool(1); + receiveClient.registerMessageHandler( + getMessageHandler(receiveClient), + new MessageHandlerOptions( + 1, + false, + Duration.ofHours(1), + Duration.ofMinutes(5) + ), + executorService + ); + return null; - IMessageHandler messageHandler = new IMessageHandler() { + } + + public IMessageHandler getMessageHandler(SubscriptionClient receiveClient) { + log.info(" Calling registerMessageHandlerOnClient in JRD "); + return new IMessageHandler() { // callback invoked when the message handler loop has obtained a message @SneakyThrows @WithSpan(value = "JRD Azure Service Bus Topic", kind = SpanKind.SERVER) @@ -94,7 +108,6 @@ public CompletableFuture onMessageAsync(IMessage message) { return receiveClient.completeAsync(message.getLockToken()); } - log.debug(" getLockToken......{}", message.getLockToken()); } else { log.info("The JRD feature flag is currently disabled. This message would be suppressed"); @@ -102,7 +115,8 @@ public CompletableFuture onMessageAsync(IMessage message) { } } catch (Exception e) { // java.lang.Throwable introduces the Sonar issues - throw new InvalidRequest("Some Network issue"); + log.error("Error processing JRD message from service bus : {}", e.getMessage()); + throw new InvalidRequest("Error processing message from service bus", e); } log.debug("Finally getLockedUntilUtc" + message.getLockedUntilUtc()); return null; @@ -110,35 +124,23 @@ public CompletableFuture onMessageAsync(IMessage message) { } public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) { - log.error("Exception occurred."); - log.error(exceptionPhase + "-" + throwable.getMessage()); + log.error( + "An error occurred when Calling onMessageAsync in JRD. Phase: {}", + exceptionPhase, + throwable + ); } }; - - ExecutorService executorService = Executors.newFixedThreadPool(1); - receiveClient.registerMessageHandler( - messageHandler, new MessageHandlerOptions(1, - false, Duration.ofHours(1), Duration.ofMinutes(5)), - executorService); - return null; - } private void processMessage(List body, AtomicBoolean result) { - - UserRequest request = deserializer.deserialize(body); log.debug("Parsing the message from JRD with size :: {}", request.getUserIds().size()); - try { - ResponseEntity response = bulkAssignmentOrchestrator.createBulkAssignmentsRequest(request, - UserType.JUDICIAL); - log.debug("Role Assignment Service Response JRD {}", response.getStatusCode()); - result.set(Boolean.TRUE); - } catch (Exception e) { - log.error("Exception from RAS service : {}", e.getMessage()); - throw e; - } - } + ResponseEntity response = bulkAssignmentOrchestrator.createBulkAssignmentsRequest(request, + UserType.JUDICIAL); + log.debug("Role Assignment Service Response JRD: {}", response.getStatusCode()); + result.set(Boolean.TRUE); + } } diff --git a/src/main/resources/validationrules/sscs/sscs-admin-mapping.drl b/src/main/resources/validationrules/sscs/sscs-admin-mapping.drl index 669e4bf03..83d6256a7 100644 --- a/src/main/resources/validationrules/sscs/sscs-admin-mapping.drl +++ b/src/main/resources/validationrules/sscs/sscs-admin-mapping.drl @@ -82,7 +82,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,post_hearing_work,decision_making_work,applications,hearing_work,routine_work,priority")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,post_hearing,decision_making_work,applications,hearing_work,routine_work,priority")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($cap.getRegionId())); insert( @@ -112,7 +112,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,post_hearing_work,decision_making_work,applications,hearing_work,routine_work,priority")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,post_hearing,decision_making_work,applications,hearing_work,routine_work,priority")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($cap.getRegionId())); insert( @@ -230,7 +230,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,post_hearing_work,decision_making_work,applications,hearing_work,routine_work,priority")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,post_hearing,decision_making_work,applications,hearing_work,routine_work,priority")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($cap.getRegionId())); insert( @@ -289,7 +289,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("applications,hearing_work,routine_work,priority")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("applications,hearing_work,routine_work,priority,pre_hearing")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($cap.getRegionId())); insert( @@ -319,7 +319,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("applications,hearing_work,routine_work,priority")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("applications,hearing_work,routine_work,priority,pre_hearing")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($cap.getRegionId())); insert( diff --git a/src/main/resources/validationrules/sscs/sscs-caseworker-mapping.drl b/src/main/resources/validationrules/sscs/sscs-caseworker-mapping.drl index b3f898f96..4d6f9e235 100644 --- a/src/main/resources/validationrules/sscs/sscs-caseworker-mapping.drl +++ b/src/main/resources/validationrules/sscs/sscs-caseworker-mapping.drl @@ -57,7 +57,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,post_hearing_work,applications,hearing_work,routine_work,priority,decision_making_work")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,post_hearing,applications,hearing_work,routine_work,priority,decision_making_work")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($cap.getRegionId())); insert( @@ -89,7 +89,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,post_hearing_work,applications,hearing_work,routine_work,priority,decision_making_work")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,post_hearing,applications,hearing_work,routine_work,priority,decision_making_work")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($cap.getRegionId())); insert( diff --git a/src/main/resources/validationrules/sscs/sscs-ctsc-mapping.drl b/src/main/resources/validationrules/sscs/sscs-ctsc-mapping.drl index 10c4516b6..03ce75e0f 100644 --- a/src/main/resources/validationrules/sscs/sscs-ctsc-mapping.drl +++ b/src/main/resources/validationrules/sscs/sscs-ctsc-mapping.drl @@ -52,7 +52,7 @@ then Map attribute = new HashMap<>(); attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($cap.getPrimaryLocationId())); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,post_hearing_work,decision_making_work,applications,hearing_work,routine_work,priority")); + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,post_hearing,decision_making_work,applications,hearing_work,routine_work,priority")); insert( RoleAssignment.builder() diff --git a/src/main/resources/validationrules/sscs/sscs-judicial-org-role-mapping.drl b/src/main/resources/validationrules/sscs/sscs-judicial-org-role-mapping.drl index 1ca06ea98..99d4116ad 100644 --- a/src/main/resources/validationrules/sscs/sscs-judicial-org-role-mapping.drl +++ b/src/main/resources/validationrules/sscs/sscs-judicial-org-role-mapping.drl @@ -65,7 +65,7 @@ then attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($joh.getPrimaryLocation())); attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Salaried")); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,hearing_work,post_hearing_work," + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,hearing_work,post_hearing," + "decision_making_work,routine_work,priority")); if (!$joh.getOffice().equalsIgnoreCase("SSCS President of Tribunal-Salaried")) { attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($joh.getRegionId())); @@ -105,7 +105,7 @@ then attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($bk.getLocationId() != null ? $bk.getLocationId():$joh.getPrimaryLocation())); attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Fee-Paid")); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,hearing_work,post_hearing_work," + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,hearing_work,post_hearing," + "decision_making_work,routine_work,priority")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($joh.getRegionId())); insert( @@ -278,7 +278,7 @@ then attribute.put("jurisdiction", JacksonUtils.convertObjectIntoJsonNode("SSCS")); attribute.put("primaryLocation", JacksonUtils.convertObjectIntoJsonNode($joh.getPrimaryLocation())); attribute.put("contractType", JacksonUtils.convertObjectIntoJsonNode("Fee-Paid")); - attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing_work,hearing_work,post_hearing_work," + attribute.put("workTypes", JacksonUtils.convertObjectIntoJsonNode("pre_hearing,hearing_work,post_hearing," + "decision_making_work,routine_work,priority")); attribute.put("region", JacksonUtils.convertObjectIntoJsonNode($joh.getRegionId())); if ($joh.getTicketCodes() != null && $joh.getTicketCodes().contains("368")) { diff --git a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsJudicialRoleMappingTest.java b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsJudicialRoleMappingTest.java index f5ae31cb8..06c98ac7b 100644 --- a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsJudicialRoleMappingTest.java +++ b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsJudicialRoleMappingTest.java @@ -35,13 +35,13 @@ class DroolSscsJudicialRoleMappingTest extends DroolBase { { expectedRoleNameWorkTypesMap.put("leadership-judge", null); - expectedRoleNameWorkTypesMap.put("judge", "pre_hearing_work,hearing_work,post_hearing_work," + expectedRoleNameWorkTypesMap.put("judge", "pre_hearing,hearing_work,post_hearing," + "decision_making_work,routine_work,priority"); expectedRoleNameWorkTypesMap.put("case-allocator", null); expectedRoleNameWorkTypesMap.put("task-supervisor", null); expectedRoleNameWorkTypesMap.put("hmcts-judiciary", null); expectedRoleNameWorkTypesMap.put("specific-access-approver-judiciary", "access_requests"); - expectedRoleNameWorkTypesMap.put("fee-paid-judge", "pre_hearing_work,hearing_work,post_hearing_work," + expectedRoleNameWorkTypesMap.put("fee-paid-judge", "pre_hearing,hearing_work,post_hearing," + "decision_making_work,routine_work,priority"); expectedRoleNameWorkTypesMap.put("fee-paid-tribunal-member", "hearing_work,priority"); expectedRoleNameWorkTypesMap.put("medical", "hearing_work,priority"); diff --git a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsStaffOrgRolesTest.java b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsStaffOrgRolesTest.java index 4e0172649..5e0c44a5f 100644 --- a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsStaffOrgRolesTest.java +++ b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/domain/service/DroolSscsStaffOrgRolesTest.java @@ -104,8 +104,8 @@ void shouldReturnSscsAdminMappings(String roleId, String serviceCode, String exp assertNull(r.getAttributes().get("workTypes")); } else if (("hearing-centre-admin").equals(r.getRoleName())) { assertThat(r.getAttributes().get("workTypes").asText().split(","), - arrayContainingInAnyOrder("pre_hearing_work", "hearing_work", - "post_hearing_work", "decision_making_work", + arrayContainingInAnyOrder("pre_hearing", "hearing_work", + "post_hearing", "decision_making_work", "routine_work", "priority", "applications")); } else if (("task-supervisor").equals(r.getRoleName())) { assertNull(r.getAttributes().get("workTypes")); @@ -117,9 +117,16 @@ void shouldReturnSscsAdminMappings(String roleId, String serviceCode, String exp assertNull(r.getAttributes().get("workTypes")); } else if (("regional-centre-admin").equals(r.getRoleName())) { assertThat(r.getAttributes().get("workTypes").asText().split(","), - arrayContainingInAnyOrder("pre_hearing_work", "hearing_work", - "post_hearing_work", "decision_making_work", + arrayContainingInAnyOrder("pre_hearing", "hearing_work", + "post_hearing", "decision_making_work", "routine_work", "priority", "applications")); + } else if (("clerk").equals(r.getRoleName())) { + assertThat(r.getAttributes().get("workTypes").asText().split(","), + arrayContainingInAnyOrder("pre_hearing", "hearing_work", + "post_hearing", "decision_making_work", + "routine_work", "priority", "applications")); + } else { + assertNull(r.getAttributes().get("workTypes")); } }); } @@ -177,8 +184,8 @@ void shouldReturnSscsCtscMappings(String roleId, String serviceCode, String expe //assert work types if (("ctsc").equals(r.getRoleName())) { assertThat(r.getAttributes().get("workTypes").asText().split(","), - arrayContainingInAnyOrder("pre_hearing_work", "hearing_work", - "post_hearing_work", "decision_making_work", + arrayContainingInAnyOrder("pre_hearing", "hearing_work", + "post_hearing", "decision_making_work", "routine_work", "priority", "applications")); } else if (("ctsc-team-leader").equals(r.getRoleName())) { assertNull(r.getAttributes().get("workTypes")); @@ -188,6 +195,8 @@ void shouldReturnSscsCtscMappings(String roleId, String serviceCode, String expe assertNull(r.getAttributes().get("workTypes")); } else if (("specific-access-approver-ctsc").equals(r.getRoleName())) { assertEquals("access_requests", r.getAttributes().get("workTypes").asText()); + } else { + assertNull(r.getAttributes().get("workTypes")); } }); } @@ -263,8 +272,8 @@ void shouldReturnSscsCaseWorkerMappings(String roleId, String serviceCode, Strin assertNull(r.getAttributes().get("workTypes")); } else if (("tribunal-caseworker").equals(r.getRoleName())) { assertThat(r.getAttributes().get("workTypes").asText().split(","), - arrayContainingInAnyOrder("pre_hearing_work", "hearing_work", - "post_hearing_work", "decision_making_work", + arrayContainingInAnyOrder("pre_hearing", "hearing_work", + "post_hearing", "decision_making_work", "routine_work", "priority", "applications")); } else if (("task-supervisor").equals(r.getRoleName())) { assertNull(r.getAttributes().get("workTypes")); @@ -274,9 +283,11 @@ void shouldReturnSscsCaseWorkerMappings(String roleId, String serviceCode, Strin assertEquals("access_requests", r.getAttributes().get("workTypes").asText()); } else if (("registrar").equals(r.getRoleName())) { assertThat(r.getAttributes().get("workTypes").asText().split(","), - arrayContainingInAnyOrder("pre_hearing_work", "hearing_work", - "post_hearing_work", "decision_making_work", + arrayContainingInAnyOrder("pre_hearing", "hearing_work", + "post_hearing", "decision_making_work", "routine_work", "priority", "applications")); + } else { + assertNull(r.getAttributes().get("workTypes")); } }); } @@ -332,11 +343,13 @@ void shouldReturnStcicOtherGovDepMappings(String roleId, String serviceCode, Str if (("dwp").equals(r.getRoleName())) { assertThat(r.getAttributes().get("workTypes").asText().split(","), arrayContainingInAnyOrder("applications", "hearing_work", - "routine_work", "priority")); + "routine_work", "priority", "pre_hearing")); } else if (("hmrc").equals(r.getRoleName())) { assertThat(r.getAttributes().get("workTypes").asText().split(","), arrayContainingInAnyOrder("applications", "hearing_work", - "routine_work", "priority")); + "routine_work", "priority", "pre_hearing")); + } else { + assertNull(r.getAttributes().get("workTypes")); } }); } diff --git a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumerTest.java b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumerTest.java index f6ee812f8..bf0d1e7d9 100644 --- a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/CRDTopicConsumerTest.java @@ -1,26 +1,39 @@ package uk.gov.hmcts.reform.orgrolemapping.servicebus; +import com.microsoft.azure.servicebus.IMessageHandler; +import com.microsoft.azure.servicebus.Message; import com.microsoft.azure.servicebus.SubscriptionClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; +import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; +import uk.gov.hmcts.reform.orgrolemapping.controller.advice.exception.InvalidRequest; +import uk.gov.hmcts.reform.orgrolemapping.domain.model.UserRequest; +import uk.gov.hmcts.reform.orgrolemapping.domain.model.enums.UserType; import uk.gov.hmcts.reform.orgrolemapping.domain.service.BulkAssignmentOrchestrator; import uk.gov.hmcts.reform.orgrolemapping.servicebus.deserializer.OrmDeserializer; +import java.util.List; import java.util.concurrent.CompletableFuture; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; class CRDTopicConsumerTest { + @Mock private BulkAssignmentOrchestrator bulkAssignmentOrchestrator; + @Mock private OrmDeserializer deserializer; - @Mock public SubscriptionClient subscriptionClient; @@ -39,19 +52,48 @@ void getSubscriptionClientThrowsServiceBusException() { sut.environment = "pr"; sut.topic = "test1"; - assertThrows(IllegalArgumentException.class, () -> sut.getSubscriptionClient()); - } - @Test void registerMessageHandlerOnClientTest() throws Exception { - CompletableFuture voidCompletableFuture = sut.registerCRDMessageHandlerOnClient( - subscriptionClient); + CompletableFuture voidCompletableFuture = sut.registerCRDMessageHandlerOnClient(subscriptionClient); assertNull(voidCompletableFuture); } + @Test + void shouldThrowExceptionWhenMessageReceivedWithIncorrectFormat() { + when(deserializer.deserialize(any())).thenThrow(RuntimeException.class); + + IMessageHandler handler = sut.getMessageHandler(subscriptionClient); + + try { + handler.onMessageAsync(new Message("{invalidUserRequest}")); + } catch (InvalidRequest exception) { + assertThat(exception.getMessage(), containsString("Error processing message from service bus")); + } + } + + @Test + void shouldThrowExceptionWhenCallToRoleAssignmentServiceIsUnsuccessful() throws JsonProcessingException { + + UserRequest userRequest = UserRequest.builder() + .userIds(List.of("9d6089ab-0459-4bb6-9174-dc111f0f661d", "1ab7da58-fa93-43b7-8df1-8f8406fdcb5a")) + .build(); + ObjectMapper mapper = new ObjectMapper(); + String request = mapper.writeValueAsString(userRequest); + + when(deserializer.deserialize(any())).thenReturn(userRequest); + when(bulkAssignmentOrchestrator.createBulkAssignmentsRequest(userRequest, UserType.CASEWORKER)) + .thenThrow(RuntimeException.class); + IMessageHandler handler = sut.getMessageHandler(subscriptionClient); + + try { + handler.onMessageAsync(new Message(request)); + } catch (InvalidRequest exception) { + assertThat(exception.getMessage(), containsString("Error processing message from service bus")); + } + } } diff --git a/src/test/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/JRDTopicConsumerTest.java b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/JRDTopicConsumerTest.java new file mode 100644 index 000000000..9ab7434f5 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/orgrolemapping/servicebus/JRDTopicConsumerTest.java @@ -0,0 +1,86 @@ +package uk.gov.hmcts.reform.orgrolemapping.servicebus; + +import com.microsoft.azure.servicebus.IMessageHandler; +import com.microsoft.azure.servicebus.Message; +import com.microsoft.azure.servicebus.SubscriptionClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; +import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; +import uk.gov.hmcts.reform.orgrolemapping.controller.advice.exception.InvalidRequest; +import uk.gov.hmcts.reform.orgrolemapping.domain.model.UserRequest; +import uk.gov.hmcts.reform.orgrolemapping.domain.model.enums.UserType; +import uk.gov.hmcts.reform.orgrolemapping.domain.service.BulkAssignmentOrchestrator; +import uk.gov.hmcts.reform.orgrolemapping.servicebus.deserializer.OrmDeserializer; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +class JRDTopicConsumerTest { + + @Mock + private BulkAssignmentOrchestrator bulkAssignmentOrchestrator; + + @Mock + private OrmDeserializer deserializer; + + @Mock + public SubscriptionClient subscriptionClient; + + JRDTopicConsumer sut; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + sut = new JRDTopicConsumer(bulkAssignmentOrchestrator, deserializer); + } + + @Test + void registerMessageHandlerOnClientTest() throws Exception { + CompletableFuture voidCompletableFuture = sut.registerJRDMessageHandlerOnClient(subscriptionClient); + assertNull(voidCompletableFuture); + } + + @Test + void shouldThrowExceptionWhenMessageReceivedWithIncorrectFormat() { + when(deserializer.deserialize(any())).thenThrow(RuntimeException.class); + + IMessageHandler handler = sut.getMessageHandler(subscriptionClient); + + try { + handler.onMessageAsync(new Message("{invalidUserRequest}")); + } catch (InvalidRequest exception) { + assertThat(exception.getMessage(), containsString("Error processing message from service bus")); + } + } + + @Test + void shouldThrowExceptionWhenCallToRoleAssignmentServiceIsUnsuccessful() throws JsonProcessingException { + + UserRequest userRequest = UserRequest.builder() + .userIds(List.of("9d6089ab-0459-4bb6-9174-dc111f0f661d", "1ab7da58-fa93-43b7-8df1-8f8406fdcb5a")) + .build(); + ObjectMapper mapper = new ObjectMapper(); + String request = mapper.writeValueAsString(userRequest); + + when(deserializer.deserialize(any())).thenReturn(userRequest); + when(bulkAssignmentOrchestrator.createBulkAssignmentsRequest(userRequest, UserType.JUDICIAL)) + .thenThrow(RuntimeException.class); + + IMessageHandler handler = sut.getMessageHandler(subscriptionClient); + + try { + handler.onMessageAsync(new Message(request)); + } catch (InvalidRequest exception) { + assertThat(exception.getMessage(), containsString("Error processing message from service bus")); + } + } +}