From 70a3c801ce68c8c4ec0b5563a46757f38a61d99f Mon Sep 17 00:00:00 2001 From: ChrisS1512 <87066931+ChrisS1512@users.noreply.github.com> Date: Fri, 22 Dec 2023 16:34:14 +0000 Subject: [PATCH 1/2] PUB-2279 - Fixed code smells --- .../B2cNotificationController.java | 6 +++- .../controllers/NotificationController.java | 22 ++++++++------ .../service/AccountManagementService.java | 6 +++- .../service/ChannelManagementService.java | 6 +++- .../service/DataManagementService.java | 6 +++- .../services/service/EmailService.java | 4 +-- .../services/service/FileCreationService.java | 23 +++++++++----- .../services/service/NotificationService.java | 14 +++++---- .../service/PersonalisationService.java | 30 ++++++++++++------- .../SubscriptionManagementService.java | 6 +++- .../service/ThirdPartyManagementService.java | 14 +++++---- .../services/service/ThirdPartyService.java | 6 +++- .../service/UserNotificationService.java | 10 ++++--- 13 files changed, 102 insertions(+), 51 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/B2cNotificationController.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/B2cNotificationController.java index e7d5d4cab..845b76d4d 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/B2cNotificationController.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/B2cNotificationController.java @@ -19,8 +19,12 @@ @RequestMapping("/notify") @IsB2C public class B2cNotificationController { + private final UserNotificationService userNotificationService; + @Autowired - private UserNotificationService userNotificationService; + public B2cNotificationController(UserNotificationService userNotificationService) { + this.userNotificationService = userNotificationService; + } @ApiResponse(responseCode = "200", description = "OTP email successfully sent with referenceId: {Id}") @ApiResponse(responseCode = "400", description = "NotifyException error message") diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/NotificationController.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/NotificationController.java index cbb65c9c5..49275cc11 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/NotificationController.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/controllers/NotificationController.java @@ -29,7 +29,6 @@ import uk.gov.hmcts.reform.pip.publication.services.service.ThirdPartyManagementService; import uk.gov.hmcts.reform.pip.publication.services.service.UserNotificationService; -import java.io.IOException; import java.util.List; @RestController @@ -39,14 +38,11 @@ @SuppressWarnings("PMD.TooManyMethods") public class NotificationController { - @Autowired - private NotificationService notificationService; + private final NotificationService notificationService; - @Autowired - private ThirdPartyManagementService thirdPartyManagementService; + private final ThirdPartyManagementService thirdPartyManagementService; - @Autowired - private UserNotificationService userNotificationService; + private final UserNotificationService userNotificationService; private static final String BAD_PAYLOAD_EXCEPTION_MESSAGE = "BadPayloadException error message"; @@ -58,6 +54,15 @@ public class NotificationController { private static final String AUTH_RESPONSE = "403"; private static final String BAD_REQUEST = "400"; + @Autowired + public NotificationController(NotificationService notificationService, + ThirdPartyManagementService thirdPartyManagementService, + UserNotificationService userNotificationService) { + this.notificationService = notificationService; + this.thirdPartyManagementService = thirdPartyManagementService; + this.userNotificationService = userNotificationService; + } + /** * api to send welcome emails to new or existing users. * @@ -189,8 +194,7 @@ public ResponseEntity sendMediaUserVerificationEmail(@RequestBody MediaV @ApiResponse(responseCode = AUTH_RESPONSE, description = NOT_AUTHORIZED_MESSAGE) @Operation(summary = "Send a media applicant a rejection email") @PostMapping("/media/reject") - public ResponseEntity sendMediaUserRejectionEmail(@RequestBody MediaRejectionEmail body) - throws IOException { + public ResponseEntity sendMediaUserRejectionEmail(@RequestBody MediaRejectionEmail body) { return ResponseEntity.ok(String.format( "Media user rejection email successfully sent with referenceId: %s", userNotificationService.mediaUserRejectionEmailRequest(body) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/AccountManagementService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/AccountManagementService.java index d0a43f6d1..b4111abca 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/AccountManagementService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/AccountManagementService.java @@ -19,8 +19,12 @@ public class AccountManagementService { @Value("${service-to-service.account-management}") private String url; + private final WebClient webClient; + @Autowired - private WebClient webClient; + public AccountManagementService(WebClient webClient) { + this.webClient = webClient; + } public String getMiData() { try { diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ChannelManagementService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ChannelManagementService.java index cbbce1faf..6b8404acc 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ChannelManagementService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ChannelManagementService.java @@ -31,8 +31,12 @@ public class ChannelManagementService { @Value("${service-to-service.channel-management}") private String url; + private final WebClient webClient; + @Autowired - private WebClient webClient; + public ChannelManagementService(WebClient webClient) { + this.webClient = webClient; + } /** * Makes a get request to channel management for the artefact summary by artefactId. diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/DataManagementService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/DataManagementService.java index 1c25e0fe7..43fff0e27 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/DataManagementService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/DataManagementService.java @@ -25,8 +25,12 @@ public class DataManagementService { @Value("${service-to-service.data-management}") private String url; + private final WebClient webClient; + @Autowired - private WebClient webClient; + public DataManagementService(WebClient webClient) { + this.webClient = webClient; + } public Artefact getArtefact(UUID artefactId) { try { diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/EmailService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/EmailService.java index f477219ee..2e359a6cf 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/EmailService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/EmailService.java @@ -22,7 +22,6 @@ import uk.gov.service.notify.NotificationClientException; import uk.gov.service.notify.SendEmailResponse; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -101,8 +100,7 @@ protected EmailToSend buildMediaUserVerificationEmail(MediaVerificationEmail bod personalisationService.buildMediaVerificationPersonalisation(body)); } - protected EmailToSend buildMediaApplicationRejectionEmail(MediaRejectionEmail body, Templates emailTemplate) - throws IOException { + protected EmailToSend buildMediaApplicationRejectionEmail(MediaRejectionEmail body, Templates emailTemplate) { rateLimitingService.validate(body.getEmail(), emailTemplate); return generateEmail(body.getEmail(), emailTemplate.getTemplate(), personalisationService.buildMediaRejectionPersonalisation(body)); diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/FileCreationService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/FileCreationService.java index ebfbf7b15..0a3c69a5a 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/FileCreationService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/FileCreationService.java @@ -25,21 +25,28 @@ @SuppressWarnings("PMD.PreserveStackTrace") public class FileCreationService { - @Autowired - private DataManagementService dataManagementService; + private final DataManagementService dataManagementService; - @Autowired - private AccountManagementService accountManagementService; + private final AccountManagementService accountManagementService; - @Autowired - private SubscriptionManagementService subscriptionManagementService; + private final SubscriptionManagementService subscriptionManagementService; - @Autowired - private ExcelGenerationService excelGenerationService; + private final ExcelGenerationService excelGenerationService; private static final String[] HEADINGS = {"Full name", "Email", "Employer", "Request date", "Status", "Status date"}; + @Autowired + public FileCreationService(DataManagementService dataManagementService, + AccountManagementService accountManagementService, + SubscriptionManagementService subscriptionManagementService, + ExcelGenerationService excelGenerationService) { + this.dataManagementService = dataManagementService; + this.accountManagementService = accountManagementService; + this.subscriptionManagementService = subscriptionManagementService; + this.excelGenerationService = excelGenerationService; + } + /** * Creates a byte array csv from a list of media applications. * diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java index aa2af981b..b5e25dee0 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java @@ -21,14 +21,18 @@ @Service @Slf4j public class NotificationService { - @Autowired - private EmailService emailService; + private final EmailService emailService; - @Autowired - private FileCreationService fileCreationService; + private final FileCreationService fileCreationService; + + private final DataManagementService dataManagementService; @Autowired - private DataManagementService dataManagementService; + public NotificationService(EmailService emailService, FileCreationService fileCreationService, DataManagementService dataManagementService) { + this.emailService = emailService; + this.fileCreationService = fileCreationService; + this.dataManagementService = dataManagementService; + } /** * Handles the incoming request for media applications reporting emails. diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/PersonalisationService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/PersonalisationService.java index 246cb20ba..24c91d1eb 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/PersonalisationService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/PersonalisationService.java @@ -52,20 +52,15 @@ public class PersonalisationService { private static final int MAX_FILE_SIZE = 2_000_000; private static final String LINK_TO_SERVICE = "link-to-service"; - @Autowired - DataManagementService dataManagementService; + private final DataManagementService dataManagementService; - @Autowired - NotifyConfigProperties notifyConfigProperties; + private final NotifyConfigProperties notifyConfigProperties; - @Autowired - ChannelManagementService channelManagementService; + private final ChannelManagementService channelManagementService; - @Autowired - FileCreationService fileCreationService; + private final FileCreationService fileCreationService; - @Autowired - CaseNameHelper caseNameHelper; + private final CaseNameHelper caseNameHelper; @Value("${env-name}") private String envName; @@ -104,6 +99,19 @@ public class PersonalisationService { private static final String ADDITIONAL_DETAILS = "Additional_change_detail"; private static final String LOCATION_NAME = "location-name"; + @Autowired + public PersonalisationService(DataManagementService dataManagementService, + NotifyConfigProperties notifyConfigProperties, + ChannelManagementService channelManagementService, + FileCreationService fileCreationService, + CaseNameHelper caseNameHelper) { + this.dataManagementService = dataManagementService; + this.notifyConfigProperties = notifyConfigProperties; + this.channelManagementService = channelManagementService; + this.fileCreationService = fileCreationService; + this.caseNameHelper = caseNameHelper; + } + /** * Handles the personalisation for the Welcome email. @@ -352,7 +360,7 @@ public Map buildMediaVerificationPersonalisation(MediaVerificati * @param body The body of the media account rejection email. * @return The personalisation map for the media rejection email. */ - public Map buildMediaRejectionPersonalisation(MediaRejectionEmail body) throws IOException { + public Map buildMediaRejectionPersonalisation(MediaRejectionEmail body) { Map personalisation = new ConcurrentHashMap<>(); personalisation.put(FULL_NAME_LOWERCASE, body.getFullName()); diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/SubscriptionManagementService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/SubscriptionManagementService.java index 98f4224ef..92b117ca0 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/SubscriptionManagementService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/SubscriptionManagementService.java @@ -19,8 +19,12 @@ public class SubscriptionManagementService { @Value("${service-to-service.subscription-management}") private String url; + private final WebClient webClient; + @Autowired - private WebClient webClient; + public SubscriptionManagementService(WebClient webClient) { + this.webClient = webClient; + } public String getAllMiData() { try { diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java index dfb6e3053..afc767b5d 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java @@ -19,14 +19,18 @@ public class ThirdPartyManagementService { private static final String SUCCESS_MESSAGE = "Successfully sent list to %s"; private static final String EMPTY_SUCCESS_MESSAGE = "Successfully sent empty list to %s"; - @Autowired - private DataManagementService dataManagementService; + private final DataManagementService dataManagementService; - @Autowired - private ChannelManagementService channelManagementService; + private final ChannelManagementService channelManagementService; + + private final ThirdPartyService thirdPartyService; @Autowired - private ThirdPartyService thirdPartyService; + public ThirdPartyManagementService(DataManagementService dataManagementService, ChannelManagementService channelManagementService, ThirdPartyService thirdPartyService) { + this.dataManagementService = dataManagementService; + this.channelManagementService = channelManagementService; + this.thirdPartyService = thirdPartyService; + } /** * Handles the incoming request for sending lists out to third party publishers, uses the artefact id from body diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyService.java index 3996c5838..a0338dac5 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyService.java @@ -40,8 +40,12 @@ public class ThirdPartyService { private static final String COURTEL = "Courtel"; private static final String CATH_PROVENANCE = "CATH"; + private final WebClient.Builder webClient; + @Autowired - private WebClient.Builder webClient; + public ThirdPartyService(WebClient.Builder webClient) { + this.webClient = webClient; + } /** * Third party call for Flat File publications. diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/UserNotificationService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/UserNotificationService.java index 12aab212f..a5a91d4b7 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/UserNotificationService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/UserNotificationService.java @@ -14,16 +14,18 @@ import uk.gov.hmcts.reform.pip.publication.services.models.request.WelcomeEmail; import uk.gov.hmcts.reform.pip.publication.services.notify.Templates; -import java.io.IOException; - import static uk.gov.hmcts.reform.pip.model.LogBuilder.writeLog; @Service @Slf4j public class UserNotificationService { + private final EmailService emailService; + @Autowired - private EmailService emailService; + public UserNotificationService(EmailService emailService) { + this.emailService = emailService; + } /** * Handles the incoming request for welcome emails, checks the json payload and builds and sends the email. @@ -89,7 +91,7 @@ public String mediaUserVerificationEmailRequest(MediaVerificationEmail body) { * @param body The body of the media rejection email. * @return The ID that references the media user rejection email. */ - public String mediaUserRejectionEmailRequest(MediaRejectionEmail body) throws IOException { + public String mediaUserRejectionEmailRequest(MediaRejectionEmail body) { EmailToSend email = emailService .buildMediaApplicationRejectionEmail(body, Templates.MEDIA_USER_REJECTION_EMAIL); From 5cb9f42792ae90ef4446e6ca23705c500bf58c19 Mon Sep 17 00:00:00 2001 From: ChrisS1512 <87066931+ChrisS1512@users.noreply.github.com> Date: Fri, 22 Dec 2023 16:37:45 +0000 Subject: [PATCH 2/2] PUB-2279 - Fixed checkstyles --- .../pip/publication/services/service/NotificationService.java | 3 ++- .../services/service/ThirdPartyManagementService.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java index b5e25dee0..6c095be69 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/NotificationService.java @@ -28,7 +28,8 @@ public class NotificationService { private final DataManagementService dataManagementService; @Autowired - public NotificationService(EmailService emailService, FileCreationService fileCreationService, DataManagementService dataManagementService) { + public NotificationService(EmailService emailService, FileCreationService fileCreationService, + DataManagementService dataManagementService) { this.emailService = emailService; this.fileCreationService = fileCreationService; this.dataManagementService = dataManagementService; diff --git a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java index afc767b5d..ad29945a8 100644 --- a/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java +++ b/src/main/java/uk/gov/hmcts/reform/pip/publication/services/service/ThirdPartyManagementService.java @@ -26,7 +26,9 @@ public class ThirdPartyManagementService { private final ThirdPartyService thirdPartyService; @Autowired - public ThirdPartyManagementService(DataManagementService dataManagementService, ChannelManagementService channelManagementService, ThirdPartyService thirdPartyService) { + public ThirdPartyManagementService(DataManagementService dataManagementService, + ChannelManagementService channelManagementService, + ThirdPartyService thirdPartyService) { this.dataManagementService = dataManagementService; this.channelManagementService = channelManagementService; this.thirdPartyService = thirdPartyService;