refactor: add lombok to rule module

This commit is contained in:
Hemant Gupta
2022-09-02 03:16:19 +02:00
committed by Aleksandar Vidakovic
parent b8e34936d2
commit 354d41d2eb
7 changed files with 76 additions and 210 deletions
@@ -246,7 +246,8 @@ public class AccountingRuleApiResource {
final Collection<CodeValueData> allowedCreditTagOptions = allowedTagOptions;
final Collection<CodeValueData> 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;
}
@@ -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<AccountingTagRuleData> creditTags;
private final List<AccountingTagRuleData> 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<AccountingTagRuleData> creditTags;
private List<AccountingTagRuleData> debitTags;
// template
@SuppressWarnings("unused")
@@ -50,81 +56,10 @@ public class AccountingRuleData {
@SuppressWarnings("unused")
private List<GLAccountData> allowedAccounts = new ArrayList<GLAccountData>();
@SuppressWarnings("unused")
private final Collection<CodeValueData> allowedCreditTagOptions;
private Collection<CodeValueData> allowedCreditTagOptions;
@SuppressWarnings("unused")
private final Collection<CodeValueData> allowedDebitTagOptions;
private final List<GLAccountDataForLookup> creditAccounts;
private final List<GLAccountDataForLookup> debitAccounts;
public AccountingRuleData(final AccountingRuleData accountingRuleData, final List<GLAccountData> allowedAccounts,
final List<OfficeData> allowedOffices, final Collection<CodeValueData> allowedCreditTagOptions,
final Collection<CodeValueData> 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<GLAccountData> allowedAccounts, final List<OfficeData> allowedOffices,
final Collection<CodeValueData> allowedCreditTagOptions, final Collection<CodeValueData> 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<AccountingTagRuleData> creditTags, final List<AccountingTagRuleData> debitTags,
final List<GLAccountDataForLookup> creditAccounts, final List<GLAccountDataForLookup> 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<AccountingTagRuleData> getCreditTags() {
return this.creditTags;
}
public List<AccountingTagRuleData> getDebitTags() {
return this.debitTags;
}
private Collection<CodeValueData> allowedDebitTagOptions;
private List<GLAccountDataForLookup> creditAccounts;
private List<GLAccountDataForLookup> debitAccounts;
}
@@ -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;
}
@@ -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<String, Object> 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<AccountingTagRule> getAccountingTagRules() {
return this.accountingTagRules;
}
public void updateAccountingRuleForTags(final List<AccountingTagRule> 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<AccountingTagRule> existedCreditTags = new HashSet<>();
final Set<AccountingTagRule> 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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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<AccountingTagRule> 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<AccountingTagRule> 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<String> retrieveExistingTagIds(final Set<AccountingTagRule> existingCreditTags) {
final Set<String> existingCreditTagIds = new HashSet<>();
for (final AccountingTagRule accountingTagRule : existingCreditTags) {
existingCreditTagIds.add(accountingTagRule.getTagId().toString());
existingCreditTagIds.add(accountingTagRule.getTagId().getId().toString());
}
return existingCreditTagIds;
}