Skip to content

Commit

Permalink
CCMSPUI-530 Created various mappers for mapping document entity for p…
Browse files Browse the repository at this point in the history
…resentation layer

Signed-off-by: Jamie Briggs <jamie.briggs@digital.justice.gov.uk>
  • Loading branch information
Jamie Briggs committed Feb 6, 2025
1 parent e35ce84 commit 22c3826
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 2 deletions.
18 changes: 16 additions & 2 deletions data-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1899,8 +1899,22 @@ components:
- $ref: "#/components/schemas/notificationInfo"
type: object
properties:
docs:
type: 'string'
notes:
type: 'array'
items:
$ref: '#/components/schemas/note'
attached_documents:
type: 'array'
items:
$ref: '#/components/schemas/document'
uploaded_documents:
type: 'array'
items:
$ref: '#/components/schemas/document'
available_responses:
type: array
items:
type: 'string'
note:
type: 'object'
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uk.gov.laa.ccms.data.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import uk.gov.laa.ccms.data.entity.NotificationDocument;
import uk.gov.laa.ccms.data.model.Document;

@Mapper(componentModel = "spring")
public interface DocumentMapper {

@Mapping(target = "text", source = "documentDescription")
@Mapping(target = "channel", source = "documentChannel")
@Mapping(target = "status", source = "documentStatus")
Document mapToNotification(NotificationDocument notificationDocument);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package uk.gov.laa.ccms.data.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import uk.gov.laa.ccms.data.entity.NotificationNote;
import uk.gov.laa.ccms.data.model.Note;

@Mapper(componentModel = "spring")
public interface NoteMapper {

@Mapping(target = "user.username", source = "noteBy")
@Mapping(target = "notesId", source = "noteId")
@Mapping(target = "message", source = "noteText")
@Mapping(target = "date", source = "noteDate")
Note mapToNote(NotificationNote notificationNote);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.laa.ccms.data.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import uk.gov.laa.ccms.data.entity.NotificationInfo;
import uk.gov.laa.ccms.data.model.Notification;

@Mapper(componentModel = "spring")
public interface NotificationMapper {

@Mapping(target = "user.loginId", source = "userLoginId")
@Mapping(target = "user.username", source = "assignedTo")
@Mapping(target = "assignDate", source = "dateAssigned")
@Mapping(target = "providerCaseReferenceNumber", source = "providerCaseReference")
@Mapping(target = "caseReferenceNumber", source = "lscCaseRefReference")
@Mapping(target = "notificationType", source = "actionNotificationInd")
@Mapping(target = "notificationOpenIndicator", source = "isOpen")
Notification mapToNotification(NotificationInfo notification);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package uk.gov.laa.ccms.data.mapper;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import uk.gov.laa.ccms.data.entity.NotificationDocument;
import uk.gov.laa.ccms.data.model.Document;

@DisplayName("Document mapper implementation test")
class DocumentMapperImplTest {

DocumentMapper mapper = new DocumentMapperImpl();

@Test
@DisplayName("Should map to document")
void shouldMapToDocument(){
// Given
NotificationDocument document = NotificationDocument.builder()
.documentId(1L)
.notificationId(2L)
.documentChannel("Channel")
.documentType("ADV_FRM")
.documentDescription("Description")
.documentStatus("Status")
.edrmsDocumentid("EDRMS")
.build();
// When
Document result = mapper.mapToNotification(document);
// Then
assertEquals("1", result.getDocumentId());
assertEquals("Channel", result.getChannel());
assertEquals("ADV_FRM", result.getDocumentType());
assertEquals("Description", result.getText());
assertEquals("Status", result.getStatus());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package uk.gov.laa.ccms.data.mapper;


import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.LocalDate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import uk.gov.laa.ccms.data.entity.NotificationNote;
import uk.gov.laa.ccms.data.model.Note;

@DisplayName("Note mapper implementation test")
class NoteMapperImplTest {

NoteMapper mapper = new NoteMapperImpl();

@Test
@DisplayName("Should map to note")
void shouldMapToNote(){
// Given
NotificationNote note = NotificationNote.builder()
.noteId(1L)
.noteBy("User Name")
.noteDate(LocalDate.of(2025, 1, 1))
.notificationId(2L)
.noteText("Note text")
.build();
// When
Note result = mapper.mapToNote(note);
// Then
assertEquals("1", result.getNotesId());
assertEquals("User Name", result.getUser().getUsername());
assertEquals(LocalDate.of(2025, 1, 1), result.getDate());
assertEquals("Note text", result.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package uk.gov.laa.ccms.data.mapper;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.LocalDate;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import uk.gov.laa.ccms.data.entity.NotificationInfo;
import uk.gov.laa.ccms.data.model.Notification;

@DisplayName("Notification mapper implementation test")
class NotificationMapperImplTest {

NotificationMapper mapper = new NotificationMapperImpl();

@Test
@DisplayName("Should map basic details")
void shouldMapBasicDetails(){
// Given
NotificationInfo notificationInfo = NotificationInfo.builder()
.assignedTo("User Name")
.userLoginId("User Login Id")
.clientName("Client Name")
.feeEarner("Fee Earner")
.notificationId(1L)
.providerFirmId(2L)
.subject("NotificationInfo Subject")
.dateAssigned(LocalDate.of(2024, 1, 1))
.dueDate(LocalDate.of(2025, 2, 1))
.status("Status")
.isOpen(true)
.actionNotificationInd("N")
.lscCaseRefReference("LSC Case Ref")
.providerCaseReference("Provider Case Ref")
.feeEarnerPartyId(4L)
.build();

// When
Notification notificationResult = mapper.mapToNotification(notificationInfo);
// Then
assertEquals("User Login Id", notificationResult.getUser().getLoginId());
assertEquals("User Name", notificationResult.getUser().getUsername());
assertEquals("Client Name", notificationResult.getClientName());
assertEquals("Fee Earner", notificationResult.getFeeEarner());
assertEquals("1", notificationResult.getNotificationId());
assertEquals("2", notificationResult.getProviderFirmId());
assertEquals("NotificationInfo Subject", notificationResult.getSubject());
assertEquals(LocalDate.of(2024, 1, 1), notificationResult.getAssignDate());
assertEquals(LocalDate.of(2025, 2, 1), notificationResult.getDueDate());
assertEquals("N", notificationResult.getNotificationType());
assertEquals("Status", notificationResult.getStatus());
assertEquals(true, notificationResult.getNotificationOpenIndicator());
assertEquals("Provider Case Ref",notificationResult.getProviderCaseReferenceNumber());
assertEquals("LSC Case Ref", notificationResult.getCaseReferenceNumber());
}

@Test
@DisplayName("Should map notes")
void shouldMapNotes(){
Assertions.fail("Test not implemented yet");
}

@Test
@DisplayName("Should map documents")
void shouldMapDocuments(){
Assertions.fail("Test not implemented yet");
}

@Test
@DisplayName("Should map attachments")
void shouldMapAttachments(){
Assertions.fail("Test not implemented yet");
}

@Test
@DisplayName("Should map available responses")
void shouldMapAvailableResponses(){
Assertions.fail("Test not implemented yet");
}

}

0 comments on commit 22c3826

Please sign in to comment.