From 354d41d2ebfd69594734a240cdcf30857b0bf5dd Mon Sep 17 00:00:00 2001 From: Hemant Gupta Date: Tue, 30 Aug 2022 03:57:38 +0530 Subject: [PATCH] refactor: add lombok to rule module --- .../rule/api/AccountingRuleApiResource.java | 13 ++- .../rule/data/AccountingRuleData.java | 105 ++++-------------- .../rule/data/AccountingTagRuleData.java | 16 +-- .../rule/domain/AccountingRule.java | 87 +++------------ .../rule/domain/AccountingTagRule.java | 40 ++----- ...AccountingRuleReadPlatformServiceImpl.java | 9 +- ...WritePlatformServiceJpaRepositoryImpl.java | 16 +-- 7 files changed, 76 insertions(+), 210 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/api/AccountingRuleApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/api/AccountingRuleApiResource.java index 50e31296b..ce32b0f70 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/api/AccountingRuleApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/api/AccountingRuleApiResource.java @@ -246,7 +246,8 @@ public class AccountingRuleApiResource { final Collection allowedCreditTagOptions = allowedTagOptions; final Collection allowedDebitTagOptions = allowedTagOptions; - accountingRuleData = new AccountingRuleData(allowedAccounts, allowedOffices, allowedCreditTagOptions, allowedDebitTagOptions); + accountingRuleData = new AccountingRuleData().setAllowedOffices(allowedOffices).setAllowedAccounts(allowedAccounts) + .setAllowedCreditTagOptions(allowedCreditTagOptions).setAllowedDebitTagOptions(allowedDebitTagOptions); } else { @@ -265,8 +266,14 @@ public class AccountingRuleApiResource { allowedDebitTagOptions = allowedTagOptions; } - accountingRuleData = new AccountingRuleData(accountingRuleData, allowedAccounts, allowedOffices, allowedCreditTagOptions, - allowedDebitTagOptions); + accountingRuleData = new AccountingRuleData().setId(accountingRuleData.getId()).setOfficeId(accountingRuleData.getOfficeId()) + .setOfficeName(accountingRuleData.getOfficeName()).setName(accountingRuleData.getName()) + .setDescription(accountingRuleData.getDescription()).setSystemDefined(accountingRuleData.isSystemDefined()) + .setAllowMultipleCreditEntries(accountingRuleData.isAllowMultipleCreditEntries()) + .setAllowMultipleDebitEntries(accountingRuleData.isAllowMultipleDebitEntries()).setAllowedAccounts(allowedAccounts) + .setAllowedOffices(allowedOffices).setAllowedCreditTagOptions(allowedCreditTagOptions) + .setAllowedDebitTagOptions(allowedDebitTagOptions); + } return accountingRuleData; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingRuleData.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingRuleData.java index 70cc8e7f6..39c67d56d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingRuleData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingRuleData.java @@ -21,6 +21,9 @@ package org.apache.fineract.accounting.rule.data; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; import org.apache.fineract.accounting.glaccount.data.GLAccountData; import org.apache.fineract.accounting.glaccount.data.GLAccountDataForLookup; import org.apache.fineract.infrastructure.codes.data.CodeValueData; @@ -31,18 +34,21 @@ import org.apache.fineract.organisation.office.data.OfficeData; * * Note: no getter/setters required as google-gson will produce json from fields of object. */ +@Data +@NoArgsConstructor +@Accessors(chain = true) public class AccountingRuleData { - private final Long id; - private final Long officeId; - private final String officeName; - private final String name; - private final String description; - private final boolean systemDefined; - private final boolean allowMultipleDebitEntries; - private final boolean allowMultipleCreditEntries; - private final List creditTags; - private final List debitTags; + private Long id; + private Long officeId; + private String officeName; + private String name; + private String description; + private boolean systemDefined; + private boolean allowMultipleDebitEntries; + private boolean allowMultipleCreditEntries; + private List creditTags; + private List debitTags; // template @SuppressWarnings("unused") @@ -50,81 +56,10 @@ public class AccountingRuleData { @SuppressWarnings("unused") private List allowedAccounts = new ArrayList(); @SuppressWarnings("unused") - private final Collection allowedCreditTagOptions; + private Collection allowedCreditTagOptions; @SuppressWarnings("unused") - private final Collection allowedDebitTagOptions; - private final List creditAccounts; - private final List debitAccounts; - - public AccountingRuleData(final AccountingRuleData accountingRuleData, final List allowedAccounts, - final List allowedOffices, final Collection allowedCreditTagOptions, - final Collection allowedDebitTagOptions) { - this.id = accountingRuleData.id; - this.officeId = accountingRuleData.officeId; - this.officeName = accountingRuleData.officeName; - this.name = accountingRuleData.name; - this.description = accountingRuleData.description; - this.systemDefined = accountingRuleData.systemDefined; - this.allowMultipleDebitEntries = accountingRuleData.allowMultipleDebitEntries; - this.allowMultipleCreditEntries = accountingRuleData.allowMultipleCreditEntries; - this.allowedOffices = allowedOffices; - this.allowedAccounts = allowedAccounts; - this.allowedCreditTagOptions = allowedCreditTagOptions; - this.allowedDebitTagOptions = allowedDebitTagOptions; - this.creditTags = accountingRuleData.creditTags; - this.debitTags = accountingRuleData.debitTags; - this.creditAccounts = accountingRuleData.creditAccounts; - this.debitAccounts = accountingRuleData.debitAccounts; - } - - public AccountingRuleData(final List allowedAccounts, final List allowedOffices, - final Collection allowedCreditTagOptions, final Collection allowedDebitTagOptions) { - this.id = null; - this.officeId = null; - this.officeName = null; - this.name = null; - this.description = null; - this.systemDefined = false; - this.allowMultipleDebitEntries = false; - this.allowMultipleCreditEntries = false; - this.allowedOffices = allowedOffices; - this.allowedAccounts = allowedAccounts; - this.allowedCreditTagOptions = allowedCreditTagOptions; - this.allowedDebitTagOptions = allowedDebitTagOptions; - this.creditTags = null; - this.debitTags = null; - this.creditAccounts = null; - this.debitAccounts = null; - } - - public AccountingRuleData(final Long id, final Long officeId, final String officeName, final String name, final String description, - final boolean systemDefined, final boolean allowMultipleDebitEntries, final boolean allowMultipleCreditEntries, - final List creditTags, final List debitTags, - final List creditAccounts, final List debitAccounts) { - this.id = id; - this.officeId = officeId; - this.officeName = officeName; - this.name = name; - this.description = description; - this.systemDefined = systemDefined; - this.allowMultipleDebitEntries = allowMultipleDebitEntries; - this.allowMultipleCreditEntries = allowMultipleCreditEntries; - this.allowedOffices = null; - this.allowedAccounts = null; - this.allowedCreditTagOptions = null; - this.allowedDebitTagOptions = null; - this.creditTags = creditTags; - this.debitTags = debitTags; - this.creditAccounts = creditAccounts; - this.debitAccounts = debitAccounts; - } - - public List getCreditTags() { - return this.creditTags; - } - - public List getDebitTags() { - return this.debitTags; - } + private Collection allowedDebitTagOptions; + private List creditAccounts; + private List debitAccounts; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingTagRuleData.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingTagRuleData.java index 1f80b609d..7e36b1744 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingTagRuleData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/data/AccountingTagRuleData.java @@ -18,16 +18,18 @@ */ package org.apache.fineract.accounting.rule.data; -import lombok.Getter; -import lombok.RequiredArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.core.data.EnumOptionData; -@RequiredArgsConstructor -@Getter +@Data +@NoArgsConstructor +@Accessors(chain = true) public class AccountingTagRuleData { - private final Long id; - private final CodeValueData tag; - private final EnumOptionData transactionType; + private Long id; + private CodeValueData tag; + private EnumOptionData transactionType; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java index eb03e655a..b48f2cdad 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingRule.java @@ -33,6 +33,10 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.Accessors; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.accounting.glaccount.domain.GLAccount; import org.apache.fineract.accounting.journalentry.domain.JournalEntryType; @@ -41,6 +45,10 @@ import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; import org.apache.fineract.organisation.office.domain.Office; +@Getter +@Setter +@NoArgsConstructor +@Accessors(chain = true) @Entity @Table(name = "acc_accounting_rule", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "accounting_rule_name_unique") }) @@ -76,31 +84,14 @@ public class AccountingRule extends AbstractPersistableCustom { @Column(name = "allow_multiple_debits", nullable = false) private boolean allowMultipleDebitEntries; - protected AccountingRule() {} - - private AccountingRule(final Office office, final GLAccount accountToDebit, final GLAccount accountToCredit, final String name, - final String description, final boolean systemDefined, final boolean allowMultipleCreditEntries, - final boolean allowMultipleDebitEntries) { - this.accountToDebit = accountToDebit; - this.accountToCredit = accountToCredit; - this.name = name; - this.office = office; - this.description = StringUtils.defaultIfEmpty(description, null); - if (this.description != null) { - this.description = this.description.trim(); - } - this.systemDefined = systemDefined; - this.allowMultipleCreditEntries = allowMultipleCreditEntries; - this.allowMultipleDebitEntries = allowMultipleDebitEntries; - } - public static AccountingRule fromJson(final Office office, final GLAccount accountToDebit, final GLAccount accountToCredit, final JsonCommand command, final boolean allowMultipleCreditEntries, final boolean allowMultipleDebitEntries) { final String name = command.stringValueOfParameterNamed(AccountingRuleJsonInputParams.NAME.getValue()); final String description = command.stringValueOfParameterNamed(AccountingRuleJsonInputParams.DESCRIPTION.getValue()); final boolean systemDefined = false; - return new AccountingRule(office, accountToDebit, accountToCredit, name, description, systemDefined, allowMultipleCreditEntries, - allowMultipleDebitEntries); + return new AccountingRule().setOffice(office).setAccountToDebit(accountToDebit).setAccountToCredit(accountToCredit).setName(name) + .setDescription(StringUtils.trim(description)).setSystemDefined(systemDefined) + .setAllowMultipleCreditEntries(allowMultipleCreditEntries).setAllowMultipleDebitEntries(allowMultipleDebitEntries); } public Map update(final JsonCommand command) { @@ -171,70 +162,20 @@ public class AccountingRule extends AbstractPersistableCustom { } } - public void setOffice(final Office office) { - this.office = office; - } - - public Office getOffice() { - return this.office; - } - - public GLAccount getAccountToDebit() { - return this.accountToDebit; - } - - public GLAccount getAccountToCredit() { - return this.accountToCredit; - } - - public void setAccountToDebit(final GLAccount accountToDebit) { - this.accountToDebit = accountToDebit; - } - - public void setAccountToCredit(final GLAccount accountToCredit) { - this.accountToCredit = accountToCredit; - } - - public String getDescription() { - return this.description; - } - - public List getAccountingTagRules() { - return this.accountingTagRules; - } - public void updateAccountingRuleForTags(final List debitAccountingTagRules) { for (final AccountingTagRule accountingTagRule : debitAccountingTagRules) { - accountingTagRule.updateAccountingTagRule(this); + accountingTagRule.setAccountingRule(this); this.accountingTagRules.add(accountingTagRule); } } - public void updateDebitAccount(final GLAccount accountToDebit) { - this.accountToDebit = accountToDebit; - this.allowMultipleDebitEntries = false; - } - - public void updateCreditAccount(final GLAccount accountToCredit) { - this.accountToCredit = accountToCredit; - this.allowMultipleCreditEntries = false; - } - - public void updateAllowMultipleCreditEntries(final boolean allowMultipleCreditEntries) { - this.allowMultipleCreditEntries = allowMultipleCreditEntries; - } - - public void updateAllowMultipleDebitEntries(final boolean allowMultipleDebitEntries) { - this.allowMultipleDebitEntries = allowMultipleDebitEntries; - } - public void updateTags(final JournalEntryType type) { final Set existedCreditTags = new HashSet<>(); final Set existedDebitTags = new HashSet<>(); for (final AccountingTagRule accountingTagRule : this.accountingTagRules) { - if (accountingTagRule.isCreditAccount()) { + if (JournalEntryType.fromInt(accountingTagRule.getAccountType()).isCreditType()) { existedCreditTags.add(accountingTagRule); - } else if (accountingTagRule.isDebitAccount()) { + } else if (JournalEntryType.fromInt(accountingTagRule.getAccountType()).isDebitType()) { existedDebitTags.add(accountingTagRule); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java index d429004b2..69572ea73 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/domain/AccountingTagRule.java @@ -24,10 +24,17 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import org.apache.fineract.accounting.journalentry.domain.JournalEntryType; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.Accessors; import org.apache.fineract.infrastructure.codes.domain.CodeValue; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; +@Getter +@Setter +@NoArgsConstructor +@Accessors(chain = true) @Entity @Table(name = "acc_rule_tags", uniqueConstraints = { @UniqueConstraint(columnNames = { "acc_rule_id", "tag_id", "acc_type_enum" }, name = "UNIQUE_ACCOUNT_RULE_TAGS") }) @@ -45,36 +52,7 @@ public class AccountingTagRule extends AbstractPersistableCustom { private Integer accountType; public static AccountingTagRule create(final CodeValue tagId, final Integer accountType) { - return new AccountingTagRule(tagId, accountType); - } - - public AccountingTagRule(final CodeValue tagId, final Integer accountType) { - this.tagId = tagId; - this.accountType = accountType; - } - - public void updateAccountingTagRule(final AccountingRule accountingRule) { - this.accountingRule = accountingRule; - } - - public AccountingTagRule() { - // TODO Auto-generated constructor stub - } - - public Integer getAccountType() { - return this.accountType; - } - - public boolean isDebitAccount() { - return JournalEntryType.fromInt(this.accountType).isDebitType(); - } - - public boolean isCreditAccount() { - return JournalEntryType.fromInt(this.accountType).isCreditType(); - } - - public Long getTagId() { - return this.tagId.getId(); + return new AccountingTagRule().setTagId(tagId).setAccountType(accountType); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java index 895918bd4..7e03d423b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java @@ -129,8 +129,11 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead .setName(debitAccountName).setGlCode(debitAccountGLCode); debitAccounts = new ArrayList<>(Arrays.asList(debitAccount)); } - accountingRuleData = new AccountingRuleData(id, officeId, officeName, name, description, systemDefined, - allowMultipleDebitEntries, allowMultipleCreditEntries, creditTags, debitTags, creditAccounts, debitAccounts); + accountingRuleData = new AccountingRuleData().setId(id).setOfficeId(officeId).setOfficeName(officeName).setName(name) + .setDescription(description).setSystemDefined(systemDefined) + .setAllowMultipleDebitEntries(allowMultipleDebitEntries) + .setAllowMultipleCreditEntries(allowMultipleCreditEntries).setCreditTags(creditTags).setDebitTags(debitTags) + .setCreditAccounts(creditAccounts).setDebitAccounts(debitAccounts); } extractedData.put(id, accountingRuleData); @@ -196,7 +199,7 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead final String tagName = rs.getString("tagName"); final CodeValueData tag = CodeValueData.instance(tagId, tagName); final EnumOptionData transactionTypeEnum = AccountingEnumerations.journalEntryType(transactionType); - return new AccountingTagRuleData(id, tag, transactionTypeEnum); + return new AccountingTagRuleData().setId(id).setTag(tag).setTransactionType(transactionTypeEnum); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java index e1c7e9392..010e0d01b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java @@ -213,13 +213,13 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco if (accountToDebitId != null && changesOnly.containsKey(AccountingRuleJsonInputParams.ACCOUNT_TO_DEBIT.getValue())) { final GLAccount accountToDebit = this.accountRepositoryWrapper.findOneWithNotFoundDetection(accountToDebitId); - accountingRule.updateDebitAccount(accountToDebit); + accountingRule.setAccountToDebit(accountToDebit); accountingRule.updateTags(JournalEntryType.CREDIT); } if (accountToCreditId != null && changesOnly.containsKey(AccountingRuleJsonInputParams.ACCOUNT_TO_CREDIT.getValue())) { final GLAccount accountToCredit = this.accountRepositoryWrapper.findOneWithNotFoundDetection(accountToCreditId); - accountingRule.updateCreditAccount(accountToCredit); + accountingRule.setAccountToCredit(accountToCredit); accountingRule.updateTags(JournalEntryType.DEBIT); } @@ -233,9 +233,9 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco List accountingTagRules = new ArrayList<>(); accountingTagRules = saveDebitOrCreditTags(creditTagsToAdd, JournalEntryType.CREDIT, accountingTagRules); accountingRule.updateAccountingRuleForTags(accountingTagRules); - accountingRule.updateCreditAccount(null); + accountingRule.setAccountToCredit(null); if (allowMultipleCreditEntries) { - accountingRule.updateAllowMultipleCreditEntries(allowMultipleCreditEntries); + accountingRule.setAllowMultipleCreditEntries(allowMultipleCreditEntries); } changesOnly.put(AccountingRuleJsonInputParams.CREDIT_ACCOUNT_TAGS.getValue(), creditTagsToAdd); } @@ -250,9 +250,9 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco List accountingTagRules = new ArrayList<>(); accountingTagRules = saveDebitOrCreditTags(debitTagsToAdd, JournalEntryType.DEBIT, accountingTagRules); accountingRule.updateAccountingRuleForTags(accountingTagRules); - accountingRule.updateDebitAccount(null); + accountingRule.setAccountToDebit(null); if (allowMultipleDebitEntries) { - accountingRule.updateAllowMultipleDebitEntries(allowMultipleDebitEntries); + accountingRule.setAllowMultipleDebitEntries(allowMultipleDebitEntries); } changesOnly.put(AccountingRuleJsonInputParams.DEBIT_ACCOUNT_TAGS.getValue(), debitTagsToAdd); } @@ -298,7 +298,7 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco if (!tagsToRemove.isEmpty()) { for (final String tagId : tagsToRemove) { for (final AccountingTagRule accountingTagRule : existingTags) { - if (tagId.equals(accountingTagRule.getTagId().toString())) { + if (tagId.equals(accountingTagRule.getTagId().getId().toString())) { accountsToRemove.put(accountingTagRule.getId(), accountingTagRule); } } @@ -311,7 +311,7 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco private Set retrieveExistingTagIds(final Set existingCreditTags) { final Set existingCreditTagIds = new HashSet<>(); for (final AccountingTagRule accountingTagRule : existingCreditTags) { - existingCreditTagIds.add(accountingTagRule.getTagId().toString()); + existingCreditTagIds.add(accountingTagRule.getTagId().getId().toString()); } return existingCreditTagIds; }