Skip to content

Commit

Permalink
CIV-9406 reverting the pr (#3447)
Browse files Browse the repository at this point in the history
* reverting  CIV-9406
  • Loading branch information
asthamalviya authored Oct 23, 2023
1 parent 0ae757c commit 87263aa
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.enums.CaseRole;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.service.docmosis.trialready.TrialReadyFormGenerator;

Expand Down Expand Up @@ -76,19 +75,10 @@ private CallbackResponse generateClaimForm(CallbackParams callbackParams) {

private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuilder<?, ?> caseDataBuilder,
CaseData caseData) {
String activityID = camundaActivityId(callbackParams);
CaseRole role = switch (activityID) {
case TASK_ID_APPLICANT -> CaseRole.CLAIMANT;
case TASK_ID_RESPONDENT1 -> CaseRole.DEFENDANT;
case TASK_ID_RESPONDENT2 -> CaseRole.RESPONDENTSOLICITORTWO;
default -> null;
};

CaseDocument caseDocument = trialReadyFormGenerator.generate(
callbackParams.getCaseData(),
callbackParams.getParams().get(BEARER_TOKEN).toString(),
camundaActivityId(callbackParams),
role
camundaActivityId(callbackParams)
);
var documents = caseData.getTrialReadyDocuments();
documents.add(element(caseDocument));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private CaseData getUpdatedCaseData(CallbackParams callbackParams) {
CaseDocument dummyDocument = new CaseDocument(null, null, null, 0, null, null, null);
LocalDateTime responseDate = time.now();
AllocatedTrack allocatedTrack = caseData.getAllocatedTrack();
return caseData.toBuilder()
CaseData updatedData = caseData.toBuilder()
.businessProcess(BusinessProcess.ready(DEFENDANT_RESPONSE_CUI))
.respondent1ResponseDate(responseDate)
.respondent1GeneratedResponseDocument(dummyDocument)
Expand All @@ -82,5 +82,6 @@ private CaseData getUpdatedCaseData(CallbackParams callbackParams) {
allocatedTrack
))
.build();
return updatedData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.CaseRole;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.utils.UserRoleCaching;
import uk.gov.hmcts.reform.civil.service.CoreCaseUserService;
import uk.gov.hmcts.reform.civil.service.UserService;
import uk.gov.hmcts.reform.idam.client.models.UserInfo;

import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -27,19 +30,15 @@
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_APPLICANT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT1;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT2;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIAL_READINESS;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.APPLICANT_TRIAL_READY_NOTIFY_OTHERS;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_APPLICANT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RESPONDENT1_TRIAL_READY_NOTIFY_OTHERS;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT1;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RESPONDENT2_TRIAL_READY_NOTIFY_OTHERS;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT2;
import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.SMALL_CLAIM;
import static uk.gov.hmcts.reform.civil.utils.HearingUtils.formatHearingDuration;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isLIPClaimant;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isApplicantSolicitor;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isLIPDefendant;
import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorOne;

@Service
@RequiredArgsConstructor
Expand All @@ -55,16 +54,17 @@ public class TrialReadinessCallbackHandler extends CallbackHandler {
+ "you will need to make an application as soon as possible and pay the appropriate fee.";
public static final String NOT_READY_HEADER = "## You have said this case is not ready for trial or hearing";
public static final String NOT_READY_BODY = "### What happens next \n\n"
+ "You can view your and other party's trial arrangements in documents in the case details. "
+ "If there are any additional changes between now and the hearing date, "
+ "you will need to make an application as soon as possible and pay the appropriate fee.\n\n"
+ "The trial will go ahead on the specified date "
+ "unless a judge makes an order changing the date of the hearing. "
+ "If you want the date of the hearing to be changed (or any other order to make the case ready for trial)"
+ "you will need to make an application to the court and pay the appropriate fee.";
+ "You can view your and other party's trial arrangements in documents in the case details. "
+ "If there are any additional changes between now and the hearing date, "
+ "you will need to make an application as soon as possible and pay the appropriate fee.\n\n"
+ "The trial will go ahead on the specified date "
+ "unless a judge makes an order changing the date of the hearing. "
+ "If you want the date of the hearing to be changed (or any other order to make the case ready for trial)"
+ "you will need to make an application to the court and pay the appropriate fee.";
private final ObjectMapper objectMapper;

private final UserRoleCaching userRoleCaching;
private final UserService userService;
private final CoreCaseUserService coreCaseUserService;

@Override
protected Map<String, Callback> callbacks() {
Expand All @@ -78,17 +78,14 @@ protected Map<String, Callback> callbacks() {
CallbackResponse populateValues(CallbackParams callbackParams) {
var caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> updatedData = caseData.toBuilder();
String bearerToken = callbackParams.getParams().get(BEARER_TOKEN).toString();
String ccdCaseRef = callbackParams.getCaseData().getCcdCaseReference().toString();
List<String> userRoles = userRoleCaching.getUserRoles(bearerToken, ccdCaseRef);

var isApplicant = YesOrNo.NO;
var isRespondent1 = YesOrNo.NO;
var isRespondent2 = YesOrNo.NO;
if (isApplicantSolicitor(userRoles)) {
if (checkUserRoles(callbackParams, CaseRole.APPLICANTSOLICITORONE)) {
isApplicant = YesOrNo.YES;
updatedData.hearingDurationTextApplicant(formatHearingDuration(caseData.getHearingDuration()));
} else if (isRespondentSolicitorOne(userRoles)) {
} else if (checkUserRoles(callbackParams, CaseRole.RESPONDENTSOLICITORONE)) {
isRespondent1 = YesOrNo.YES;
updatedData.hearingDurationTextRespondent1(formatHearingDuration(caseData.getHearingDuration()));
} else {
Expand Down Expand Up @@ -120,17 +117,19 @@ CallbackResponse setBusinessProcess(CallbackParams callbackParams) {
var caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder updatedData = caseData.toBuilder();

String bearerToken = callbackParams.getParams().get(BEARER_TOKEN).toString();
String ccdCaseRef = callbackParams.getCaseData().getCcdCaseReference().toString();
List<String> roles = userRoleCaching.getUserRoles(bearerToken, ccdCaseRef);

if (isApplicantSolicitor(roles) || isLIPClaimant(roles)) {
if (checkUserRoles(callbackParams, CaseRole.APPLICANTSOLICITORONE) || checkUserRoles(
callbackParams,
CaseRole.CLAIMANT
)) {
if (caseData.getTrialReadyApplicant() == YesOrNo.YES) {
updatedData.businessProcess(BusinessProcess.ready(APPLICANT_TRIAL_READY_NOTIFY_OTHERS));
} else {
updatedData.businessProcess(BusinessProcess.ready(GENERATE_TRIAL_READY_DOCUMENT_APPLICANT));
}
} else if (isRespondentSolicitorOne(roles) || isLIPDefendant(roles)) {
} else if (checkUserRoles(callbackParams, CaseRole.RESPONDENTSOLICITORONE) || checkUserRoles(
callbackParams,
CaseRole.DEFENDANT
)) {
if (caseData.getTrialReadyRespondent1() == YesOrNo.YES) {
updatedData.businessProcess(BusinessProcess.ready(RESPONDENT1_TRIAL_READY_NOTIFY_OTHERS));
} else {
Expand Down Expand Up @@ -159,19 +158,23 @@ private SubmittedCallbackResponse buildConfirmation(CallbackParams callbackParam

private YesOrNo checkUserReady(CallbackParams callbackParams) {
var caseData = callbackParams.getCaseData();
String bearerToken = callbackParams.getParams().get(BEARER_TOKEN).toString();
String ccdCaseRef = callbackParams.getCaseData().getCcdCaseReference().toString();
List<String> userRoles = userRoleCaching.getUserRoles(bearerToken, ccdCaseRef);

if (isApplicantSolicitor(userRoles) || isLIPClaimant(userRoles)) {
if (checkUserRoles(callbackParams, CaseRole.APPLICANTSOLICITORONE)) {
return caseData.getTrialReadyApplicant();
} else if (isRespondentSolicitorOne(userRoles) || isLIPDefendant(userRoles)) {
} else if (checkUserRoles(callbackParams, CaseRole.RESPONDENTSOLICITORONE)) {
return caseData.getTrialReadyRespondent1();
} else {
return caseData.getTrialReadyRespondent2();
}
}

private boolean checkUserRoles(CallbackParams callbackParams, CaseRole userRole) {
UserInfo userInfo = userService.getUserInfo(callbackParams.getParams().get(BEARER_TOKEN).toString());
return coreCaseUserService.userHasCaseRole(callbackParams.getCaseData().getCcdCaseReference().toString(),
userInfo.getUid(), userRole
);
}

@Override
public List<CaseEvent> handledEvents() {
return EVENTS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType;
import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF;
import uk.gov.hmcts.reform.civil.enums.CaseRole;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.Party;
Expand Down Expand Up @@ -36,21 +35,19 @@ public class TrialReadyFormGenerator {
private static final String TASK_ID_APPLICANT = "GenerateTrialReadyFormApplicant";
private static final String TASK_ID_RESPONDENT1 = "GenerateTrialReadyFormRespondent1";

public CaseDocument generate(CaseData caseData, String authorisation, String camundaActivity, CaseRole userRole) {
public CaseDocument generate(CaseData caseData, String authorisation, String camundaActivity) {
TrialReadyForm templateData = getTemplateData(caseData, camundaActivity);

DocmosisTemplates template = TRIAL_READY;
DocmosisDocument document = documentGeneratorService.generateDocmosisDocument(templateData, template);
CaseDocument trialReadyDocument = documentManagementService.uploadDocument(
return documentManagementService.uploadDocument(
authorisation,
new PDF(
getFileName(caseData, template, camundaActivity),
document.getBytes(),
DocumentType.TRIAL_READY_DOCUMENT
)
);

return trialReadyDocument.toBuilder().ownedBy(userRole).build();
}

private TrialReadyForm getTemplateData(CaseData caseData, String camundaActivity) {
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/uk/gov/hmcts/reform/civil/utils/UserRoleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import static uk.gov.hmcts.reform.civil.enums.CaseRole.APPLICANTSOLICITORONE;
import static uk.gov.hmcts.reform.civil.enums.CaseRole.RESPONDENTSOLICITORONE;
import static uk.gov.hmcts.reform.civil.enums.CaseRole.RESPONDENTSOLICITORTWO;
import static uk.gov.hmcts.reform.civil.enums.CaseRole.CLAIMANT;
import static uk.gov.hmcts.reform.civil.enums.CaseRole.DEFENDANT;

public class UserRoleUtils {

Expand All @@ -27,14 +25,6 @@ public static boolean isRespondentSolicitorTwo(List<String> roles) {
return hasRole(roles, RESPONDENTSOLICITORTWO);
}

public static boolean isLIPClaimant(List<String> roles) {
return hasRole(roles, CLAIMANT);
}

public static boolean isLIPDefendant(List<String> roles) {
return hasRole(roles, DEFENDANT);
}

private static boolean hasRole(List<String> roles, CaseRole role) {
return roles.stream().anyMatch(role.getFormattedName()::contains);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.documentmanagement.model.Document;
import uk.gov.hmcts.reform.civil.enums.CaseRole;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter;
import uk.gov.hmcts.reform.civil.model.CaseData;
Expand Down Expand Up @@ -69,21 +68,20 @@ public void shouldGenerateForm_when1v1() {
.documentFileName("file-name")
.documentBinaryUrl("binary-url")
.build())
.ownedBy(CaseRole.CLAIMANT)
.build();

when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString(), any(CaseRole.class))).thenReturn(document);
when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString())).thenReturn(document);
CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build();
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
params.getRequest().setEventId(GENERATE_TRIAL_READY_FORM_APPLICANT.name());
// When
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
// Then
verify(trialReadyFormGenerator).generate(
any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormApplicant"), eq(CaseRole.CLAIMANT));
any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormApplicant"));

CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class);
assertThat(updatedData.getTrialReadyDocuments()).hasSize(1);
assertThat(updatedData.getTrialReadyDocuments().size()).isEqualTo(1);

}

Expand All @@ -101,21 +99,20 @@ public void shouldGenerateForm_when1v1AndRespondent1() {
.documentFileName("file-name")
.documentBinaryUrl("binary-url")
.build())
.ownedBy(CaseRole.DEFENDANT)
.build();

when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString(), any(CaseRole.class))).thenReturn(document);
when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString())).thenReturn(document);
CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build();
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
params.getRequest().setEventId(GENERATE_TRIAL_READY_FORM_RESPONDENT1.name());
// When
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
// Then
verify(trialReadyFormGenerator).generate(
any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent1"), eq(CaseRole.DEFENDANT));
any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent1"));

CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class);
assertThat(updatedData.getTrialReadyDocuments()).hasSize(1);
assertThat(updatedData.getTrialReadyDocuments().size()).isEqualTo(1);

}

Expand All @@ -133,12 +130,11 @@ public void shouldGenerateForm_when1v2AndOneSeveralPartiesGeneratesDocument() {
.documentFileName("file-name")
.documentBinaryUrl("binary-url")
.build())
.ownedBy(CaseRole.RESPONDENTSOLICITORTWO)
.build();
List<Element<CaseDocument>> systemGeneratedCaseDocuments = new ArrayList<>();
systemGeneratedCaseDocuments.add(element(document));

when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString(), any(CaseRole.class))).thenReturn(document);
when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString())).thenReturn(document);
CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.trialReadyDocuments(systemGeneratedCaseDocuments).build();
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
Expand All @@ -147,10 +143,10 @@ public void shouldGenerateForm_when1v2AndOneSeveralPartiesGeneratesDocument() {
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
// Then
verify(trialReadyFormGenerator).generate(
any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent2"), eq(CaseRole.RESPONDENTSOLICITORTWO));
any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent2"));

CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class);
assertThat(updatedData.getTrialReadyDocuments()).hasSize(2);
assertThat(updatedData.getTrialReadyDocuments().size()).isEqualTo(2);

}
}
Loading

0 comments on commit 87263aa

Please sign in to comment.