Skip to content

Commit 0ba1745

Browse files
Aman-Mittaladamsaghy
authored andcommitted
FINERACT-2421: Refractor redundant and some deprecated code as per new Java 21 style (Phase 3)
1 parent 7dac82a commit 0ba1745

File tree

18 files changed

+82
-145
lines changed

18 files changed

+82
-145
lines changed

fineract-cob/src/main/java/org/apache/fineract/cob/service/BusinessStepMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
2525
import org.mapstruct.Mapper;
2626
import org.mapstruct.Mapping;
27-
import org.mapstruct.Mappings;
2827

2928
@Mapper(config = MapstructMapperConfig.class)
3029
public interface BusinessStepMapper {
3130

32-
@Mappings({ @Mapping(target = "order", source = "source.stepOrder") })
31+
@Mapping(target = "order", source = "source.stepOrder")
3332
BusinessStep map(BatchBusinessStep source);
3433

3534
List<BusinessStep> map(List<BatchBusinessStep> source);

fineract-core/src/main/java/org/apache/fineract/batch/api/BatchApiResource.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.swagger.v3.oas.annotations.media.Schema;
2626
import io.swagger.v3.oas.annotations.parameters.RequestBody;
2727
import io.swagger.v3.oas.annotations.responses.ApiResponse;
28-
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2928
import io.swagger.v3.oas.annotations.tags.Tag;
3029
import jakarta.ws.rs.Consumes;
3130
import jakarta.ws.rs.DefaultValue;
@@ -63,13 +62,14 @@
6362
*/
6463
@Path("/v1/batches")
6564
@Component
66-
@Tag(name = "Batch API", description = "The Apache Fineract Batch API enables a consumer to access significant amounts of data in a single call or to make changes to several objects at once. Batching allows a consumer to pass instructions for several operations in a single HTTP request. A consumer can also specify dependencies between related operations. Once all operations have been completed, a consolidated response will be passed back and the HTTP connection will be closed.\n"
67-
+ "\n"
68-
+ "The Batch API takes in an array of logical HTTP requests represented as JSON arrays - each request has a requestId (the id of a request used to specify the sequence and as a dependency between requests), a method (corresponding to HTTP method GET/PUT/POST/DELETE etc.), a relativeUrl (the portion of the URL after https://example.org/api/v2/), optional headers array (corresponding to HTTP headers), optional reference parameter if a request is dependent on another request and an optional body (for POST and PUT requests). The Batch API returns an array of logical HTTP responses represented as JSON arrays - each response has a requestId, a status code, an optional headers array and an optional body (which is a JSON encoded string).\n"
69-
+ "\n"
70-
+ "Batch API uses Json Path to handle dependent parameters. For example, if request '2' is referencing request '1' and in the \"body\" or in \"relativeUrl\" of request '2', there is a dependent parameter (which will look like \"$.parameter_name\"), then Batch API will internally substitute this dependent parameter from the response body of request '1'.\n"
71-
+ "\n"
72-
+ "Batch API is able to handle deeply nested dependent requests as well nested parameters. As shown in the example, requests are dependent on each other as, 1<--2<--6, i.e a nested dependency, where request '6' is not directly dependent on request '1' but still it is one of the nested child of request '1'. In the same way Batch API could handle a deeply nested dependent value, such as {..[..{..,$.parameter_name,..}..]}.")
65+
@Tag(name = "Batch API", description = """
66+
The Apache Fineract Batch API enables a consumer to access significant amounts of data in a single call or to make changes to several objects at once. Batching allows a consumer to pass instructions for several operations in a single HTTP request. A consumer can also specify dependencies between related operations. Once all operations have been completed, a consolidated response will be passed back and the HTTP connection will be closed.
67+
68+
The Batch API takes in an array of logical HTTP requests represented as JSON arrays - each request has a requestId (the id of a request used to specify the sequence and as a dependency between requests), a method (corresponding to HTTP method GET/PUT/POST/DELETE etc.), a relativeUrl (the portion of the URL after https://example.org/api/v2/), optional headers array (corresponding to HTTP headers), optional reference parameter if a request is dependent on another request and an optional body (for POST and PUT requests). The Batch API returns an array of logical HTTP responses represented as JSON arrays - each response has a requestId, a status code, an optional headers array and an optional body (which is a JSON encoded string).
69+
70+
Batch API uses Json Path to handle dependent parameters. For example, if request '2' is referencing request '1' and in the "body" or in "relativeUrl" of request '2', there is a dependent parameter (which will look like "$.parameter_name"), then Batch API will internally substitute this dependent parameter from the response body of request '1'.
71+
72+
Batch API is able to handle deeply nested dependent requests as well nested parameters. As shown in the example, requests are dependent on each other as, 1<--2<--6, i.e a nested dependency, where request '6' is not directly dependent on request '1' but still it is one of the nested child of request '1'. In the same way Batch API could handle a deeply nested dependent value, such as {..[..{..,$.parameter_name,..}..]}.""")
7373
@RequiredArgsConstructor
7474
public class BatchApiResource {
7575

@@ -88,12 +88,12 @@ public class BatchApiResource {
8888
@POST
8989
@Consumes({ MediaType.APPLICATION_JSON })
9090
@Produces({ MediaType.APPLICATION_JSON })
91-
@Operation(summary = "Batch requests in a single transaction", description = "The Apache Fineract Batch API is also capable of executing all the requests in a single transaction, by setting a Query Parameter, \"enclosingTransaction=true\". So, if one or more of the requests in a batch returns an erroneous response all of the Data base transactions made by other successful requests will be rolled back.\n"
92-
+ "\n"
93-
+ "If there has been a rollback in a transaction then a single response will be provided, with a '400' status code and a body consisting of the error details of the first failed request.")
91+
@Operation(summary = "Batch requests in a single transaction", description = """
92+
The Apache Fineract Batch API is also capable of executing all the requests in a single transaction, by setting a Query Parameter, "enclosingTransaction=true". So, if one or more of the requests in a batch returns an erroneous response all of the Data base transactions made by other successful requests will be rolled back.
93+
94+
If there has been a rollback in a transaction then a single response will be provided, with a '400' status code and a body consisting of the error details of the first failed request.""")
9495
@RequestBody(required = true, content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchRequest.class, description = "request body"))))
95-
@ApiResponses({
96-
@ApiResponse(responseCode = "200", description = "Success", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchResponse.class)))) })
96+
@ApiResponse(responseCode = "200", description = "Success", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchResponse.class))))
9797
public List<BatchResponse> handleBatchRequests(
9898
@DefaultValue("false") @QueryParam("enclosingTransaction") @Parameter(description = "enclosingTransaction", required = false) final boolean enclosingTransaction,
9999
@Parameter(hidden = true) List<BatchRequest> requestList, @Context UriInfo uriInfo) {

fineract-core/src/main/java/org/apache/fineract/batch/serialization/BatchRequestJsonHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class BatchRequestJsonHelper extends FromJsonHelper {
4545
*/
4646
public List<BatchRequest> extractList(final String json) {
4747
final Type listType = new TypeToken<List<BatchRequest>>() {}.getType();
48-
final List<BatchRequest> requests = super.getGsonConverter().fromJson(json, listType);
49-
return requests;
48+
return super.getGsonConverter().fromJson(json, listType);
5049
}
5150
}

fineract-core/src/main/java/org/apache/fineract/infrastructure/bulkimport/data/GlobalEntityType.java

Lines changed: 5 additions & 13 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 GlobalEntityType {
2527

2628
INVALID(0, "invalid"), //
@@ -91,27 +93,17 @@ public enum GlobalEntityType {
9193
this.code = code;
9294
}
9395

94-
public Integer getValue() {
95-
return this.value;
96-
}
97-
98-
public String getCode() {
99-
return this.code;
100-
}
101-
10296
public static GlobalEntityType fromInt(final int i) {
103-
final GlobalEntityType entityType = intToEnumMap.get(Integer.valueOf(i));
104-
return entityType;
97+
return intToEnumMap.get(i);
10598
}
10699

107100
public static GlobalEntityType fromCode(final String key) {
108-
final GlobalEntityType entityType = stringToEnumMap.get(key);
109-
return entityType;
101+
return stringToEnumMap.get(key);
110102
}
111103

112104
@Override
113105
public String toString() {
114-
return name().toString();
106+
return name();
115107
}
116108

117109
}

fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
2828
import org.mapstruct.Mapper;
2929
import org.mapstruct.Mapping;
30-
import org.mapstruct.Mappings;
3130

3231
@Mapper(config = MapstructMapperConfig.class)
3332
public interface BusinessDateMapper {
3433

35-
@Mappings({ @Mapping(target = "description", source = "type.description"), @Mapping(target = "changes", ignore = true) })
34+
@Mapping(target = "description", source = "type.description")
35+
@Mapping(target = "changes", ignore = true)
3636
BusinessDateDTO mapEntity(BusinessDate source);
3737

3838
List<BusinessDateDTO> mapEntity(List<BusinessDate> sources);

fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain/ApplicationCurrencyRepositoryWrapper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ public ApplicationCurrency findOneWithNotFoundDetection(final MonetaryCurrency c
5050
throw new CurrencyNotFoundException(currency.getCode());
5151
}
5252

53-
final ApplicationCurrency applicationCurrency = ApplicationCurrency.from(defaultApplicationCurrency,
54-
currency.getDigitsAfterDecimal(), currency.getInMultiplesOf());
55-
56-
return applicationCurrency;
53+
return ApplicationCurrency.from(defaultApplicationCurrency, currency.getDigitsAfterDecimal(), currency.getInMultiplesOf());
5754
}
5855

5956
/**

fineract-core/src/main/java/org/apache/fineract/portfolio/savings/domain/interest/AnnualCompoundingPeriod.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private BigDecimal calculateUsingAverageDailyBalanceMethod(final BigDecimal inte
7272
final BigDecimal minOverdraftForInterestCalculation) {
7373

7474
BigDecimal cumulativeBalance = BigDecimal.ZERO;
75-
Integer numberOfDays = Integer.valueOf(0);
75+
Integer numberOfDays = 0;
7676

7777
for (final EndOfDayBalance balance : this.endOfDayBalances) {
7878
final BigDecimal endOfDayCumulativeBalance = balance.cumulativeBalance(interestToCompound);
@@ -126,28 +126,10 @@ private BigDecimal calculateUsingDailyBalanceMethod(final SavingsCompoundingInte
126126
daysInYear, minBalanceForInterestCalculation, overdraftInterestRateAsFraction,
127127
minOverdraftForInterestCalculation);
128128
break;
129-
case MONTHLY:
129+
case MONTHLY, ANNUAL, BI_ANNUAL, QUATERLY:
130130
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
131131
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
132132
break;
133-
case QUATERLY:
134-
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
135-
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
136-
break;
137-
// case WEEKLY:
138-
// break;
139-
// case BIWEEKLY:
140-
// break;
141-
case BI_ANNUAL:
142-
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
143-
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
144-
break;
145-
case ANNUAL:
146-
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
147-
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
148-
break;
149-
// case NO_COMPOUNDING_SIMPLE_INTEREST:
150-
// break;
151133
case INVALID:
152134
break;
153135
}

fineract-core/src/main/java/org/apache/fineract/useradministration/data/AppUserData.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
import java.util.Collection;
2222
import java.util.List;
23+
import java.util.Objects;
2324
import java.util.Set;
25+
import lombok.Getter;
26+
import lombok.Setter;
2427
import org.apache.fineract.organisation.office.data.OfficeData;
2528
import org.apache.fineract.organisation.staff.data.StaffData;
2629
import org.apache.fineract.portfolio.client.data.ClientData;
@@ -43,6 +46,7 @@ public final class AppUserData {
4346
private List<Long> roles;
4447
private Boolean sendPasswordToEmail;
4548
private Long staffId;
49+
@Getter
4650
private transient Integer rowIndex;
4751

4852
@SuppressWarnings("unused")
@@ -53,6 +57,7 @@ public final class AppUserData {
5357
private final StaffData staff;
5458
private final Boolean isSelfServiceUser;
5559

60+
@Setter
5661
@SuppressWarnings("unused")
5762
private Set<ClientData> clients;
5863

@@ -85,10 +90,6 @@ private AppUserData(Long officeId, Long staffId, String username, String firstna
8590
this.clients = null;
8691
}
8792

88-
public Integer getRowIndex() {
89-
return rowIndex;
90-
}
91-
9293
public static AppUserData template(final AppUserData user, final Collection<OfficeData> officesForDropdown) {
9394
return new AppUserData(user.id, user.username, user.email, user.officeId, user.officeName, user.firstname, user.lastname,
9495
user.availableRoles, user.selfServiceRoles, user.selectedRoles, officesForDropdown, user.staff, user.passwordNeverExpires,
@@ -146,30 +147,20 @@ public boolean equals(Object o) {
146147
if (this == o) {
147148
return true;
148149
}
149-
if (o == null || !(o instanceof AppUserData)) {
150-
return false;
151-
}
152-
153-
AppUserData that = (AppUserData) o;
154-
155-
if (id != null ? !id.equals(that.id) : that.id != null) {
150+
if (!(o instanceof AppUserData that)) {
156151
return false;
157152
}
158153

159-
return true;
154+
return Objects.equals(id, that.id);
160155
}
161156

162157
@Override
163158
public int hashCode() {
164159
return id != null ? id.hashCode() : 0;
165160
}
166161

167-
public void setClients(Set<ClientData> clients) {
168-
this.clients = clients;
169-
}
170-
171162
public boolean isSelfServiceUser() {
172-
return this.isSelfServiceUser == null ? false : this.isSelfServiceUser;
163+
return this.isSelfServiceUser != null && this.isSelfServiceUser;
173164
}
174165

175166
}

fineract-core/src/main/java/org/apache/fineract/useradministration/domain/AppUserClientMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public boolean equals(Object obj) {
7272

7373
AppUserClientMapping that = (AppUserClientMapping) obj;
7474

75-
return null == this.client.getId() ? false : this.client.getId().equals(that.client.getId());
75+
return null != this.client.getId() && this.client.getId().equals(that.client.getId());
7676
}
7777

7878
@Override

fineract-document/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ public Long createInternalDocument(final String entityType, final Long entityId,
101101
final DocumentCommand documentCommand = new DocumentCommand(null, null, entityType, entityId, name, fileName, fileSize, mimeType,
102102
description, null);
103103

104-
final Long documentId = createDocument(documentCommand, inputStream);
105-
106-
return documentId;
104+
return createDocument(documentCommand, inputStream);
107105

108106
}
109107

@@ -196,7 +194,7 @@ public enum DocumentManagementEntity {
196194

197195
@Override
198196
public String toString() {
199-
return name().toString().toLowerCase();
197+
return name().toLowerCase();
200198
}
201199
}
202200
}

0 commit comments

Comments
 (0)