Skip to content

Commit

Permalink
Add logs and confirmation message after successful data changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alivenichoppa committed Nov 5, 2024
1 parent ffe2eab commit 6c314c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ sonarqube {
"src/main/java/uk/gov/hmcts/reform/iacaseapi/Application.java," +
"src/main/java/uk/gov/hmcts/reform/iacaseapi/infrastructure/security/idam/IdamAuthoritiesConverter.java," +
"src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/entities/CaseFlag.java," +
"src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/RevokeLegalRepresentativeAccessHandler.java"
"src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/RevokeLegalRepresentativeAccessHandler.java," +
"src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/postsubmit/RevokeCaseAccessConfirmation.java"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1687,9 +1687,6 @@ public enum AsylumCaseFieldDefinition {
LOCAL_AUTHORITY_POLICY(
"localAuthorityPolicy", new TypeReference<OrganisationPolicy>(){}),

CASE_ROLE_ASSIGNMENTS(
"caseRoleAssignments", new TypeReference<String>(){}),

REVOKE_ACCESS_FOR_USER_ID(
"revokeAccessForUserId", new TypeReference<String>(){}),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.postsubmit;

import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse;
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PostSubmitCallbackHandler;

import static java.util.Objects.requireNonNull;

@Component
public class RevokeCaseAccessConfirmation implements PostSubmitCallbackHandler<AsylumCase> {

public boolean canHandle(
Callback<AsylumCase> callback
) {
requireNonNull(callback, "callback must not be null");

return callback.getEvent() == Event.REVOKE_CASE_ACCESS;
}

public PostSubmitCallbackResponse handle(
Callback<AsylumCase> callback
) {
if (!canHandle(callback)) {
throw new IllegalStateException("Cannot handle callback");
}

PostSubmitCallbackResponse postSubmitResponse =
new PostSubmitCallbackResponse();

postSubmitResponse.setConfirmationHeader("# You have revoke case access for the appeal");

return postSubmitResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

@Component
@Slf4j
public class RevokeLegalRepresentativeAccessHandler implements PreSubmitCallbackHandler<AsylumCase> {
public class RevokeCaseAccessHandler implements PreSubmitCallbackHandler<AsylumCase> {
private final RoleAssignmentService roleAssignmentService;

public RevokeLegalRepresentativeAccessHandler(RoleAssignmentService roleAssignmentService) {
public RevokeCaseAccessHandler(RoleAssignmentService roleAssignmentService) {
this.roleAssignmentService = roleAssignmentService;
}

Expand Down Expand Up @@ -59,6 +59,8 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
Optional<String> userIdToRevokeAccessFrom
= asylumCase.read(AsylumCaseFieldDefinition.REVOKE_ACCESS_FOR_USER_ID, String.class);

log.info("Revoke case roles for the appeal with case ID {} and userId {}", caseId, userIdToRevokeAccessFrom);

if (userIdToRevokeAccessFrom.isEmpty()) {
response.addError("User ID is required to revoke case access");
return response;
Expand All @@ -67,7 +69,7 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
RoleAssignmentResource roleAssignmentResource
= getRoleAssignmentsForUser(userIdToRevokeAccessFrom.get(), caseId);

log.debug("Found {} 'Creator', 'Legal Representative' roles for case access in the appeal with case ID {}",
log.info("Found '{}' '[CREATOR]' and '[LEGALREPRESENTATIVE]' case roles in the appeal with case ID {}",
roleAssignmentResource.getRoleAssignmentResponse().size(), caseId);

if (roleAssignmentResource.getRoleAssignmentResponse().isEmpty()) {
Expand All @@ -92,7 +94,7 @@ private RoleAssignmentResource getRoleAssignmentsForUser(String userId, long cas
Attributes.CASE_ID, List.of(String.valueOf(caseId))
)).build();

log.debug("Query role assignment with the parameters: {}, for case reference: {}",
log.info("Query role assignment with the parameters: {}, for case reference: {}",
queryRequest, caseId);

return roleAssignmentService.queryRoleAssignments(queryRequest);
Expand Down

0 comments on commit 6c314c3

Please sign in to comment.