FINERACT-2181: Refactor code quality

This commit is contained in:
a7med3del1973
2025-06-03 10:47:39 +02:00
committed by Adam Saghy
parent a308a96bed
commit 9e12e3b1cd
13 changed files with 31 additions and 32 deletions
@@ -18,6 +18,7 @@
*/ */
package com.acme.fineract.portfolio.note.service; package com.acme.fineract.portfolio.note.service;
import java.util.Collections;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.portfolio.note.data.NoteData; import org.apache.fineract.portfolio.note.data.NoteData;
@@ -43,6 +44,6 @@ public class AcmeNoteReadPlatformService implements NoteReadPlatformService, Ini
@Override @Override
public List<NoteData> retrieveNotesByResource(Long resourceId, Integer noteTypeId) { public List<NoteData> retrieveNotesByResource(Long resourceId, Integer noteTypeId) {
return null; return Collections.emptyList();
} }
} }
@@ -42,7 +42,7 @@ public class AcmeNoteServiceStepDefinitions implements En {
}); });
When("/^The user retrieves the service of interface class (.*)$/", (String interfaceClassName) -> { When("/^The user retrieves the service of interface class (.*)$/", (String interfaceClassName) -> {
contextRunner.run((ctx) -> { contextRunner.run(ctx -> {
this.interfaceClass = Class.forName(interfaceClassName.trim()); this.interfaceClass = Class.forName(interfaceClassName.trim());
assertThat(this.interfaceClass.isInterface()).isTrue(); assertThat(this.interfaceClass.isInterface()).isTrue();
@@ -40,7 +40,7 @@ final class AccrualAccountingApiResourceSwagger {
public String locale; public String locale;
@Schema(example = "dd MMMM yyyy") @Schema(example = "dd MMMM yyyy")
public String dateFormat; public String dateFormat;
@Schema(example = "04 June 2014", description = "which specifies periodic accruals should happen till the given Date", required = true) @Schema(example = "04 June 2014", description = "which specifies periodic accruals should happen till the given Date")
public String tillDate; public String tillDate;
} }
@@ -126,7 +126,7 @@ public class GLClosuresApiResource {
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update an Accounting closure", description = "Once an accounting closure is created, only the comments associated with it may be edited") @Operation(summary = "Update an Accounting closure", description = "Once an accounting closure is created, only the comments associated with it may be edited")
@RequestBody(content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PutGlClosuresRequest.class, required = true))) @RequestBody(content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PutGlClosuresRequest.class)))
@ApiResponses({ @ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PutGlClosuresResponse.class))) }) @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GLClosuresApiResourceSwagger.PutGlClosuresResponse.class))) })
public CommandProcessingResult updateGLClosure(@PathParam("glClosureId") @Parameter(description = "glClosureId") final Long glClosureId, public CommandProcessingResult updateGLClosure(@PathParam("glClosureId") @Parameter(description = "glClosureId") final Long glClosureId,
@@ -59,6 +59,7 @@ import org.springframework.transaction.annotation.Transactional;
public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccountWritePlatformService { public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccountWritePlatformService {
private static final Logger LOG = LoggerFactory.getLogger(GLAccountWritePlatformServiceJpaRepositoryImpl.class); private static final Logger LOG = LoggerFactory.getLogger(GLAccountWritePlatformServiceJpaRepositoryImpl.class);
private static final String GL_ACCOUNT = "glAccount";
private final GLAccountRepository glAccountRepository; private final GLAccountRepository glAccountRepository;
private final JournalEntryRepository glJournalEntryRepository; private final JournalEntryRepository glJournalEntryRepository;
@@ -146,13 +147,11 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
/** /**
* a detail account cannot be changed to a header account if transactions are already logged against it * a detail account cannot be changed to a header account if transactions are already logged against it
**/ **/
if (changesOnly.containsKey(GLAccountJsonInputParams.USAGE.getValue())) { if (changesOnly.containsKey(GLAccountJsonInputParams.USAGE.getValue()) && glAccount.isHeaderAccount()) {
if (glAccount.isHeaderAccount()) { final boolean journalEntriesForAccountExist = this.glJournalEntryRepository
final boolean journalEntriesForAccountExist = this.glJournalEntryRepository .exists((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get(GL_ACCOUNT).get("id"), glAccountId));
.exists((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("glAccount").get("id"), glAccountId)); if (journalEntriesForAccountExist) {
if (journalEntriesForAccountExist) { throw new GLAccountInvalidUpdateException(GlAccountInvalidUpdateReason.TRANSANCTIONS_LOGGED, glAccountId);
throw new GLAccountInvalidUpdateException(GlAccountInvalidUpdateReason.TRANSANCTIONS_LOGGED, glAccountId);
}
} }
} }
@@ -194,13 +193,13 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
// does this account have transactions logged against it // does this account have transactions logged against it
final boolean journalEntriesForAccountExist = this.glJournalEntryRepository final boolean journalEntriesForAccountExist = this.glJournalEntryRepository
.exists((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("glAccount").get("id"), glAccountId)); .exists((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get(GL_ACCOUNT).get("id"), glAccountId));
if (journalEntriesForAccountExist) { if (journalEntriesForAccountExist) {
throw new GLAccountInvalidDeleteException(GlAccountInvalidDeleteReason.TRANSACTIONS_LOGGED, glAccountId); throw new GLAccountInvalidDeleteException(GlAccountInvalidDeleteReason.TRANSACTIONS_LOGGED, glAccountId);
} }
// does this account mapped to product // does this account mapped to product
final boolean accountMappingForAccountExists = this.productToGLAccountMappingRepository final boolean accountMappingForAccountExists = this.productToGLAccountMappingRepository
.exists((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("glAccount").get("id"), glAccountId)); .exists((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get(GL_ACCOUNT).get("id"), glAccountId));
if (accountMappingForAccountExists) { if (accountMappingForAccountExists) {
throw new GLAccountInvalidDeleteException(GlAccountInvalidDeleteReason.PRODUCT_MAPPING, glAccountId); throw new GLAccountInvalidDeleteException(GlAccountInvalidDeleteReason.PRODUCT_MAPPING, glAccountId);
} }
@@ -90,7 +90,7 @@ public class ProductToGLAccountMappingHelper {
final ProductToGLAccountMapping accountMapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(productId, final ProductToGLAccountMapping accountMapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(productId,
portfolioProductType.getValue(), accountTypeId); portfolioProductType.getValue(), accountTypeId);
if (accountMapping == null) { if (accountMapping == null) {
ArrayList<String> optionalProductToGLAccountMappingEntries = new ArrayList<String>(); ArrayList<String> optionalProductToGLAccountMappingEntries = new ArrayList<>();
optionalProductToGLAccountMappingEntries.add(LoanProductAccountingParams.GOODWILL_CREDIT.getValue()); optionalProductToGLAccountMappingEntries.add(LoanProductAccountingParams.GOODWILL_CREDIT.getValue());
optionalProductToGLAccountMappingEntries.add(LoanProductAccountingParams.INCOME_FROM_CHARGE_OFF_INTEREST.getValue()); optionalProductToGLAccountMappingEntries.add(LoanProductAccountingParams.INCOME_FROM_CHARGE_OFF_INTEREST.getValue());
optionalProductToGLAccountMappingEntries.add(LoanProductAccountingParams.INCOME_FROM_CHARGE_OFF_FEES.getValue()); optionalProductToGLAccountMappingEntries.add(LoanProductAccountingParams.INCOME_FROM_CHARGE_OFF_FEES.getValue());
@@ -560,7 +560,7 @@ public class ProductToGLAccountMappingHelper {
public void deleteProductToGLAccountMapping(final Long loanProductId, final PortfolioProductType portfolioProductType) { public void deleteProductToGLAccountMapping(final Long loanProductId, final PortfolioProductType portfolioProductType) {
final List<ProductToGLAccountMapping> productToGLAccountMappings = this.accountMappingRepository final List<ProductToGLAccountMapping> productToGLAccountMappings = this.accountMappingRepository
.findByProductIdAndProductType(loanProductId, portfolioProductType.getValue()); .findByProductIdAndProductType(loanProductId, portfolioProductType.getValue());
if (productToGLAccountMappings != null && productToGLAccountMappings.size() > 0) { if (productToGLAccountMappings != null && !productToGLAccountMappings.isEmpty()) {
this.accountMappingRepository.deleteAllInBatch(productToGLAccountMappings); this.accountMappingRepository.deleteAllInBatch(productToGLAccountMappings);
} }
} }
@@ -262,7 +262,7 @@ public class ProvisioningEntriesReadPlatformServiceImpl implements ProvisioningE
LoanProductProvisioningEntryRowMapper mapper = new LoanProductProvisioningEntryRowMapper(); LoanProductProvisioningEntryRowMapper mapper = new LoanProductProvisioningEntryRowMapper();
final String sql = "select " + mapper.getSchema() + " where entry.criteria_id = ?"; final String sql = "select " + mapper.getSchema() + " where entry.criteria_id = ?";
Collection<LoanProductProvisioningEntryData> entries = this.jdbcTemplate.query(sql, mapper, criteriaId); // NOSONAR Collection<LoanProductProvisioningEntryData> entries = this.jdbcTemplate.query(sql, mapper, criteriaId); // NOSONAR
if (entries != null && entries.size() > 0) { if (entries != null && !entries.isEmpty()) {
Long entryId = ((LoanProductProvisioningEntryData) entries.toArray()[0]).getHistoryId(); Long entryId = ((LoanProductProvisioningEntryData) entries.toArray()[0]).getHistoryId();
ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper(); ProvisioningEntryDataMapper mapper1 = new ProvisioningEntryDataMapper();
final String sql1 = "select " + mapper1.getSchema() + " where entry.id = ?"; final String sql1 = "select " + mapper1.getSchema() + " where entry.id = ?";
@@ -58,7 +58,7 @@ public enum AccountingRuleJsonInputParams {
@Override @Override
public String toString() { public String toString() {
return name().toString().replace("_", " "); return name().replace("_", " ");
} }
public String getValue() { public String getValue() {
@@ -52,9 +52,9 @@ public class AccountingRuleData {
// template // template
@SuppressWarnings("unused") @SuppressWarnings("unused")
private List<OfficeData> allowedOffices = new ArrayList<OfficeData>(); private List<OfficeData> allowedOffices = new ArrayList<>();
@SuppressWarnings("unused") @SuppressWarnings("unused")
private List<GLAccountData> allowedAccounts = new ArrayList<GLAccountData>(); private List<GLAccountData> allowedAccounts = new ArrayList<>();
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Collection<CodeValueData> allowedCreditTagOptions; private Collection<CodeValueData> allowedCreditTagOptions;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@@ -138,10 +138,9 @@ public class AccountingRule extends AbstractPersistableCustom<Long> {
if (this.accountToCredit == null) { if (this.accountToCredit == null) {
this.allowMultipleCreditEntries = newValue; this.allowMultipleCreditEntries = newValue;
} }
} else if (paramName.equals(AccountingRuleJsonInputParams.ALLOW_MULTIPLE_DEBIT_ENTRIES.getValue())) { } else if (paramName.equals(AccountingRuleJsonInputParams.ALLOW_MULTIPLE_DEBIT_ENTRIES.getValue())
if (this.accountToDebit == null) { && this.accountToDebit == null) {
this.allowMultipleDebitEntries = newValue; this.allowMultipleDebitEntries = newValue;
}
} }
} }
} }
@@ -33,21 +33,21 @@ public class AccountingRuleInvalidException extends AbstractPlatformDomainRuleEx
ACCOUNTING_CLOSED; // ACCOUNTING_CLOSED; //
public String errorMessage() { public String errorMessage() {
if (name().toString().equalsIgnoreCase("FUTURE_DATE")) { if (name().equalsIgnoreCase("FUTURE_DATE")) {
return "Accounting closures cannot be made for a future date"; return "Accounting closures cannot be made for a future date";
} else if (name().toString().equalsIgnoreCase("ACCOUNTING_CLOSED")) { } else if (name().equalsIgnoreCase("ACCOUNTING_CLOSED")) {
return "Accounting Closure for this branch has already been defined for a greater date"; return "Accounting Closure for this branch has already been defined for a greater date";
} }
return name().toString(); return name();
} }
public String errorCode() { public String errorCode() {
if (name().toString().equalsIgnoreCase("FUTURE_DATE")) { if (name().equalsIgnoreCase("FUTURE_DATE")) {
return "error.msg.glclosure.invalid.future.date"; return "error.msg.glclosure.invalid.future.date";
} else if (name().toString().equalsIgnoreCase("ACCOUNTING_CLOSED")) { } else if (name().equalsIgnoreCase("ACCOUNTING_CLOSED")) {
return "error.msg.glclosure.invalid.accounting.closed"; return "error.msg.glclosure.invalid.accounting.closed";
} }
return name().toString(); return name();
} }
} }
@@ -111,8 +111,8 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco
// get the GL Accounts or tags to Debit and Credit // get the GL Accounts or tags to Debit and Credit
final String[] debitTags = command.arrayValueOfParameterNamed(AccountingRuleJsonInputParams.DEBIT_ACCOUNT_TAGS.getValue()); final String[] debitTags = command.arrayValueOfParameterNamed(AccountingRuleJsonInputParams.DEBIT_ACCOUNT_TAGS.getValue());
final String[] creditTags = command.arrayValueOfParameterNamed(AccountingRuleJsonInputParams.CREDIT_ACCOUNT_TAGS.getValue()); final String[] creditTags = command.arrayValueOfParameterNamed(AccountingRuleJsonInputParams.CREDIT_ACCOUNT_TAGS.getValue());
final Set<String> incomingDebitTags = debitTags == null ? new HashSet<String>() : new HashSet<>(Arrays.asList(debitTags)); final Set<String> incomingDebitTags = debitTags == null ? new HashSet<>() : new HashSet<>(Arrays.asList(debitTags));
final Set<String> incomingCreditTags = creditTags == null ? new HashSet<String>() : new HashSet<>(Arrays.asList(creditTags)); final Set<String> incomingCreditTags = creditTags == null ? new HashSet<>() : new HashSet<>(Arrays.asList(creditTags));
final Long accountToDebitId = command.longValueOfParameterNamed(AccountingRuleJsonInputParams.ACCOUNT_TO_DEBIT.getValue()); final Long accountToDebitId = command.longValueOfParameterNamed(AccountingRuleJsonInputParams.ACCOUNT_TO_DEBIT.getValue());
final Long accountToCreditId = command.longValueOfParameterNamed(AccountingRuleJsonInputParams.ACCOUNT_TO_CREDIT.getValue()); final Long accountToCreditId = command.longValueOfParameterNamed(AccountingRuleJsonInputParams.ACCOUNT_TO_CREDIT.getValue());
@@ -25,7 +25,7 @@ public abstract class JournalEntryBusinessEvent extends AbstractBusinessEvent<Jo
private static final String CATEGORY = "Accounting"; private static final String CATEGORY = "Accounting";
public JournalEntryBusinessEvent(JournalEntry value) { protected JournalEntryBusinessEvent(JournalEntry value) {
super(value); super(value);
} }