Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUB-2279 - Fixed code smells #401

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";

Expand All @@ -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.
*
Expand Down Expand Up @@ -189,8 +194,7 @@ public ResponseEntity<String> 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<String> sendMediaUserRejectionEmail(@RequestBody MediaRejectionEmail body)
throws IOException {
public ResponseEntity<String> sendMediaUserRejectionEmail(@RequestBody MediaRejectionEmail body) {
return ResponseEntity.ok(String.format(
"Media user rejection email successfully sent with referenceId: %s",
userNotificationService.mediaUserRejectionEmailRequest(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
@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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -352,7 +360,7 @@ public Map<String, Object> buildMediaVerificationPersonalisation(MediaVerificati
* @param body The body of the media account rejection email.
* @return The personalisation map for the media rejection email.
*/
public Map<String, Object> buildMediaRejectionPersonalisation(MediaRejectionEmail body) throws IOException {
public Map<String, Object> buildMediaRejectionPersonalisation(MediaRejectionEmail body) {
Map<String, Object> personalisation = new ConcurrentHashMap<>();

personalisation.put(FULL_NAME_LOWERCASE, body.getFullName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down