FINERACT-2421: Refractor redundant and some deprecated code as per new Java 21 style (Phase 3)

This commit is contained in:
Aman-Mittal
2025-12-26 19:27:38 +01:00
committed by Adam Saghy
parent 7dac82a4fc
commit 0ba1745443
18 changed files with 82 additions and 145 deletions
@@ -25,7 +25,6 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DefaultValue;
@@ -63,13 +62,14 @@ import org.springframework.stereotype.Component;
*/
@Path("/v1/batches")
@Component
@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"
+ "\n"
+ "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"
+ "\n"
+ "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"
+ "\n"
+ "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,..}..]}.")
@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.
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).
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'.
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,..}..]}.""")
@RequiredArgsConstructor
public class BatchApiResource {
@@ -88,12 +88,12 @@ public class BatchApiResource {
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@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"
+ "\n"
+ "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.")
@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.
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.""")
@RequestBody(required = true, content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchRequest.class, description = "request body"))))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "Success", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchResponse.class)))) })
@ApiResponse(responseCode = "200", description = "Success", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchResponse.class))))
public List<BatchResponse> handleBatchRequests(
@DefaultValue("false") @QueryParam("enclosingTransaction") @Parameter(description = "enclosingTransaction", required = false) final boolean enclosingTransaction,
@Parameter(hidden = true) List<BatchRequest> requestList, @Context UriInfo uriInfo) {
@@ -45,7 +45,6 @@ public class BatchRequestJsonHelper extends FromJsonHelper {
*/
public List<BatchRequest> extractList(final String json) {
final Type listType = new TypeToken<List<BatchRequest>>() {}.getType();
final List<BatchRequest> requests = super.getGsonConverter().fromJson(json, listType);
return requests;
return super.getGsonConverter().fromJson(json, listType);
}
}
@@ -20,7 +20,9 @@ package org.apache.fineract.infrastructure.bulkimport.data;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
@Getter
public enum GlobalEntityType {
INVALID(0, "invalid"), //
@@ -91,27 +93,17 @@ public enum GlobalEntityType {
this.code = code;
}
public Integer getValue() {
return this.value;
}
public String getCode() {
return this.code;
}
public static GlobalEntityType fromInt(final int i) {
final GlobalEntityType entityType = intToEnumMap.get(Integer.valueOf(i));
return entityType;
return intToEnumMap.get(i);
}
public static GlobalEntityType fromCode(final String key) {
final GlobalEntityType entityType = stringToEnumMap.get(key);
return entityType;
return stringToEnumMap.get(key);
}
@Override
public String toString() {
return name().toString();
return name();
}
}
@@ -27,12 +27,12 @@ import org.apache.fineract.infrastructure.businessdate.domain.BusinessDate;
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
@Mapper(config = MapstructMapperConfig.class)
public interface BusinessDateMapper {
@Mappings({ @Mapping(target = "description", source = "type.description"), @Mapping(target = "changes", ignore = true) })
@Mapping(target = "description", source = "type.description")
@Mapping(target = "changes", ignore = true)
BusinessDateDTO mapEntity(BusinessDate source);
List<BusinessDateDTO> mapEntity(List<BusinessDate> sources);
@@ -50,10 +50,7 @@ public class ApplicationCurrencyRepositoryWrapper {
throw new CurrencyNotFoundException(currency.getCode());
}
final ApplicationCurrency applicationCurrency = ApplicationCurrency.from(defaultApplicationCurrency,
currency.getDigitsAfterDecimal(), currency.getInMultiplesOf());
return applicationCurrency;
return ApplicationCurrency.from(defaultApplicationCurrency, currency.getDigitsAfterDecimal(), currency.getInMultiplesOf());
}
/**
@@ -72,7 +72,7 @@ public final class AnnualCompoundingPeriod implements CompoundingPeriod {
final BigDecimal minOverdraftForInterestCalculation) {
BigDecimal cumulativeBalance = BigDecimal.ZERO;
Integer numberOfDays = Integer.valueOf(0);
Integer numberOfDays = 0;
for (final EndOfDayBalance balance : this.endOfDayBalances) {
final BigDecimal endOfDayCumulativeBalance = balance.cumulativeBalance(interestToCompound);
@@ -126,28 +126,10 @@ public final class AnnualCompoundingPeriod implements CompoundingPeriod {
daysInYear, minBalanceForInterestCalculation, overdraftInterestRateAsFraction,
minOverdraftForInterestCalculation);
break;
case MONTHLY:
case MONTHLY, ANNUAL, BI_ANNUAL, QUATERLY:
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
break;
case QUATERLY:
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
break;
// case WEEKLY:
// break;
// case BIWEEKLY:
// break;
case BI_ANNUAL:
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
break;
case ANNUAL:
interestOnBalanceUnrounded = balance.calculateInterestOnBalance(interestToCompound, interestRateAsFraction, daysInYear,
minBalanceForInterestCalculation, overdraftInterestRateAsFraction, minOverdraftForInterestCalculation);
break;
// case NO_COMPOUNDING_SIMPLE_INTEREST:
// break;
case INVALID:
break;
}
@@ -20,7 +20,10 @@ package org.apache.fineract.useradministration.data;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.organisation.staff.data.StaffData;
import org.apache.fineract.portfolio.client.data.ClientData;
@@ -43,6 +46,7 @@ public final class AppUserData {
private List<Long> roles;
private Boolean sendPasswordToEmail;
private Long staffId;
@Getter
private transient Integer rowIndex;
@SuppressWarnings("unused")
@@ -53,6 +57,7 @@ public final class AppUserData {
private final StaffData staff;
private final Boolean isSelfServiceUser;
@Setter
@SuppressWarnings("unused")
private Set<ClientData> clients;
@@ -85,10 +90,6 @@ public final class AppUserData {
this.clients = null;
}
public Integer getRowIndex() {
return rowIndex;
}
public static AppUserData template(final AppUserData user, final Collection<OfficeData> officesForDropdown) {
return new AppUserData(user.id, user.username, user.email, user.officeId, user.officeName, user.firstname, user.lastname,
user.availableRoles, user.selfServiceRoles, user.selectedRoles, officesForDropdown, user.staff, user.passwordNeverExpires,
@@ -146,17 +147,11 @@ public final class AppUserData {
if (this == o) {
return true;
}
if (o == null || !(o instanceof AppUserData)) {
if (!(o instanceof AppUserData that)) {
return false;
}
AppUserData that = (AppUserData) o;
if (id != null ? !id.equals(that.id) : that.id != null) {
return false;
}
return true;
return Objects.equals(id, that.id);
}
@Override
@@ -164,12 +159,8 @@ public final class AppUserData {
return id != null ? id.hashCode() : 0;
}
public void setClients(Set<ClientData> clients) {
this.clients = clients;
}
public boolean isSelfServiceUser() {
return this.isSelfServiceUser == null ? false : this.isSelfServiceUser;
return this.isSelfServiceUser != null && this.isSelfServiceUser;
}
}
@@ -72,7 +72,7 @@ public class AppUserClientMapping extends AbstractPersistableCustom<Long> {
AppUserClientMapping that = (AppUserClientMapping) obj;
return null == this.client.getId() ? false : this.client.getId().equals(that.client.getId());
return null != this.client.getId() && this.client.getId().equals(that.client.getId());
}
@Override