Skip to content

Commit c1f049c

Browse files
committed
FINERACT-2421: Refractor redundant and some deprecated code as per new Java 21 style (Phase 5)
1 parent 61d361f commit c1f049c

File tree

18 files changed

+127
-291
lines changed

18 files changed

+127
-291
lines changed

fineract-accounting/src/main/java/org/apache/fineract/accounting/financialactivityaccount/serialization/FinancialActivityAccountDataValidator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public void validateForCreate(final String json) {
7272
}
7373

7474
private DataValidatorBuilder getDataValidator(final List<ApiParameterError> dataValidationErrors) {
75-
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("financialactivityaccount");
76-
return baseDataValidator;
75+
return new DataValidatorBuilder(dataValidationErrors).resource("financialactivityaccount");
7776
}
7877

7978
public void validateForUpdate(final String json) {

fineract-charge/src/main/java/org/apache/fineract/portfolio/charge/domain/Charge.java

Lines changed: 36 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.Locale;
3434
import java.util.Map;
3535
import java.util.Objects;
36+
import lombok.Getter;
37+
import lombok.Setter;
3638
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
3739
import org.apache.fineract.accounting.glaccount.domain.GLAccount;
3840
import org.apache.fineract.infrastructure.core.api.JsonCommand;
@@ -66,34 +68,41 @@ public class Charge extends AbstractPersistableCustom<Long> {
6668
public static final String LOCALE_PARAM_NAME = "locale";
6769
public static final String FEE_FREQUENCY_PARAM_NAME = "feeFrequency";
6870

71+
@Getter
6972
@Column(name = "name", length = 100)
7073
private String name;
7174

75+
@Getter
7276
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
7377
private BigDecimal amount;
7478

79+
@Getter
7580
@Column(name = "currency_code", length = 3)
7681
private String currencyCode;
7782

7883
@Column(name = "charge_applies_to_enum", nullable = false)
7984
private Integer chargeAppliesTo;
8085

86+
@Getter
8187
@Column(name = "charge_time_enum", nullable = false)
8288
private Integer chargeTimeType;
8389

90+
@Getter
8491
@Column(name = "charge_calculation_enum")
8592
private Integer chargeCalculation;
8693

87-
@Column(name = "charge_payment_mode_enum", nullable = true)
94+
@Getter
95+
@Column(name = "charge_payment_mode_enum")
8896
private Integer chargePaymentMode;
8997

90-
@Column(name = "fee_on_day", nullable = true)
98+
@Column(name = "fee_on_day")
9199
private Integer feeOnDay;
92100

93-
@Column(name = "fee_interval", nullable = true)
101+
@Getter
102+
@Column(name = "fee_interval")
94103
private Integer feeInterval;
95104

96-
@Column(name = "fee_on_month", nullable = true)
105+
@Column(name = "fee_on_month")
97106
private Integer feeOnMonth;
98107

99108
@Column(name = "is_penalty", nullable = false)
@@ -105,10 +114,12 @@ public class Charge extends AbstractPersistableCustom<Long> {
105114
@Column(name = "is_deleted", nullable = false)
106115
private boolean deleted = false;
107116

108-
@Column(name = "min_cap", scale = 6, precision = 19, nullable = true)
117+
@Getter
118+
@Column(name = "min_cap", scale = 6, precision = 19)
109119
private BigDecimal minCap;
110120

111-
@Column(name = "max_cap", scale = 6, precision = 19, nullable = true)
121+
@Getter
122+
@Column(name = "max_cap", scale = 6, precision = 19)
112123
private BigDecimal maxCap;
113124

114125
@Column(name = "fee_frequency", nullable = true)
@@ -117,26 +128,35 @@ public class Charge extends AbstractPersistableCustom<Long> {
117128
@Column(name = "is_free_withdrawal", nullable = false)
118129
private boolean enableFreeWithdrawal;
119130

120-
@Column(name = "free_withdrawal_charge_frequency", nullable = true)
131+
@Column(name = "free_withdrawal_charge_frequency")
121132
private Integer freeWithdrawalFrequency;
122133

123-
@Column(name = "restart_frequency", nullable = true)
134+
@Getter
135+
@Column(name = "restart_frequency")
124136
private Integer restartFrequency;
125137

126-
@Column(name = "restart_frequency_enum", nullable = true)
138+
@Getter
139+
@Column(name = "restart_frequency_enum")
127140
private Integer restartFrequencyEnum;
128141

142+
@Getter
129143
@Column(name = "is_payment_type", nullable = false)
130144
private boolean enablePaymentType;
131145

146+
@Setter
147+
@Getter
132148
@ManyToOne
133149
@JoinColumn(name = "payment_type_id", nullable = false)
134150
private PaymentType paymentType;
135151

152+
@Getter
153+
@Setter
136154
@ManyToOne(fetch = FetchType.LAZY)
137155
@JoinColumn(name = "income_or_liability_account_id")
138156
private GLAccount account;
139157

158+
@Getter
159+
@Setter
140160
@ManyToOne
141161
@JoinColumn(name = "tax_group_id")
142162
private TaxGroup taxGroup;
@@ -245,12 +265,9 @@ private Charge(final String name, final BigDecimal amount, final String currency
245265
this.restartFrequencyEnum = restartFrequencyEnum.getValue();
246266
}
247267

248-
if (enablePaymentType) {
249-
if (paymentType != null) {
250-
251-
this.enablePaymentType = true;
252-
this.paymentType = paymentType;
253-
}
268+
if (enablePaymentType && paymentType != null) {
269+
this.enablePaymentType = true;
270+
this.paymentType = paymentType;
254271
}
255272

256273
} else if (isLoanCharge()) {
@@ -279,26 +296,6 @@ private Charge(final String name, final BigDecimal amount, final String currency
279296
}
280297
}
281298

282-
public String getName() {
283-
return this.name;
284-
}
285-
286-
public BigDecimal getAmount() {
287-
return this.amount;
288-
}
289-
290-
public String getCurrencyCode() {
291-
return this.currencyCode;
292-
}
293-
294-
public Integer getChargeTimeType() {
295-
return this.chargeTimeType;
296-
}
297-
298-
public Integer getChargeCalculation() {
299-
return this.chargeCalculation;
300-
}
301-
302299
public boolean isActive() {
303300
return this.active;
304301
}
@@ -351,14 +348,6 @@ public boolean isPercentageOfDisbursementAmount() {
351348
return ChargeCalculationType.fromInt(this.chargeCalculation).isPercentageOfDisbursementAmount();
352349
}
353350

354-
public BigDecimal getMinCap() {
355-
return this.minCap;
356-
}
357-
358-
public BigDecimal getMaxCap() {
359-
return this.maxCap;
360-
}
361-
362351
public boolean isEnableFreeWithdrawal() {
363352
return this.enableFreeWithdrawal;
364353
}
@@ -371,22 +360,6 @@ public Integer getFrequencyFreeWithdrawalCharge() {
371360
return this.freeWithdrawalFrequency;
372361
}
373362

374-
public Integer getRestartFrequency() {
375-
return this.restartFrequency;
376-
}
377-
378-
public Integer getRestartFrequencyEnum() {
379-
return this.restartFrequencyEnum;
380-
}
381-
382-
public PaymentType getPaymentType() {
383-
return this.paymentType;
384-
}
385-
386-
public void setPaymentType(PaymentType paymentType) {
387-
this.paymentType = paymentType;
388-
}
389-
390363
private Long getPaymentTypeId() {
391364
Long paymentTypeId = null;
392365
if (this.paymentType != null) {
@@ -450,11 +423,9 @@ public Map<String, Object> update(final JsonCommand command) {
450423
baseDataValidator.reset().parameter(CHARGE_TIME_PARAM_NAME).value(this.chargeTimeType)
451424
.failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.loan");
452425
}
453-
} else if (isClientCharge()) {
454-
if (!isAllowedLoanChargeTime()) {
455-
baseDataValidator.reset().parameter(CHARGE_TIME_PARAM_NAME).value(this.chargeTimeType)
456-
.failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.client");
457-
}
426+
} else if (isClientCharge() && !isAllowedLoanChargeTime()) {
427+
baseDataValidator.reset().parameter(CHARGE_TIME_PARAM_NAME).value(this.chargeTimeType)
428+
.failWithCodeNoParameterAddedToErrorCode("not.allowed.charge.time.for.client");
458429
}
459430
}
460431

@@ -647,7 +618,7 @@ public Map<String, Object> update(final JsonCommand command) {
647618
}
648619

649620
/**
650-
* Delete is a <i>soft delete</i>. Updates flag on charge so it wont appear in query/report results.
621+
* Delete is a <i>soft delete</i>. Updates flag on charge so it won't appear in query/report results.
651622
*
652623
* Any fields with unique constraints and prepended with id of record.
653624
*/
@@ -690,14 +661,6 @@ public ChargeData toData() {
690661

691662
}
692663

693-
public Integer getChargePaymentMode() {
694-
return this.chargePaymentMode;
695-
}
696-
697-
public Integer getFeeInterval() {
698-
return this.feeInterval;
699-
}
700-
701664
public boolean isMonthlyFee() {
702665
return ChargeTimeType.fromInt(this.chargeTimeType).isMonthlyFee();
703666
}
@@ -726,14 +689,6 @@ public Integer feeFrequency() {
726689
return this.feeFrequency;
727690
}
728691

729-
public GLAccount getAccount() {
730-
return this.account;
731-
}
732-
733-
public void setAccount(GLAccount account) {
734-
this.account = account;
735-
}
736-
737692
public Long getIncomeAccountId() {
738693
Long incomeAccountId = null;
739694
if (this.account != null) {
@@ -755,14 +710,6 @@ public boolean isDisbursementCharge() {
755710
|| ChargeTimeType.fromInt(this.chargeTimeType).equals(ChargeTimeType.TRANCHE_DISBURSEMENT);
756711
}
757712

758-
public TaxGroup getTaxGroup() {
759-
return this.taxGroup;
760-
}
761-
762-
public void setTaxGroup(TaxGroup taxGroup) {
763-
this.taxGroup = taxGroup;
764-
}
765-
766713
@Override
767714
public boolean equals(Object o) {
768715
if (this == o) {

fineract-client-feign/src/main/java/org/apache/fineract/client/feign/FineractErrorDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private String extractField(JsonNode node, String fieldName) {
7979

8080
private String extractValidationErrors(JsonNode rootNode) {
8181
JsonNode errorsNode = rootNode.get("errors");
82-
if (errorsNode != null && errorsNode.isArray() && errorsNode.size() > 0) {
82+
if (errorsNode != null && errorsNode.isArray() && !errorsNode.isEmpty()) {
8383
StringBuilder errors = new StringBuilder("Validation errors: ");
8484
for (JsonNode error : errorsNode) {
8585
String parameterName = extractField(error, "parameterName");

fineract-client-feign/src/main/java/org/apache/fineract/client/feign/services/ImagesApi.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,13 @@ private static String detectMediaType(String fileName) {
7777
}
7878
String ext = fileName.substring(dotPos + 1).toLowerCase();
7979

80-
switch (ext) {
81-
case "jpg":
82-
case "jpeg":
83-
return "image/jpeg";
84-
case "png":
85-
return "image/png";
86-
case "gif":
87-
return "image/gif";
88-
case "tif":
89-
case "tiff":
90-
return "image/tiff";
91-
case "pdf":
92-
return "application/pdf";
93-
default:
94-
return "application/octet-stream";
95-
}
80+
return switch (ext) {
81+
case "jpg", "jpeg" -> "image/jpeg";
82+
case "png" -> "image/png";
83+
case "gif" -> "image/gif";
84+
case "tif", "tiff" -> "image/tiff";
85+
case "pdf" -> "application/pdf";
86+
default -> "application/octet-stream";
87+
};
9688
}
9789
}

fineract-client-feign/src/main/java/org/apache/fineract/client/feign/support/ApiResponseDecoder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,15 @@ public Object decode(Response response, Type type) throws IOException {
6060
}
6161

6262
private boolean isApiResponseType(Type type) {
63-
if (type instanceof ParameterizedType) {
64-
ParameterizedType paramType = (ParameterizedType) type;
63+
if (type instanceof ParameterizedType paramType) {
6564
Type rawType = paramType.getRawType();
6665
return rawType == ApiResponse.class;
6766
}
6867
return type == ApiResponse.class;
6968
}
7069

7170
private Type getApiResponseInnerType(Type type) {
72-
if (type instanceof ParameterizedType) {
73-
ParameterizedType paramType = (ParameterizedType) type;
71+
if (type instanceof ParameterizedType paramType) {
7472
Type[] typeArgs = paramType.getActualTypeArguments();
7573
if (typeArgs.length > 0) {
7674
return typeArgs[0];

fineract-core/src/main/java/org/apache/fineract/infrastructure/cache/domain/CacheType.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
import java.util.HashMap;
2222
import java.util.Map;
23+
import lombok.Getter;
2324

25+
@Getter
2426
public enum CacheType {
2527

2628
INVALID(0, "cacheType.invalid"), //
@@ -54,15 +56,7 @@ public static CacheType fromInt(final Integer value) {
5456

5557
@Override
5658
public String toString() {
57-
return name().toString().replaceAll("_", " ");
58-
}
59-
60-
public Integer getValue() {
61-
return this.value;
62-
}
63-
64-
public String getCode() {
65-
return this.code;
59+
return name().replace("_", " ");
6660
}
6761

6862
public boolean isNoCache() {

fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/CalendarConstants.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.HashSet;
2222
import java.util.Set;
23+
import lombok.Getter;
2324

2425
public final class CalendarConstants {
2526

@@ -29,6 +30,7 @@ private CalendarConstants() {
2930

3031
public static final String CALENDAR_RESOURCE_NAME = "calendar";
3132

33+
@Getter
3234
public enum CalendarSupportedParameters {
3335

3436
CALENDAR_ID("id"), //
@@ -80,12 +82,9 @@ public static Set<String> getAllValues() {
8082

8183
@Override
8284
public String toString() {
83-
return name().toString().replaceAll("_", " ");
85+
return name().replace("_", " ");
8486
}
8587

86-
public String getValue() {
87-
return this.value;
88-
}
8988
}
9089

9190
}

0 commit comments

Comments
 (0)