FINERACT-2009: Upgrade latest framework libs

This commit is contained in:
Aleksandar Vidakovic
2024-01-06 14:13:33 +01:00
committed by Aleksandar Vidakovic
parent 1f3bb34e13
commit e4944c44d6
193 changed files with 1567 additions and 1390 deletions
@@ -70,7 +70,7 @@ public class GLClosuresApiResource {
Arrays.asList("id", "officeId", "officeName", "closingDate", "deleted", "createdDate", "lastUpdatedDate", "createdByUserId",
"createdByUsername", "lastUpdatedByUserId", "lastUpdatedByUsername"));
private final String resourceNameForPermission = "GLCLOSURE";
private static final String RESOURCE_NAME_FOR_PERMISSION = "GLCLOSURE";
private final PlatformSecurityContext context;
private final GLClosureReadPlatformService glClosureReadPlatformService;
@@ -88,7 +88,7 @@ public class GLClosuresApiResource {
public String retrieveAllClosures(@Context final UriInfo uriInfo,
@QueryParam("officeId") @Parameter(name = "officeId") final Long officeId) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
final List<GLClosureData> glClosureDatas = this.glClosureReadPlatformService.retrieveAllGLClosures(officeId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -106,7 +106,7 @@ public class GLClosuresApiResource {
public String retreiveClosure(@PathParam("glClosureId") @Parameter(description = "glClosureId") final Long glClosureId,
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -85,7 +85,7 @@ public class GLAccountsApiResource {
"allowedAssetsTagOptions", "allowedLiabilitiesTagOptions", "allowedEquityTagOptions", "allowedIncomeTagOptions",
"allowedExpensesTagOptions", "creditAccounts", "debitAccounts"));
private final String resourceNameForPermission = "GLACCOUNT";
private static final String RESOURCE_NAME_FOR_PERMISSION = "GLACCOUNT";
private final PlatformSecurityContext context;
private final GLAccountReadPlatformService glAccountReadPlatformService;
@@ -111,7 +111,7 @@ public class GLAccountsApiResource {
public String retrieveNewAccountDetails(@Context final UriInfo uriInfo,
@QueryParam("type") @Parameter(description = "type") final Integer type) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
GLAccountData glAccountData = this.glAccountReadPlatformService.retrieveNewGLAccountDetails(type);
glAccountData = handleTemplate(glAccountData);
@@ -137,7 +137,7 @@ public class GLAccountsApiResource {
@QueryParam("disabled") @Parameter(description = "disabled") final Boolean disabled,
@QueryParam("fetchRunningBalance") @Parameter(description = "fetchRunningBalance") final boolean runningBalance) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
JournalEntryAssociationParametersData associationParametersData = new JournalEntryAssociationParametersData(false, runningBalance);
final List<GLAccountData> glAccountDatas = this.glAccountReadPlatformService.retrieveAllGLAccounts(type, searchParam, usage,
manualEntriesAllowed, disabled, associationParametersData);
@@ -159,7 +159,7 @@ public class GLAccountsApiResource {
@Context final UriInfo uriInfo,
@QueryParam("fetchRunningBalance") @Parameter(description = "fetchRunningBalance") final boolean runningBalance) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission);
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSION);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
JournalEntryAssociationParametersData associationParametersData = new JournalEntryAssociationParametersData(false, runningBalance);
@@ -18,8 +18,6 @@
*/
package org.apache.fineract.accounting.glaccount.domain;
import java.util.HashMap;
import java.util.Map;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
public enum GLAccountType {
@@ -43,7 +41,6 @@ public enum GLAccountType {
return this.code;
}
private static final Map<Integer, GLAccountType> intToEnumMap = new HashMap<>();
private static int minValue;
private static int maxValue;
@@ -53,7 +50,6 @@ public enum GLAccountType {
if (i == 0) {
minValue = type.value;
}
intToEnumMap.put(type.value, type);
if (minValue >= type.value) {
minValue = type.value;
}
@@ -86,9 +82,25 @@ public enum GLAccountType {
}
}
public static GLAccountType fromInt(final int i) {
final GLAccountType type = intToEnumMap.get(Integer.valueOf(i));
return type;
public static GLAccountType fromInt(final Integer v) {
if (v == null) {
return null;
}
switch (v) {
case 1:
return ASSET;
case 2:
return LIABILITY;
case 3:
return EQUITY;
case 4:
return INCOME;
case 5:
return EXPENSE;
default:
return null;
}
}
public static int getMinValue() {
@@ -170,8 +170,8 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
private void validateForAttachedProduct(Long glAccountId) {
String sql = "select count(*) from acc_product_mapping acc where acc.gl_account_id = ?";
try {
int count = this.jdbcTemplate.queryForObject(sql, Integer.class, glAccountId);
if (count > 0) {
Integer count = this.jdbcTemplate.queryForObject(sql, Integer.class, glAccountId);
if (count == null || count > 0) {
throw new GLAccountDisableException();
}
} catch (EmptyResultDataAccessException e) {
@@ -18,9 +18,6 @@
*/
package org.apache.fineract.accounting.journalentry.domain;
import java.util.HashMap;
import java.util.Map;
public enum JournalEntryType {
CREDIT(1, "journalEntryType.credit"), DEBIT(2, "journalEntrytType.debit");
@@ -41,16 +38,19 @@ public enum JournalEntryType {
return this.code;
}
private static final Map<Integer, JournalEntryType> intToEnumMap = new HashMap<>();
static {
for (final JournalEntryType type : JournalEntryType.values()) {
intToEnumMap.put(type.value, type);
public static JournalEntryType fromInt(final Integer v) {
if (v == null) {
return null;
}
}
public static JournalEntryType fromInt(final int i) {
return intToEnumMap.get(i);
switch (v) {
case 1:
return CREDIT;
case 2:
return DEBIT;
default:
return null;
}
}
@Override
@@ -59,11 +59,11 @@ public enum JournalEntryType {
}
public boolean isDebitType() {
return this.value.equals(JournalEntryType.DEBIT.getValue());
return this.equals(DEBIT);
}
public boolean isCreditType() {
return this.value.equals(JournalEntryType.CREDIT.getValue());
return this.equals(CREDIT);
}
}
@@ -18,9 +18,6 @@
*/
package org.apache.fineract.accounting.producttoaccountmapping.domain;
import java.util.HashMap;
import java.util.Map;
public enum PortfolioProductType {
LOAN(1, "productType.loan"), SAVING(2, "productType.saving"), CLIENT(5, "productType.client"), PROVISIONING(3,
@@ -47,33 +44,41 @@ public enum PortfolioProductType {
return this.code;
}
private static final Map<Integer, PortfolioProductType> intToEnumMap = new HashMap<>();
public static PortfolioProductType fromInt(final Integer v) {
if (v == null) {
return null;
}
static {
for (final PortfolioProductType type : PortfolioProductType.values()) {
intToEnumMap.put(type.value, type);
switch (v) {
case 1:
return LOAN;
case 2:
return SAVING;
case 3:
return CLIENT;
case 4:
return PROVISIONING;
case 5:
return SHARES;
default:
return null;
}
}
public static PortfolioProductType fromInt(final int i) {
final PortfolioProductType type = intToEnumMap.get(Integer.valueOf(i));
return type;
}
public boolean isSavingProduct() {
return this.value.equals(PortfolioProductType.SAVING.getValue());
return this.equals(SAVING);
}
public boolean isLoanProduct() {
return this.value.equals(PortfolioProductType.LOAN.getValue());
return this.equals(LOAN);
}
public boolean isClient() {
return this.value.equals(PortfolioProductType.CLIENT.getValue());
return this.equals(CLIENT);
}
public boolean isShareProduct() {
return this.value.equals(PortfolioProductType.SHARES.getValue());
return this.equals(SHARES);
}
}
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.accounting.common.AccountingConstants.CashAccountsForLoan;
@@ -99,7 +100,7 @@ public class ProductToGLAccountMappingHelper {
throw new ProductToGLAccountMappingNotFoundException(portfolioProductType, productId, accountTypeName);
}
} else {
if (!accountMapping.getGlAccount().getId().equals(accountId)) {
if (accountMapping.getGlAccount() != null && !Objects.equals(accountMapping.getGlAccount().getId(), accountId)) {
final GLAccount glAccount = getAccountByIdAndType(paramName, expectedAccountType, accountId);
changes.put(paramName, accountId);
accountMapping.setGlAccount(glAccount);
@@ -124,7 +125,7 @@ public class ProductToGLAccountMappingHelper {
ProductToGLAccountMapping newAccountMapping = new ProductToGLAccountMapping().setGlAccount(glAccount)
.setProductId(productId).setProductType(portfolioProductType.getValue()).setFinancialAccountType(accountTypeId);
this.accountMappingRepository.saveAndFlush(newAccountMapping);
} else if (!accountMapping.getGlAccount().getId().equals(accountId)) {
} else if (accountMapping.getGlAccount() != null && !Objects.equals(accountMapping.getGlAccount().getId(), accountId)) {
final GLAccount glAccount = getAccountByIdAndType(paramName, expectedAccountType, accountId);
changes.put(paramName, accountId);
accountMapping.setGlAccount(glAccount);
@@ -272,14 +273,11 @@ public class ProductToGLAccountMappingHelper {
this.accountMappingRepository.delete(chargeToIncomeAccountMapping);
}
}
// create new mappings
final Set<Long> incomingCharges = inputChargeToIncomeAccountMap.keySet();
incomingCharges.removeAll(existingCharges);
// incomingPaymentTypes now only contains the newly added
// payment Type mappings
for (final Long newCharge : incomingCharges) {
final Long newGLAccountId = inputChargeToIncomeAccountMap.get(newCharge);
saveChargeToFundSourceMapping(productId, newCharge, newGLAccountId, portfolioProductType, isPenalty);
// only the newly added
for (Map.Entry<Long, Long> entry : inputChargeToIncomeAccountMap.entrySet().stream()
.filter(e -> !existingCharges.contains(e.getKey())).toList()) {
saveChargeToFundSourceMapping(productId, entry.getKey(), entry.getValue(), portfolioProductType, isPenalty);
}
}
}
@@ -321,7 +319,7 @@ public class ProductToGLAccountMappingHelper {
}
// If input map is empty, delete all existing mappings
if (inputPaymentChannelFundSourceMap.size() == 0) {
if (inputPaymentChannelFundSourceMap.isEmpty()) {
this.accountMappingRepository.deleteAllInBatch(existingPaymentChannelToFundSourceMappings);
} /**
* Else, <br/>
@@ -348,14 +346,11 @@ public class ProductToGLAccountMappingHelper {
this.accountMappingRepository.delete(existingPaymentChannelToFundSourceMapping);
}
}
// create new mappings
final Set<Long> incomingPaymentTypes = inputPaymentChannelFundSourceMap.keySet();
incomingPaymentTypes.removeAll(existingPaymentTypes);
// incomingPaymentTypes now only contains the newly added
// payment Type mappings
for (final Long newPaymentType : incomingPaymentTypes) {
final Long newGLAccountId = inputPaymentChannelFundSourceMap.get(newPaymentType);
savePaymentChannelToFundSourceMapping(productId, newPaymentType, newGLAccountId, portfolioProductType);
// only the newly added
for (Map.Entry<Long, Long> entry : inputPaymentChannelFundSourceMap.entrySet().stream()
.filter(e -> !existingPaymentTypes.contains(e.getKey())).toList()) {
savePaymentChannelToFundSourceMapping(productId, entry.getKey(), entry.getValue(), portfolioProductType);
}
}
}
@@ -37,7 +37,6 @@ import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
@@ -112,7 +111,7 @@ public class BatchApiResource {
validateRequestMethodsAllowedOnInstanceType(requestList);
// Gets back the consolidated BatchResponse from BatchApiservice
List<BatchResponse> result = new ArrayList<>();
List<BatchResponse> result;
// If the request is to be handled as a Transaction. All requests will
// be rolled back on error
@@ -23,6 +23,7 @@ import static org.apache.http.HttpStatus.SC_OK;
import com.google.gson.Gson;
import com.jayway.jsonpath.JsonPathException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.github.resilience4j.core.functions.Either;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@@ -380,6 +381,7 @@ public class BatchApiServiceImpl implements BatchApiService {
return List.of(buildErrorResponse(requestId, statusCode, body, headers));
}
@SuppressFBWarnings(value = "BX_UNBOXING_IMMEDIATELY_REBOXED", justification = "TODO: fix this!")
private BatchResponse buildErrorResponse(Long requestId, Integer statusCode, String body, Set<Header> headers) {
return new BatchResponse().setRequestId(requestId).setStatusCode(statusCode == null ? SC_INTERNAL_SERVER_ERROR : statusCode)
.setBody(body == null ? "Request with id " + requestId + " was erroneous!" : body).setHeaders(headers);
@@ -65,7 +65,11 @@ public class CommandHandlerProvider implements ApplicationContextAware, Initiali
log.debug("Register command handler '{}' ...", commandHandlerName);
final CommandType commandType = applicationContext.findAnnotationOnBean(commandHandlerName, CommandType.class);
try {
registeredHandlers.put(commandType.entity() + "|" + commandType.action(), commandHandlerName);
if (commandType != null) {
registeredHandlers.put(commandType.entity() + "|" + commandType.action(), commandHandlerName);
} else {
log.error("Unable to register command handler '{}'!", commandHandlerName);
}
} catch (final Throwable th) {
log.error("Unable to register command handler '{}'!", commandHandlerName, th);
}
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.commands.service;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.infrastructure.accountnumberformat.service.AccountNumberFormatConstants;
import org.apache.fineract.portfolio.client.api.ClientApiConstants;
@@ -47,6 +48,7 @@ public class CommandWrapperBuilder {
private String jobName;
private String idempotencyKey;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "TODO: fix this!")
public CommandWrapper build() {
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, this.entityName,
this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId, this.templateId,
@@ -18,10 +18,12 @@
*/
package org.apache.fineract.infrastructure.cache.service;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.cache.CacheApiConstants;
@@ -105,7 +107,7 @@ public class RuntimeDelegatingCacheManager implements CacheManager, Initializing
}
currentCacheManager = ehCacheManager;
if (currentCacheManager.getCacheNames().size() == 0) {
if (currentCacheManager.getCacheNames().isEmpty()) {
log.error("No caches configured for activated CacheManager {}", currentCacheManager);
}
}
@@ -115,10 +117,17 @@ public class RuntimeDelegatingCacheManager implements CacheManager, Initializing
return changes;
}
@SuppressFBWarnings(value = "DCN_NULLPOINTER_EXCEPTION", justification = "TODO: fix this!")
private void clearEhCache() {
Iterable<String> cacheNames = ehCacheManager.getCacheNames();
for (String cacheName : cacheNames) {
ehCacheManager.getCache(cacheName).clear();
try {
if (Objects.nonNull(ehCacheManager.getCache(cacheName))) {
Objects.requireNonNull(ehCacheManager.getCache(cacheName)).clear();
}
} catch (NullPointerException npe) {
log.warn(npe.getMessage());
}
}
}
}
@@ -38,6 +38,8 @@ public class FineractProperties {
private String idempotencyKeyHeaderName;
private Boolean insecureHttpClient;
private FineractTenantProperties tenant;
private FineractModeProperties mode;
@@ -39,6 +39,6 @@ public class IdempotentCommandProcessFailedException extends AbstractIdempotentC
@NotNull
public Integer getStatusCode() {
// If the database inconsistent we return http 500 instead of null pointer exception
return statusCode == null ? SC_INTERNAL_SERVER_ERROR : statusCode;
return statusCode == null ? Integer.valueOf(SC_INTERNAL_SERVER_ERROR) : statusCode;
}
}
@@ -736,6 +736,7 @@ public class JsonParserHelper {
/***
* TODO: Vishwas move all Locale related code to a separate Utils class
***/
@SuppressWarnings("StringSplitter")
public static Locale localeFromString(final String localeAsString) {
if (StringUtils.isBlank(localeAsString)) {
@@ -754,16 +755,16 @@ public class JsonParserHelper {
final String[] localeParts = localeAsString.split("_");
if (localeParts != null && localeParts.length == 1) {
if (localeParts.length == 1) {
languageCode = localeParts[0];
}
if (localeParts != null && localeParts.length == 2) {
if (localeParts.length == 2) {
languageCode = localeParts[0];
countryCode = localeParts[1];
}
if (localeParts != null && localeParts.length == 3) {
if (localeParts.length == 3) {
languageCode = localeParts[0];
countryCode = localeParts[1];
variantCode = localeParts[2];
@@ -23,10 +23,10 @@ import java.util.List;
public class Page<E> implements Serializable {
private final int totalFilteredRecords;
private final Integer totalFilteredRecords;
private final List<E> pageItems;
public Page(final List<E> pageItems, final int totalFilteredRecords) {
public Page(final List<E> pageItems, final Integer totalFilteredRecords) {
this.pageItems = pageItems;
this.totalFilteredRecords = totalFilteredRecords;
}
@@ -19,6 +19,7 @@
package org.apache.fineract.infrastructure.core.service;
import java.util.Locale;
import java.util.Objects;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@@ -38,4 +39,25 @@ public class PagedLocalRequest<T> extends PagedRequest<T> {
public Locale getLocaleObject() {
return locale == null ? null : JsonParserHelper.localeFromString(locale);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || !(o instanceof PagedLocalRequest)) {
return false;
}
if (!super.equals(o)) {
return false;
}
PagedLocalRequest<?> that = (PagedLocalRequest<?>) o;
return Objects.equals(dateFormat, that.dateFormat) && Objects.equals(dateTimeFormat, that.dateTimeFormat)
&& Objects.equals(locale, that.locale);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), dateFormat, dateTimeFormat, locale);
}
}
@@ -37,7 +37,7 @@ public class PagedRequest<T> {
private int page;
private int size = DEFAULT_PAGE_SIZE;
private List<SortOrder> sorts = new ArrayList<>();
private final List<SortOrder> sorts = new ArrayList<>();
public Optional<T> getRequest() {
return Optional.ofNullable(request);
@@ -45,7 +45,7 @@ public class PaginationHelper {
// determine how many rows are available
final String sqlCountRows = sqlGenerator.countLastExecutedQueryResult(sqlFetchRows);
final int totalFilteredRecords;
final Integer totalFilteredRecords;
if (databaseTypeResolver.isMySQL()) {
totalFilteredRecords = jt.queryForObject(sqlCountRows, Integer.class); // NOSONAR
} else {
@@ -91,9 +91,7 @@ public enum JavaType {
OBJECT(Object.class), //
;
public static final JavaType[] VALUES = values();
private static final Map<Class<?>, JavaType> BY_TYPE = Arrays.stream(VALUES).filter(e -> e.type != null)
private static final Map<Class<?>, JavaType> BY_TYPE = Arrays.stream(values()).filter(e -> e.type != null)
.collect(Collectors.toMap(JavaType::getTypeClass, v -> v));
private final Class<?> type;
@@ -244,9 +242,9 @@ public enum JavaType {
// have to do this first to catch custom collection and map types;
// on resolve we figure out if these custom types are
// persistence-capable
for (Class<?> aType : BY_TYPE.keySet()) {
if (aType.isAssignableFrom(type)) {
return BY_TYPE.get(aType);
for (Map.Entry<Class<?>, JavaType> entry : BY_TYPE.entrySet()) {
if (entry.getKey().isAssignableFrom(type)) {
return entry.getValue();
}
}
@@ -136,11 +136,19 @@ public enum JdbcJavaType {
for (JdbcJavaType type : values()) {
DialectType dialectType = type.getDialectType(dialect);
if (dialectType.getNameResolved().equals(name)) {
// NOTE: make MySQL systems happy aka TINYINT vs BOOLEAN issue!
if (type.canBooleanType(dialect)) {
return BOOLEAN;
}
return type;
}
if (dialectType.alterNames != null) {
for (String alterName : dialectType.alterNames) {
if (alterName.equals(name)) {
// NOTE: make MySQL systems happy aka TINYINT vs BOOLEAN issue!
if (type.canBooleanType(dialect)) {
return BOOLEAN;
}
return type;
}
}
@@ -48,14 +48,15 @@ public class ExternalEventConfigurationWritePlatformServiceImpl implements Exter
final Map<String, Object> changes = new HashMap<>();
final Map<String, Boolean> changedConfigurations = new HashMap<>();
final List<ExternalEventConfiguration> modifiedConfigurations = new ArrayList<>();
for (final String eventType : commandConfigurations.keySet()) {
for (Map.Entry<String, Boolean> entry : commandConfigurations.entrySet()) {
final ExternalEventConfiguration configuration = repository
.findExternalEventConfigurationByTypeWithNotFoundDetection(eventType);
final boolean canEnable = commandConfigurations.get(eventType).booleanValue();
configuration.setEnabled(canEnable);
changedConfigurations.put(eventType, canEnable);
.findExternalEventConfigurationByTypeWithNotFoundDetection(entry.getKey());
configuration.setEnabled(entry.getValue());
changedConfigurations.put(entry.getKey(), entry.getValue());
modifiedConfigurations.add(configuration);
}
if (!modifiedConfigurations.isEmpty()) {
this.repository.saveAll(modifiedConfigurations);
}
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.infrastructure.security.utils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
@@ -28,6 +29,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -48,17 +50,18 @@ public class ColumnValidator {
this.jdbcTemplate = jdbcTemplate;
}
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "TODO: fix this!")
private void validateColumn(Map<String, Set<String>> tableColumnMap) {
Connection connection = null;
try {
connection = this.jdbcTemplate.getDataSource().getConnection();
connection = Objects.requireNonNull(this.jdbcTemplate.getDataSource()).getConnection();
DatabaseMetaData dbMetaData = connection.getMetaData();
ResultSet resultSet = null;
for (Map.Entry<String, Set<String>> entry : tableColumnMap.entrySet()) {
Set<String> columns = entry.getValue();
resultSet = dbMetaData.getColumns(null, null, entry.getKey(), null);
ResultSet resultSet = dbMetaData.getColumns(null, null, entry.getKey(), null);
Set<String> tableColumns = getTableColumns(resultSet);
if (columns.size() > 0 && tableColumns.size() == 0) {
if (!columns.isEmpty() && tableColumns.isEmpty()) {
throw new SQLInjectionException();
}
for (String requestedColumn : columns) {
@@ -111,17 +114,19 @@ public class ColumnValidator {
private static Map<String, Set<String>> getTableColumnMap(String schema, Map<String, Set<String>> tableColumnAliasMap) {
Map<String, Set<String>> tableColumnMap = new HashMap<>();
schema = schema.substring(schema.indexOf("from"));
for (String alias : tableColumnAliasMap.keySet()) {
int index = schema.indexOf(" " + alias + " ");
for (Map.Entry<String, Set<String>> entry : tableColumnAliasMap.entrySet()) {
int index = schema.indexOf(" " + entry.getKey() + " ");
if (index > -1) {
int startPos = 0;
int startPos;
startPos = schema.substring(0, index - 1).lastIndexOf(' ', index);
Set<String> columns = tableColumnAliasMap.get(alias);
Set<String> columns = entry.getValue();
tableColumnMap.put(schema.substring(startPos, index).trim(), columns);
} else {
throw new SQLInjectionException();
}
}
return tableColumnMap;
}
@@ -31,20 +31,21 @@ public enum HolidayStatusType {
private final Integer value;
private final String code;
public static HolidayStatusType fromInt(final Integer type) {
HolidayStatusType enumeration = HolidayStatusType.INVALID;
switch (type) {
public static HolidayStatusType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 100:
enumeration = HolidayStatusType.PENDING_FOR_ACTIVATION;
break;
return PENDING_FOR_ACTIVATION;
case 300:
enumeration = HolidayStatusType.ACTIVE;
break;
return ACTIVE;
case 600:
enumeration = HolidayStatusType.DELETED;
break;
return DELETED;
default:
return INVALID;
}
return enumeration;
}
HolidayStatusType(final Integer value, final String code) {
@@ -52,10 +53,6 @@ public enum HolidayStatusType {
this.code = code;
}
public boolean hasStateOf(final HolidayStatusType state) {
return this.value.equals(state.getValue());
}
public Integer getValue() {
return this.value;
}
@@ -31,17 +31,19 @@ public enum RescheduleType {
this.code = code;
}
public static RescheduleType fromInt(int rescheduleTypeValue) {
RescheduleType enumerration = RescheduleType.INVALID;
switch (rescheduleTypeValue) {
public static RescheduleType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 1:
enumerration = RescheduleType.RESCHEDULETONEXTREPAYMENTDATE;
break;
return RESCHEDULETONEXTREPAYMENTDATE;
case 2:
enumerration = RescheduleType.RESCHEDULETOSPECIFICDATE;
break;
return RESCHEDULETOSPECIFICDATE;
default:
return INVALID;
}
return enumerration;
}
public boolean isRescheduleToSpecificDate() {
@@ -18,9 +18,6 @@
*/
package org.apache.fineract.portfolio.account;
import java.util.ArrayList;
import java.util.List;
public enum PortfolioAccountType {
INVALID(0, "accountType.invalid"), //
@@ -43,20 +40,9 @@ public enum PortfolioAccountType {
return this.code;
}
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final PortfolioAccountType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
}
public static PortfolioAccountType fromInt(final Integer type) {
PortfolioAccountType enumType = PortfolioAccountType.INVALID;
PortfolioAccountType enumType = INVALID;
if (type != null) {
switch (type) {
case 1:
@@ -65,16 +51,20 @@ public enum PortfolioAccountType {
case 2:
enumType = SAVINGS;
break;
default:
enumType = INVALID;
}
}
return enumType;
}
// TODO: bad practice and unnecessary code! why not just use the enum values themselves!?!
public boolean isSavingsAccount() {
return this.value.equals(2);
return this.equals(SAVINGS);
}
// TODO: bad practice and unnecessary code! why not just use the enum values themselves!?!
public boolean isLoanAccount() {
return this.value.equals(1);
return this.equals(LOAN);
}
}
@@ -272,12 +272,14 @@ public final class CalendarUtils {
humanReadable += " on ";
final WeekDayList weekDayList = recur.getDayList();
StringBuilder sb = new StringBuilder();
for (@SuppressWarnings("rawtypes")
final Iterator iterator = weekDayList.iterator(); iterator.hasNext();) {
final WeekDay weekDay = (WeekDay) iterator.next();
humanReadable += DayNameEnum.from(weekDay.getDay().name()).getCode();
sb.append(DayNameEnum.from(weekDay.getDay().name()).getCode());
}
humanReadable += sb.toString();
} else if (recur.getFrequency().equals(Recur.Frequency.MONTHLY)) {
NumberList nthDays = recur.getSetPosList();
@@ -684,13 +686,15 @@ public final class CalendarUtils {
* @return
*/
public static String getSqlCalendarTypeOptionsInString(final List<Integer> calendarTypeOptions) {
String sqlCalendarTypeOptions = "";
final int size = calendarTypeOptions.size();
for (int i = 0; i < size - 1; i++) {
sqlCalendarTypeOptions += calendarTypeOptions.get(i).toString() + ",";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < calendarTypeOptions.size() - 1; i++) {
sb.append(calendarTypeOptions.get(i).toString() + ",");
}
sqlCalendarTypeOptions += calendarTypeOptions.get(size - 1).toString();
return sqlCalendarTypeOptions;
sb.append(calendarTypeOptions.get(calendarTypeOptions.size() - 1).toString());
return sb.toString();
}
public static LocalDate getRecentEligibleMeetingDate(final String recurringRule, final LocalDate seedDate,
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.common.domain;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
*
@@ -51,15 +50,9 @@ public enum DaysInMonthType {
return this.code;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final DaysInMonthType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
public static DaysInMonthType fromInt(final Integer type) {
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.common.domain;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
*
@@ -55,15 +54,9 @@ public enum DaysInYearType {
return this.code;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final DaysInYearType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
public static DaysInYearType fromInt(final Integer type) {
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.common.domain;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public enum PeriodFrequencyType {
@@ -46,62 +45,59 @@ public enum PeriodFrequencyType {
return this.code;
}
public static PeriodFrequencyType fromInt(final Integer frequency) {
PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.INVALID;
if (frequency != null) {
switch (frequency) {
case 0:
repaymentFrequencyType = PeriodFrequencyType.DAYS;
break;
case 1:
repaymentFrequencyType = PeriodFrequencyType.WEEKS;
break;
case 2:
repaymentFrequencyType = PeriodFrequencyType.MONTHS;
break;
case 3:
repaymentFrequencyType = PeriodFrequencyType.YEARS;
break;
case 4:
repaymentFrequencyType = PeriodFrequencyType.WHOLE_TERM;
break;
}
public static PeriodFrequencyType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 0:
return DAYS;
case 1:
return WEEKS;
case 2:
return MONTHS;
case 3:
return YEARS;
case 4:
return WHOLE_TERM;
default:
return INVALID;
}
return repaymentFrequencyType;
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isMonthly() {
return this.value.equals(PeriodFrequencyType.MONTHS.getValue());
return this.equals(MONTHS);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isYearly() {
return this.value.equals(PeriodFrequencyType.YEARS.getValue());
return this.equals(YEARS);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isWeekly() {
return this.value.equals(PeriodFrequencyType.WEEKS.getValue());
return this.equals(WEEKS);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isDaily() {
return this.value.equals(PeriodFrequencyType.DAYS.getValue());
return this.equals(DAYS);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isWholeTerm() {
return this.value.equals(PeriodFrequencyType.WHOLE_TERM.getValue());
return this.equals(WHOLE_TERM);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isInvalid() {
return this.value.equals(PeriodFrequencyType.INVALID.getValue());
return this.equals(INVALID);
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final PeriodFrequencyType enumType : values()) {
if (!enumType.isInvalid()) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
* An enumeration of different options available on account closure {@link FixedDepositAccount} &amp;
@@ -49,63 +48,57 @@ public enum DepositAccountOnClosureType {
return this.code;
}
public static DepositAccountOnClosureType fromInt(final Integer closureTypeValue) {
if (closureTypeValue == null) {
return DepositAccountOnClosureType.INVALID;
public static DepositAccountOnClosureType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
DepositAccountOnClosureType accountOnClosureType = DepositAccountOnClosureType.INVALID;
switch (closureTypeValue) {
switch (v) {
case 100:
accountOnClosureType = DepositAccountOnClosureType.WITHDRAW_DEPOSIT;
break;
return WITHDRAW_DEPOSIT;
case 200:
accountOnClosureType = DepositAccountOnClosureType.TRANSFER_TO_SAVINGS;
break;
return TRANSFER_TO_SAVINGS;
case 300:
accountOnClosureType = DepositAccountOnClosureType.REINVEST_PRINCIPAL_AND_INTEREST;
break;
return REINVEST_PRINCIPAL_AND_INTEREST;
case 400:
accountOnClosureType = DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY;
break;
return REINVEST_PRINCIPAL_ONLY;
default:
return INVALID;
}
return accountOnClosureType;
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isWithdarwDeposit() {
return this.value.equals(DepositAccountOnClosureType.WITHDRAW_DEPOSIT.getValue());
return this.equals(WITHDRAW_DEPOSIT);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isTransferToSavings() {
return this.value.equals(DepositAccountOnClosureType.TRANSFER_TO_SAVINGS.getValue());
return this.equals(TRANSFER_TO_SAVINGS);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isReinvest() {
return this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_AND_INTEREST.getValue())
|| this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY.getValue());
return this.equals(REINVEST_PRINCIPAL_AND_INTEREST) || this.equals(REINVEST_PRINCIPAL_ONLY);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isReinvestPrincipal() {
return this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_ONLY.getValue());
return this.equals(REINVEST_PRINCIPAL_ONLY);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isReinvestPrincipalAndInterest() {
return this.value.equals(DepositAccountOnClosureType.REINVEST_PRINCIPAL_AND_INTEREST.getValue());
return this.equals(REINVEST_PRINCIPAL_AND_INTEREST);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isInvalid() {
return this.value.equals(DepositAccountOnClosureType.INVALID.getValue());
return this.equals(INVALID);
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final DepositAccountOnClosureType enumType : values()) {
if (!enumType.isInvalid()) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
}
@@ -43,31 +43,28 @@ public enum DepositAccountOnHoldTransactionType {
return this.code;
}
public static DepositAccountOnHoldTransactionType fromInt(final Integer transactionType) {
if (transactionType == null) {
return DepositAccountOnHoldTransactionType.INVALID;
public static DepositAccountOnHoldTransactionType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
DepositAccountOnHoldTransactionType savingsAccountTransactionType = DepositAccountOnHoldTransactionType.INVALID;
switch (transactionType) {
switch (v) {
case 1:
savingsAccountTransactionType = DepositAccountOnHoldTransactionType.HOLD;
break;
return HOLD;
case 2:
savingsAccountTransactionType = DepositAccountOnHoldTransactionType.RELEASE;
break;
return RELEASE;
default:
return INVALID;
}
return savingsAccountTransactionType;
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isHold() {
return this.value.equals(DepositAccountOnHoldTransactionType.HOLD.getValue());
return this.equals(HOLD);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isRelease() {
return this.value.equals(DepositAccountOnHoldTransactionType.RELEASE.getValue());
return this.equals(RELEASE);
}
}
@@ -48,44 +48,48 @@ public enum DepositAccountType {
return this.code;
}
public static DepositAccountType fromInt(final Integer transactionType) {
if (transactionType == null) {
return DepositAccountType.INVALID;
public static DepositAccountType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
DepositAccountType depositAccountType = DepositAccountType.INVALID;
switch (transactionType) {
switch (v) {
case 100:
depositAccountType = DepositAccountType.SAVINGS_DEPOSIT;
break;
return SAVINGS_DEPOSIT;
case 200:
depositAccountType = DepositAccountType.FIXED_DEPOSIT;
break;
return FIXED_DEPOSIT;
case 300:
depositAccountType = DepositAccountType.RECURRING_DEPOSIT;
break;
return RECURRING_DEPOSIT;
case 400:
depositAccountType = DepositAccountType.CURRENT_DEPOSIT;
break;
return CURRENT_DEPOSIT;
default:
return INVALID;
}
return depositAccountType;
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isSavingsDeposit() {
return this.value.equals(DepositAccountType.SAVINGS_DEPOSIT.getValue());
return this.equals(SAVINGS_DEPOSIT);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isFixedDeposit() {
return this.value.equals(DepositAccountType.FIXED_DEPOSIT.getValue());
return this.equals(FIXED_DEPOSIT);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isRecurringDeposit() {
return this.value.equals(DepositAccountType.RECURRING_DEPOSIT.getValue());
return this.equals(RECURRING_DEPOSIT);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isCurrentDeposit() {
return this.value.equals(DepositAccountType.CURRENT_DEPOSIT.getValue());
return this.equals(CURRENT_DEPOSIT);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isInvalid() {
return this.equals(INVALID);
}
@Override
@@ -94,28 +98,15 @@ public enum DepositAccountType {
}
public String resourceName() {
String resourceName;
switch (this) {
case FIXED_DEPOSIT:
resourceName = DepositsApiConstants.FIXED_DEPOSIT_ACCOUNT_RESOURCE_NAME;
break;
return DepositsApiConstants.FIXED_DEPOSIT_ACCOUNT_RESOURCE_NAME;
case RECURRING_DEPOSIT:
resourceName = DepositsApiConstants.RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME;
break;
return DepositsApiConstants.RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME;
case SAVINGS_DEPOSIT:
resourceName = DepositsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
break;
return DepositsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
default:
resourceName = "INVALID";
break;
return "INVALID";
}
return resourceName;
}
public boolean isInvalid() {
return this.value.equals(DepositAccountType.INVALID.value);
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
* An enumeration of supported calendar periods used in savings.
@@ -45,41 +44,38 @@ public enum PreClosurePenalInterestOnType {
return this.code;
}
public static PreClosurePenalInterestOnType fromInt(final Integer type) {
PreClosurePenalInterestOnType penalInterestType = PreClosurePenalInterestOnType.INVALID;
if (type != null) {
switch (type) {
case 1:
penalInterestType = PreClosurePenalInterestOnType.WHOLE_TERM;
break;
case 2:
penalInterestType = PreClosurePenalInterestOnType.TILL_PREMATURE_WITHDRAWAL;
break;
}
public static PreClosurePenalInterestOnType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 1:
return WHOLE_TERM;
case 2:
return TILL_PREMATURE_WITHDRAWAL;
default:
return INVALID;
}
return penalInterestType;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final PreClosurePenalInterestOnType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isInvalid() {
return this.value.equals(PreClosurePenalInterestOnType.INVALID.value);
return this.equals(INVALID);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isWholeTerm() {
return this.value.equals(PreClosurePenalInterestOnType.WHOLE_TERM.getValue());
return this.equals(WHOLE_TERM);
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isTillPrematureWithdrawal() {
return this.value.equals(PreClosurePenalInterestOnType.TILL_PREMATURE_WITHDRAWAL.getValue());
return this.equals(TILL_PREMATURE_WITHDRAWAL);
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
* An enumeration of supported calendar periods used in savings.
@@ -45,32 +44,27 @@ public enum RecurringDepositType {
return this.code;
}
public static RecurringDepositType fromInt(final Integer type) {
RecurringDepositType rdType = RecurringDepositType.INVALID;
if (type != null) {
switch (type) {
case 1:
rdType = RecurringDepositType.VOLUNTARY;
break;
case 2:
rdType = RecurringDepositType.MANDATORY;
break;
}
public static RecurringDepositType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 1:
return VOLUNTARY;
case 2:
return MANDATORY;
default:
return INVALID;
}
return rdType;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final RecurringDepositType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isInvalid() {
return this.value.equals(RecurringDepositType.INVALID.value);
}
@@ -51,9 +51,7 @@ public enum SavingsAccountTransactionType {
AMOUNT_HOLD(20, "savingsAccountTransactionType.onHold", TransactionEntryType.DEBIT), //
AMOUNT_RELEASE(21, "savingsAccountTransactionType.release", TransactionEntryType.CREDIT); //
public static final SavingsAccountTransactionType[] VALUES = values();
private static final Map<Integer, SavingsAccountTransactionType> BY_ID = Arrays.stream(VALUES)
private static final Map<Integer, SavingsAccountTransactionType> BY_ID = Arrays.stream(values())
.collect(Collectors.toMap(SavingsAccountTransactionType::getValue, v -> v));
private final int value;
@@ -195,6 +193,6 @@ public enum SavingsAccountTransactionType {
@NotNull
public static List<SavingsAccountTransactionType> getFiltered(Predicate<SavingsAccountTransactionType> filter) {
return Arrays.stream(VALUES).filter(filter).toList();
return Arrays.stream(values()).filter(filter).toList();
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
* <p>
@@ -28,18 +27,15 @@ import java.util.List;
*/
public enum SavingsCompoundingInterestPeriodType {
INVALID(0, "savingsCompoundingInterestPeriodType.invalid"), //
DAILY(1, "savingsCompoundingInterestPeriodType.daily"), //
// WEEKLY(2, "savingsCompoundingInterestPeriodType.weekly"), //
// BIWEEKLY(3, "savingsCompoundingInterestPeriodType.biweekly"), //
INVALID(0, "savingsCompoundingInterestPeriodType.invalid"), DAILY(1, "savingsCompoundingInterestPeriodType.daily"),
// WEEKLY(2, "savingsCompoundingInterestPeriodType.weekly"),
// BIWEEKLY(3, "savingsCompoundingInterestPeriodType.biweekly"),
MONTHLY(4, "savingsCompoundingInterestPeriodType.monthly"),
QUATERLY(5, "savingsCompoundingInterestPeriodType.quarterly"), //
BI_ANNUAL(6, "savingsCompoundingInterestPeriodType.biannual"), //
ANNUAL(7, "savingsCompoundingInterestPeriodType.annual"); //
QUATERLY(5, "savingsCompoundingInterestPeriodType.quarterly"), BI_ANNUAL(6, "savingsCompoundingInterestPeriodType.biannual"), ANNUAL(7,
"savingsCompoundingInterestPeriodType.annual");
// NO_COMPOUNDING_SIMPLE_INTEREST(8,
// "savingsCompoundingInterestPeriodType.nocompounding");
// NO_COMPOUNDING_SIMPLE_INTEREST(8, "savingsCompoundingInterestPeriodType.nocompounding");
private final Integer value;
private final String code;
@@ -57,50 +53,35 @@ public enum SavingsCompoundingInterestPeriodType {
return this.code;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final SavingsCompoundingInterestPeriodType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
public static SavingsCompoundingInterestPeriodType fromInt(final Integer type) {
SavingsCompoundingInterestPeriodType repaymentFrequencyType = SavingsCompoundingInterestPeriodType.INVALID;
if (type != null) {
switch (type) {
case 1:
repaymentFrequencyType = SavingsCompoundingInterestPeriodType.DAILY;
break;
case 2:
// repaymentFrequencyType =
// SavingsCompoundingInterestPeriodType.WEEKLY;
break;
case 3:
// repaymentFrequencyType =
// SavingsCompoundingInterestPeriodType.BIWEEKLY;
break;
case 4:
repaymentFrequencyType = SavingsCompoundingInterestPeriodType.MONTHLY;
break;
case 5:
repaymentFrequencyType = SavingsCompoundingInterestPeriodType.QUATERLY;
break;
case 6:
repaymentFrequencyType = SavingsCompoundingInterestPeriodType.BI_ANNUAL;
break;
case 7:
repaymentFrequencyType = SavingsCompoundingInterestPeriodType.ANNUAL;
break;
case 8:
// repaymentFrequencyType =
// SavingsCompoundingInterestPeriodType.NO_COMPOUNDING_SIMPLE_INTEREST;
break;
}
public static SavingsCompoundingInterestPeriodType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 1:
return DAILY;
// case 2:
// return WEEKLY;
// case 3:
// return BIWEEKLY;
case 4:
return MONTHLY;
case 5:
return QUATERLY;
case 6:
return BI_ANNUAL;
case 7:
return ANNUAL;
// case 8:
// return NO_COMPOUNDING_SIMPLE_INTEREST;
default:
return INVALID;
}
return repaymentFrequencyType;
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
*
@@ -51,29 +50,23 @@ public enum SavingsInterestCalculationDaysInYearType {
return this.code;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final SavingsInterestCalculationDaysInYearType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
public static SavingsInterestCalculationDaysInYearType fromInt(final Integer type) {
SavingsInterestCalculationDaysInYearType repaymentFrequencyType = SavingsInterestCalculationDaysInYearType.INVALID;
if (type != null) {
switch (type) {
case 360:
repaymentFrequencyType = SavingsInterestCalculationDaysInYearType.DAYS_360;
break;
case 365:
repaymentFrequencyType = SavingsInterestCalculationDaysInYearType.DAYS_365;
break;
}
public static SavingsInterestCalculationDaysInYearType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 360:
return DAYS_360;
case 365:
return DAYS_365;
default:
return INVALID;
}
return repaymentFrequencyType;
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
*
@@ -64,29 +63,23 @@ public enum SavingsInterestCalculationType {
return this.code;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final SavingsInterestCalculationType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
public static SavingsInterestCalculationType fromInt(final Integer type) {
SavingsInterestCalculationType repaymentFrequencyType = SavingsInterestCalculationType.INVALID;
if (type != null) {
switch (type) {
case 1:
repaymentFrequencyType = SavingsInterestCalculationType.DAILY_BALANCE;
break;
case 2:
repaymentFrequencyType = SavingsInterestCalculationType.AVERAGE_DAILY_BALANCE;
break;
}
public static SavingsInterestCalculationType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 1:
return DAILY_BALANCE;
case 2:
return AVERAGE_DAILY_BALANCE;
default:
return INVALID;
}
return repaymentFrequencyType;
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
* An enumeration of supported calendar periods used in savings.
@@ -48,39 +47,32 @@ public enum SavingsPeriodFrequencyType {
return this.code;
}
public static SavingsPeriodFrequencyType fromInt(final Integer type) {
SavingsPeriodFrequencyType repaymentFrequencyType = SavingsPeriodFrequencyType.INVALID;
if (type != null) {
switch (type) {
case 0:
repaymentFrequencyType = SavingsPeriodFrequencyType.DAYS;
break;
case 1:
repaymentFrequencyType = SavingsPeriodFrequencyType.WEEKS;
break;
case 2:
repaymentFrequencyType = SavingsPeriodFrequencyType.MONTHS;
break;
case 3:
repaymentFrequencyType = SavingsPeriodFrequencyType.YEARS;
break;
}
public static SavingsPeriodFrequencyType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 0:
return DAYS;
case 1:
return WEEKS;
case 2:
return MONTHS;
case 3:
return YEARS;
default:
return INVALID;
}
return repaymentFrequencyType;
}
// TODO: why not just use the enum values... just more boilerplate code here!!
public boolean isInvalid() {
return this.value.equals(SavingsPeriodFrequencyType.INVALID.value);
return this.equals(INVALID);
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final SavingsPeriodFrequencyType enumType : values()) {
if (!enumType.isInvalid()) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
/**
* The interest posting period is the span of time at the end of which savings earned but not yet credited/posted in a
@@ -49,38 +48,29 @@ public enum SavingsPostingInterestPeriodType {
return this.code;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final SavingsPostingInterestPeriodType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
public static SavingsPostingInterestPeriodType fromInt(final Integer type) {
SavingsPostingInterestPeriodType repaymentFrequencyType = SavingsPostingInterestPeriodType.INVALID;
if (type != null) {
switch (type) {
case 1:
repaymentFrequencyType = SavingsPostingInterestPeriodType.DAILY;
break;
case 4:
repaymentFrequencyType = SavingsPostingInterestPeriodType.MONTHLY;
break;
case 5:
repaymentFrequencyType = SavingsPostingInterestPeriodType.QUATERLY;
break;
case 6:
repaymentFrequencyType = SavingsPostingInterestPeriodType.BIANNUAL;
break;
case 7:
repaymentFrequencyType = SavingsPostingInterestPeriodType.ANNUAL;
break;
}
public static SavingsPostingInterestPeriodType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
switch (v) {
case 1:
return DAILY;
case 4:
return MONTHLY;
case 5:
return QUATERLY;
case 6:
return BIANNUAL;
case 7:
return ANNUAL;
default:
return INVALID;
}
return repaymentFrequencyType;
}
}
@@ -18,8 +18,7 @@
*/
package org.apache.fineract.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public enum SavingsWithdrawalFeesType {
@@ -43,28 +42,23 @@ public enum SavingsWithdrawalFeesType {
return this.code;
}
// TODO: do we really need this?!?
public static Object[] integerValues() {
final List<Integer> values = new ArrayList<>();
for (final SavingsWithdrawalFeesType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
return Arrays.stream(values()).filter(value -> !INVALID.equals(value)).map(value -> value.value).toList().toArray();
}
public static SavingsWithdrawalFeesType fromInt(final Integer type) {
public static SavingsWithdrawalFeesType fromInt(final Integer v) {
if (v == null) {
return INVALID;
}
SavingsWithdrawalFeesType withdrawalFeeType = SavingsWithdrawalFeesType.INVALID;
switch (type) {
switch (v) {
case 1:
withdrawalFeeType = FLAT;
break;
return FLAT;
case 2:
withdrawalFeeType = PERCENT_OF_AMOUNT;
break;
return PERCENT_OF_AMOUNT;
default:
return INVALID;
}
return withdrawalFeeType;
}
}