Skip to content

Commit

Permalink
CIV-11556 judgecasenotes tab (#3589)
Browse files Browse the repository at this point in the history
* updates to judge case notes for more meta data items

* updates to judge case notes for more meta data items

* point at CCD

* Update Jenkinsfile_CNP to remove CCD pointing

---------

Co-authored-by: vasudevganesanhmcts <[email protected]>
  • Loading branch information
drummondjm and vasudevganesanhmcts authored Nov 22, 2023
1 parent 4b18cc2 commit 67305d1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import uk.gov.hmcts.reform.civil.model.documents.DocumentWithName;
import uk.gov.hmcts.reform.civil.service.CaseNoteService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;

import static java.lang.String.format;
import static java.util.Objects.nonNull;
import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
Expand Down Expand Up @@ -75,10 +77,11 @@ private AboutToStartOrSubmitCallbackResponse removeCaseNoteType(CallbackParams c
private AboutToStartOrSubmitCallbackResponse populateSubmittedDateTime(CallbackParams callbackParams) {
var caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
String userAuth = callbackParams.getParams().get(BEARER_TOKEN).toString();

if (caseData.getCaseNoteType().equals(CaseNoteType.NOTE_ONLY)) {
CaseNote caseNoteTA = caseNoteService.buildCaseNote(
callbackParams.getParams().get(BEARER_TOKEN).toString(),
userAuth,
caseData.getCaseNoteTA()
);

Expand All @@ -92,35 +95,28 @@ private AboutToStartOrSubmitCallbackResponse populateSubmittedDateTime(CallbackP

if (caseData.getCaseNoteType().equals(CaseNoteType.DOCUMENT_ONLY)) {
List<Element<DocumentWithName>> documentAndNameToAdd = caseData.getDocumentAndNameToAdd();
List<Element<DocumentWithName>> documentAndNameCurrent = caseData.getDocumentAndName();

if (documentAndNameCurrent == null) {
documentAndNameCurrent = documentAndNameToAdd;
} else {
for (Element<DocumentWithName> document : documentAndNameToAdd) {
documentAndNameCurrent.add(document);
}
List<Element<DocumentWithName>> documentAndNameCurrent = new ArrayList<>();
if (nonNull(caseData.getDocumentAndName())) {
documentAndNameCurrent.addAll(caseData.getDocumentAndName());
}
caseDataBuilder
.documentAndName(documentAndNameCurrent)
.build();
documentAndNameToAdd.forEach(documentAndName -> {
List<Element<DocumentWithName>> newJudgeCaseNoteDocumentAndName = caseNoteService.buildJudgeCaseNoteDocumentAndName(documentAndName.getValue(), userAuth);
documentAndNameCurrent.addAll(newJudgeCaseNoteDocumentAndName);
});
caseDataBuilder.documentAndName(documentAndNameCurrent);
}

if (caseData.getCaseNoteType().equals(CaseNoteType.DOCUMENT_AND_NOTE)) {
List<Element<DocumentAndNote>> documentAndNoteToAdd = caseData.getDocumentAndNoteToAdd();
List<Element<DocumentAndNote>> documentAndNoteCurrent = caseData.getDocumentAndNote();

if (documentAndNoteCurrent == null) {
documentAndNoteCurrent = documentAndNoteToAdd;
} else {
for (Element<DocumentAndNote> document : documentAndNoteToAdd) {
documentAndNoteCurrent.add(document);
}
List<Element<DocumentAndNote>> documentAndNoteCurrent = new ArrayList<>();
if (nonNull(caseData.getDocumentAndNote())) {
documentAndNoteCurrent.addAll(caseData.getDocumentAndNote());
}
caseDataBuilder
.documentAndNote(documentAndNoteCurrent)
.build();

documentAndNoteToAdd.forEach(documentAndNote -> {
List<Element<DocumentAndNote>> newJudgeCaseNoteAndDocument = caseNoteService.buildJudgeCaseNoteAndDocument(documentAndNote.getValue(), userAuth);
documentAndNoteCurrent.addAll(newJudgeCaseNoteAndDocument);
});
caseDataBuilder.documentAndNote(documentAndNoteCurrent);
}

return AboutToStartOrSubmitCallbackResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public class DocumentAndNote {
private String documentNote;
@Builder.Default
private LocalDateTime createdDateTime = LocalDateTime.now(ZoneId.of("Europe/London"));
private String createdBy;
private String documentNoteForTab;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class DocumentWithName {
private String documentName;
@Builder.Default
private LocalDateTime createdDateTime = LocalDateTime.now(ZoneId.of("Europe/London"));
private String createdBy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.civil.model.CaseNote;
import uk.gov.hmcts.reform.civil.model.common.Element;
import uk.gov.hmcts.reform.civil.model.documents.DocumentAndNote;
import uk.gov.hmcts.reform.civil.model.documents.DocumentWithName;
import uk.gov.hmcts.reform.idam.client.IdamClient;
import uk.gov.hmcts.reform.idam.client.models.UserDetails;

Expand Down Expand Up @@ -43,4 +45,35 @@ public List<Element<CaseNote>> addNoteToListEnd(CaseNote caseNote, List<Element<

return updatedCaseNotes;
}

public List<Element<DocumentAndNote>> buildJudgeCaseNoteAndDocument(DocumentAndNote documentAndNote, String authorisation) {
UserDetails userDetails = idamClient.getUserDetails(authorisation);

var updatedJudgeNote = DocumentAndNote.builder()
.documentName(documentAndNote.getDocumentName())
.document(documentAndNote.getDocument())
.documentNote(documentAndNote.getDocumentNote())
.createdBy(userDetails.getFullName())
.documentNoteForTab(documentAndNote.getDocumentNote())
.build();
List<Element<DocumentAndNote>> updatedJudgeNoteAndDocument = newArrayList();
updatedJudgeNoteAndDocument.add(element(updatedJudgeNote));

return updatedJudgeNoteAndDocument;
}

public List<Element<DocumentWithName>> buildJudgeCaseNoteDocumentAndName(DocumentWithName documentAndNote, String authorisation) {
UserDetails userDetails = idamClient.getUserDetails(authorisation);

var updatedJudgeNote = DocumentWithName.builder()
.document(documentAndNote.getDocument())
.documentName(documentAndNote.getDocumentName())
.createdBy(userDetails.getFullName())
.build();
List<Element<DocumentWithName>> updatedJudgeNoteDocumentAndName = newArrayList();
updatedJudgeNoteDocumentAndName.add(element(updatedJudgeNote));

return updatedJudgeNoteDocumentAndName;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
Expand Down Expand Up @@ -104,109 +105,83 @@ void shouldPopulateNoteDateTime_whenNoteIsAddedToCase() {
@Test
void shouldCopyDocumentAndNameToAdd_whenDocumentWithNameIsNull() {
Document document = Document.builder().documentFileName("fileName").build();
DocumentWithName testDocument = DocumentWithName.builder()
.documentName("testDocument")
.document(document)
.build();
DocumentWithName testDocument = DocumentWithName.builder().documentName("testDocument").document(document).createdBy("bill bob").build();
List<Element<DocumentWithName>> documentWithNameToAdd = wrapElements(testDocument);

CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.caseNoteType(CaseNoteType.DOCUMENT_ONLY)
.documentAndNameToAdd(documentWithNameToAdd)
.caseNoteTA(null)
.build();
when(caseNoteService.buildJudgeCaseNoteDocumentAndName(any(), any())).thenReturn(documentWithNameToAdd);

CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

assertThat(response.getData()).extracting("documentAndName")
.isEqualTo(objectMapper.convertValue(documentWithNameToAdd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("documentAndName").isEqualTo(objectMapper.convertValue(documentWithNameToAdd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("caseNotesTA").isNull();
assertThat(response.getData()).extracting("documentAndNote").isNull();

}

@Test
void shouldAddDocument_whenDocumentWithNameIsNotNull() {
Document document = Document.builder().documentFileName("fileName").build();
DocumentWithName testDocument = DocumentWithName.builder()
.documentName("testDocument")
.document(document)
.build();
List<Element<DocumentWithName>> documentWithNameToAdd = wrapElements(testDocument);
DocumentWithName testDocument = DocumentWithName.builder().documentName("testDocument").document(document).createdBy("John Doe").build();
List<Element<DocumentWithName>> documentWithNameStart = wrapElements(testDocument);
List<Element<DocumentWithName>> documentWithNameToAdd = wrapElements(testDocument);
List<Element<DocumentWithName>> documentWithNameEnd = wrapElements(testDocument, testDocument);

CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.caseNoteType(CaseNoteType.DOCUMENT_ONLY)
.documentAndNameToAdd(documentWithNameToAdd)
.documentAndName(documentWithNameStart)
.caseNoteTA(null)
.build();
when(caseNoteService.buildJudgeCaseNoteDocumentAndName(any(), any())).thenReturn(documentWithNameToAdd);

CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

assertThat(response.getData()).extracting("documentAndName")
.isEqualTo(objectMapper.convertValue(documentWithNameEnd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("documentAndName").isEqualTo(objectMapper.convertValue(documentWithNameEnd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("caseNotesTA").isNull();
assertThat(response.getData()).extracting("documentAndNote").isNull();

}

@Test
void shouldAddNote_whenDocumentWithNoteIsNotNull() {
Document document = Document.builder().documentFileName("fileName").build();
DocumentAndNote testDocument = DocumentAndNote.builder()
.documentName("testDocument")
.document(document)
.documentNote("Note")
.build();
DocumentAndNote testDocument = DocumentAndNote.builder().documentName("testDocument").document(document).documentNote("Note").createdBy("john smith").build();
List<Element<DocumentAndNote>> documentAndNoteToAdd = wrapElements(testDocument);
List<Element<DocumentAndNote>> documentAndNoteStart = wrapElements(testDocument);
List<Element<DocumentAndNote>> documentAndNoteEnd = wrapElements(testDocument, testDocument);

CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.caseNoteType(CaseNoteType.DOCUMENT_AND_NOTE)
.documentAndNoteToAdd(documentAndNoteToAdd)
.documentAndNote(documentAndNoteStart)
.build();
when(caseNoteService.buildJudgeCaseNoteAndDocument(any(), any())).thenReturn(documentAndNoteToAdd);

CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

assertThat(response.getData()).extracting("documentAndNote")
.isEqualTo(objectMapper.convertValue(documentAndNoteEnd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("documentAndNote").isEqualTo(objectMapper.convertValue(documentAndNoteEnd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("caseNotesTA").isNull();
assertThat(response.getData()).extracting("documentAndName").isNull();

}

@Test
void shouldCopyDocumentAndNoteToAdd_whenDocumentWithNoteIsNull() {
Document document = Document.builder().documentFileName("fileName").build();
DocumentAndNote testDocument = DocumentAndNote.builder()
.documentName("testDocument")
.document(document)
.documentNote("Note")
.build();
DocumentAndNote testDocument = DocumentAndNote.builder().documentName("testDocument").document(document).documentNote("Note").createdBy("Jason Bourne").build();
List<Element<DocumentAndNote>> documentAndNoteToAdd = wrapElements(testDocument);

CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.caseNoteType(CaseNoteType.DOCUMENT_AND_NOTE)
.documentAndNoteToAdd(documentAndNoteToAdd)
.build();
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
when(caseNoteService.buildJudgeCaseNoteAndDocument(any(), any())).thenReturn(documentAndNoteToAdd);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

assertThat(response.getData()).extracting("documentAndNote")
.isEqualTo(objectMapper.convertValue(documentAndNoteToAdd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("documentAndNote").isEqualTo(objectMapper.convertValue(documentAndNoteToAdd, new TypeReference<>() {}));
assertThat(response.getData()).extracting("caseNotesTA").isNull();
assertThat(response.getData()).extracting("documentAndName").isNull();

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import uk.gov.hmcts.reform.civil.documentmanagement.model.Document;
import uk.gov.hmcts.reform.civil.model.CaseNote;
import uk.gov.hmcts.reform.civil.model.common.Element;
import uk.gov.hmcts.reform.civil.model.documents.DocumentAndNote;
import uk.gov.hmcts.reform.civil.model.documents.DocumentWithName;
import uk.gov.hmcts.reform.idam.client.IdamClient;
import uk.gov.hmcts.reform.idam.client.models.UserDetails;

Expand Down Expand Up @@ -95,6 +98,34 @@ void shouldAddNoteToListWithNewestAtTop_WhenExistingNotes() {

assertThat(unwrapElements(caseNotes)).isEqualTo(List.of(newNote, oldNote));
}

@Test
void shouldBuildJudgeNote_whenInvokedAndDocumentAndNote() {
Document document = Document.builder().documentFileName("fileName").build();
DocumentAndNote testDocument = DocumentAndNote.builder().documentName("testDocument").document(document).documentNote("Note").build();
when(idamClient.getUserDetails(BEARER_TOKEN)).thenReturn(USER_DETAILS);

var builtDoc = caseNoteService.buildJudgeCaseNoteAndDocument(testDocument, BEARER_TOKEN);

assertThat(builtDoc.get(0).getValue().getDocumentName()).isEqualTo("testDocument");;
assertThat(builtDoc.get(0).getValue().getDocument()).isEqualTo(document);
assertThat(builtDoc.get(0).getValue().getDocumentNote()).isEqualTo("Note");
assertThat(builtDoc.get(0).getValue().getCreatedBy()).isEqualTo("John Smith");;
}

@Test
void shouldBuildJudgeNote_whenInvokedAndDocumentAndName() {
Document document = Document.builder().documentFileName("fileName").build();
DocumentWithName testDocument = DocumentWithName.builder().documentName("testDocument").document(document).build();
when(idamClient.getUserDetails(BEARER_TOKEN)).thenReturn(USER_DETAILS);

var builtDoc = caseNoteService.buildJudgeCaseNoteDocumentAndName(testDocument, BEARER_TOKEN);

assertThat(builtDoc.get(0).getValue().getDocumentName()).isEqualTo("testDocument");;
assertThat(builtDoc.get(0).getValue().getDocument()).isEqualTo(document);
assertThat(builtDoc.get(0).getValue().getCreatedBy()).isEqualTo("John Smith");;
}

}

private CaseNote caseNoteForToday(String note) {
Expand Down

0 comments on commit 67305d1

Please sign in to comment.