Skip to content

Commit 4bfae04

Browse files
Aman-Mittaladamsaghy
authored andcommitted
FINERACT-2326: Refractor redundant and some deprecated code as per new Java 21 style (Phase 2)
1 parent 695816f commit 4bfae04

File tree

21 files changed

+196
-206
lines changed

21 files changed

+196
-206
lines changed

custom/acme/event/starter/src/main/java/com/acme/fineract/event/starter/AcmeEventAutoConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
import org.springframework.boot.autoconfigure.AutoConfiguration;
2222
import org.springframework.context.annotation.ComponentScan;
23-
import org.springframework.context.annotation.ComponentScans;
2423

2524
@AutoConfiguration
26-
@ComponentScans({ @ComponentScan("com.acme.fineract.event.externalevent") })
25+
@ComponentScan("com.acme.fineract.event.externalevent")
2726
public class AcmeEventAutoConfiguration {}

custom/acme/loan/starter/src/main/java/com/acme/fineract/loan/starter/AcmeLoanAutoConfiguration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.ComponentScan;
29-
import org.springframework.context.annotation.ComponentScans;
3029

3130
@AutoConfiguration
32-
@ComponentScans({ @ComponentScan("com.acme.fineract.loan.cob"), @ComponentScan("com.acme.fineract.loan.processor"),
33-
@ComponentScan("com.acme.fineract.loan.job") })
31+
@ComponentScan(basePackages = { "com.acme.fineract.loan.cob", "com.acme.fineract.loan.processor", "com.acme.fineract.loan.job" })
3432
@ConditionalOnProperty("acme.loan.enabled")
3533
public class AcmeLoanAutoConfiguration {
3634

fineract-accounting/src/main/java/org/apache/fineract/accounting/accrual/api/AccrualAccountingApiResource.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.swagger.v3.oas.annotations.media.Schema;
2525
import io.swagger.v3.oas.annotations.parameters.RequestBody;
2626
import io.swagger.v3.oas.annotations.responses.ApiResponse;
27-
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2827
import io.swagger.v3.oas.annotations.tags.Tag;
2928
import jakarta.ws.rs.Consumes;
3029
import jakarta.ws.rs.POST;
@@ -52,9 +51,13 @@ public class AccrualAccountingApiResource {
5251
@POST
5352
@Consumes({ MediaType.APPLICATION_JSON })
5453
@Produces({ MediaType.APPLICATION_JSON })
55-
@Operation(summary = "Executes Periodic Accrual Accounting", method = "POST", description = "Mandatory Fields\n" + "\n" + "tillDate\n")
54+
@Operation(summary = "Executes Periodic Accrual Accounting", method = "POST", description = """
55+
Mandatory Fields
56+
57+
tillDate
58+
""")
5659
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = AccrualAccountingApiResourceSwagger.PostRunaccrualsRequest.class)))
57-
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK") })
60+
@ApiResponse(responseCode = "200", description = "OK")
5861
public CommandProcessingResult executePeriodicAccrualAccounting(@Parameter(hidden = true) AccrualAccountRequest accrualAccountRequest) {
5962
final CommandWrapper commandRequest = new CommandWrapperBuilder().excuteAccrualAccounting()
6063
.withJson(apiJsonSerializerService.serialize(accrualAccountRequest)).build();

fineract-accounting/src/main/java/org/apache/fineract/accounting/rule/api/AccountingRuleApiResource.java

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.swagger.v3.oas.annotations.media.Schema;
2525
import io.swagger.v3.oas.annotations.parameters.RequestBody;
2626
import io.swagger.v3.oas.annotations.responses.ApiResponse;
27-
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2827
import io.swagger.v3.oas.annotations.tags.Tag;
2928
import jakarta.ws.rs.Consumes;
3029
import jakarta.ws.rs.DELETE;
@@ -69,13 +68,15 @@
6968

7069
@Path("/v1/accountingrules")
7170
@Component
72-
@Tag(name = "Accounting Rules", description = "It is typical scenario in MFI's that non accountants pass journal entries on a regular basis. For Ex: A branch office might deposit their entire cash at hand to their Bank account at the end of a working day. The branch office users might not understand enough of accounting to figure out which account needs to get credited and which account needs to be debited to represent this transaction.\n"
73-
+ "\n"
74-
+ "Enter accounting rules, an abstraction on top of manual Journal entires for enabling simpler data entry. An accounting rule can define any of the following abstractions\n"
75-
+ "\n" + "A Simple journal entry where both the credit and debit account have been preselected\n"
76-
+ "A Simple journal entry where either credit or debit accounts have been limited to a pre-selected list of accounts (Ex: Debit account should be one of \"Bank of America\" of \"JP Morgan\" and credit account should be \"Cash\")\n"
77-
+ "A Compound journal entry where multiple debits and / or multiple credits may be made amongst a set of preselected list of accounts (Ex: Credit account should be either \"Bank Of America\" or \"Cash\" and debit account can be \"Employee Salary\" and/or \"Miscellenous Expenses\")\n"
78-
+ "An accounting rule can also be optionally associated with a branch, so that only a particular Branch's users have access to the rule")
71+
@Tag(name = "Accounting Rules", description = """
72+
It is typical scenario in MFI's that non accountants pass journal entries on a regular basis. For Ex: A branch office might deposit their entire cash at hand to their Bank account at the end of a working day. The branch office users might not understand enough of accounting to figure out which account needs to get credited and which account needs to be debited to represent this transaction.
73+
74+
Enter accounting rules, an abstraction on top of manual Journal entires for enabling simpler data entry. An accounting rule can define any of the following abstractions
75+
76+
A Simple journal entry where both the credit and debit account have been preselected
77+
A Simple journal entry where either credit or debit accounts have been limited to a pre-selected list of accounts (Ex: Debit account should be one of "Bank of America" of "JP Morgan" and credit account should be "Cash")
78+
A Compound journal entry where multiple debits and / or multiple credits may be made amongst a set of preselected list of accounts (Ex: Credit account should be either "Bank Of America" or "Cash" and debit account can be "Employee Salary" and/or "Miscellenous Expenses")
79+
An accounting rule can also be optionally associated with a branch, so that only a particular Branch's users have access to the rule""")
7980
@RequiredArgsConstructor
8081
public class AccountingRuleApiResource {
8182

@@ -94,8 +95,14 @@ public class AccountingRuleApiResource {
9495
@Path("template")
9596
@Consumes({ MediaType.APPLICATION_JSON })
9697
@Produces({ MediaType.APPLICATION_JSON })
97-
@Operation(summary = "Retrieve Accounting Rule Details Template", description = "This is a convenience resource. It can be useful when building maintenance user interface screens for client applications. The template data returned consists of any or all of:\n"
98-
+ "\n" + "Field Defaults\n" + "Allowed Value Lists\n" + "Example Request:\n" + "\n" + "accountingrules/template")
98+
@Operation(summary = "Retrieve Accounting Rule Details Template", description = """
99+
This is a convenience resource. It can be useful when building maintenance user interface screens for client applications. The template data returned consists of any or all of:
100+
101+
Field Defaults
102+
Allowed Value Lists
103+
Example Request:
104+
105+
accountingrules/template""")
99106
public AccountingRuleData retrieveTemplate() {
100107
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
101108
return handleTemplate(null);
@@ -104,8 +111,12 @@ public AccountingRuleData retrieveTemplate() {
104111
@GET
105112
@Consumes({ MediaType.APPLICATION_JSON })
106113
@Produces({ MediaType.APPLICATION_JSON })
107-
@Operation(summary = "Retrieve Accounting Rules", description = "Returns the list of defined accounting rules.\n" + "\n"
108-
+ "Example Requests:\n" + "\n" + "accountingrules")
114+
@Operation(summary = "Retrieve Accounting Rules", description = """
115+
Returns the list of defined accounting rules.
116+
117+
Example Requests:
118+
119+
accountingrules""")
109120
public List<AccountingRuleData> retrieveAllAccountingRules(@Context final UriInfo uriInfo) {
110121
final AppUser currentUser = context.authenticatedUser();
111122
currentUser.validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
@@ -122,8 +133,12 @@ public List<AccountingRuleData> retrieveAllAccountingRules(@Context final UriInf
122133
@Path("{accountingRuleId}")
123134
@Consumes({ MediaType.APPLICATION_JSON })
124135
@Produces({ MediaType.APPLICATION_JSON })
125-
@Operation(summary = "Retrieve a Accounting rule", description = "Returns the details of a defined Accounting rule.\n" + "\n"
126-
+ "Example Requests:\n" + "\n" + "accountingrules/1")
136+
@Operation(summary = "Retrieve a Accounting rule", description = """
137+
Returns the details of a defined Accounting rule.
138+
139+
Example Requests:
140+
141+
accountingrules/1""")
127142
public AccountingRuleData retreiveAccountingRule(
128143
@PathParam("accountingRuleId") @Parameter(description = "accountingRuleId") final Long accountingRuleId,
129144
@Context final UriInfo uriInfo) {
@@ -138,12 +153,18 @@ public AccountingRuleData retreiveAccountingRule(
138153
@POST
139154
@Consumes({ MediaType.APPLICATION_JSON })
140155
@Produces({ MediaType.APPLICATION_JSON })
141-
@Operation(summary = "Create/Define a Accounting rule", description = "Define a new Accounting rule.\n" + "\n" + "Mandatory Fields\n"
142-
+ "name, officeId,\n" + "accountToDebit OR debitTags,\n" + "accountToCredit OR creditTags.\n" + "\n" + "Optional Fields\n"
143-
+ "description")
156+
@Operation(summary = "Create/Define a Accounting rule", description = """
157+
Define a new Accounting rule.
158+
159+
Mandatory Fields
160+
name, officeId,
161+
accountToDebit OR debitTags,
162+
accountToCredit OR creditTags.
163+
164+
Optional Fields
165+
description""")
144166
@RequestBody(content = @Content(schema = @Schema(implementation = AccountRuleRequest.class)))
145-
@ApiResponses({
146-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountingRuleApiResourceSwagger.PostAccountingRulesResponse.class))) })
167+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountingRuleApiResourceSwagger.PostAccountingRulesResponse.class)))
147168
public CommandProcessingResult createAccountingRule(@Parameter(hidden = true) AccountRuleRequest accountRuleRequest) {
148169
final CommandWrapper commandRequest = new CommandWrapperBuilder().createAccountingRule()
149170
.withJson(apiJsonSerializerService.serialize(accountRuleRequest)).build();
@@ -157,8 +178,7 @@ public CommandProcessingResult createAccountingRule(@Parameter(hidden = true) Ac
157178
@Produces({ MediaType.APPLICATION_JSON })
158179
@Operation(summary = "Update a Accounting Rule", description = "Updates the details of a Accounting rule.")
159180
@RequestBody(content = @Content(schema = @Schema(implementation = AccountRuleRequest.class)))
160-
@ApiResponses({
161-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountingRuleApiResourceSwagger.PutAccountingRulesResponse.class))) })
181+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountingRuleApiResourceSwagger.PutAccountingRulesResponse.class)))
162182
public CommandProcessingResult updateAccountingRule(
163183
@PathParam("accountingRuleId") @Parameter(description = "accountingRuleId") final Long accountingRuleId,
164184
@Parameter(hidden = true) AccountRuleRequest accountRuleRequest) {
@@ -173,8 +193,7 @@ public CommandProcessingResult updateAccountingRule(
173193
@Consumes({ MediaType.APPLICATION_JSON })
174194
@Produces({ MediaType.APPLICATION_JSON })
175195
@Operation(summary = "Delete a Accounting Rule", description = "Deletes a Accounting rule.")
176-
@ApiResponses({
177-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountingRuleApiResourceSwagger.DeleteAccountingRulesResponse.class))) })
196+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountingRuleApiResourceSwagger.DeleteAccountingRulesResponse.class)))
178197
public CommandProcessingResult deleteAccountingRule(
179198
@PathParam("accountingRuleId") @Parameter(description = "accountingRuleId") final Long accountingRuleId) {
180199

fineract-core/src/main/java/org/apache/fineract/accounting/common/AccountingConstants.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public Integer getValue() {
8181
}
8282

8383
public static CashAccountsForLoan fromInt(final int i) {
84-
final CashAccountsForLoan type = intToEnumMap.get(Integer.valueOf(i));
85-
return type;
84+
return intToEnumMap.get(i);
8685
}
8786
}
8887

@@ -142,8 +141,7 @@ public Integer getValue() {
142141
}
143142

144143
public static AccrualAccountsForLoan fromInt(final int i) {
145-
final AccrualAccountsForLoan type = intToEnumMap.get(Integer.valueOf(i));
146-
return type;
144+
return intToEnumMap.get(i);
147145
}
148146

149147
}
@@ -297,8 +295,7 @@ public Integer getValue() {
297295
}
298296

299297
public static CashAccountsForSavings fromInt(final int i) {
300-
final CashAccountsForSavings type = intToEnumMap.get(Integer.valueOf(i));
301-
return type;
298+
return intToEnumMap.get(i);
302299
}
303300
}
304301

@@ -346,8 +343,7 @@ public Integer getValue() {
346343
}
347344

348345
public static AccrualAccountsForSavings fromInt(final int i) {
349-
final AccrualAccountsForSavings type = intToEnumMap.get(Integer.valueOf(i));
350-
return type;
346+
return intToEnumMap.get(i);
351347
}
352348
}
353349

@@ -492,8 +488,7 @@ public String getValueAsString() {
492488
}
493489

494490
public static FinancialActivity fromInt(final int financialActivityId) {
495-
final FinancialActivity type = intToEnumMap.get(Integer.valueOf(financialActivityId));
496-
return type;
491+
return intToEnumMap.get(financialActivityId);
497492
}
498493

499494
public static FinancialActivityData toFinancialActivityData(final int financialActivityId) {
@@ -506,8 +501,7 @@ public static List<FinancialActivityData> getAllFinancialActivities() {
506501
}
507502

508503
private static FinancialActivityData convertToFinancialActivityData(final FinancialActivity type) {
509-
FinancialActivityData financialActivityData = new FinancialActivityData(type.value, type.code, type.getMappedGLAccountType());
510-
return financialActivityData;
504+
return new FinancialActivityData(type.value, type.code, type.getMappedGLAccountType());
511505
}
512506
}
513507

@@ -545,8 +539,7 @@ public Integer getValue() {
545539
}
546540

547541
public static CashAccountsForShares fromInt(final int i) {
548-
final CashAccountsForShares type = intToEnumMap.get(Integer.valueOf(i));
549-
return type;
542+
return intToEnumMap.get(i);
550543
}
551544
}
552545

fineract-core/src/main/java/org/apache/fineract/accounting/common/AccountingEnumerations.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public static EnumOptionData gLAccountType(final int id) {
3737
}
3838

3939
public static EnumOptionData gLAccountType(final GLAccountType accountType) {
40-
final EnumOptionData optionData = new EnumOptionData(accountType.getValue().longValue(), accountType.getCode(),
41-
accountType.toString());
42-
return optionData;
40+
return new EnumOptionData(accountType.getValue().longValue(), accountType.getCode(), accountType.toString());
4341
}
4442

4543
public static List<EnumOptionData> gLAccountType(final GLAccountType[] accountTypes) {
@@ -55,9 +53,7 @@ public static EnumOptionData gLAccountUsage(final int id) {
5553
}
5654

5755
public static EnumOptionData gLAccountUsage(final GLAccountUsage accountUsage) {
58-
final EnumOptionData optionData = new EnumOptionData(accountUsage.getValue().longValue(), accountUsage.getCode(),
59-
accountUsage.toString());
60-
return optionData;
56+
return new EnumOptionData(accountUsage.getValue().longValue(), accountUsage.getCode(), accountUsage.toString());
6157
}
6258

6359
public static List<EnumOptionData> gLAccountUsage(final GLAccountUsage[] accountUsages) {
@@ -73,9 +69,7 @@ public static EnumOptionData journalEntryType(final int id) {
7369
}
7470

7571
public static EnumOptionData journalEntryType(final JournalEntryType journalEntryType) {
76-
final EnumOptionData optionData = new EnumOptionData(journalEntryType.getValue().longValue(), journalEntryType.getCode(),
77-
journalEntryType.toString());
78-
return optionData;
72+
return new EnumOptionData(journalEntryType.getValue().longValue(), journalEntryType.getCode(), journalEntryType.toString());
7973
}
8074

8175
public static List<EnumOptionData> journalEntryTypes(final JournalEntryType[] journalEntryTypes) {
@@ -91,18 +85,16 @@ public static EnumOptionData portfolioProductType(final int id) {
9185
}
9286

9387
public static EnumOptionData portfolioProductType(final PortfolioProductType portfolioProductType) {
94-
final EnumOptionData optionData = new EnumOptionData(portfolioProductType.getValue().longValue(), portfolioProductType.getCode(),
88+
return new EnumOptionData(portfolioProductType.getValue().longValue(), portfolioProductType.getCode(),
9589
portfolioProductType.toString());
96-
return optionData;
9790
}
9891

9992
public static EnumOptionData accountingRuleType(final int id) {
10093
return accountingRuleType(AccountingRuleType.fromInt(id));
10194
}
10295

10396
public static EnumOptionData accountingRuleType(final AccountingRuleType type) {
104-
final EnumOptionData optionData = new EnumOptionData(type.getValue().longValue(), type.getCode(), type.toString());
105-
return optionData;
97+
return new EnumOptionData(type.getValue().longValue(), type.getCode(), type.toString());
10698
}
10799

108100
public static List<EnumOptionData> accountingRuleTypes(final AccountingRuleType[] accountingRuleTypes) {

fineract-core/src/main/java/org/apache/fineract/accounting/common/AccountingRuleType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public enum AccountingRuleType {
4545
}
4646

4747
public static AccountingRuleType fromInt(final Integer ruleTypeValue) {
48-
final AccountingRuleType type = intToEnumMap.get(ruleTypeValue);
49-
return type;
48+
return intToEnumMap.get(ruleTypeValue);
5049
}
5150

5251
AccountingRuleType(final Integer value, final String code, final String description) {

fineract-core/src/main/java/org/apache/fineract/portfolio/accountdetails/domain/AccountType.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,14 @@ public enum AccountType {
4444
}
4545

4646
public static AccountType fromInt(final Integer accountTypeValue) {
47-
48-
AccountType enumeration = AccountType.INVALID;
49-
switch (accountTypeValue) {
50-
case 1:
51-
enumeration = AccountType.INDIVIDUAL;
52-
break;
53-
case 2:
54-
enumeration = AccountType.GROUP;
55-
break;
56-
case 3:
57-
enumeration = AccountType.JLG;
58-
break;
59-
case 4:
60-
enumeration = AccountType.GLIM;
61-
break;
62-
case 5:
63-
enumeration = AccountType.GSIM;
64-
break;
65-
}
66-
return enumeration;
47+
return switch (accountTypeValue) {
48+
case 1 -> AccountType.INDIVIDUAL;
49+
case 2 -> AccountType.GROUP;
50+
case 3 -> AccountType.JLG;
51+
case 4 -> AccountType.GLIM;
52+
case 5 -> AccountType.GSIM;
53+
default -> AccountType.INVALID;
54+
};
6755
}
6856

6957
public static AccountType fromName(final String name) {

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/api/FineractClientConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public FineractFeignClient fineractFeignClient() {
4242
String apiBaseUrl = baseUrl + "/fineract-provider/api/";
4343
boolean debugEnabled = Boolean.parseBoolean(System.getProperty("fineract.feign.debug", "false"));
4444

45-
FineractFeignClient client = FineractFeignClient.builder().baseUrl(apiBaseUrl).credentials(username, password).tenantId(tenantId)
45+
return FineractFeignClient.builder().baseUrl(apiBaseUrl).credentials(username, password).tenantId(tenantId)
4646
.disableSslVerification(true).debug(debugEnabled).connectTimeout(60, TimeUnit.SECONDS)
4747
.readTimeout((int) readTimeout, TimeUnit.SECONDS).build();
48-
return client;
4948
}
5049
}

0 commit comments

Comments
 (0)