FINERACT-2326: Refractor redundant and some deprecated code as per new Java 21 style

This commit is contained in:
Aman-Mittal
2025-12-08 13:49:44 +01:00
committed by Adam Saghy
parent 399789ba42
commit dce3c66def
29 changed files with 117 additions and 232 deletions
@@ -68,8 +68,7 @@ public enum EntityAccountType {
}
public static EntityAccountType fromInt(final int i) {
final EntityAccountType type = intToEnumMap.get(Integer.valueOf(i));
return type;
return intToEnumMap.get(i);
}
public static int getMinValue() {
@@ -82,7 +81,7 @@ public enum EntityAccountType {
@Override
public String toString() {
return name().toString();
return name();
}
public boolean isClientAccount() {
@@ -94,9 +94,7 @@ public final class EmailConfigurationValidator {
public boolean isValidEmail(String email) {
// this is the easiest check
if (email == null) {
return false;
} else if (email.endsWith(".")) {
if (email == null || email.endsWith(".")) {
return false;
}
@@ -104,10 +102,6 @@ public final class EmailConfigurationValidator {
Matcher emailMatcher = EMAIL_PATTERN.matcher(email);
// check if the Matcher matches the email pattern
if (!emailMatcher.matches()) {
return false;
}
return true;
return emailMatcher.matches();
}
}
@@ -262,11 +262,7 @@ public final class EmailDataValidator {
Matcher emailMatcher = EMAIL_PATTERN.matcher(email);
// check if the Matcher matches the email pattern
if (!emailMatcher.matches()) {
return false;
}
return true;
return emailMatcher.matches();
}
/**
@@ -36,17 +36,12 @@ public enum EmailCampaignStatus {
public static EmailCampaignStatus fromInt(final Integer statusValue) {
EmailCampaignStatus enumeration = EmailCampaignStatus.INVALID;
switch (statusValue) {
case 100:
enumeration = EmailCampaignStatus.PENDING;
break;
case 300:
enumeration = EmailCampaignStatus.ACTIVE;
break;
case 600:
enumeration = EmailCampaignStatus.CLOSED;
break;
}
enumeration = switch (statusValue) {
case 100 -> EmailCampaignStatus.PENDING;
case 300 -> EmailCampaignStatus.ACTIVE;
case 600 -> EmailCampaignStatus.CLOSED;
default -> enumeration;
};
return enumeration;
}
@@ -41,19 +41,12 @@ public enum EmailCampaignType {
}
public static EmailCampaignType fromInt(final Integer typeValue) {
EmailCampaignType type = null;
switch (typeValue) {
case 1:
type = DIRECT;
break;
case 2:
type = SCHEDULE;
break;
case 3:
type = TRIGGERED;
break;
}
return type;
return switch (typeValue) {
case 1 -> DIRECT;
case 2 -> SCHEDULE;
case 3 -> TRIGGERED;
default -> null;
};
}
public boolean isDirect() {
@@ -32,20 +32,13 @@ public enum EmailMessageStatusType {
public static EmailMessageStatusType fromInt(final Integer statusValue) {
EmailMessageStatusType enumeration = EmailMessageStatusType.INVALID;
switch (statusValue) {
case 100:
enumeration = EmailMessageStatusType.PENDING;
break;
case 200:
enumeration = EmailMessageStatusType.SENT;
break;
case 300:
enumeration = EmailMessageStatusType.DELIVERED;
break;
case 400:
enumeration = EmailMessageStatusType.FAILED;
break;
}
enumeration = switch (statusValue) {
case 100 -> EmailMessageStatusType.PENDING;
case 200 -> EmailMessageStatusType.SENT;
case 300 -> EmailMessageStatusType.DELIVERED;
case 400 -> EmailMessageStatusType.FAILED;
default -> enumeration;
};
return enumeration;
}
@@ -117,8 +117,6 @@ public class EmailCampaignDomainServiceImpl implements EmailCampaignDomainServic
}
private List<EmailCampaign> retrieveEmailCampaigns(String paramValue) {
List<EmailCampaign> emailCampaigns = emailCampaignRepository.findActiveEmailCampaigns("%" + paramValue + "%",
SmsCampaignTriggerType.TRIGGERED.getValue());
return emailCampaigns;
return emailCampaignRepository.findActiveEmailCampaigns("%" + paramValue + "%", SmsCampaignTriggerType.TRIGGERED.getValue());
}
}
@@ -62,7 +62,7 @@ public final class EmailMessageJobEmailServiceImpl implements EmailMessageJobEma
mimeMessageHelper.setText(emailMessageWithAttachmentData.getText(), true);
mimeMessageHelper.setSubject(emailMessageWithAttachmentData.getSubject());
final List<File> attachments = emailMessageWithAttachmentData.getAttachments();
if (attachments != null && attachments.size() > 0) {
if (attachments != null && !attachments.isEmpty()) {
for (final File attachment : attachments) {
if (attachment != null) {
mimeMessageHelper.addAttachment(attachment.getName(), attachment);
@@ -36,7 +36,7 @@ public class DeleteDatatableCommandHandler implements NewCommandSourceHandler {
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
final String datatableName = command.getUrl().replaceAll("/datatables/", "");
final String datatableName = command.getUrl().replace("/datatables/", "");
datatableWriteService.deleteDatatable(datatableName);
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withResourceIdAsString(datatableName).build();
}
@@ -121,10 +121,10 @@ public class EntityDatatableChecksReadPlatformServiceImpl implements EntityDatat
tableRequiredBeforeAction = this.entityDatatableChecksRepository.findByEntityStatusAndProduct(entity, status, productId);
}
if (tableRequiredBeforeAction == null || tableRequiredBeforeAction.size() < 1) {
if (tableRequiredBeforeAction == null || tableRequiredBeforeAction.isEmpty()) {
tableRequiredBeforeAction = this.entityDatatableChecksRepository.findByEntityStatusAndNoProduct(entity, status);
}
if (tableRequiredBeforeAction != null && tableRequiredBeforeAction.size() > 0) {
if (tableRequiredBeforeAction != null && !tableRequiredBeforeAction.isEmpty()) {
List<DatatableData> ret = new ArrayList<>();
for (EntityDatatableChecks t : tableRequiredBeforeAction) {
ret.add(this.datatableReadService.retrieveDatatable(t.getDatatableName()));
@@ -37,34 +37,28 @@ public class DropdownReadPlatformServiceImpl implements DropdownReadPlatformServ
@Override
public List<EnumOptionData> retrievePeriodFrequencyTypeOptions() {
final List<EnumOptionData> loanTermFrequencyOptions = Arrays.asList(termFrequencyType(PeriodFrequencyType.DAYS, "frequency"),
return Arrays.asList(termFrequencyType(PeriodFrequencyType.DAYS, "frequency"),
termFrequencyType(PeriodFrequencyType.WEEKS, "frequency"), termFrequencyType(PeriodFrequencyType.MONTHS, "frequency"),
termFrequencyType(PeriodFrequencyType.YEARS, "frequency"), termFrequencyType(PeriodFrequencyType.WHOLE_TERM, "frequency"));
return loanTermFrequencyOptions;
}
@Override
public List<EnumOptionData> retrieveConditionTypeOptions() {
final List<EnumOptionData> loanTermFrequencyOptions = Arrays.asList(conditionType(ConditionType.EQUAL, "condition"),
conditionType(ConditionType.NOT_EQUAL, "condition"), conditionType(ConditionType.GRETERTHAN, "condition"),
conditionType(ConditionType.LESSTHAN, "condition"));
return loanTermFrequencyOptions;
return Arrays.asList(conditionType(ConditionType.EQUAL, "condition"), conditionType(ConditionType.NOT_EQUAL, "condition"),
conditionType(ConditionType.GRETERTHAN, "condition"), conditionType(ConditionType.LESSTHAN, "condition"));
}
@Override
public List<EnumOptionData> retrieveDaysInMonthTypeOptions() {
final List<EnumOptionData> daysInMonthTypeOptions = Arrays.asList(daysInMonthType(DaysInMonthType.ACTUAL),
daysInMonthType(DaysInMonthType.DAYS_30));
return daysInMonthTypeOptions;
return Arrays.asList(daysInMonthType(DaysInMonthType.ACTUAL), daysInMonthType(DaysInMonthType.DAYS_30));
}
@Override
public List<EnumOptionData> retrieveDaysInYearTypeOptions() {
final List<EnumOptionData> daysInYearTypeOptions = Arrays.asList(daysInYearType(DaysInYearType.ACTUAL),
daysInYearType(DaysInYearType.DAYS_360), daysInYearType(DaysInYearType.DAYS_364), daysInYearType(DaysInYearType.DAYS_365));
return daysInYearTypeOptions;
return Arrays.asList(daysInYearType(DaysInYearType.ACTUAL), daysInYearType(DaysInYearType.DAYS_360),
daysInYearType(DaysInYearType.DAYS_364), daysInYearType(DaysInYearType.DAYS_365));
}
}
@@ -440,9 +440,7 @@ public class DepositAccountAssembler {
final DepositRecurringDetail depositRecurringDetail = DepositRecurringDetail.createFrom(isMandatoryDeposit, allowWithdrawal,
adjustAdvanceTowardsFuturePayments);
final DepositAccountRecurringDetail depositAccountRecurringDetail = DepositAccountRecurringDetail.createNew(recurringDepositAmount,
depositRecurringDetail, null, isCalendarInherited);
return depositAccountRecurringDetail;
return DepositAccountRecurringDetail.createNew(recurringDepositAmount, depositRecurringDetail, null, isCalendarInherited);
}
public Collection<SavingsAccountTransactionDTO> assembleBulkMandatorySavingsAccountTransactionDTOs(final JsonCommand command,
@@ -747,16 +747,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
private void checkClientOrGroupActive(final SavingsAccount account) {
final Client client = account.getClient();
if (client != null) {
if (client.isNotActive()) {
throw new ClientNotActiveException(client.getId());
}
if (client != null && client.isNotActive()) {
throw new ClientNotActiveException(client.getId());
}
final Group group = account.group();
if (group != null) {
if (group.isNotActive()) {
throw new GroupNotActiveException(group.getId());
}
if (group != null && group.isNotActive()) {
throw new GroupNotActiveException(group.getId());
}
}
@@ -729,19 +729,17 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
private void checkClientOrGroupActive(final SavingsAccount account) {
final Client client = account.getClient();
if (client != null) {
if (client.isNotActive()) {
throw new ClientNotActiveException(client.getId());
}
if (client != null && client.isNotActive()) {
throw new ClientNotActiveException(client.getId());
}
final Group group = account.group();
if (group != null) {
if (group.isNotActive()) {
if (group.isCenter()) {
throw new CenterNotActiveException(group.getId());
}
throw new GroupNotActiveException(group.getId());
if (group != null && group.isNotActive()) {
if (group.isCenter()) {
throw new CenterNotActiveException(group.getId());
}
throw new GroupNotActiveException(group.getId());
}
}
}
@@ -67,8 +67,7 @@ public class DeviceRegistrationApiResource {
Long clientId = json.get(DeviceRegistrationApiConstants.clientIdParamName).getAsLong();
String registrationId = json.get(DeviceRegistrationApiConstants.registrationIdParamName).getAsString();
DeviceRegistration deviceRegistration = this.deviceRegistrationWritePlatformService.registerDevice(clientId, registrationId);
String response = gson.toJson(deviceRegistration.getId());
return response;
return gson.toJson(deviceRegistration.getId());
}
@GET
@@ -125,8 +124,7 @@ public class DeviceRegistrationApiResource {
String registrationId = json.get(DeviceRegistrationApiConstants.registrationIdParamName).getAsString();
DeviceRegistration deviceRegistration = this.deviceRegistrationWritePlatformService.updateDeviceRegistration(id, clientId,
registrationId);
String response = gson.toJson(deviceRegistration.getId());
return response;
return gson.toJson(deviceRegistration.getId());
}
@DELETE