Skip to content

Commit

Permalink
CCMSPUI-453: Fixes to codestyle violations
Browse files Browse the repository at this point in the history
Signed-off-by: Jamie Briggs <jamie.briggs@digital.justice.gov.uk>
  • Loading branch information
Jamie Briggs committed Dec 16, 2024
1 parent bc4cb34 commit 71bc49a
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 46 deletions.
4 changes: 2 additions & 2 deletions data-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1680,8 +1680,8 @@ components:
properties:
#client_reference_number:
# type: 'string'
#case_reference_number:
# type: 'string'
case_reference_number:
type: 'string'
provider_case_reference_number:
type: 'string'
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.laa.ccms.data.api.NotificationsApi;
import uk.gov.laa.ccms.data.model.Notification;
import uk.gov.laa.ccms.data.model.NotificationSummary;
import uk.gov.laa.ccms.data.model.Notifications;
import uk.gov.laa.ccms.data.model.UserDetail;
import uk.gov.laa.ccms.data.service.NotificationService;

/**
Expand All @@ -31,6 +34,16 @@ public ResponseEntity<Notifications> getNotifications(String caseReferenceNumber
String providerCaseReference, String assignedToUserId, String clientSurname,
Integer feeEarnerId, Boolean includeClosed, String notificationType, LocalDate dateFrom,
LocalDate dateTo, List<String> sort, Integer maxRecords, Pageable pageable) {
// Notification to filter by
Notification notification = new Notification()
.providerCaseReferenceNumber(providerCaseReference)
.clientName(clientSurname)
.feeEarner(Optional.ofNullable(feeEarnerId).map(String::valueOf).orElse(""))
.notificationType(notificationType)
.user(
new UserDetail()
.username(assignedToUserId)
);
return ResponseEntity.ok(notificationService.getNotifications(pageable).get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
import lombok.RequiredArgsConstructor;
import org.hibernate.annotations.Immutable;

/**
* Represents a notification entity from the "XXCCMS_GET_NOTIFICATIONS_V" database view.
*
* <p>This entity captures details about notifications, such as the user it is assigned to,
* associated case references, client information, deadlines, and related metadata.
* It provides essential fields to track the status, associated parties,
* supporting documents, and notes.</p>
*
* <p>The class is immutable, and its instances can be created using the builder pattern.</p>
*
* @author Jamie Briggs
*/
@Entity
@Table(name = "XXCCMS_GET_NOTIFICATIONS_V")
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public interface NotificationsMapper {
* Maps a Page of Notification objects to a Notifications object.
*
* @param notificationPage a Page containing Notification entities to be mapped
* @return a Notifications object containing the mapped notifications along with pagination details
* @return a Notifications object containing the mapped notifications along
* with pagination details
*/
Notifications mapToNotificationsList(Page<Notification> notificationPage);

Expand All @@ -51,9 +52,12 @@ public interface NotificationsMapper {
* @return the mapped uk.gov.laa.ccms.data.model.Notification object
*/
@Mapping(target = "notes", source = "notes", qualifiedByName = "formatNotes")
@Mapping(target = "uploadedDocuments", source = "uploadedDocuments", qualifiedByName = "formatUploadedDocuments")
@Mapping(target = "attachedDocuments", source = "attachedDocuments", qualifiedByName = "formatAttachedDocuments")
@Mapping(target = "availableResponses", source = "availableResponses", qualifiedByName = "formatResponses")
@Mapping(target = "uploadedDocuments", source = "uploadedDocuments",
qualifiedByName = "formatUploadedDocuments")
@Mapping(target = "attachedDocuments", source = "attachedDocuments",
qualifiedByName = "formatAttachedDocuments")
@Mapping(target = "availableResponses", source = "availableResponses",
qualifiedByName = "formatResponses")
@Mapping(target = "user.loginId", source = "userLoginId")
@Mapping(target = "user.username", source = "assignedTo")
@Mapping(target = "subject", source = "notificationSubject")
Expand All @@ -62,14 +66,15 @@ public interface NotificationsMapper {
@Mapping(target = "notificationType", source = "actionNotificationInd")
@Mapping(target = "notificationOpenIndicator", source = "isOpen")
@Mapping(target = "evidenceAllowed", source = "evidenceAllowedInd")
@Mapping(target = "caseReferenceNumber", source = "lscCaseRefReference")
uk.gov.laa.ccms.data.model.Notification mapToNotification(Notification notification);

/**
* Maps a String containing XML representation of notes to a List of Note objects.
*
* @param notesString the XML String representing the notes
* @return a List of Note objects derived from the XML String or
* an empty list if the input is null or empty
* an empty list if the input is null or empty
* @throws JsonProcessingException if an error occurs during the processing of the XML String
*/
@Named("formatNotes")
Expand All @@ -78,10 +83,12 @@ static List<Note> mapToNoteList(String notesString) throws JsonProcessingExcepti
if (notesString == null || notesString.isEmpty()) {
return Collections.emptyList();
}
List<NoteXml> noteXmls = xmlMapper.readValue(notesString, NotesXml.class).noteXmls();
List<NoteXml> noteXmls = xmlMapper.readValue(notesString, NotesXml.class).notes();

// Return empty list if noteXmls is null
if(noteXmls == null) return Collections.emptyList();
// Return empty list if notes is null
if (noteXmls == null) {
return Collections.emptyList();
}

return noteXmls.stream().map(
x -> new Note().notesId(x.noteId()).user(new UserDetail().username(x.noteBy()))
Expand All @@ -90,39 +97,48 @@ static List<Note> mapToNoteList(String notesString) throws JsonProcessingExcepti

/**
* Maps a String containing the XML representation of uploaded documents to
* a List of {@link Document} objects.
* a List of {@link Document} objects.
*
* @param uploadedDocuments the XML String representing the uploaded documents
* @return a List of Document objects derived from the XML String or an empty list if the input is null or empty
* @return a List of Document objects derived from the XML String or an
* empty list if the input is null or empty
* @throws JsonProcessingException if an error occurs during the processing of the XML String
*/
@Named("formatUploadedDocuments")
static List<Document> mapToFormattedDocuments(String uploadedDocuments) throws JsonProcessingException {
static List<Document> mapToFormattedDocuments(String uploadedDocuments)
throws JsonProcessingException {
XmlMapper xmlMapper = getXmlMapper();
if (uploadedDocuments == null || uploadedDocuments.isEmpty()) {
return Collections.emptyList();
}
List<UploadedDocumentXml> uploadedDocumentsXmls = xmlMapper.readValue(uploadedDocuments,
UploadedDocumentsXml.class).uploadedDocument();
UploadedDocumentsXml.class).uploadedDocuments();

// Return empty list if uploadedDocumentsXmls is null
if(uploadedDocumentsXmls == null) return Collections.emptyList();
if (uploadedDocumentsXmls == null) {
return Collections.emptyList();
}

return uploadedDocumentsXmls.stream().map(
x -> new Document().documentId(x.documentId()).documentType(x.documentType())
.channel(x.documentChannel()).text(x.text())).toList();
x -> new Document().documentId(x.documentId())
.documentType(x.documentType())
.channel(x.documentChannel())
.text(x.text()))
.toList();
}

/**
* Maps a String containing the XML representation of attached documents to a
* List of {@link Document} objects.
* List of {@link Document} objects.
*
* @param attachedDocuments the XML String representing the attached documents
* @return a List of Document objects derived from the XML String or an empty list if the input is null or empty
* @return a List of Document objects derived from the XML String or an empty
* list if the input is null or empty
* @throws JsonProcessingException if an error occurs during the processing of the XML String
*/
@Named("formatAttachedDocuments")
static List<Document> mapToAttachedDocuments(String attachedDocuments) throws JsonProcessingException {
static List<Document> mapToAttachedDocuments(String attachedDocuments)
throws JsonProcessingException {
XmlMapper xmlMapper = getXmlMapper();
if (attachedDocuments == null || attachedDocuments.isEmpty()) {
return Collections.emptyList();
Expand All @@ -131,19 +147,27 @@ static List<Document> mapToAttachedDocuments(String attachedDocuments) throws Js
AttachedDocumentsXml.class).attachedDocuments();

// Return empty list if uploadedDocumentsXmls is null
if(attachedDocumentXmls == null) return Collections.emptyList();
if (attachedDocumentXmls == null) {
return Collections.emptyList();
}

return attachedDocumentXmls.stream().map(
x -> new Document().documentId(x.documentId()).title(x.attachmentTitle()).text(x.text())).toList();
x -> new Document()
.documentId(x.documentId())
.title(x.attachmentTitle())
.text(x.text()))
.toList();
}

/**
* Maps a String containing XML representation of available responses
* to a {@link List} of String objects.
* to a {@link List} of String objects.
*
* @param availableResponses the XML String representing the available responses
* @return a List of String objects derived from the XML String or an empty list if the input is null or empty
* @throws JsonProcessingException if an error occurs during the processing of the XML String
* @return a List of String objects derived from the XML String or an empty
* list if the input is null or empty
* @throws JsonProcessingException if an error occurs during the processing
* of the XML String
*/
@Named("formatResponses")
static List<String> mapToAvailableResponses(String availableResponses)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

/**
* Represents a single attached document in XML format.
*
* <p>This record is primarily utilized for mapping XML data to Java objects
* using the Jackson data format library for XML deserialization/serialization.</p>
*
* @param documentId A unique identifier for the document.
* @param attachmentTitle The title of the attached document.
* @param text Text describing the document.
* @see AttachedDocumentsXml
* @author Jamie Briggs
*/
public record AttachedDocumentXml(
@JacksonXmlProperty(localName = "document_id") String documentId,
@JacksonXmlProperty(localName = "ATTACHMENT_TITLE") String attachmentTitle,
@JacksonXmlProperty(localName = "Text") String text
) {
@JacksonXmlProperty(localName = "Text") String text) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.util.List;

/**
* Represents a collection of attached documents in XML format.
* Each document is represented as an instance of the AttachedDocumentXml record.
*
* <p>The XML structure for this record is defined such that the "Documents" element contains
* a list of attached documents without an additional wrapper element.</p>
*
* <p>This class is primarily used for mapping XML data to Java objects
* using the Jackson data format library.</p>
*
* <p>An attached document typically includes properties such as:</p>
* <ul>
* <li>Document ID: A unique identifier for the document.</li>
* <li>Attachment title: The title of the attached document.</li>
* <li>Text: Text describing the document</li>
* </ul>
*
* @param attachedDocuments A list of metadata for documents which were attached
* @see AttachedDocumentXml
* @author Jamie Briggs
*/
public record AttachedDocumentsXml(@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "Documents")
List<AttachedDocumentXml> attachedDocuments) {
@JacksonXmlProperty(localName = "Documents")
List<AttachedDocumentXml> attachedDocuments) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.util.List;

/**
* Represents a collection of available responses in XML format.
*
* <p>This record maps to an XML structure where the "Response" elements are provided as a list
* without any additional wrapping element. Each entry in the list corresponds to an individual
* response.</p>
*
* <p>It is primarily used for mapping XML data to Java objects
* using the Jackson data format library.</p>
*
* @param responses A list of responses available
* @author Jamie Briggs
*/
public record AvailableResponsesXml(@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "Response")
List<String> responses) {
@JacksonXmlProperty(localName = "Response")
List<String> responses) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.LocalDate;

/**
* Represents a single note in XML format.
*
* <p>This record is used for mapping between XML data and Java objects when handling notes, using
* the Jackson XML data format library. The properties of this record correspond to fields
* in the XML representation.</p>
*
* @param noteId A unique identifier for the note.
* @param noteBy The author of the note.
* @param date The date the note was created.
* @param message The contents of the note.
* @see NotesXml
* @author Jamie Briggs
*/
public record NoteXml(@JacksonXmlProperty(localName = "note_id") String noteId,
@JacksonXmlProperty(localName = "note_by") String noteBy,
@JacksonXmlProperty(localName = "date")
LocalDate date,
@JacksonXmlProperty(localName = "Message") String message) {
@JacksonXmlProperty(localName = "note_by") String noteBy,
@JacksonXmlProperty(localName = "date")
LocalDate date,
@JacksonXmlProperty(localName = "Message") String message) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.util.List;

/**
* Represents a collection of notes in XML format.
*
* <p>The XML structure for this record is defined such that the "notes" element contains
* a list of attached notes without an additional wrapper element.</p>
*
* <p>This class is primarily used for mapping XML data to Java objects
* using the Jackson data format library.</p>
*
* <p>A note typically includes properties such as:</p>
* <ul>
* <li>Note ID: A unique identifier for the note.</li>
* <li>Note By: The author of the note.</li>
* <li>Date: The date the note was created.</li>
* <li>Message: The contents of the note</li>
* </ul>
*
* @see NoteXml
* @param notes A list of notes.
* @author Jamie Briggs
*/
public record NotesXml(
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "Note")
List<NoteXml> noteXmls) {
List<NoteXml> notes) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

/**
* Represents a single uploaded document in XML format.
*
* <p>This record is used for mapping XML data to Java objects when handling uploaded documents.
* Each field in this record corresponds to a specific element or attribute in the XML data.</p>
*
* <p>This record is typically part of a collection represented
* by {@link UploadedDocumentsXml}, which aggregates multiple uploaded documents.</p>
*
* @param documentId A unique identifier for the document.
* @param documentType The type or category of the document.
* @param documentChannel The source in which the document was uplaoded from.
* @param text Text describing the document.
* @see UploadedDocumentsXml
*/
public record UploadedDocumentXml(
@JacksonXmlProperty(localName = "document_id") String documentId,
@JacksonXmlProperty(localName = "document_type") String documentType,
@JacksonXmlProperty(localName = "document_channel") String documentChannel,
@JacksonXmlProperty(localName = "Text") String text
) {
@JacksonXmlProperty(localName = "Text") String text) {

}
Loading

0 comments on commit 71bc49a

Please sign in to comment.